blob: c4ddbbc6231acf24c3fe8b4a98d468c3c3aac615 [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;
213 hda_nid_t dig_in_nid;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +0200214 hda_nid_t dig_in_pin;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100215
216 /* capture source */
217 const struct hda_input_mux *input_mux;
218 unsigned int cur_mux[3];
219
220 /* PCM information */
Harald Welte98aa34c2008-09-09 16:02:09 +0800221 struct hda_pcm pcm_rec[3];
Joseph Chanc577b8a2006-11-29 15:29:40 +0100222
223 /* dynamic controls, init_verbs and input_mux */
224 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200225 struct snd_array kctls;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800226 struct hda_input_mux private_imux[2];
Takashi Iwai41923e42007-10-22 17:20:10 +0200227 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200228
Harald Welte0aa62ae2008-09-09 15:58:27 +0800229 /* HP mode source */
230 const struct hda_input_mux *hp_mux;
231 unsigned int hp_independent_mode;
232
Takashi Iwaicb53c622007-08-10 17:21:45 +0200233#ifdef CONFIG_SND_HDA_POWER_SAVE
234 struct hda_loopback_check loopback;
235#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +0100236};
237
238static hda_nid_t vt1708_adc_nids[2] = {
239 /* ADC1-2 */
240 0x15, 0x27
241};
242
243static hda_nid_t vt1709_adc_nids[3] = {
244 /* ADC1-2 */
245 0x14, 0x15, 0x16
246};
247
Josepch Chanf7278fd2007-12-13 16:40:40 +0100248static hda_nid_t vt1708B_adc_nids[2] = {
249 /* ADC1-2 */
250 0x13, 0x14
251};
252
Harald Welted949cac2008-09-09 15:56:01 +0800253static hda_nid_t vt1708S_adc_nids[2] = {
254 /* ADC1-2 */
255 0x13, 0x14
256};
257
258static hda_nid_t vt1702_adc_nids[3] = {
259 /* ADC1-2 */
260 0x12, 0x20, 0x1F
261};
262
Joseph Chanc577b8a2006-11-29 15:29:40 +0100263/* add dynamic controls */
264static int via_add_control(struct via_spec *spec, int type, const char *name,
265 unsigned long val)
266{
267 struct snd_kcontrol_new *knew;
268
Takashi Iwai603c4012008-07-30 15:01:44 +0200269 snd_array_init(&spec->kctls, sizeof(*knew), 32);
270 knew = snd_array_new(&spec->kctls);
271 if (!knew)
272 return -ENOMEM;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100273 *knew = vt1708_control_templates[type];
274 knew->name = kstrdup(name, GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100275 if (!knew->name)
276 return -ENOMEM;
277 knew->private_value = val;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100278 return 0;
279}
280
Takashi Iwai603c4012008-07-30 15:01:44 +0200281static void via_free_kctls(struct hda_codec *codec)
282{
283 struct via_spec *spec = codec->spec;
284
285 if (spec->kctls.list) {
286 struct snd_kcontrol_new *kctl = spec->kctls.list;
287 int i;
288 for (i = 0; i < spec->kctls.used; i++)
289 kfree(kctl[i].name);
290 }
291 snd_array_free(&spec->kctls);
292}
293
Joseph Chanc577b8a2006-11-29 15:29:40 +0100294/* create input playback/capture controls for the given pin */
295static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
296 const char *ctlname, int idx, int mix_nid)
297{
298 char name[32];
299 int err;
300
301 sprintf(name, "%s Playback Volume", ctlname);
302 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
303 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
304 if (err < 0)
305 return err;
306 sprintf(name, "%s Playback Switch", ctlname);
307 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
308 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
309 if (err < 0)
310 return err;
311 return 0;
312}
313
314static void via_auto_set_output_and_unmute(struct hda_codec *codec,
315 hda_nid_t nid, int pin_type,
316 int dac_idx)
317{
318 /* set as output */
319 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
320 pin_type);
321 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
322 AMP_OUT_UNMUTE);
323}
324
325
326static void via_auto_init_multi_out(struct hda_codec *codec)
327{
328 struct via_spec *spec = codec->spec;
329 int i;
330
331 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
332 hda_nid_t nid = spec->autocfg.line_out_pins[i];
333 if (nid)
334 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
335 }
336}
337
338static void via_auto_init_hp_out(struct hda_codec *codec)
339{
340 struct via_spec *spec = codec->spec;
341 hda_nid_t pin;
342
343 pin = spec->autocfg.hp_pins[0];
344 if (pin) /* connect to front */
345 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
346}
347
348static void via_auto_init_analog_input(struct hda_codec *codec)
349{
350 struct via_spec *spec = codec->spec;
351 int i;
352
353 for (i = 0; i < AUTO_PIN_LAST; i++) {
354 hda_nid_t nid = spec->autocfg.input_pins[i];
355
356 snd_hda_codec_write(codec, nid, 0,
357 AC_VERB_SET_PIN_WIDGET_CONTROL,
358 (i <= AUTO_PIN_FRONT_MIC ?
359 PIN_VREF50 : PIN_IN));
360
361 }
362}
363/*
364 * input MUX handling
365 */
366static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
367 struct snd_ctl_elem_info *uinfo)
368{
369 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
370 struct via_spec *spec = codec->spec;
371 return snd_hda_input_mux_info(spec->input_mux, uinfo);
372}
373
374static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
375 struct snd_ctl_elem_value *ucontrol)
376{
377 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
378 struct via_spec *spec = codec->spec;
379 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
380
381 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
382 return 0;
383}
384
385static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
386 struct snd_ctl_elem_value *ucontrol)
387{
388 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
389 struct via_spec *spec = codec->spec;
390 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
391 unsigned int vendor_id = codec->vendor_id;
392
393 /* AIW0 lydia 060801 add for correct sw0 input select */
394 if (IS_VT1708_VENDORID(vendor_id) && (adc_idx == 0))
395 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
396 0x18, &spec->cur_mux[adc_idx]);
397 else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
Harald Welteeb14a462008-09-09 15:40:38 +0800398 IS_VT1709_6CH_VENDORID(vendor_id)) && (adc_idx == 0))
Joseph Chanc577b8a2006-11-29 15:29:40 +0100399 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
400 0x19, &spec->cur_mux[adc_idx]);
Josepch Chanf7278fd2007-12-13 16:40:40 +0100401 else if ((IS_VT1708B_8CH_VENDORID(vendor_id) ||
Harald Welteeb14a462008-09-09 15:40:38 +0800402 IS_VT1708B_4CH_VENDORID(vendor_id)) && (adc_idx == 0))
Josepch Chanf7278fd2007-12-13 16:40:40 +0100403 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
404 0x17, &spec->cur_mux[adc_idx]);
Harald Welted949cac2008-09-09 15:56:01 +0800405 else if (IS_VT1702_VENDORID(vendor_id) && (adc_idx == 0))
406 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
407 0x13, &spec->cur_mux[adc_idx]);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100408 else
409 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
410 spec->adc_nids[adc_idx],
411 &spec->cur_mux[adc_idx]);
412}
413
Harald Welte0aa62ae2008-09-09 15:58:27 +0800414static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
415 struct snd_ctl_elem_info *uinfo)
416{
417 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
418 struct via_spec *spec = codec->spec;
419 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
420}
421
422static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
423 struct snd_ctl_elem_value *ucontrol)
424{
425 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
426 struct via_spec *spec = codec->spec;
427 hda_nid_t nid = spec->autocfg.hp_pins[0];
428 unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
429 AC_VERB_GET_CONNECT_SEL,
430 0x00);
431
432 ucontrol->value.enumerated.item[0] = pinsel;
433
434 return 0;
435}
436
437static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
438 struct snd_ctl_elem_value *ucontrol)
439{
440 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
441 struct via_spec *spec = codec->spec;
442 hda_nid_t nid = spec->autocfg.hp_pins[0];
443 unsigned int pinsel = ucontrol->value.enumerated.item[0];
444 unsigned int con_nid = snd_hda_codec_read(codec, nid, 0,
445 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
446
447 if (con_nid == spec->multiout.hp_nid) {
448 if (pinsel == 0) {
449 if (!spec->hp_independent_mode) {
450 if (spec->multiout.num_dacs > 1)
451 spec->multiout.num_dacs -= 1;
452 spec->hp_independent_mode = 1;
453 }
454 } else if (pinsel == 1) {
455 if (spec->hp_independent_mode) {
456 if (spec->multiout.num_dacs > 1)
457 spec->multiout.num_dacs += 1;
458 spec->hp_independent_mode = 0;
459 }
460 }
461 } else {
462 if (pinsel == 0) {
463 if (spec->hp_independent_mode) {
464 if (spec->multiout.num_dacs > 1)
465 spec->multiout.num_dacs += 1;
466 spec->hp_independent_mode = 0;
467 }
468 } else if (pinsel == 1) {
469 if (!spec->hp_independent_mode) {
470 if (spec->multiout.num_dacs > 1)
471 spec->multiout.num_dacs -= 1;
472 spec->hp_independent_mode = 1;
473 }
474 }
475 }
476 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
477 pinsel);
478
479 if (spec->multiout.hp_nid &&
480 spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
481 snd_hda_codec_setup_stream(codec,
482 spec->multiout.hp_nid,
483 0, 0, 0);
484
485 return 0;
486}
487
488static struct snd_kcontrol_new via_hp_mixer[] = {
489 {
490 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
491 .name = "Independent HP",
492 .count = 1,
493 .info = via_independent_hp_info,
494 .get = via_independent_hp_get,
495 .put = via_independent_hp_put,
496 },
497 { } /* end */
498};
499
Joseph Chanc577b8a2006-11-29 15:29:40 +0100500/* capture mixer elements */
501static struct snd_kcontrol_new vt1708_capture_mixer[] = {
502 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
503 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
504 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
505 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
506 {
507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
508 /* The multiple "Capture Source" controls confuse alsamixer
509 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +0100510 */
511 /* .name = "Capture Source", */
512 .name = "Input Source",
513 .count = 1,
514 .info = via_mux_enum_info,
515 .get = via_mux_enum_get,
516 .put = via_mux_enum_put,
517 },
518 { } /* end */
519};
520/*
521 * generic initialization of ADC, input mixers and output mixers
522 */
523static struct hda_verb vt1708_volume_init_verbs[] = {
524 /*
525 * Unmute ADC0-1 and set the default input to mic-in
526 */
527 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
528 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
529
530
Josepch Chanf7278fd2007-12-13 16:40:40 +0100531 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +0100532 * mixer widget
533 */
534 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +0100535 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
536 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
537 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
538 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
539 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +0100540
541 /*
542 * Set up output mixers (0x19 - 0x1b)
543 */
544 /* set vol=0 to output mixers */
545 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
546 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
547 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
548
549 /* Setup default input to PW4 */
550 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
Joseph Chanc577b8a2006-11-29 15:29:40 +0100551 /* PW9 Output enable */
552 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Josepch Chanf7278fd2007-12-13 16:40:40 +0100553 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100554};
555
556static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
557 struct hda_codec *codec,
558 struct snd_pcm_substream *substream)
559{
560 struct via_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100561 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
562 hinfo);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100563}
564
565static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
566 struct hda_codec *codec,
567 unsigned int stream_tag,
568 unsigned int format,
569 struct snd_pcm_substream *substream)
570{
571 struct via_spec *spec = codec->spec;
572 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
573 stream_tag, format, substream);
574}
575
576static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
577 struct hda_codec *codec,
578 struct snd_pcm_substream *substream)
579{
580 struct via_spec *spec = codec->spec;
581 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
582}
583
Harald Welte0aa62ae2008-09-09 15:58:27 +0800584
585static void playback_multi_pcm_prep_0(struct hda_codec *codec,
586 unsigned int stream_tag,
587 unsigned int format,
588 struct snd_pcm_substream *substream)
589{
590 struct via_spec *spec = codec->spec;
591 struct hda_multi_out *mout = &spec->multiout;
592 hda_nid_t *nids = mout->dac_nids;
593 int chs = substream->runtime->channels;
594 int i;
595
596 mutex_lock(&codec->spdif_mutex);
597 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
598 if (chs == 2 &&
599 snd_hda_is_supported_format(codec, mout->dig_out_nid,
600 format) &&
601 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
602 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
603 /* turn off SPDIF once; otherwise the IEC958 bits won't
604 * be updated */
605 if (codec->spdif_ctls & AC_DIG1_ENABLE)
606 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
607 AC_VERB_SET_DIGI_CONVERT_1,
608 codec->spdif_ctls &
609 ~AC_DIG1_ENABLE & 0xff);
610 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
611 stream_tag, 0, format);
612 /* turn on again (if needed) */
613 if (codec->spdif_ctls & AC_DIG1_ENABLE)
614 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
615 AC_VERB_SET_DIGI_CONVERT_1,
616 codec->spdif_ctls & 0xff);
617 } else {
618 mout->dig_out_used = 0;
619 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
620 0, 0, 0);
621 }
622 }
623 mutex_unlock(&codec->spdif_mutex);
624
625 /* front */
626 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
627 0, format);
628
629 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
630 !spec->hp_independent_mode)
631 /* headphone out will just decode front left/right (stereo) */
632 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
633 0, format);
634
635 /* extra outputs copied from front */
636 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
637 if (mout->extra_out_nid[i])
638 snd_hda_codec_setup_stream(codec,
639 mout->extra_out_nid[i],
640 stream_tag, 0, format);
641
642 /* surrounds */
643 for (i = 1; i < mout->num_dacs; i++) {
644 if (chs >= (i + 1) * 2) /* independent out */
645 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
646 i * 2, format);
647 else /* copy front */
648 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
649 0, format);
650 }
651}
652
653static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
654 struct hda_codec *codec,
655 unsigned int stream_tag,
656 unsigned int format,
657 struct snd_pcm_substream *substream)
658{
659 struct via_spec *spec = codec->spec;
660 struct hda_multi_out *mout = &spec->multiout;
661 hda_nid_t *nids = mout->dac_nids;
662
663 if (substream->number == 0)
664 playback_multi_pcm_prep_0(codec, stream_tag, format,
665 substream);
666 else {
667 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
668 spec->hp_independent_mode)
669 snd_hda_codec_setup_stream(codec, mout->hp_nid,
670 stream_tag, 0, format);
671 }
672
673 return 0;
674}
675
676static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
677 struct hda_codec *codec,
678 struct snd_pcm_substream *substream)
679{
680 struct via_spec *spec = codec->spec;
681 struct hda_multi_out *mout = &spec->multiout;
682 hda_nid_t *nids = mout->dac_nids;
683 int i;
684
685 if (substream->number == 0) {
686 for (i = 0; i < mout->num_dacs; i++)
687 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
688
689 if (mout->hp_nid && !spec->hp_independent_mode)
690 snd_hda_codec_setup_stream(codec, mout->hp_nid,
691 0, 0, 0);
692
693 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
694 if (mout->extra_out_nid[i])
695 snd_hda_codec_setup_stream(codec,
696 mout->extra_out_nid[i],
697 0, 0, 0);
698 mutex_lock(&codec->spdif_mutex);
699 if (mout->dig_out_nid &&
700 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
701 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
702 0, 0, 0);
703 mout->dig_out_used = 0;
704 }
705 mutex_unlock(&codec->spdif_mutex);
706 } else {
707 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
708 spec->hp_independent_mode)
709 snd_hda_codec_setup_stream(codec, mout->hp_nid,
710 0, 0, 0);
711 }
712
713 return 0;
714}
715
Joseph Chanc577b8a2006-11-29 15:29:40 +0100716/*
717 * Digital out
718 */
719static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
720 struct hda_codec *codec,
721 struct snd_pcm_substream *substream)
722{
723 struct via_spec *spec = codec->spec;
724 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
725}
726
727static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
728 struct hda_codec *codec,
729 struct snd_pcm_substream *substream)
730{
731 struct via_spec *spec = codec->spec;
732 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
733}
734
Harald Welte5691ec72008-09-15 22:42:26 +0800735static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Harald Welte98aa34c2008-09-09 16:02:09 +0800736 struct hda_codec *codec,
737 unsigned int stream_tag,
738 unsigned int format,
739 struct snd_pcm_substream *substream)
740{
741 struct via_spec *spec = codec->spec;
Takashi Iwai9da29272009-05-07 16:31:14 +0200742 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
743 stream_tag, format, substream);
744}
Harald Welte5691ec72008-09-15 22:42:26 +0800745
Takashi Iwai9da29272009-05-07 16:31:14 +0200746static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
747 struct hda_codec *codec,
748 struct snd_pcm_substream *substream)
749{
750 struct via_spec *spec = codec->spec;
751 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
Harald Welte98aa34c2008-09-09 16:02:09 +0800752 return 0;
753}
754
Joseph Chanc577b8a2006-11-29 15:29:40 +0100755/*
756 * Analog capture
757 */
758static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
759 struct hda_codec *codec,
760 unsigned int stream_tag,
761 unsigned int format,
762 struct snd_pcm_substream *substream)
763{
764 struct via_spec *spec = codec->spec;
765
766 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
767 stream_tag, 0, format);
768 return 0;
769}
770
771static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
772 struct hda_codec *codec,
773 struct snd_pcm_substream *substream)
774{
775 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100776 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100777 return 0;
778}
779
780static struct hda_pcm_stream vt1708_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +0800781 .substreams = 2,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100782 .channels_min = 2,
783 .channels_max = 8,
784 .nid = 0x10, /* NID to query formats and rates */
785 .ops = {
786 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +0800787 .prepare = via_playback_multi_pcm_prepare,
788 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +0100789 },
790};
791
Takashi Iwaibc9b562382008-05-23 17:50:27 +0200792static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
793 .substreams = 1,
794 .channels_min = 2,
795 .channels_max = 8,
796 .nid = 0x10, /* NID to query formats and rates */
797 /* We got noisy outputs on the right channel on VT1708 when
798 * 24bit samples are used. Until any workaround is found,
799 * disable the 24bit format, so far.
800 */
801 .formats = SNDRV_PCM_FMTBIT_S16_LE,
802 .ops = {
803 .open = via_playback_pcm_open,
804 .prepare = via_playback_pcm_prepare,
805 .cleanup = via_playback_pcm_cleanup
806 },
807};
808
Joseph Chanc577b8a2006-11-29 15:29:40 +0100809static struct hda_pcm_stream vt1708_pcm_analog_capture = {
810 .substreams = 2,
811 .channels_min = 2,
812 .channels_max = 2,
813 .nid = 0x15, /* NID to query formats and rates */
814 .ops = {
815 .prepare = via_capture_pcm_prepare,
816 .cleanup = via_capture_pcm_cleanup
817 },
818};
819
820static struct hda_pcm_stream vt1708_pcm_digital_playback = {
821 .substreams = 1,
822 .channels_min = 2,
823 .channels_max = 2,
824 /* NID is set in via_build_pcms */
825 .ops = {
826 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200827 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +0200828 .prepare = via_dig_playback_pcm_prepare,
829 .cleanup = via_dig_playback_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +0100830 },
831};
832
833static struct hda_pcm_stream vt1708_pcm_digital_capture = {
834 .substreams = 1,
835 .channels_min = 2,
836 .channels_max = 2,
837};
838
839static int via_build_controls(struct hda_codec *codec)
840{
841 struct via_spec *spec = codec->spec;
842 int err;
843 int i;
844
845 for (i = 0; i < spec->num_mixers; i++) {
846 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
847 if (err < 0)
848 return err;
849 }
850
851 if (spec->multiout.dig_out_nid) {
852 err = snd_hda_create_spdif_out_ctls(codec,
853 spec->multiout.dig_out_nid);
854 if (err < 0)
855 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100856 err = snd_hda_create_spdif_share_sw(codec,
857 &spec->multiout);
858 if (err < 0)
859 return err;
860 spec->multiout.share_spdif = 1;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100861 }
862 if (spec->dig_in_nid) {
863 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
864 if (err < 0)
865 return err;
866 }
Takashi Iwai603c4012008-07-30 15:01:44 +0200867 via_free_kctls(codec); /* no longer needed */
Joseph Chanc577b8a2006-11-29 15:29:40 +0100868 return 0;
869}
870
871static int via_build_pcms(struct hda_codec *codec)
872{
873 struct via_spec *spec = codec->spec;
874 struct hda_pcm *info = spec->pcm_rec;
875
876 codec->num_pcms = 1;
877 codec->pcm_info = info;
878
879 info->name = spec->stream_name_analog;
880 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
881 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
882 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
883 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
884
885 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
886 spec->multiout.max_channels;
887
888 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
889 codec->num_pcms++;
890 info++;
891 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100892 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100893 if (spec->multiout.dig_out_nid) {
894 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
895 *(spec->stream_digital_playback);
896 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
897 spec->multiout.dig_out_nid;
898 }
899 if (spec->dig_in_nid) {
900 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
901 *(spec->stream_digital_capture);
902 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
903 spec->dig_in_nid;
904 }
905 }
906
907 return 0;
908}
909
910static void via_free(struct hda_codec *codec)
911{
912 struct via_spec *spec = codec->spec;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100913
914 if (!spec)
915 return;
916
Takashi Iwai603c4012008-07-30 15:01:44 +0200917 via_free_kctls(codec);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100918 kfree(codec->spec);
919}
920
Harald Welte69e52a82008-09-09 15:57:32 +0800921/* mute internal speaker if HP is plugged */
922static void via_hp_automute(struct hda_codec *codec)
923{
924 unsigned int present;
925 struct via_spec *spec = codec->spec;
926
927 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
928 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
929 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
930 HDA_OUTPUT, 0, HDA_AMP_MUTE,
931 present ? HDA_AMP_MUTE : 0);
932}
933
934static void via_gpio_control(struct hda_codec *codec)
935{
936 unsigned int gpio_data;
937 unsigned int vol_counter;
938 unsigned int vol;
939 unsigned int master_vol;
940
941 struct via_spec *spec = codec->spec;
942
943 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
944 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
945
946 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
947 0xF84, 0) & 0x3F0000) >> 16;
948
949 vol = vol_counter & 0x1F;
950 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
951 AC_VERB_GET_AMP_GAIN_MUTE,
952 AC_AMP_GET_INPUT);
953
954 if (gpio_data == 0x02) {
955 /* unmute line out */
956 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
957 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
958
959 if (vol_counter & 0x20) {
960 /* decrease volume */
961 if (vol > master_vol)
962 vol = master_vol;
963 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
964 0, HDA_AMP_VOLMASK,
965 master_vol-vol);
966 } else {
967 /* increase volume */
968 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
969 HDA_AMP_VOLMASK,
970 ((master_vol+vol) > 0x2A) ? 0x2A :
971 (master_vol+vol));
972 }
973 } else if (!(gpio_data & 0x02)) {
974 /* mute line out */
975 snd_hda_codec_amp_stereo(codec,
976 spec->autocfg.line_out_pins[0],
977 HDA_OUTPUT, 0, HDA_AMP_MUTE,
978 HDA_AMP_MUTE);
979 }
980}
981
982/* unsolicited event for jack sensing */
983static void via_unsol_event(struct hda_codec *codec,
984 unsigned int res)
985{
986 res >>= 26;
987 if (res == VIA_HP_EVENT)
988 via_hp_automute(codec);
989 else if (res == VIA_GPIO_EVENT)
990 via_gpio_control(codec);
991}
992
Joseph Chanc577b8a2006-11-29 15:29:40 +0100993static int via_init(struct hda_codec *codec)
994{
995 struct via_spec *spec = codec->spec;
Harald Welte69e52a82008-09-09 15:57:32 +0800996 int i;
997 for (i = 0; i < spec->num_iverbs; i++)
998 snd_hda_sequence_write(codec, spec->init_verbs[i]);
999
Josepch Chanf7278fd2007-12-13 16:40:40 +01001000 /* Lydia Add for EAPD enable */
1001 if (!spec->dig_in_nid) { /* No Digital In connection */
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001002 if (spec->dig_in_pin) {
1003 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001004 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +01001005 PIN_OUT);
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001006 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001007 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1008 }
Takashi Iwai12b74c82008-01-15 12:39:38 +01001009 } else /* enable SPDIF-input pin */
1010 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1011 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
Josepch Chanf7278fd2007-12-13 16:40:40 +01001012
Takashi Iwai9da29272009-05-07 16:31:14 +02001013 /* assign slave outs */
1014 if (spec->slave_dig_outs[0])
1015 codec->slave_dig_outs = spec->slave_dig_outs;
Harald Welte5691ec72008-09-15 22:42:26 +08001016
Joseph Chanc577b8a2006-11-29 15:29:40 +01001017 return 0;
1018}
1019
Takashi Iwaicb53c622007-08-10 17:21:45 +02001020#ifdef CONFIG_SND_HDA_POWER_SAVE
1021static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1022{
1023 struct via_spec *spec = codec->spec;
1024 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1025}
1026#endif
1027
Joseph Chanc577b8a2006-11-29 15:29:40 +01001028/*
1029 */
1030static struct hda_codec_ops via_patch_ops = {
1031 .build_controls = via_build_controls,
1032 .build_pcms = via_build_pcms,
1033 .init = via_init,
1034 .free = via_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02001035#ifdef CONFIG_SND_HDA_POWER_SAVE
1036 .check_power_status = via_check_power_status,
1037#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001038};
1039
1040/* fill in the dac_nids table from the parsed pin configuration */
1041static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1042 const struct auto_pin_cfg *cfg)
1043{
1044 int i;
1045 hda_nid_t nid;
1046
1047 spec->multiout.num_dacs = cfg->line_outs;
1048
1049 spec->multiout.dac_nids = spec->private_dac_nids;
1050
1051 for(i = 0; i < 4; i++) {
1052 nid = cfg->line_out_pins[i];
1053 if (nid) {
1054 /* config dac list */
1055 switch (i) {
1056 case AUTO_SEQ_FRONT:
1057 spec->multiout.dac_nids[i] = 0x10;
1058 break;
1059 case AUTO_SEQ_CENLFE:
1060 spec->multiout.dac_nids[i] = 0x12;
1061 break;
1062 case AUTO_SEQ_SURROUND:
Harald Weltefb4cb772008-09-09 15:53:36 +08001063 spec->multiout.dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001064 break;
1065 case AUTO_SEQ_SIDE:
Harald Weltefb4cb772008-09-09 15:53:36 +08001066 spec->multiout.dac_nids[i] = 0x13;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001067 break;
1068 }
1069 }
1070 }
1071
1072 return 0;
1073}
1074
1075/* add playback controls from the parsed DAC table */
1076static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1077 const struct auto_pin_cfg *cfg)
1078{
1079 char name[32];
1080 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1081 hda_nid_t nid, nid_vol = 0;
1082 int i, err;
1083
1084 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1085 nid = cfg->line_out_pins[i];
1086
1087 if (!nid)
1088 continue;
1089
1090 if (i != AUTO_SEQ_FRONT)
Harald Weltefb4cb772008-09-09 15:53:36 +08001091 nid_vol = 0x18 + i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001092
1093 if (i == AUTO_SEQ_CENLFE) {
1094 /* Center/LFE */
1095 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001096 "Center Playback Volume",
1097 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1098 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001099 if (err < 0)
1100 return err;
1101 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1102 "LFE Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001103 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1104 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001105 if (err < 0)
1106 return err;
1107 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1108 "Center Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001109 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1110 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001111 if (err < 0)
1112 return err;
1113 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1114 "LFE Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001115 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1116 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001117 if (err < 0)
1118 return err;
1119 } else if (i == AUTO_SEQ_FRONT){
1120 /* add control to mixer index 0 */
1121 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1122 "Master Front Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001123 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1124 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001125 if (err < 0)
1126 return err;
1127 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1128 "Master Front Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001129 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1130 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001131 if (err < 0)
1132 return err;
1133
1134 /* add control to PW3 */
1135 sprintf(name, "%s Playback Volume", chname[i]);
1136 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001137 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1138 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001139 if (err < 0)
1140 return err;
1141 sprintf(name, "%s Playback Switch", chname[i]);
1142 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001143 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1144 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001145 if (err < 0)
1146 return err;
1147 } else {
1148 sprintf(name, "%s Playback Volume", chname[i]);
1149 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001150 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1151 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001152 if (err < 0)
1153 return err;
1154 sprintf(name, "%s Playback Switch", chname[i]);
1155 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001156 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1157 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001158 if (err < 0)
1159 return err;
1160 }
1161 }
1162
1163 return 0;
1164}
1165
Harald Welte0aa62ae2008-09-09 15:58:27 +08001166static void create_hp_imux(struct via_spec *spec)
1167{
1168 int i;
1169 struct hda_input_mux *imux = &spec->private_imux[1];
1170 static const char *texts[] = { "OFF", "ON", NULL};
1171
1172 /* for hp mode select */
1173 i = 0;
1174 while (texts[i] != NULL) {
1175 imux->items[imux->num_items].label = texts[i];
1176 imux->items[imux->num_items].index = i;
1177 imux->num_items++;
1178 i++;
1179 }
1180
1181 spec->hp_mux = &spec->private_imux[1];
1182}
1183
Joseph Chanc577b8a2006-11-29 15:29:40 +01001184static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1185{
1186 int err;
1187
1188 if (!pin)
1189 return 0;
1190
1191 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1192
1193 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1194 "Headphone Playback Volume",
1195 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1196 if (err < 0)
1197 return err;
1198 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1199 "Headphone Playback Switch",
1200 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1201 if (err < 0)
1202 return err;
1203
Harald Welte0aa62ae2008-09-09 15:58:27 +08001204 create_hp_imux(spec);
1205
Joseph Chanc577b8a2006-11-29 15:29:40 +01001206 return 0;
1207}
1208
1209/* create playback/capture controls for input pins */
1210static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1211 const struct auto_pin_cfg *cfg)
1212{
1213 static char *labels[] = {
1214 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1215 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08001216 struct hda_input_mux *imux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001217 int i, err, idx = 0;
1218
1219 /* for internal loopback recording select */
1220 imux->items[imux->num_items].label = "Stereo Mixer";
1221 imux->items[imux->num_items].index = idx;
1222 imux->num_items++;
1223
1224 for (i = 0; i < AUTO_PIN_LAST; i++) {
1225 if (!cfg->input_pins[i])
1226 continue;
1227
1228 switch (cfg->input_pins[i]) {
1229 case 0x1d: /* Mic */
1230 idx = 2;
1231 break;
1232
1233 case 0x1e: /* Line In */
1234 idx = 3;
1235 break;
1236
1237 case 0x21: /* Front Mic */
1238 idx = 4;
1239 break;
1240
1241 case 0x24: /* CD */
1242 idx = 1;
1243 break;
1244 }
1245 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1246 idx, 0x17);
1247 if (err < 0)
1248 return err;
1249 imux->items[imux->num_items].label = labels[i];
1250 imux->items[imux->num_items].index = idx;
1251 imux->num_items++;
1252 }
1253 return 0;
1254}
1255
Takashi Iwaicb53c622007-08-10 17:21:45 +02001256#ifdef CONFIG_SND_HDA_POWER_SAVE
1257static struct hda_amp_list vt1708_loopbacks[] = {
1258 { 0x17, HDA_INPUT, 1 },
1259 { 0x17, HDA_INPUT, 2 },
1260 { 0x17, HDA_INPUT, 3 },
1261 { 0x17, HDA_INPUT, 4 },
1262 { } /* end */
1263};
1264#endif
1265
Harald Welte76d9b0d2008-09-09 15:50:37 +08001266static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1267{
1268 unsigned int def_conf;
1269 unsigned char seqassoc;
1270
Takashi Iwai2f334f92009-02-20 14:37:42 +01001271 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Harald Welte76d9b0d2008-09-09 15:50:37 +08001272 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1273 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1274 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
1275 if (seqassoc == 0xff) {
1276 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
Takashi Iwai2f334f92009-02-20 14:37:42 +01001277 snd_hda_codec_set_pincfg(codec, nid, def_conf);
Harald Welte76d9b0d2008-09-09 15:50:37 +08001278 }
1279 }
1280
1281 return;
1282}
1283
Joseph Chanc577b8a2006-11-29 15:29:40 +01001284static int vt1708_parse_auto_config(struct hda_codec *codec)
1285{
1286 struct via_spec *spec = codec->spec;
1287 int err;
1288
Harald Welte76d9b0d2008-09-09 15:50:37 +08001289 /* Add HP and CD pin config connect bit re-config action */
1290 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
1291 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
1292
Joseph Chanc577b8a2006-11-29 15:29:40 +01001293 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1294 if (err < 0)
1295 return err;
1296 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
1297 if (err < 0)
1298 return err;
1299 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1300 return 0; /* can't find valid BIOS pin config */
1301
1302 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
1303 if (err < 0)
1304 return err;
1305 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1306 if (err < 0)
1307 return err;
1308 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1309 if (err < 0)
1310 return err;
1311
1312 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1313
Takashi Iwai0852d7a2009-02-11 11:35:15 +01001314 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001315 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001316 spec->dig_in_pin = VT1708_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001317 if (spec->autocfg.dig_in_pin)
1318 spec->dig_in_nid = VT1708_DIGIN_NID;
1319
Takashi Iwai603c4012008-07-30 15:01:44 +02001320 if (spec->kctls.list)
1321 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001322
Harald Welte69e52a82008-09-09 15:57:32 +08001323 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001324
Harald Welte0aa62ae2008-09-09 15:58:27 +08001325 spec->input_mux = &spec->private_imux[0];
1326
Harald Weltef8fdd492008-09-15 22:41:31 +08001327 if (spec->hp_mux)
1328 spec->mixers[spec->num_mixers++] = via_hp_mixer;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001329
1330 return 1;
1331}
1332
1333/* init callback for auto-configuration model -- overriding the default init */
1334static int via_auto_init(struct hda_codec *codec)
1335{
1336 via_init(codec);
1337 via_auto_init_multi_out(codec);
1338 via_auto_init_hp_out(codec);
1339 via_auto_init_analog_input(codec);
1340 return 0;
1341}
1342
1343static int patch_vt1708(struct hda_codec *codec)
1344{
1345 struct via_spec *spec;
1346 int err;
1347
1348 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08001349 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001350 if (spec == NULL)
1351 return -ENOMEM;
1352
1353 codec->spec = spec;
1354
1355 /* automatic parse from the BIOS config */
1356 err = vt1708_parse_auto_config(codec);
1357 if (err < 0) {
1358 via_free(codec);
1359 return err;
1360 } else if (!err) {
1361 printk(KERN_INFO "hda_codec: Cannot set up configuration "
1362 "from BIOS. Using genenic mode...\n");
1363 }
1364
1365
1366 spec->stream_name_analog = "VT1708 Analog";
1367 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
Takashi Iwaibc9b562382008-05-23 17:50:27 +02001368 /* disable 32bit format on VT1708 */
1369 if (codec->vendor_id == 0x11061708)
1370 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001371 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
1372
1373 spec->stream_name_digital = "VT1708 Digital";
1374 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1375 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1376
1377
1378 if (!spec->adc_nids && spec->input_mux) {
1379 spec->adc_nids = vt1708_adc_nids;
1380 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
1381 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
1382 spec->num_mixers++;
1383 }
1384
1385 codec->patch_ops = via_patch_ops;
1386
1387 codec->patch_ops.init = via_auto_init;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001388#ifdef CONFIG_SND_HDA_POWER_SAVE
1389 spec->loopback.amplist = vt1708_loopbacks;
1390#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001391
1392 return 0;
1393}
1394
1395/* capture mixer elements */
1396static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1397 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
1398 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
1399 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
1400 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
1401 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
1402 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
1403 {
1404 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1405 /* The multiple "Capture Source" controls confuse alsamixer
1406 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01001407 */
1408 /* .name = "Capture Source", */
1409 .name = "Input Source",
1410 .count = 1,
1411 .info = via_mux_enum_info,
1412 .get = via_mux_enum_get,
1413 .put = via_mux_enum_put,
1414 },
1415 { } /* end */
1416};
1417
Harald Welte69e52a82008-09-09 15:57:32 +08001418static struct hda_verb vt1709_uniwill_init_verbs[] = {
1419 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
1420 { }
1421};
1422
Joseph Chanc577b8a2006-11-29 15:29:40 +01001423/*
1424 * generic initialization of ADC, input mixers and output mixers
1425 */
1426static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1427 /*
1428 * Unmute ADC0-2 and set the default input to mic-in
1429 */
1430 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1431 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1432 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1433
1434
Josepch Chanf7278fd2007-12-13 16:40:40 +01001435 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01001436 * mixer widget
1437 */
1438 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01001439 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1440 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1441 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1442 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1443 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001444
1445 /*
1446 * Set up output selector (0x1a, 0x1b, 0x29)
1447 */
1448 /* set vol=0 to output mixers */
1449 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1450 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1451 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1452
1453 /*
1454 * Unmute PW3 and PW4
1455 */
1456 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1457 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1458
1459 /* Set input of PW4 as AOW4 */
1460 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001461 /* PW9 Output enable */
1462 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1463 { }
1464};
1465
1466static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1467 .substreams = 1,
1468 .channels_min = 2,
1469 .channels_max = 10,
1470 .nid = 0x10, /* NID to query formats and rates */
1471 .ops = {
1472 .open = via_playback_pcm_open,
1473 .prepare = via_playback_pcm_prepare,
1474 .cleanup = via_playback_pcm_cleanup
1475 },
1476};
1477
1478static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1479 .substreams = 1,
1480 .channels_min = 2,
1481 .channels_max = 6,
1482 .nid = 0x10, /* NID to query formats and rates */
1483 .ops = {
1484 .open = via_playback_pcm_open,
1485 .prepare = via_playback_pcm_prepare,
1486 .cleanup = via_playback_pcm_cleanup
1487 },
1488};
1489
1490static struct hda_pcm_stream vt1709_pcm_analog_capture = {
1491 .substreams = 2,
1492 .channels_min = 2,
1493 .channels_max = 2,
1494 .nid = 0x14, /* NID to query formats and rates */
1495 .ops = {
1496 .prepare = via_capture_pcm_prepare,
1497 .cleanup = via_capture_pcm_cleanup
1498 },
1499};
1500
1501static struct hda_pcm_stream vt1709_pcm_digital_playback = {
1502 .substreams = 1,
1503 .channels_min = 2,
1504 .channels_max = 2,
1505 /* NID is set in via_build_pcms */
1506 .ops = {
1507 .open = via_dig_playback_pcm_open,
1508 .close = via_dig_playback_pcm_close
1509 },
1510};
1511
1512static struct hda_pcm_stream vt1709_pcm_digital_capture = {
1513 .substreams = 1,
1514 .channels_min = 2,
1515 .channels_max = 2,
1516};
1517
1518static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1519 const struct auto_pin_cfg *cfg)
1520{
1521 int i;
1522 hda_nid_t nid;
1523
1524 if (cfg->line_outs == 4) /* 10 channels */
1525 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
1526 else if (cfg->line_outs == 3) /* 6 channels */
1527 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
1528
1529 spec->multiout.dac_nids = spec->private_dac_nids;
1530
1531 if (cfg->line_outs == 4) { /* 10 channels */
1532 for (i = 0; i < cfg->line_outs; i++) {
1533 nid = cfg->line_out_pins[i];
1534 if (nid) {
1535 /* config dac list */
1536 switch (i) {
1537 case AUTO_SEQ_FRONT:
1538 /* AOW0 */
1539 spec->multiout.dac_nids[i] = 0x10;
1540 break;
1541 case AUTO_SEQ_CENLFE:
1542 /* AOW2 */
1543 spec->multiout.dac_nids[i] = 0x12;
1544 break;
1545 case AUTO_SEQ_SURROUND:
1546 /* AOW3 */
Harald Weltefb4cb772008-09-09 15:53:36 +08001547 spec->multiout.dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001548 break;
1549 case AUTO_SEQ_SIDE:
1550 /* AOW1 */
Harald Weltefb4cb772008-09-09 15:53:36 +08001551 spec->multiout.dac_nids[i] = 0x27;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001552 break;
1553 default:
1554 break;
1555 }
1556 }
1557 }
1558 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1559
1560 } else if (cfg->line_outs == 3) { /* 6 channels */
1561 for(i = 0; i < cfg->line_outs; i++) {
1562 nid = cfg->line_out_pins[i];
1563 if (nid) {
1564 /* config dac list */
1565 switch(i) {
1566 case AUTO_SEQ_FRONT:
1567 /* AOW0 */
1568 spec->multiout.dac_nids[i] = 0x10;
1569 break;
1570 case AUTO_SEQ_CENLFE:
1571 /* AOW2 */
1572 spec->multiout.dac_nids[i] = 0x12;
1573 break;
1574 case AUTO_SEQ_SURROUND:
1575 /* AOW1 */
1576 spec->multiout.dac_nids[i] = 0x11;
1577 break;
1578 default:
1579 break;
1580 }
1581 }
1582 }
1583 }
1584
1585 return 0;
1586}
1587
1588/* add playback controls from the parsed DAC table */
1589static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1590 const struct auto_pin_cfg *cfg)
1591{
1592 char name[32];
1593 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1594 hda_nid_t nid = 0;
1595 int i, err;
1596
1597 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1598 nid = cfg->line_out_pins[i];
1599
1600 if (!nid)
1601 continue;
1602
1603 if (i == AUTO_SEQ_CENLFE) {
1604 /* Center/LFE */
1605 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1606 "Center Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001607 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1608 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001609 if (err < 0)
1610 return err;
1611 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1612 "LFE Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001613 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1614 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001615 if (err < 0)
1616 return err;
1617 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1618 "Center Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001619 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1620 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001621 if (err < 0)
1622 return err;
1623 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1624 "LFE Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001625 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1626 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001627 if (err < 0)
1628 return err;
1629 } else if (i == AUTO_SEQ_FRONT){
1630 /* add control to mixer index 0 */
1631 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1632 "Master Front Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001633 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1634 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001635 if (err < 0)
1636 return err;
1637 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1638 "Master Front Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001639 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1640 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001641 if (err < 0)
1642 return err;
1643
1644 /* add control to PW3 */
1645 sprintf(name, "%s Playback Volume", chname[i]);
1646 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001647 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1648 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001649 if (err < 0)
1650 return err;
1651 sprintf(name, "%s Playback Switch", chname[i]);
1652 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001653 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1654 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001655 if (err < 0)
1656 return err;
1657 } else if (i == AUTO_SEQ_SURROUND) {
1658 sprintf(name, "%s Playback Volume", chname[i]);
1659 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Harald Weltefb4cb772008-09-09 15:53:36 +08001660 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001661 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001662 if (err < 0)
1663 return err;
1664 sprintf(name, "%s Playback Switch", chname[i]);
1665 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Harald Weltefb4cb772008-09-09 15:53:36 +08001666 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001667 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001668 if (err < 0)
1669 return err;
1670 } else if (i == AUTO_SEQ_SIDE) {
1671 sprintf(name, "%s Playback Volume", chname[i]);
1672 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Harald Weltefb4cb772008-09-09 15:53:36 +08001673 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001674 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001675 if (err < 0)
1676 return err;
1677 sprintf(name, "%s Playback Switch", chname[i]);
1678 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Harald Weltefb4cb772008-09-09 15:53:36 +08001679 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001680 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001681 if (err < 0)
1682 return err;
1683 }
1684 }
1685
1686 return 0;
1687}
1688
1689static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1690{
1691 int err;
1692
1693 if (!pin)
1694 return 0;
1695
1696 if (spec->multiout.num_dacs == 5) /* 10 channels */
1697 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1698 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1699 spec->multiout.hp_nid = 0;
1700
1701 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1702 "Headphone Playback Volume",
1703 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1704 if (err < 0)
1705 return err;
1706 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1707 "Headphone Playback Switch",
1708 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1709 if (err < 0)
1710 return err;
1711
1712 return 0;
1713}
1714
1715/* create playback/capture controls for input pins */
1716static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1717 const struct auto_pin_cfg *cfg)
1718{
1719 static char *labels[] = {
1720 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1721 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08001722 struct hda_input_mux *imux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001723 int i, err, idx = 0;
1724
1725 /* for internal loopback recording select */
1726 imux->items[imux->num_items].label = "Stereo Mixer";
1727 imux->items[imux->num_items].index = idx;
1728 imux->num_items++;
1729
1730 for (i = 0; i < AUTO_PIN_LAST; i++) {
1731 if (!cfg->input_pins[i])
1732 continue;
1733
1734 switch (cfg->input_pins[i]) {
1735 case 0x1d: /* Mic */
1736 idx = 2;
1737 break;
1738
1739 case 0x1e: /* Line In */
1740 idx = 3;
1741 break;
1742
1743 case 0x21: /* Front Mic */
1744 idx = 4;
1745 break;
1746
1747 case 0x23: /* CD */
1748 idx = 1;
1749 break;
1750 }
1751 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1752 idx, 0x18);
1753 if (err < 0)
1754 return err;
1755 imux->items[imux->num_items].label = labels[i];
1756 imux->items[imux->num_items].index = idx;
1757 imux->num_items++;
1758 }
1759 return 0;
1760}
1761
1762static int vt1709_parse_auto_config(struct hda_codec *codec)
1763{
1764 struct via_spec *spec = codec->spec;
1765 int err;
1766
1767 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1768 if (err < 0)
1769 return err;
1770 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
1771 if (err < 0)
1772 return err;
1773 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1774 return 0; /* can't find valid BIOS pin config */
1775
1776 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
1777 if (err < 0)
1778 return err;
1779 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1780 if (err < 0)
1781 return err;
1782 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
1783 if (err < 0)
1784 return err;
1785
1786 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1787
Takashi Iwai0852d7a2009-02-11 11:35:15 +01001788 if (spec->autocfg.dig_outs)
Joseph Chanc577b8a2006-11-29 15:29:40 +01001789 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02001790 spec->dig_in_pin = VT1709_DIGIN_PIN;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001791 if (spec->autocfg.dig_in_pin)
1792 spec->dig_in_nid = VT1709_DIGIN_NID;
1793
Takashi Iwai603c4012008-07-30 15:01:44 +02001794 if (spec->kctls.list)
1795 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001796
Harald Welte0aa62ae2008-09-09 15:58:27 +08001797 spec->input_mux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001798
Harald Weltef8fdd492008-09-15 22:41:31 +08001799 if (spec->hp_mux)
1800 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1801
Joseph Chanc577b8a2006-11-29 15:29:40 +01001802 return 1;
1803}
1804
Takashi Iwaicb53c622007-08-10 17:21:45 +02001805#ifdef CONFIG_SND_HDA_POWER_SAVE
1806static struct hda_amp_list vt1709_loopbacks[] = {
1807 { 0x18, HDA_INPUT, 1 },
1808 { 0x18, HDA_INPUT, 2 },
1809 { 0x18, HDA_INPUT, 3 },
1810 { 0x18, HDA_INPUT, 4 },
1811 { } /* end */
1812};
1813#endif
1814
Joseph Chanc577b8a2006-11-29 15:29:40 +01001815static int patch_vt1709_10ch(struct hda_codec *codec)
1816{
1817 struct via_spec *spec;
1818 int err;
1819
1820 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08001821 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001822 if (spec == NULL)
1823 return -ENOMEM;
1824
1825 codec->spec = spec;
1826
1827 err = vt1709_parse_auto_config(codec);
1828 if (err < 0) {
1829 via_free(codec);
1830 return err;
1831 } else if (!err) {
1832 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1833 "Using genenic mode...\n");
1834 }
1835
Harald Welte69e52a82008-09-09 15:57:32 +08001836 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
1837 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001838
1839 spec->stream_name_analog = "VT1709 Analog";
1840 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
1841 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1842
1843 spec->stream_name_digital = "VT1709 Digital";
1844 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1845 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1846
1847
1848 if (!spec->adc_nids && spec->input_mux) {
1849 spec->adc_nids = vt1709_adc_nids;
1850 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1851 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1852 spec->num_mixers++;
1853 }
1854
1855 codec->patch_ops = via_patch_ops;
1856
1857 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08001858 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001859#ifdef CONFIG_SND_HDA_POWER_SAVE
1860 spec->loopback.amplist = vt1709_loopbacks;
1861#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001862
1863 return 0;
1864}
1865/*
1866 * generic initialization of ADC, input mixers and output mixers
1867 */
1868static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
1869 /*
1870 * Unmute ADC0-2 and set the default input to mic-in
1871 */
1872 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1873 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1874 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1875
1876
1877 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1878 * mixer widget
1879 */
1880 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1881 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1882 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1883 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1884 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1885 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1886
1887 /*
1888 * Set up output selector (0x1a, 0x1b, 0x29)
1889 */
1890 /* set vol=0 to output mixers */
1891 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1892 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1893 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1894
1895 /*
1896 * Unmute PW3 and PW4
1897 */
1898 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1899 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1900
1901 /* Set input of PW4 as MW0 */
1902 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001903 /* PW9 Output enable */
1904 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1905 { }
1906};
1907
1908static int patch_vt1709_6ch(struct hda_codec *codec)
1909{
1910 struct via_spec *spec;
1911 int err;
1912
1913 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08001914 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001915 if (spec == NULL)
1916 return -ENOMEM;
1917
1918 codec->spec = spec;
1919
1920 err = vt1709_parse_auto_config(codec);
1921 if (err < 0) {
1922 via_free(codec);
1923 return err;
1924 } else if (!err) {
1925 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1926 "Using genenic mode...\n");
1927 }
1928
Harald Welte69e52a82008-09-09 15:57:32 +08001929 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
1930 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001931
1932 spec->stream_name_analog = "VT1709 Analog";
1933 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
1934 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1935
1936 spec->stream_name_digital = "VT1709 Digital";
1937 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1938 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1939
1940
1941 if (!spec->adc_nids && spec->input_mux) {
1942 spec->adc_nids = vt1709_adc_nids;
1943 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1944 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1945 spec->num_mixers++;
1946 }
1947
1948 codec->patch_ops = via_patch_ops;
1949
1950 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08001951 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001952#ifdef CONFIG_SND_HDA_POWER_SAVE
1953 spec->loopback.amplist = vt1709_loopbacks;
1954#endif
Josepch Chanf7278fd2007-12-13 16:40:40 +01001955 return 0;
1956}
1957
1958/* capture mixer elements */
1959static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
1960 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
1961 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
1962 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
1963 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
1964 {
1965 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1966 /* The multiple "Capture Source" controls confuse alsamixer
1967 * So call somewhat different..
Josepch Chanf7278fd2007-12-13 16:40:40 +01001968 */
1969 /* .name = "Capture Source", */
1970 .name = "Input Source",
1971 .count = 1,
1972 .info = via_mux_enum_info,
1973 .get = via_mux_enum_get,
1974 .put = via_mux_enum_put,
1975 },
1976 { } /* end */
1977};
1978/*
1979 * generic initialization of ADC, input mixers and output mixers
1980 */
1981static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
1982 /*
1983 * Unmute ADC0-1 and set the default input to mic-in
1984 */
1985 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1986 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1987
1988
1989 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1990 * mixer widget
1991 */
1992 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1993 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1994 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1995 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1996 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1997 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1998
1999 /*
2000 * Set up output mixers
2001 */
2002 /* set vol=0 to output mixers */
2003 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2004 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2005 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2006
2007 /* Setup default input to PW4 */
2008 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
2009 /* PW9 Output enable */
2010 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2011 /* PW10 Input enable */
2012 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2013 { }
2014};
2015
2016static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2017 /*
2018 * Unmute ADC0-1 and set the default input to mic-in
2019 */
2020 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2021 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2022
2023
2024 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2025 * mixer widget
2026 */
2027 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2028 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2029 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2030 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2031 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2032 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2033
2034 /*
2035 * Set up output mixers
2036 */
2037 /* set vol=0 to output mixers */
2038 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2039 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2040 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2041
2042 /* Setup default input of PW4 to MW0 */
2043 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2044 /* PW9 Output enable */
2045 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2046 /* PW10 Input enable */
2047 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2048 { }
2049};
2050
Harald Welte69e52a82008-09-09 15:57:32 +08002051static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2052 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2053 { }
2054};
2055
Josepch Chanf7278fd2007-12-13 16:40:40 +01002056static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002057 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002058 .channels_min = 2,
2059 .channels_max = 8,
2060 .nid = 0x10, /* NID to query formats and rates */
2061 .ops = {
2062 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002063 .prepare = via_playback_multi_pcm_prepare,
2064 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002065 },
2066};
2067
2068static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002069 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002070 .channels_min = 2,
2071 .channels_max = 4,
2072 .nid = 0x10, /* NID to query formats and rates */
2073 .ops = {
2074 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002075 .prepare = via_playback_multi_pcm_prepare,
2076 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002077 },
2078};
2079
2080static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2081 .substreams = 2,
2082 .channels_min = 2,
2083 .channels_max = 2,
2084 .nid = 0x13, /* NID to query formats and rates */
2085 .ops = {
2086 .prepare = via_capture_pcm_prepare,
2087 .cleanup = via_capture_pcm_cleanup
2088 },
2089};
2090
2091static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2092 .substreams = 1,
2093 .channels_min = 2,
2094 .channels_max = 2,
2095 /* NID is set in via_build_pcms */
2096 .ops = {
2097 .open = via_dig_playback_pcm_open,
2098 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02002099 .prepare = via_dig_playback_pcm_prepare,
2100 .cleanup = via_dig_playback_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002101 },
2102};
2103
2104static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
2105 .substreams = 1,
2106 .channels_min = 2,
2107 .channels_max = 2,
2108};
2109
2110/* fill in the dac_nids table from the parsed pin configuration */
2111static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
2112 const struct auto_pin_cfg *cfg)
2113{
2114 int i;
2115 hda_nid_t nid;
2116
2117 spec->multiout.num_dacs = cfg->line_outs;
2118
2119 spec->multiout.dac_nids = spec->private_dac_nids;
2120
2121 for (i = 0; i < 4; i++) {
2122 nid = cfg->line_out_pins[i];
2123 if (nid) {
2124 /* config dac list */
2125 switch (i) {
2126 case AUTO_SEQ_FRONT:
2127 spec->multiout.dac_nids[i] = 0x10;
2128 break;
2129 case AUTO_SEQ_CENLFE:
2130 spec->multiout.dac_nids[i] = 0x24;
2131 break;
2132 case AUTO_SEQ_SURROUND:
Harald Weltefb4cb772008-09-09 15:53:36 +08002133 spec->multiout.dac_nids[i] = 0x11;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002134 break;
2135 case AUTO_SEQ_SIDE:
Harald Weltefb4cb772008-09-09 15:53:36 +08002136 spec->multiout.dac_nids[i] = 0x25;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002137 break;
2138 }
2139 }
2140 }
2141
2142 return 0;
2143}
2144
2145/* add playback controls from the parsed DAC table */
2146static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
2147 const struct auto_pin_cfg *cfg)
2148{
2149 char name[32];
2150 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
Harald Weltefb4cb772008-09-09 15:53:36 +08002151 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
Josepch Chanf7278fd2007-12-13 16:40:40 +01002152 hda_nid_t nid, nid_vol = 0;
2153 int i, err;
2154
2155 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2156 nid = cfg->line_out_pins[i];
2157
2158 if (!nid)
2159 continue;
2160
2161 nid_vol = nid_vols[i];
2162
2163 if (i == AUTO_SEQ_CENLFE) {
2164 /* Center/LFE */
2165 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2166 "Center Playback Volume",
2167 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2168 HDA_OUTPUT));
2169 if (err < 0)
2170 return err;
2171 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2172 "LFE Playback Volume",
2173 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2174 HDA_OUTPUT));
2175 if (err < 0)
2176 return err;
2177 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2178 "Center Playback Switch",
2179 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2180 HDA_OUTPUT));
2181 if (err < 0)
2182 return err;
2183 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2184 "LFE Playback Switch",
2185 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2186 HDA_OUTPUT));
2187 if (err < 0)
2188 return err;
2189 } else if (i == AUTO_SEQ_FRONT) {
2190 /* add control to mixer index 0 */
2191 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2192 "Master Front Playback Volume",
2193 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2194 HDA_INPUT));
2195 if (err < 0)
2196 return err;
2197 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2198 "Master Front Playback Switch",
2199 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2200 HDA_INPUT));
2201 if (err < 0)
2202 return err;
2203
2204 /* add control to PW3 */
2205 sprintf(name, "%s Playback Volume", chname[i]);
2206 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2207 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2208 HDA_OUTPUT));
2209 if (err < 0)
2210 return err;
2211 sprintf(name, "%s Playback Switch", chname[i]);
2212 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2213 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2214 HDA_OUTPUT));
2215 if (err < 0)
2216 return err;
2217 } else {
2218 sprintf(name, "%s Playback Volume", chname[i]);
2219 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2220 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2221 HDA_OUTPUT));
2222 if (err < 0)
2223 return err;
2224 sprintf(name, "%s Playback Switch", chname[i]);
2225 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2226 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2227 HDA_OUTPUT));
2228 if (err < 0)
2229 return err;
2230 }
2231 }
2232
2233 return 0;
2234}
2235
2236static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2237{
2238 int err;
2239
2240 if (!pin)
2241 return 0;
2242
2243 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
2244
2245 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2246 "Headphone Playback Volume",
2247 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2248 if (err < 0)
2249 return err;
2250 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2251 "Headphone Playback Switch",
2252 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2253 if (err < 0)
2254 return err;
2255
Harald Welte0aa62ae2008-09-09 15:58:27 +08002256 create_hp_imux(spec);
2257
Josepch Chanf7278fd2007-12-13 16:40:40 +01002258 return 0;
2259}
2260
2261/* create playback/capture controls for input pins */
2262static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2263 const struct auto_pin_cfg *cfg)
2264{
2265 static char *labels[] = {
2266 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2267 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08002268 struct hda_input_mux *imux = &spec->private_imux[0];
Josepch Chanf7278fd2007-12-13 16:40:40 +01002269 int i, err, idx = 0;
2270
2271 /* for internal loopback recording select */
2272 imux->items[imux->num_items].label = "Stereo Mixer";
2273 imux->items[imux->num_items].index = idx;
2274 imux->num_items++;
2275
2276 for (i = 0; i < AUTO_PIN_LAST; i++) {
2277 if (!cfg->input_pins[i])
2278 continue;
2279
2280 switch (cfg->input_pins[i]) {
2281 case 0x1a: /* Mic */
2282 idx = 2;
2283 break;
2284
2285 case 0x1b: /* Line In */
2286 idx = 3;
2287 break;
2288
2289 case 0x1e: /* Front Mic */
2290 idx = 4;
2291 break;
2292
2293 case 0x1f: /* CD */
2294 idx = 1;
2295 break;
2296 }
2297 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2298 idx, 0x16);
2299 if (err < 0)
2300 return err;
2301 imux->items[imux->num_items].label = labels[i];
2302 imux->items[imux->num_items].index = idx;
2303 imux->num_items++;
2304 }
2305 return 0;
2306}
2307
2308static int vt1708B_parse_auto_config(struct hda_codec *codec)
2309{
2310 struct via_spec *spec = codec->spec;
2311 int err;
2312
2313 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2314 if (err < 0)
2315 return err;
2316 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
2317 if (err < 0)
2318 return err;
2319 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2320 return 0; /* can't find valid BIOS pin config */
2321
2322 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
2323 if (err < 0)
2324 return err;
2325 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2326 if (err < 0)
2327 return err;
2328 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
2329 if (err < 0)
2330 return err;
2331
2332 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2333
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002334 if (spec->autocfg.dig_outs)
Josepch Chanf7278fd2007-12-13 16:40:40 +01002335 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
Takashi Iwai55d1d6c2009-07-07 13:39:03 +02002336 spec->dig_in_pin = VT1708B_DIGIN_PIN;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002337 if (spec->autocfg.dig_in_pin)
2338 spec->dig_in_nid = VT1708B_DIGIN_NID;
2339
Takashi Iwai603c4012008-07-30 15:01:44 +02002340 if (spec->kctls.list)
2341 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002342
Harald Welte0aa62ae2008-09-09 15:58:27 +08002343 spec->input_mux = &spec->private_imux[0];
2344
Harald Weltef8fdd492008-09-15 22:41:31 +08002345 if (spec->hp_mux)
2346 spec->mixers[spec->num_mixers++] = via_hp_mixer;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002347
2348 return 1;
2349}
2350
2351#ifdef CONFIG_SND_HDA_POWER_SAVE
2352static struct hda_amp_list vt1708B_loopbacks[] = {
2353 { 0x16, HDA_INPUT, 1 },
2354 { 0x16, HDA_INPUT, 2 },
2355 { 0x16, HDA_INPUT, 3 },
2356 { 0x16, HDA_INPUT, 4 },
2357 { } /* end */
2358};
2359#endif
2360
2361static int patch_vt1708B_8ch(struct hda_codec *codec)
2362{
2363 struct via_spec *spec;
2364 int err;
2365
2366 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08002367 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002368 if (spec == NULL)
2369 return -ENOMEM;
2370
2371 codec->spec = spec;
2372
2373 /* automatic parse from the BIOS config */
2374 err = vt1708B_parse_auto_config(codec);
2375 if (err < 0) {
2376 via_free(codec);
2377 return err;
2378 } else if (!err) {
2379 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2380 "from BIOS. Using genenic mode...\n");
2381 }
2382
Harald Welte69e52a82008-09-09 15:57:32 +08002383 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
2384 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002385
2386 spec->stream_name_analog = "VT1708B Analog";
2387 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
2388 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2389
2390 spec->stream_name_digital = "VT1708B Digital";
2391 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2392 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2393
2394 if (!spec->adc_nids && spec->input_mux) {
2395 spec->adc_nids = vt1708B_adc_nids;
2396 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2397 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2398 spec->num_mixers++;
2399 }
2400
2401 codec->patch_ops = via_patch_ops;
2402
2403 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002404 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002405#ifdef CONFIG_SND_HDA_POWER_SAVE
2406 spec->loopback.amplist = vt1708B_loopbacks;
2407#endif
2408
2409 return 0;
2410}
2411
2412static int patch_vt1708B_4ch(struct hda_codec *codec)
2413{
2414 struct via_spec *spec;
2415 int err;
2416
2417 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08002418 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002419 if (spec == NULL)
2420 return -ENOMEM;
2421
2422 codec->spec = spec;
2423
2424 /* automatic parse from the BIOS config */
2425 err = vt1708B_parse_auto_config(codec);
2426 if (err < 0) {
2427 via_free(codec);
2428 return err;
2429 } else if (!err) {
2430 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2431 "from BIOS. Using genenic mode...\n");
2432 }
2433
Harald Welte69e52a82008-09-09 15:57:32 +08002434 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
2435 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002436
2437 spec->stream_name_analog = "VT1708B Analog";
2438 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
2439 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2440
2441 spec->stream_name_digital = "VT1708B Digital";
2442 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2443 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2444
2445 if (!spec->adc_nids && spec->input_mux) {
2446 spec->adc_nids = vt1708B_adc_nids;
2447 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2448 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2449 spec->num_mixers++;
2450 }
2451
2452 codec->patch_ops = via_patch_ops;
2453
2454 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002455 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002456#ifdef CONFIG_SND_HDA_POWER_SAVE
2457 spec->loopback.amplist = vt1708B_loopbacks;
2458#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002459
2460 return 0;
2461}
2462
Harald Welted949cac2008-09-09 15:56:01 +08002463/* Patch for VT1708S */
2464
Harald Welted7426322008-09-15 22:43:23 +08002465/* VT1708S software backdoor based override for buggy hardware micboost
2466 * setting */
2467#define MIC_BOOST_VOLUME(xname, nid) { \
2468 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2469 .name = xname, \
2470 .index = 0, \
2471 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2472 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2473 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2474 .info = mic_boost_volume_info, \
2475 .get = snd_hda_mixer_amp_volume_get, \
2476 .put = snd_hda_mixer_amp_volume_put, \
2477 .tlv = { .c = mic_boost_tlv }, \
2478 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2479
Harald Welted949cac2008-09-09 15:56:01 +08002480/* capture mixer elements */
2481static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2482 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2483 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2484 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2485 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
Harald Welted7426322008-09-15 22:43:23 +08002486 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2487 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
Harald Welted949cac2008-09-09 15:56:01 +08002488 {
2489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2490 /* The multiple "Capture Source" controls confuse alsamixer
2491 * So call somewhat different..
2492 */
2493 /* .name = "Capture Source", */
2494 .name = "Input Source",
2495 .count = 1,
2496 .info = via_mux_enum_info,
2497 .get = via_mux_enum_get,
2498 .put = via_mux_enum_put,
2499 },
2500 { } /* end */
2501};
2502
2503static struct hda_verb vt1708S_volume_init_verbs[] = {
2504 /* Unmute ADC0-1 and set the default input to mic-in */
2505 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2506 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2507
2508 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2509 * analog-loopback mixer widget */
2510 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2511 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2512 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2513 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2514 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2515 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2516
2517 /* Setup default input of PW4 to MW0 */
2518 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
Harald Welte5691ec72008-09-15 22:42:26 +08002519 /* PW9, PW10 Output enable */
Harald Welted949cac2008-09-09 15:56:01 +08002520 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welte5691ec72008-09-15 22:42:26 +08002521 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Harald Welted7426322008-09-15 22:43:23 +08002522 /* Enable Mic Boost Volume backdoor */
2523 {0x1, 0xf98, 0x1},
Harald Welted949cac2008-09-09 15:56:01 +08002524 { }
2525};
2526
Harald Welte69e52a82008-09-09 15:57:32 +08002527static struct hda_verb vt1708S_uniwill_init_verbs[] = {
2528 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2529 { }
2530};
2531
Harald Welted949cac2008-09-09 15:56:01 +08002532static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2533 .substreams = 2,
2534 .channels_min = 2,
2535 .channels_max = 8,
2536 .nid = 0x10, /* NID to query formats and rates */
2537 .ops = {
2538 .open = via_playback_pcm_open,
2539 .prepare = via_playback_pcm_prepare,
2540 .cleanup = via_playback_pcm_cleanup
2541 },
2542};
2543
2544static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2545 .substreams = 2,
2546 .channels_min = 2,
2547 .channels_max = 2,
2548 .nid = 0x13, /* NID to query formats and rates */
2549 .ops = {
2550 .prepare = via_capture_pcm_prepare,
2551 .cleanup = via_capture_pcm_cleanup
2552 },
2553};
2554
2555static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
Takashi Iwai9da29272009-05-07 16:31:14 +02002556 .substreams = 1,
Harald Welted949cac2008-09-09 15:56:01 +08002557 .channels_min = 2,
2558 .channels_max = 2,
2559 /* NID is set in via_build_pcms */
2560 .ops = {
2561 .open = via_dig_playback_pcm_open,
2562 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02002563 .prepare = via_dig_playback_pcm_prepare,
2564 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08002565 },
2566};
2567
2568/* fill in the dac_nids table from the parsed pin configuration */
2569static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
2570 const struct auto_pin_cfg *cfg)
2571{
2572 int i;
2573 hda_nid_t nid;
2574
2575 spec->multiout.num_dacs = cfg->line_outs;
2576
2577 spec->multiout.dac_nids = spec->private_dac_nids;
2578
2579 for (i = 0; i < 4; i++) {
2580 nid = cfg->line_out_pins[i];
2581 if (nid) {
2582 /* config dac list */
2583 switch (i) {
2584 case AUTO_SEQ_FRONT:
2585 spec->multiout.dac_nids[i] = 0x10;
2586 break;
2587 case AUTO_SEQ_CENLFE:
2588 spec->multiout.dac_nids[i] = 0x24;
2589 break;
2590 case AUTO_SEQ_SURROUND:
2591 spec->multiout.dac_nids[i] = 0x11;
2592 break;
2593 case AUTO_SEQ_SIDE:
2594 spec->multiout.dac_nids[i] = 0x25;
2595 break;
2596 }
2597 }
2598 }
2599
2600 return 0;
2601}
2602
2603/* add playback controls from the parsed DAC table */
2604static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
2605 const struct auto_pin_cfg *cfg)
2606{
2607 char name[32];
2608 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2609 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
2610 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
2611 hda_nid_t nid, nid_vol, nid_mute;
2612 int i, err;
2613
2614 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2615 nid = cfg->line_out_pins[i];
2616
2617 if (!nid)
2618 continue;
2619
2620 nid_vol = nid_vols[i];
2621 nid_mute = nid_mutes[i];
2622
2623 if (i == AUTO_SEQ_CENLFE) {
2624 /* Center/LFE */
2625 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2626 "Center Playback Volume",
2627 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2628 HDA_OUTPUT));
2629 if (err < 0)
2630 return err;
2631 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2632 "LFE Playback Volume",
2633 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2634 HDA_OUTPUT));
2635 if (err < 0)
2636 return err;
2637 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2638 "Center Playback Switch",
2639 HDA_COMPOSE_AMP_VAL(nid_mute,
2640 1, 0,
2641 HDA_OUTPUT));
2642 if (err < 0)
2643 return err;
2644 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2645 "LFE Playback Switch",
2646 HDA_COMPOSE_AMP_VAL(nid_mute,
2647 2, 0,
2648 HDA_OUTPUT));
2649 if (err < 0)
2650 return err;
2651 } else if (i == AUTO_SEQ_FRONT) {
2652 /* add control to mixer index 0 */
2653 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2654 "Master Front Playback Volume",
2655 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2656 HDA_INPUT));
2657 if (err < 0)
2658 return err;
2659 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2660 "Master Front Playback Switch",
2661 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2662 HDA_INPUT));
2663 if (err < 0)
2664 return err;
2665
2666 /* Front */
2667 sprintf(name, "%s Playback Volume", chname[i]);
2668 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2669 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2670 HDA_OUTPUT));
2671 if (err < 0)
2672 return err;
2673 sprintf(name, "%s Playback Switch", chname[i]);
2674 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2675 HDA_COMPOSE_AMP_VAL(nid_mute,
2676 3, 0,
2677 HDA_OUTPUT));
2678 if (err < 0)
2679 return err;
2680 } else {
2681 sprintf(name, "%s Playback Volume", chname[i]);
2682 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2683 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2684 HDA_OUTPUT));
2685 if (err < 0)
2686 return err;
2687 sprintf(name, "%s Playback Switch", chname[i]);
2688 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2689 HDA_COMPOSE_AMP_VAL(nid_mute,
2690 3, 0,
2691 HDA_OUTPUT));
2692 if (err < 0)
2693 return err;
2694 }
2695 }
2696
2697 return 0;
2698}
2699
2700static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2701{
2702 int err;
2703
2704 if (!pin)
2705 return 0;
2706
2707 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
2708
2709 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2710 "Headphone Playback Volume",
2711 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
2712 if (err < 0)
2713 return err;
2714
2715 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2716 "Headphone Playback Switch",
2717 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2718 if (err < 0)
2719 return err;
2720
Harald Welte0aa62ae2008-09-09 15:58:27 +08002721 create_hp_imux(spec);
2722
Harald Welted949cac2008-09-09 15:56:01 +08002723 return 0;
2724}
2725
2726/* create playback/capture controls for input pins */
2727static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2728 const struct auto_pin_cfg *cfg)
2729{
2730 static char *labels[] = {
2731 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2732 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08002733 struct hda_input_mux *imux = &spec->private_imux[0];
Harald Welted949cac2008-09-09 15:56:01 +08002734 int i, err, idx = 0;
2735
2736 /* for internal loopback recording select */
2737 imux->items[imux->num_items].label = "Stereo Mixer";
2738 imux->items[imux->num_items].index = 5;
2739 imux->num_items++;
2740
2741 for (i = 0; i < AUTO_PIN_LAST; i++) {
2742 if (!cfg->input_pins[i])
2743 continue;
2744
2745 switch (cfg->input_pins[i]) {
2746 case 0x1a: /* Mic */
2747 idx = 2;
2748 break;
2749
2750 case 0x1b: /* Line In */
2751 idx = 3;
2752 break;
2753
2754 case 0x1e: /* Front Mic */
2755 idx = 4;
2756 break;
2757
2758 case 0x1f: /* CD */
2759 idx = 1;
2760 break;
2761 }
2762 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2763 idx, 0x16);
2764 if (err < 0)
2765 return err;
2766 imux->items[imux->num_items].label = labels[i];
2767 imux->items[imux->num_items].index = idx-1;
2768 imux->num_items++;
2769 }
2770 return 0;
2771}
2772
Takashi Iwai9da29272009-05-07 16:31:14 +02002773/* fill out digital output widgets; one for master and one for slave outputs */
2774static void fill_dig_outs(struct hda_codec *codec)
2775{
2776 struct via_spec *spec = codec->spec;
2777 int i;
2778
2779 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2780 hda_nid_t nid;
2781 int conn;
2782
2783 nid = spec->autocfg.dig_out_pins[i];
2784 if (!nid)
2785 continue;
2786 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2787 if (conn < 1)
2788 continue;
2789 if (!spec->multiout.dig_out_nid)
2790 spec->multiout.dig_out_nid = nid;
2791 else {
2792 spec->slave_dig_outs[0] = nid;
2793 break; /* at most two dig outs */
2794 }
2795 }
2796}
2797
Harald Welted949cac2008-09-09 15:56:01 +08002798static int vt1708S_parse_auto_config(struct hda_codec *codec)
2799{
2800 struct via_spec *spec = codec->spec;
2801 int err;
Harald Welted949cac2008-09-09 15:56:01 +08002802
Takashi Iwai9da29272009-05-07 16:31:14 +02002803 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08002804 if (err < 0)
2805 return err;
2806 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
2807 if (err < 0)
2808 return err;
2809 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2810 return 0; /* can't find valid BIOS pin config */
2811
2812 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
2813 if (err < 0)
2814 return err;
2815 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2816 if (err < 0)
2817 return err;
2818 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
2819 if (err < 0)
2820 return err;
2821
2822 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2823
Takashi Iwai9da29272009-05-07 16:31:14 +02002824 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08002825
Takashi Iwai603c4012008-07-30 15:01:44 +02002826 if (spec->kctls.list)
2827 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08002828
Harald Welte0aa62ae2008-09-09 15:58:27 +08002829 spec->input_mux = &spec->private_imux[0];
2830
Harald Weltef8fdd492008-09-15 22:41:31 +08002831 if (spec->hp_mux)
2832 spec->mixers[spec->num_mixers++] = via_hp_mixer;
Harald Welted949cac2008-09-09 15:56:01 +08002833
2834 return 1;
2835}
2836
2837#ifdef CONFIG_SND_HDA_POWER_SAVE
2838static struct hda_amp_list vt1708S_loopbacks[] = {
2839 { 0x16, HDA_INPUT, 1 },
2840 { 0x16, HDA_INPUT, 2 },
2841 { 0x16, HDA_INPUT, 3 },
2842 { 0x16, HDA_INPUT, 4 },
2843 { } /* end */
2844};
2845#endif
2846
2847static int patch_vt1708S(struct hda_codec *codec)
2848{
2849 struct via_spec *spec;
2850 int err;
2851
2852 /* create a codec specific record */
2853 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2854 if (spec == NULL)
2855 return -ENOMEM;
2856
2857 codec->spec = spec;
2858
2859 /* automatic parse from the BIOS config */
2860 err = vt1708S_parse_auto_config(codec);
2861 if (err < 0) {
2862 via_free(codec);
2863 return err;
2864 } else if (!err) {
2865 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2866 "from BIOS. Using genenic mode...\n");
2867 }
2868
Harald Welte69e52a82008-09-09 15:57:32 +08002869 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
2870 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08002871
2872 spec->stream_name_analog = "VT1708S Analog";
2873 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2874 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2875
2876 spec->stream_name_digital = "VT1708S Digital";
2877 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
2878
2879 if (!spec->adc_nids && spec->input_mux) {
2880 spec->adc_nids = vt1708S_adc_nids;
2881 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2882 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2883 spec->num_mixers++;
2884 }
2885
2886 codec->patch_ops = via_patch_ops;
2887
2888 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002889 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08002890#ifdef CONFIG_SND_HDA_POWER_SAVE
2891 spec->loopback.amplist = vt1708S_loopbacks;
2892#endif
2893
2894 return 0;
2895}
2896
2897/* Patch for VT1702 */
2898
2899/* capture mixer elements */
2900static struct snd_kcontrol_new vt1702_capture_mixer[] = {
2901 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
2902 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
2903 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
2904 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
2905 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
2906 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
2907 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2908 HDA_INPUT),
2909 {
2910 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2911 /* The multiple "Capture Source" controls confuse alsamixer
2912 * So call somewhat different..
2913 */
2914 /* .name = "Capture Source", */
2915 .name = "Input Source",
2916 .count = 1,
2917 .info = via_mux_enum_info,
2918 .get = via_mux_enum_get,
2919 .put = via_mux_enum_put,
2920 },
2921 { } /* end */
2922};
2923
2924static struct hda_verb vt1702_volume_init_verbs[] = {
2925 /*
2926 * Unmute ADC0-1 and set the default input to mic-in
2927 */
2928 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2929 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2930 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2931
2932
2933 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2934 * mixer widget
2935 */
2936 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2937 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2938 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2939 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2940 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2941 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2942
2943 /* Setup default input of PW4 to MW0 */
2944 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
2945 /* PW6 PW7 Output enable */
2946 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2947 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2948 { }
2949};
2950
Harald Welte69e52a82008-09-09 15:57:32 +08002951static struct hda_verb vt1702_uniwill_init_verbs[] = {
2952 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
2953 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2954 { }
2955};
2956
Harald Welted949cac2008-09-09 15:56:01 +08002957static struct hda_pcm_stream vt1702_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002958 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08002959 .channels_min = 2,
2960 .channels_max = 2,
2961 .nid = 0x10, /* NID to query formats and rates */
2962 .ops = {
2963 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002964 .prepare = via_playback_multi_pcm_prepare,
2965 .cleanup = via_playback_multi_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08002966 },
2967};
2968
2969static struct hda_pcm_stream vt1702_pcm_analog_capture = {
2970 .substreams = 3,
2971 .channels_min = 2,
2972 .channels_max = 2,
2973 .nid = 0x12, /* NID to query formats and rates */
2974 .ops = {
2975 .prepare = via_capture_pcm_prepare,
2976 .cleanup = via_capture_pcm_cleanup
2977 },
2978};
2979
2980static struct hda_pcm_stream vt1702_pcm_digital_playback = {
Harald Welte5691ec72008-09-15 22:42:26 +08002981 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08002982 .channels_min = 2,
2983 .channels_max = 2,
2984 /* NID is set in via_build_pcms */
2985 .ops = {
2986 .open = via_dig_playback_pcm_open,
2987 .close = via_dig_playback_pcm_close,
Takashi Iwai9da29272009-05-07 16:31:14 +02002988 .prepare = via_dig_playback_pcm_prepare,
2989 .cleanup = via_dig_playback_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08002990 },
2991};
2992
2993/* fill in the dac_nids table from the parsed pin configuration */
2994static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
2995 const struct auto_pin_cfg *cfg)
2996{
2997 spec->multiout.num_dacs = 1;
2998 spec->multiout.dac_nids = spec->private_dac_nids;
2999
3000 if (cfg->line_out_pins[0]) {
3001 /* config dac list */
3002 spec->multiout.dac_nids[0] = 0x10;
3003 }
3004
3005 return 0;
3006}
3007
3008/* add playback controls from the parsed DAC table */
3009static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
3010 const struct auto_pin_cfg *cfg)
3011{
3012 int err;
3013
3014 if (!cfg->line_out_pins[0])
3015 return -1;
3016
3017 /* add control to mixer index 0 */
3018 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3019 "Master Front Playback Volume",
3020 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3021 if (err < 0)
3022 return err;
3023 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3024 "Master Front Playback Switch",
3025 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3026 if (err < 0)
3027 return err;
3028
3029 /* Front */
3030 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3031 "Front Playback Volume",
3032 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
3033 if (err < 0)
3034 return err;
3035 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3036 "Front Playback Switch",
3037 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
3038 if (err < 0)
3039 return err;
3040
3041 return 0;
3042}
3043
3044static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3045{
3046 int err;
3047
3048 if (!pin)
3049 return 0;
3050
3051 spec->multiout.hp_nid = 0x1D;
3052
3053 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3054 "Headphone Playback Volume",
3055 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
3056 if (err < 0)
3057 return err;
3058
3059 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3060 "Headphone Playback Switch",
3061 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3062 if (err < 0)
3063 return err;
3064
Harald Welte0aa62ae2008-09-09 15:58:27 +08003065 create_hp_imux(spec);
3066
Harald Welted949cac2008-09-09 15:56:01 +08003067 return 0;
3068}
3069
3070/* create playback/capture controls for input pins */
3071static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3072 const struct auto_pin_cfg *cfg)
3073{
3074 static char *labels[] = {
3075 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3076 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08003077 struct hda_input_mux *imux = &spec->private_imux[0];
Harald Welted949cac2008-09-09 15:56:01 +08003078 int i, err, idx = 0;
3079
3080 /* for internal loopback recording select */
3081 imux->items[imux->num_items].label = "Stereo Mixer";
3082 imux->items[imux->num_items].index = 3;
3083 imux->num_items++;
3084
3085 for (i = 0; i < AUTO_PIN_LAST; i++) {
3086 if (!cfg->input_pins[i])
3087 continue;
3088
3089 switch (cfg->input_pins[i]) {
3090 case 0x14: /* Mic */
3091 idx = 1;
3092 break;
3093
3094 case 0x15: /* Line In */
3095 idx = 2;
3096 break;
3097
3098 case 0x18: /* Front Mic */
3099 idx = 3;
3100 break;
3101 }
3102 err = via_new_analog_input(spec, cfg->input_pins[i],
3103 labels[i], idx, 0x1A);
3104 if (err < 0)
3105 return err;
3106 imux->items[imux->num_items].label = labels[i];
3107 imux->items[imux->num_items].index = idx-1;
3108 imux->num_items++;
3109 }
3110 return 0;
3111}
3112
3113static int vt1702_parse_auto_config(struct hda_codec *codec)
3114{
3115 struct via_spec *spec = codec->spec;
3116 int err;
Harald Welted949cac2008-09-09 15:56:01 +08003117
Takashi Iwai9da29272009-05-07 16:31:14 +02003118 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
Harald Welted949cac2008-09-09 15:56:01 +08003119 if (err < 0)
3120 return err;
3121 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
3122 if (err < 0)
3123 return err;
3124 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3125 return 0; /* can't find valid BIOS pin config */
3126
3127 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
3128 if (err < 0)
3129 return err;
3130 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3131 if (err < 0)
3132 return err;
3133 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3134 if (err < 0)
3135 return err;
3136
3137 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3138
Takashi Iwai9da29272009-05-07 16:31:14 +02003139 fill_dig_outs(codec);
Harald Welte98aa34c2008-09-09 16:02:09 +08003140
Takashi Iwai603c4012008-07-30 15:01:44 +02003141 if (spec->kctls.list)
3142 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Harald Welted949cac2008-09-09 15:56:01 +08003143
Harald Welte0aa62ae2008-09-09 15:58:27 +08003144 spec->input_mux = &spec->private_imux[0];
3145
Harald Weltef8fdd492008-09-15 22:41:31 +08003146 if (spec->hp_mux)
3147 spec->mixers[spec->num_mixers++] = via_hp_mixer;
Harald Welted949cac2008-09-09 15:56:01 +08003148
3149 return 1;
3150}
3151
3152#ifdef CONFIG_SND_HDA_POWER_SAVE
3153static struct hda_amp_list vt1702_loopbacks[] = {
3154 { 0x1A, HDA_INPUT, 1 },
3155 { 0x1A, HDA_INPUT, 2 },
3156 { 0x1A, HDA_INPUT, 3 },
3157 { 0x1A, HDA_INPUT, 4 },
3158 { } /* end */
3159};
3160#endif
3161
3162static int patch_vt1702(struct hda_codec *codec)
3163{
3164 struct via_spec *spec;
3165 int err;
3166 unsigned int response;
3167 unsigned char control;
3168
3169 /* create a codec specific record */
3170 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3171 if (spec == NULL)
3172 return -ENOMEM;
3173
3174 codec->spec = spec;
3175
3176 /* automatic parse from the BIOS config */
3177 err = vt1702_parse_auto_config(codec);
3178 if (err < 0) {
3179 via_free(codec);
3180 return err;
3181 } else if (!err) {
3182 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3183 "from BIOS. Using genenic mode...\n");
3184 }
3185
Harald Welte69e52a82008-09-09 15:57:32 +08003186 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
3187 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003188
3189 spec->stream_name_analog = "VT1702 Analog";
3190 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
3191 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
3192
3193 spec->stream_name_digital = "VT1702 Digital";
3194 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
3195
3196 if (!spec->adc_nids && spec->input_mux) {
3197 spec->adc_nids = vt1702_adc_nids;
3198 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
3199 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3200 spec->num_mixers++;
3201 }
3202
3203 codec->patch_ops = via_patch_ops;
3204
3205 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003206 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08003207#ifdef CONFIG_SND_HDA_POWER_SAVE
3208 spec->loopback.amplist = vt1702_loopbacks;
3209#endif
3210
3211 /* Open backdoor */
3212 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
3213 control = (unsigned char)(response & 0xff);
3214 control |= 0x3;
3215 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control);
3216
3217 /* Enable GPIO 0&1 for volume&mute control */
3218 /* Enable GPIO 2 for DMIC-DATA */
3219 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
3220 control = (unsigned char)((response >> 16) & 0x3f);
3221 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control);
3222
3223 return 0;
3224}
3225
Joseph Chanc577b8a2006-11-29 15:29:40 +01003226/*
3227 * patch entries
3228 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003229static struct hda_codec_preset snd_hda_preset_via[] = {
Takashi Iwai3218c172008-12-18 09:17:56 +01003230 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3231 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3232 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3233 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3234 { .id = 0x1106e710, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003235 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003236 { .id = 0x1106e711, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003237 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003238 { .id = 0x1106e712, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003239 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003240 { .id = 0x1106e713, .name = "VT1709 10-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003241 .patch = patch_vt1709_10ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003242 { .id = 0x1106e714, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003243 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003244 { .id = 0x1106e715, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003245 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003246 { .id = 0x1106e716, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003247 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003248 { .id = 0x1106e717, .name = "VT1709 6-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003249 .patch = patch_vt1709_6ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003250 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003251 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003252 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003253 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003254 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003255 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003256 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003257 .patch = patch_vt1708B_8ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003258 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003259 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003260 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003261 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003262 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003263 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003264 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01003265 .patch = patch_vt1708B_4ch},
Takashi Iwai3218c172008-12-18 09:17:56 +01003266 { .id = 0x11060397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003267 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003268 { .id = 0x11061397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003269 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003270 { .id = 0x11062397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003271 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003272 { .id = 0x11063397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003273 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003274 { .id = 0x11064397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003275 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003276 { .id = 0x11065397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003277 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003278 { .id = 0x11066397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003279 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003280 { .id = 0x11067397, .name = "VT1708S",
Harald Welted949cac2008-09-09 15:56:01 +08003281 .patch = patch_vt1708S},
Takashi Iwai3218c172008-12-18 09:17:56 +01003282 { .id = 0x11060398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003283 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003284 { .id = 0x11061398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003285 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003286 { .id = 0x11062398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003287 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003288 { .id = 0x11063398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003289 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003290 { .id = 0x11064398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003291 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003292 { .id = 0x11065398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003293 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003294 { .id = 0x11066398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003295 .patch = patch_vt1702},
Takashi Iwai3218c172008-12-18 09:17:56 +01003296 { .id = 0x11067398, .name = "VT1702",
Harald Welted949cac2008-09-09 15:56:01 +08003297 .patch = patch_vt1702},
Joseph Chanc577b8a2006-11-29 15:29:40 +01003298 {} /* terminator */
3299};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01003300
3301MODULE_ALIAS("snd-hda-codec-id:1106*");
3302
3303static struct hda_codec_preset_list via_list = {
3304 .preset = snd_hda_preset_via,
3305 .owner = THIS_MODULE,
3306};
3307
3308MODULE_LICENSE("GPL");
3309MODULE_DESCRIPTION("VIA HD-audio codec");
3310
3311static int __init patch_via_init(void)
3312{
3313 return snd_hda_add_codec_preset(&via_list);
3314}
3315
3316static void __exit patch_via_exit(void)
3317{
3318 snd_hda_delete_codec_preset(&via_list);
3319}
3320
3321module_init(patch_via_init)
3322module_exit(patch_via_exit)