blob: 43fb96538b806bd4aceaaac60c0eb459c7bb3afa [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 */
Joseph Chanc577b8a2006-11-29 15:29:40 +010038/* */
39/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
40
41
Joseph Chanc577b8a2006-11-29 15:29:40 +010042#include <linux/init.h>
43#include <linux/delay.h>
44#include <linux/slab.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010045#include <sound/core.h>
Harald Welte0aa62ae2008-09-09 15:58:27 +080046#include <sound/asoundef.h>
Joseph Chanc577b8a2006-11-29 15:29:40 +010047#include "hda_codec.h"
48#include "hda_local.h"
Harvey Harrison3c9a3202008-02-29 11:59:26 +010049#include "hda_patch.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
55#define NUM_CONTROL_ALLOC 32
56#define NUM_VERB_ALLOC 32
57
58/* Pin Widget NID */
59#define VT1708_HP_NID 0x13
60#define VT1708_DIGOUT_NID 0x14
61#define VT1708_DIGIN_NID 0x16
Josepch Chanf7278fd2007-12-13 16:40:40 +010062#define VT1708_DIGIN_PIN 0x26
Harald Welted949cac2008-09-09 15:56:01 +080063#define VT1708_HP_PIN_NID 0x20
64#define VT1708_CD_PIN_NID 0x24
Joseph Chanc577b8a2006-11-29 15:29:40 +010065
66#define VT1709_HP_DAC_NID 0x28
67#define VT1709_DIGOUT_NID 0x13
68#define VT1709_DIGIN_NID 0x17
Josepch Chanf7278fd2007-12-13 16:40:40 +010069#define VT1709_DIGIN_PIN 0x25
70
71#define VT1708B_HP_NID 0x25
72#define VT1708B_DIGOUT_NID 0x12
73#define VT1708B_DIGIN_NID 0x15
74#define VT1708B_DIGIN_PIN 0x21
Joseph Chanc577b8a2006-11-29 15:29:40 +010075
Harald Welted949cac2008-09-09 15:56:01 +080076#define VT1708S_HP_NID 0x25
77#define VT1708S_DIGOUT_NID 0x12
78
79#define VT1702_HP_NID 0x17
80#define VT1702_DIGOUT_NID 0x11
81
Joseph Chanc577b8a2006-11-29 15:29:40 +010082#define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
83#define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
84#define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
Josepch Chanf7278fd2007-12-13 16:40:40 +010085#define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
86#define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
Harald Welted949cac2008-09-09 15:56:01 +080087#define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
88#define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
Joseph Chanc577b8a2006-11-29 15:29:40 +010089
Harald Welte69e52a82008-09-09 15:57:32 +080090#define VIA_HP_EVENT 0x01
91#define VIA_GPIO_EVENT 0x02
92
Joseph Chanc577b8a2006-11-29 15:29:40 +010093enum {
94 VIA_CTL_WIDGET_VOL,
95 VIA_CTL_WIDGET_MUTE,
96};
97
98enum {
Harald Welteeb14a462008-09-09 15:40:38 +080099 AUTO_SEQ_FRONT = 0,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100100 AUTO_SEQ_SURROUND,
101 AUTO_SEQ_CENLFE,
102 AUTO_SEQ_SIDE
103};
104
105static struct snd_kcontrol_new vt1708_control_templates[] = {
106 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
107 HDA_CODEC_MUTE(NULL, 0, 0, 0),
108};
109
110
111struct via_spec {
112 /* codec parameterization */
113 struct snd_kcontrol_new *mixers[3];
114 unsigned int num_mixers;
115
Harald Welte69e52a82008-09-09 15:57:32 +0800116 struct hda_verb *init_verbs[5];
117 unsigned int num_iverbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100118
119 char *stream_name_analog;
120 struct hda_pcm_stream *stream_analog_playback;
121 struct hda_pcm_stream *stream_analog_capture;
122
123 char *stream_name_digital;
124 struct hda_pcm_stream *stream_digital_playback;
125 struct hda_pcm_stream *stream_digital_capture;
Harald Welte98aa34c2008-09-09 16:02:09 +0800126 struct hda_pcm_stream *stream_extra_digital_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100127
128 /* playback */
129 struct hda_multi_out multiout;
Harald Welte98aa34c2008-09-09 16:02:09 +0800130 hda_nid_t extra_dig_out_nid;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100131
132 /* capture */
133 unsigned int num_adc_nids;
134 hda_nid_t *adc_nids;
135 hda_nid_t dig_in_nid;
136
137 /* capture source */
138 const struct hda_input_mux *input_mux;
139 unsigned int cur_mux[3];
140
141 /* PCM information */
Harald Welte98aa34c2008-09-09 16:02:09 +0800142 struct hda_pcm pcm_rec[3];
Joseph Chanc577b8a2006-11-29 15:29:40 +0100143
144 /* dynamic controls, init_verbs and input_mux */
145 struct auto_pin_cfg autocfg;
146 unsigned int num_kctl_alloc, num_kctl_used;
147 struct snd_kcontrol_new *kctl_alloc;
Harald Welte0aa62ae2008-09-09 15:58:27 +0800148 struct hda_input_mux private_imux[2];
Takashi Iwai41923e42007-10-22 17:20:10 +0200149 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200150
Harald Welte0aa62ae2008-09-09 15:58:27 +0800151 /* HP mode source */
152 const struct hda_input_mux *hp_mux;
153 unsigned int hp_independent_mode;
154
Takashi Iwaicb53c622007-08-10 17:21:45 +0200155#ifdef CONFIG_SND_HDA_POWER_SAVE
156 struct hda_loopback_check loopback;
157#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +0100158};
159
160static hda_nid_t vt1708_adc_nids[2] = {
161 /* ADC1-2 */
162 0x15, 0x27
163};
164
165static hda_nid_t vt1709_adc_nids[3] = {
166 /* ADC1-2 */
167 0x14, 0x15, 0x16
168};
169
Josepch Chanf7278fd2007-12-13 16:40:40 +0100170static hda_nid_t vt1708B_adc_nids[2] = {
171 /* ADC1-2 */
172 0x13, 0x14
173};
174
Harald Welted949cac2008-09-09 15:56:01 +0800175static hda_nid_t vt1708S_adc_nids[2] = {
176 /* ADC1-2 */
177 0x13, 0x14
178};
179
180static hda_nid_t vt1702_adc_nids[3] = {
181 /* ADC1-2 */
182 0x12, 0x20, 0x1F
183};
184
Joseph Chanc577b8a2006-11-29 15:29:40 +0100185/* add dynamic controls */
186static int via_add_control(struct via_spec *spec, int type, const char *name,
187 unsigned long val)
188{
189 struct snd_kcontrol_new *knew;
190
191 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
192 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
193
194 /* array + terminator */
195 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
196 if (!knew)
197 return -ENOMEM;
198 if (spec->kctl_alloc) {
199 memcpy(knew, spec->kctl_alloc,
200 sizeof(*knew) * spec->num_kctl_alloc);
201 kfree(spec->kctl_alloc);
202 }
203 spec->kctl_alloc = knew;
204 spec->num_kctl_alloc = num;
205 }
206
207 knew = &spec->kctl_alloc[spec->num_kctl_used];
208 *knew = vt1708_control_templates[type];
209 knew->name = kstrdup(name, GFP_KERNEL);
210
211 if (!knew->name)
212 return -ENOMEM;
213 knew->private_value = val;
214 spec->num_kctl_used++;
215 return 0;
216}
217
218/* create input playback/capture controls for the given pin */
219static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
220 const char *ctlname, int idx, int mix_nid)
221{
222 char name[32];
223 int err;
224
225 sprintf(name, "%s Playback Volume", ctlname);
226 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
227 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
228 if (err < 0)
229 return err;
230 sprintf(name, "%s Playback Switch", ctlname);
231 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
232 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
233 if (err < 0)
234 return err;
235 return 0;
236}
237
238static void via_auto_set_output_and_unmute(struct hda_codec *codec,
239 hda_nid_t nid, int pin_type,
240 int dac_idx)
241{
242 /* set as output */
243 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
244 pin_type);
245 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
246 AMP_OUT_UNMUTE);
247}
248
249
250static void via_auto_init_multi_out(struct hda_codec *codec)
251{
252 struct via_spec *spec = codec->spec;
253 int i;
254
255 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
256 hda_nid_t nid = spec->autocfg.line_out_pins[i];
257 if (nid)
258 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
259 }
260}
261
262static void via_auto_init_hp_out(struct hda_codec *codec)
263{
264 struct via_spec *spec = codec->spec;
265 hda_nid_t pin;
266
267 pin = spec->autocfg.hp_pins[0];
268 if (pin) /* connect to front */
269 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
270}
271
272static void via_auto_init_analog_input(struct hda_codec *codec)
273{
274 struct via_spec *spec = codec->spec;
275 int i;
276
277 for (i = 0; i < AUTO_PIN_LAST; i++) {
278 hda_nid_t nid = spec->autocfg.input_pins[i];
279
280 snd_hda_codec_write(codec, nid, 0,
281 AC_VERB_SET_PIN_WIDGET_CONTROL,
282 (i <= AUTO_PIN_FRONT_MIC ?
283 PIN_VREF50 : PIN_IN));
284
285 }
286}
287/*
288 * input MUX handling
289 */
290static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
291 struct snd_ctl_elem_info *uinfo)
292{
293 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
294 struct via_spec *spec = codec->spec;
295 return snd_hda_input_mux_info(spec->input_mux, uinfo);
296}
297
298static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
299 struct snd_ctl_elem_value *ucontrol)
300{
301 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
302 struct via_spec *spec = codec->spec;
303 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
304
305 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
306 return 0;
307}
308
309static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
310 struct snd_ctl_elem_value *ucontrol)
311{
312 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
313 struct via_spec *spec = codec->spec;
314 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
315 unsigned int vendor_id = codec->vendor_id;
316
317 /* AIW0 lydia 060801 add for correct sw0 input select */
318 if (IS_VT1708_VENDORID(vendor_id) && (adc_idx == 0))
319 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
320 0x18, &spec->cur_mux[adc_idx]);
321 else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
Harald Welteeb14a462008-09-09 15:40:38 +0800322 IS_VT1709_6CH_VENDORID(vendor_id)) && (adc_idx == 0))
Joseph Chanc577b8a2006-11-29 15:29:40 +0100323 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
324 0x19, &spec->cur_mux[adc_idx]);
Josepch Chanf7278fd2007-12-13 16:40:40 +0100325 else if ((IS_VT1708B_8CH_VENDORID(vendor_id) ||
Harald Welteeb14a462008-09-09 15:40:38 +0800326 IS_VT1708B_4CH_VENDORID(vendor_id)) && (adc_idx == 0))
Josepch Chanf7278fd2007-12-13 16:40:40 +0100327 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
328 0x17, &spec->cur_mux[adc_idx]);
Harald Welted949cac2008-09-09 15:56:01 +0800329 else if (IS_VT1702_VENDORID(vendor_id) && (adc_idx == 0))
330 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
331 0x13, &spec->cur_mux[adc_idx]);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100332 else
333 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
334 spec->adc_nids[adc_idx],
335 &spec->cur_mux[adc_idx]);
336}
337
Harald Welte0aa62ae2008-09-09 15:58:27 +0800338static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
339 struct snd_ctl_elem_info *uinfo)
340{
341 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
342 struct via_spec *spec = codec->spec;
343 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
344}
345
346static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
347 struct snd_ctl_elem_value *ucontrol)
348{
349 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
350 struct via_spec *spec = codec->spec;
351 hda_nid_t nid = spec->autocfg.hp_pins[0];
352 unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
353 AC_VERB_GET_CONNECT_SEL,
354 0x00);
355
356 ucontrol->value.enumerated.item[0] = pinsel;
357
358 return 0;
359}
360
361static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
362 struct snd_ctl_elem_value *ucontrol)
363{
364 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
365 struct via_spec *spec = codec->spec;
366 hda_nid_t nid = spec->autocfg.hp_pins[0];
367 unsigned int pinsel = ucontrol->value.enumerated.item[0];
368 unsigned int con_nid = snd_hda_codec_read(codec, nid, 0,
369 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
370
371 if (con_nid == spec->multiout.hp_nid) {
372 if (pinsel == 0) {
373 if (!spec->hp_independent_mode) {
374 if (spec->multiout.num_dacs > 1)
375 spec->multiout.num_dacs -= 1;
376 spec->hp_independent_mode = 1;
377 }
378 } else if (pinsel == 1) {
379 if (spec->hp_independent_mode) {
380 if (spec->multiout.num_dacs > 1)
381 spec->multiout.num_dacs += 1;
382 spec->hp_independent_mode = 0;
383 }
384 }
385 } else {
386 if (pinsel == 0) {
387 if (spec->hp_independent_mode) {
388 if (spec->multiout.num_dacs > 1)
389 spec->multiout.num_dacs += 1;
390 spec->hp_independent_mode = 0;
391 }
392 } else if (pinsel == 1) {
393 if (!spec->hp_independent_mode) {
394 if (spec->multiout.num_dacs > 1)
395 spec->multiout.num_dacs -= 1;
396 spec->hp_independent_mode = 1;
397 }
398 }
399 }
400 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
401 pinsel);
402
403 if (spec->multiout.hp_nid &&
404 spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
405 snd_hda_codec_setup_stream(codec,
406 spec->multiout.hp_nid,
407 0, 0, 0);
408
409 return 0;
410}
411
412static struct snd_kcontrol_new via_hp_mixer[] = {
413 {
414 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
415 .name = "Independent HP",
416 .count = 1,
417 .info = via_independent_hp_info,
418 .get = via_independent_hp_get,
419 .put = via_independent_hp_put,
420 },
421 { } /* end */
422};
423
Joseph Chanc577b8a2006-11-29 15:29:40 +0100424/* capture mixer elements */
425static struct snd_kcontrol_new vt1708_capture_mixer[] = {
426 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
427 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
428 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
429 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
430 {
431 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
432 /* The multiple "Capture Source" controls confuse alsamixer
433 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +0100434 */
435 /* .name = "Capture Source", */
436 .name = "Input Source",
437 .count = 1,
438 .info = via_mux_enum_info,
439 .get = via_mux_enum_get,
440 .put = via_mux_enum_put,
441 },
442 { } /* end */
443};
444/*
445 * generic initialization of ADC, input mixers and output mixers
446 */
447static struct hda_verb vt1708_volume_init_verbs[] = {
448 /*
449 * Unmute ADC0-1 and set the default input to mic-in
450 */
451 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
452 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
453
454
Josepch Chanf7278fd2007-12-13 16:40:40 +0100455 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +0100456 * mixer widget
457 */
458 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +0100459 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
460 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
461 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
462 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
463 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +0100464
465 /*
466 * Set up output mixers (0x19 - 0x1b)
467 */
468 /* set vol=0 to output mixers */
469 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
470 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
471 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
472
473 /* Setup default input to PW4 */
474 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
Joseph Chanc577b8a2006-11-29 15:29:40 +0100475 /* PW9 Output enable */
476 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
Josepch Chanf7278fd2007-12-13 16:40:40 +0100477 { }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100478};
479
480static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
481 struct hda_codec *codec,
482 struct snd_pcm_substream *substream)
483{
484 struct via_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100485 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
486 hinfo);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100487}
488
489static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
490 struct hda_codec *codec,
491 unsigned int stream_tag,
492 unsigned int format,
493 struct snd_pcm_substream *substream)
494{
495 struct via_spec *spec = codec->spec;
496 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
497 stream_tag, format, substream);
498}
499
500static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
501 struct hda_codec *codec,
502 struct snd_pcm_substream *substream)
503{
504 struct via_spec *spec = codec->spec;
505 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
506}
507
Harald Welte0aa62ae2008-09-09 15:58:27 +0800508
509static void playback_multi_pcm_prep_0(struct hda_codec *codec,
510 unsigned int stream_tag,
511 unsigned int format,
512 struct snd_pcm_substream *substream)
513{
514 struct via_spec *spec = codec->spec;
515 struct hda_multi_out *mout = &spec->multiout;
516 hda_nid_t *nids = mout->dac_nids;
517 int chs = substream->runtime->channels;
518 int i;
519
520 mutex_lock(&codec->spdif_mutex);
521 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
522 if (chs == 2 &&
523 snd_hda_is_supported_format(codec, mout->dig_out_nid,
524 format) &&
525 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
526 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
527 /* turn off SPDIF once; otherwise the IEC958 bits won't
528 * be updated */
529 if (codec->spdif_ctls & AC_DIG1_ENABLE)
530 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
531 AC_VERB_SET_DIGI_CONVERT_1,
532 codec->spdif_ctls &
533 ~AC_DIG1_ENABLE & 0xff);
534 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
535 stream_tag, 0, format);
536 /* turn on again (if needed) */
537 if (codec->spdif_ctls & AC_DIG1_ENABLE)
538 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
539 AC_VERB_SET_DIGI_CONVERT_1,
540 codec->spdif_ctls & 0xff);
541 } else {
542 mout->dig_out_used = 0;
543 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
544 0, 0, 0);
545 }
546 }
547 mutex_unlock(&codec->spdif_mutex);
548
549 /* front */
550 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
551 0, format);
552
553 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
554 !spec->hp_independent_mode)
555 /* headphone out will just decode front left/right (stereo) */
556 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
557 0, format);
558
559 /* extra outputs copied from front */
560 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
561 if (mout->extra_out_nid[i])
562 snd_hda_codec_setup_stream(codec,
563 mout->extra_out_nid[i],
564 stream_tag, 0, format);
565
566 /* surrounds */
567 for (i = 1; i < mout->num_dacs; i++) {
568 if (chs >= (i + 1) * 2) /* independent out */
569 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
570 i * 2, format);
571 else /* copy front */
572 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
573 0, format);
574 }
575}
576
577static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
578 struct hda_codec *codec,
579 unsigned int stream_tag,
580 unsigned int format,
581 struct snd_pcm_substream *substream)
582{
583 struct via_spec *spec = codec->spec;
584 struct hda_multi_out *mout = &spec->multiout;
585 hda_nid_t *nids = mout->dac_nids;
586
587 if (substream->number == 0)
588 playback_multi_pcm_prep_0(codec, stream_tag, format,
589 substream);
590 else {
591 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
592 spec->hp_independent_mode)
593 snd_hda_codec_setup_stream(codec, mout->hp_nid,
594 stream_tag, 0, format);
595 }
596
597 return 0;
598}
599
600static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
601 struct hda_codec *codec,
602 struct snd_pcm_substream *substream)
603{
604 struct via_spec *spec = codec->spec;
605 struct hda_multi_out *mout = &spec->multiout;
606 hda_nid_t *nids = mout->dac_nids;
607 int i;
608
609 if (substream->number == 0) {
610 for (i = 0; i < mout->num_dacs; i++)
611 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
612
613 if (mout->hp_nid && !spec->hp_independent_mode)
614 snd_hda_codec_setup_stream(codec, mout->hp_nid,
615 0, 0, 0);
616
617 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
618 if (mout->extra_out_nid[i])
619 snd_hda_codec_setup_stream(codec,
620 mout->extra_out_nid[i],
621 0, 0, 0);
622 mutex_lock(&codec->spdif_mutex);
623 if (mout->dig_out_nid &&
624 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
625 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
626 0, 0, 0);
627 mout->dig_out_used = 0;
628 }
629 mutex_unlock(&codec->spdif_mutex);
630 } else {
631 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
632 spec->hp_independent_mode)
633 snd_hda_codec_setup_stream(codec, mout->hp_nid,
634 0, 0, 0);
635 }
636
637 return 0;
638}
639
Joseph Chanc577b8a2006-11-29 15:29:40 +0100640/*
641 * Digital out
642 */
643static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
644 struct hda_codec *codec,
645 struct snd_pcm_substream *substream)
646{
647 struct via_spec *spec = codec->spec;
648 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
649}
650
651static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
652 struct hda_codec *codec,
653 struct snd_pcm_substream *substream)
654{
655 struct via_spec *spec = codec->spec;
656 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
657}
658
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200659static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
660 struct hda_codec *codec,
661 unsigned int stream_tag,
662 unsigned int format,
663 struct snd_pcm_substream *substream)
664{
665 struct via_spec *spec = codec->spec;
666 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
667 stream_tag, format, substream);
668}
669
Harald Welte98aa34c2008-09-09 16:02:09 +0800670/* setup SPDIF output stream */
671static void setup_dig_playback_stream(struct hda_codec *codec, hda_nid_t nid,
672 unsigned int stream_tag, unsigned int format)
673{
674 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
675 if (codec->spdif_ctls & AC_DIG1_ENABLE)
676 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
677 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
678 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
679 /* turn on again (if needed) */
680 if (codec->spdif_ctls & AC_DIG1_ENABLE)
681 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
682 codec->spdif_ctls & 0xff);
683}
684
685static int via_extra_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
686 struct hda_codec *codec,
687 unsigned int stream_tag,
688 unsigned int format,
689 struct snd_pcm_substream *substream)
690{
691 struct via_spec *spec = codec->spec;
692
693 mutex_lock(&codec->spdif_mutex);
694 setup_dig_playback_stream(codec, spec->extra_dig_out_nid, stream_tag,
695 format);
696 mutex_unlock(&codec->spdif_mutex);
697 return 0;
698}
699
Joseph Chanc577b8a2006-11-29 15:29:40 +0100700/*
701 * Analog capture
702 */
703static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
704 struct hda_codec *codec,
705 unsigned int stream_tag,
706 unsigned int format,
707 struct snd_pcm_substream *substream)
708{
709 struct via_spec *spec = codec->spec;
710
711 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
712 stream_tag, 0, format);
713 return 0;
714}
715
716static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
717 struct hda_codec *codec,
718 struct snd_pcm_substream *substream)
719{
720 struct via_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100721 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Joseph Chanc577b8a2006-11-29 15:29:40 +0100722 return 0;
723}
724
725static struct hda_pcm_stream vt1708_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +0800726 .substreams = 2,
Joseph Chanc577b8a2006-11-29 15:29:40 +0100727 .channels_min = 2,
728 .channels_max = 8,
729 .nid = 0x10, /* NID to query formats and rates */
730 .ops = {
731 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +0800732 .prepare = via_playback_multi_pcm_prepare,
733 .cleanup = via_playback_multi_pcm_cleanup
Joseph Chanc577b8a2006-11-29 15:29:40 +0100734 },
735};
736
Takashi Iwaibc9b5622008-05-23 17:50:27 +0200737static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
738 .substreams = 1,
739 .channels_min = 2,
740 .channels_max = 8,
741 .nid = 0x10, /* NID to query formats and rates */
742 /* We got noisy outputs on the right channel on VT1708 when
743 * 24bit samples are used. Until any workaround is found,
744 * disable the 24bit format, so far.
745 */
746 .formats = SNDRV_PCM_FMTBIT_S16_LE,
747 .ops = {
748 .open = via_playback_pcm_open,
749 .prepare = via_playback_pcm_prepare,
750 .cleanup = via_playback_pcm_cleanup
751 },
752};
753
Joseph Chanc577b8a2006-11-29 15:29:40 +0100754static struct hda_pcm_stream vt1708_pcm_analog_capture = {
755 .substreams = 2,
756 .channels_min = 2,
757 .channels_max = 2,
758 .nid = 0x15, /* NID to query formats and rates */
759 .ops = {
760 .prepare = via_capture_pcm_prepare,
761 .cleanup = via_capture_pcm_cleanup
762 },
763};
764
765static struct hda_pcm_stream vt1708_pcm_digital_playback = {
766 .substreams = 1,
767 .channels_min = 2,
768 .channels_max = 2,
769 /* NID is set in via_build_pcms */
770 .ops = {
771 .open = via_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200772 .close = via_dig_playback_pcm_close,
773 .prepare = via_dig_playback_pcm_prepare
Joseph Chanc577b8a2006-11-29 15:29:40 +0100774 },
775};
776
777static struct hda_pcm_stream vt1708_pcm_digital_capture = {
778 .substreams = 1,
779 .channels_min = 2,
780 .channels_max = 2,
781};
782
783static int via_build_controls(struct hda_codec *codec)
784{
785 struct via_spec *spec = codec->spec;
786 int err;
787 int i;
788
789 for (i = 0; i < spec->num_mixers; i++) {
790 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
791 if (err < 0)
792 return err;
793 }
794
795 if (spec->multiout.dig_out_nid) {
796 err = snd_hda_create_spdif_out_ctls(codec,
797 spec->multiout.dig_out_nid);
798 if (err < 0)
799 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100800 err = snd_hda_create_spdif_share_sw(codec,
801 &spec->multiout);
802 if (err < 0)
803 return err;
804 spec->multiout.share_spdif = 1;
Harald Welte98aa34c2008-09-09 16:02:09 +0800805
806 if (spec->extra_dig_out_nid) {
807 err = snd_hda_create_spdif_out_ctls(codec,
808 spec->extra_dig_out_nid);
809 if (err < 0)
810 return err;
811 }
Joseph Chanc577b8a2006-11-29 15:29:40 +0100812 }
813 if (spec->dig_in_nid) {
814 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
815 if (err < 0)
816 return err;
817 }
818 return 0;
819}
820
821static int via_build_pcms(struct hda_codec *codec)
822{
823 struct via_spec *spec = codec->spec;
824 struct hda_pcm *info = spec->pcm_rec;
825
826 codec->num_pcms = 1;
827 codec->pcm_info = info;
828
829 info->name = spec->stream_name_analog;
830 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
831 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
832 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
833 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
834
835 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
836 spec->multiout.max_channels;
837
838 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
839 codec->num_pcms++;
840 info++;
841 info->name = spec->stream_name_digital;
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100842 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Joseph Chanc577b8a2006-11-29 15:29:40 +0100843 if (spec->multiout.dig_out_nid) {
844 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
845 *(spec->stream_digital_playback);
846 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
847 spec->multiout.dig_out_nid;
848 }
849 if (spec->dig_in_nid) {
850 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
851 *(spec->stream_digital_capture);
852 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
853 spec->dig_in_nid;
854 }
855 }
856
Harald Welte98aa34c2008-09-09 16:02:09 +0800857 if (spec->extra_dig_out_nid) {
858 codec->num_pcms++;
859 info++;
860 info->name = spec->stream_name_digital;
861 info->pcm_type = HDA_PCM_TYPE_HDMI;
862 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
863 *(spec->stream_extra_digital_playback);
864 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
865 spec->extra_dig_out_nid;
866 }
867
Joseph Chanc577b8a2006-11-29 15:29:40 +0100868 return 0;
869}
870
871static void via_free(struct hda_codec *codec)
872{
873 struct via_spec *spec = codec->spec;
874 unsigned int i;
875
876 if (!spec)
877 return;
878
879 if (spec->kctl_alloc) {
880 for (i = 0; i < spec->num_kctl_used; i++)
881 kfree(spec->kctl_alloc[i].name);
882 kfree(spec->kctl_alloc);
883 }
884
885 kfree(codec->spec);
886}
887
Harald Welte69e52a82008-09-09 15:57:32 +0800888/* mute internal speaker if HP is plugged */
889static void via_hp_automute(struct hda_codec *codec)
890{
891 unsigned int present;
892 struct via_spec *spec = codec->spec;
893
894 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
895 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
896 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
897 HDA_OUTPUT, 0, HDA_AMP_MUTE,
898 present ? HDA_AMP_MUTE : 0);
899}
900
901static void via_gpio_control(struct hda_codec *codec)
902{
903 unsigned int gpio_data;
904 unsigned int vol_counter;
905 unsigned int vol;
906 unsigned int master_vol;
907
908 struct via_spec *spec = codec->spec;
909
910 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
911 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
912
913 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
914 0xF84, 0) & 0x3F0000) >> 16;
915
916 vol = vol_counter & 0x1F;
917 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
918 AC_VERB_GET_AMP_GAIN_MUTE,
919 AC_AMP_GET_INPUT);
920
921 if (gpio_data == 0x02) {
922 /* unmute line out */
923 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
924 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
925
926 if (vol_counter & 0x20) {
927 /* decrease volume */
928 if (vol > master_vol)
929 vol = master_vol;
930 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
931 0, HDA_AMP_VOLMASK,
932 master_vol-vol);
933 } else {
934 /* increase volume */
935 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
936 HDA_AMP_VOLMASK,
937 ((master_vol+vol) > 0x2A) ? 0x2A :
938 (master_vol+vol));
939 }
940 } else if (!(gpio_data & 0x02)) {
941 /* mute line out */
942 snd_hda_codec_amp_stereo(codec,
943 spec->autocfg.line_out_pins[0],
944 HDA_OUTPUT, 0, HDA_AMP_MUTE,
945 HDA_AMP_MUTE);
946 }
947}
948
949/* unsolicited event for jack sensing */
950static void via_unsol_event(struct hda_codec *codec,
951 unsigned int res)
952{
953 res >>= 26;
954 if (res == VIA_HP_EVENT)
955 via_hp_automute(codec);
956 else if (res == VIA_GPIO_EVENT)
957 via_gpio_control(codec);
958}
959
Joseph Chanc577b8a2006-11-29 15:29:40 +0100960static int via_init(struct hda_codec *codec)
961{
962 struct via_spec *spec = codec->spec;
Harald Welte69e52a82008-09-09 15:57:32 +0800963 int i;
964 for (i = 0; i < spec->num_iverbs; i++)
965 snd_hda_sequence_write(codec, spec->init_verbs[i]);
966
Josepch Chanf7278fd2007-12-13 16:40:40 +0100967 /* Lydia Add for EAPD enable */
968 if (!spec->dig_in_nid) { /* No Digital In connection */
969 if (IS_VT1708_VENDORID(codec->vendor_id)) {
970 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
971 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +0100972 PIN_OUT);
Josepch Chanf7278fd2007-12-13 16:40:40 +0100973 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
974 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
975 } else if (IS_VT1709_10CH_VENDORID(codec->vendor_id) ||
976 IS_VT1709_6CH_VENDORID(codec->vendor_id)) {
977 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
978 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +0100979 PIN_OUT);
Josepch Chanf7278fd2007-12-13 16:40:40 +0100980 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
981 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
982 } else if (IS_VT1708B_8CH_VENDORID(codec->vendor_id) ||
983 IS_VT1708B_4CH_VENDORID(codec->vendor_id)) {
984 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
985 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai12b74c82008-01-15 12:39:38 +0100986 PIN_OUT);
Josepch Chanf7278fd2007-12-13 16:40:40 +0100987 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
988 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
989 }
Takashi Iwai12b74c82008-01-15 12:39:38 +0100990 } else /* enable SPDIF-input pin */
991 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
992 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
Josepch Chanf7278fd2007-12-13 16:40:40 +0100993
Joseph Chanc577b8a2006-11-29 15:29:40 +0100994 return 0;
995}
996
Takashi Iwaicb53c622007-08-10 17:21:45 +0200997#ifdef CONFIG_SND_HDA_POWER_SAVE
998static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
999{
1000 struct via_spec *spec = codec->spec;
1001 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1002}
1003#endif
1004
Joseph Chanc577b8a2006-11-29 15:29:40 +01001005/*
1006 */
1007static struct hda_codec_ops via_patch_ops = {
1008 .build_controls = via_build_controls,
1009 .build_pcms = via_build_pcms,
1010 .init = via_init,
1011 .free = via_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02001012#ifdef CONFIG_SND_HDA_POWER_SAVE
1013 .check_power_status = via_check_power_status,
1014#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001015};
1016
1017/* fill in the dac_nids table from the parsed pin configuration */
1018static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1019 const struct auto_pin_cfg *cfg)
1020{
1021 int i;
1022 hda_nid_t nid;
1023
1024 spec->multiout.num_dacs = cfg->line_outs;
1025
1026 spec->multiout.dac_nids = spec->private_dac_nids;
1027
1028 for(i = 0; i < 4; i++) {
1029 nid = cfg->line_out_pins[i];
1030 if (nid) {
1031 /* config dac list */
1032 switch (i) {
1033 case AUTO_SEQ_FRONT:
1034 spec->multiout.dac_nids[i] = 0x10;
1035 break;
1036 case AUTO_SEQ_CENLFE:
1037 spec->multiout.dac_nids[i] = 0x12;
1038 break;
1039 case AUTO_SEQ_SURROUND:
Harald Weltefb4cb772008-09-09 15:53:36 +08001040 spec->multiout.dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001041 break;
1042 case AUTO_SEQ_SIDE:
Harald Weltefb4cb772008-09-09 15:53:36 +08001043 spec->multiout.dac_nids[i] = 0x13;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001044 break;
1045 }
1046 }
1047 }
1048
1049 return 0;
1050}
1051
1052/* add playback controls from the parsed DAC table */
1053static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1054 const struct auto_pin_cfg *cfg)
1055{
1056 char name[32];
1057 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1058 hda_nid_t nid, nid_vol = 0;
1059 int i, err;
1060
1061 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1062 nid = cfg->line_out_pins[i];
1063
1064 if (!nid)
1065 continue;
1066
1067 if (i != AUTO_SEQ_FRONT)
Harald Weltefb4cb772008-09-09 15:53:36 +08001068 nid_vol = 0x18 + i;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001069
1070 if (i == AUTO_SEQ_CENLFE) {
1071 /* Center/LFE */
1072 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001073 "Center Playback Volume",
1074 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1075 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001076 if (err < 0)
1077 return err;
1078 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1079 "LFE Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001080 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1081 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001082 if (err < 0)
1083 return err;
1084 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1085 "Center Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001086 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1087 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001088 if (err < 0)
1089 return err;
1090 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1091 "LFE Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001092 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1093 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001094 if (err < 0)
1095 return err;
1096 } else if (i == AUTO_SEQ_FRONT){
1097 /* add control to mixer index 0 */
1098 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1099 "Master Front Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001100 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1101 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001102 if (err < 0)
1103 return err;
1104 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1105 "Master Front Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001106 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1107 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001108 if (err < 0)
1109 return err;
1110
1111 /* add control to PW3 */
1112 sprintf(name, "%s Playback Volume", chname[i]);
1113 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001114 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1115 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001116 if (err < 0)
1117 return err;
1118 sprintf(name, "%s Playback Switch", chname[i]);
1119 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001120 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1121 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001122 if (err < 0)
1123 return err;
1124 } else {
1125 sprintf(name, "%s Playback Volume", chname[i]);
1126 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001127 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1128 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001129 if (err < 0)
1130 return err;
1131 sprintf(name, "%s Playback Switch", chname[i]);
1132 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001133 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1134 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001135 if (err < 0)
1136 return err;
1137 }
1138 }
1139
1140 return 0;
1141}
1142
Harald Welte0aa62ae2008-09-09 15:58:27 +08001143static void create_hp_imux(struct via_spec *spec)
1144{
1145 int i;
1146 struct hda_input_mux *imux = &spec->private_imux[1];
1147 static const char *texts[] = { "OFF", "ON", NULL};
1148
1149 /* for hp mode select */
1150 i = 0;
1151 while (texts[i] != NULL) {
1152 imux->items[imux->num_items].label = texts[i];
1153 imux->items[imux->num_items].index = i;
1154 imux->num_items++;
1155 i++;
1156 }
1157
1158 spec->hp_mux = &spec->private_imux[1];
1159}
1160
Joseph Chanc577b8a2006-11-29 15:29:40 +01001161static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1162{
1163 int err;
1164
1165 if (!pin)
1166 return 0;
1167
1168 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1169
1170 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1171 "Headphone Playback Volume",
1172 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1173 if (err < 0)
1174 return err;
1175 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1176 "Headphone Playback Switch",
1177 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1178 if (err < 0)
1179 return err;
1180
Harald Welte0aa62ae2008-09-09 15:58:27 +08001181 create_hp_imux(spec);
1182
Joseph Chanc577b8a2006-11-29 15:29:40 +01001183 return 0;
1184}
1185
1186/* create playback/capture controls for input pins */
1187static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1188 const struct auto_pin_cfg *cfg)
1189{
1190 static char *labels[] = {
1191 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1192 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08001193 struct hda_input_mux *imux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001194 int i, err, idx = 0;
1195
1196 /* for internal loopback recording select */
1197 imux->items[imux->num_items].label = "Stereo Mixer";
1198 imux->items[imux->num_items].index = idx;
1199 imux->num_items++;
1200
1201 for (i = 0; i < AUTO_PIN_LAST; i++) {
1202 if (!cfg->input_pins[i])
1203 continue;
1204
1205 switch (cfg->input_pins[i]) {
1206 case 0x1d: /* Mic */
1207 idx = 2;
1208 break;
1209
1210 case 0x1e: /* Line In */
1211 idx = 3;
1212 break;
1213
1214 case 0x21: /* Front Mic */
1215 idx = 4;
1216 break;
1217
1218 case 0x24: /* CD */
1219 idx = 1;
1220 break;
1221 }
1222 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1223 idx, 0x17);
1224 if (err < 0)
1225 return err;
1226 imux->items[imux->num_items].label = labels[i];
1227 imux->items[imux->num_items].index = idx;
1228 imux->num_items++;
1229 }
1230 return 0;
1231}
1232
Takashi Iwaicb53c622007-08-10 17:21:45 +02001233#ifdef CONFIG_SND_HDA_POWER_SAVE
1234static struct hda_amp_list vt1708_loopbacks[] = {
1235 { 0x17, HDA_INPUT, 1 },
1236 { 0x17, HDA_INPUT, 2 },
1237 { 0x17, HDA_INPUT, 3 },
1238 { 0x17, HDA_INPUT, 4 },
1239 { } /* end */
1240};
1241#endif
1242
Harald Welte76d9b0d2008-09-09 15:50:37 +08001243static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1244{
1245 unsigned int def_conf;
1246 unsigned char seqassoc;
1247
1248 def_conf = snd_hda_codec_read(codec, nid, 0,
1249 AC_VERB_GET_CONFIG_DEFAULT, 0);
1250 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1251 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1252 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
1253 if (seqassoc == 0xff) {
1254 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1255 snd_hda_codec_write(codec, nid, 0,
1256 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1257 def_conf >> 24);
1258 }
1259 }
1260
1261 return;
1262}
1263
Joseph Chanc577b8a2006-11-29 15:29:40 +01001264static int vt1708_parse_auto_config(struct hda_codec *codec)
1265{
1266 struct via_spec *spec = codec->spec;
1267 int err;
1268
Harald Welte76d9b0d2008-09-09 15:50:37 +08001269 /* Add HP and CD pin config connect bit re-config action */
1270 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
1271 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
1272
Joseph Chanc577b8a2006-11-29 15:29:40 +01001273 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1274 if (err < 0)
1275 return err;
1276 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
1277 if (err < 0)
1278 return err;
1279 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1280 return 0; /* can't find valid BIOS pin config */
1281
1282 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
1283 if (err < 0)
1284 return err;
1285 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1286 if (err < 0)
1287 return err;
1288 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1289 if (err < 0)
1290 return err;
1291
1292 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1293
1294 if (spec->autocfg.dig_out_pin)
1295 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
1296 if (spec->autocfg.dig_in_pin)
1297 spec->dig_in_nid = VT1708_DIGIN_NID;
1298
1299 if (spec->kctl_alloc)
1300 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1301
Harald Welte69e52a82008-09-09 15:57:32 +08001302 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001303
Harald Welte0aa62ae2008-09-09 15:58:27 +08001304 spec->input_mux = &spec->private_imux[0];
1305
Harald Weltef8fdd492008-09-15 22:41:31 +08001306 if (spec->hp_mux)
1307 spec->mixers[spec->num_mixers++] = via_hp_mixer;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001308
1309 return 1;
1310}
1311
1312/* init callback for auto-configuration model -- overriding the default init */
1313static int via_auto_init(struct hda_codec *codec)
1314{
1315 via_init(codec);
1316 via_auto_init_multi_out(codec);
1317 via_auto_init_hp_out(codec);
1318 via_auto_init_analog_input(codec);
1319 return 0;
1320}
1321
1322static int patch_vt1708(struct hda_codec *codec)
1323{
1324 struct via_spec *spec;
1325 int err;
1326
1327 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08001328 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001329 if (spec == NULL)
1330 return -ENOMEM;
1331
1332 codec->spec = spec;
1333
1334 /* automatic parse from the BIOS config */
1335 err = vt1708_parse_auto_config(codec);
1336 if (err < 0) {
1337 via_free(codec);
1338 return err;
1339 } else if (!err) {
1340 printk(KERN_INFO "hda_codec: Cannot set up configuration "
1341 "from BIOS. Using genenic mode...\n");
1342 }
1343
1344
1345 spec->stream_name_analog = "VT1708 Analog";
1346 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
Takashi Iwaibc9b5622008-05-23 17:50:27 +02001347 /* disable 32bit format on VT1708 */
1348 if (codec->vendor_id == 0x11061708)
1349 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001350 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
1351
1352 spec->stream_name_digital = "VT1708 Digital";
1353 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1354 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1355
1356
1357 if (!spec->adc_nids && spec->input_mux) {
1358 spec->adc_nids = vt1708_adc_nids;
1359 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
1360 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
1361 spec->num_mixers++;
1362 }
1363
1364 codec->patch_ops = via_patch_ops;
1365
1366 codec->patch_ops.init = via_auto_init;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001367#ifdef CONFIG_SND_HDA_POWER_SAVE
1368 spec->loopback.amplist = vt1708_loopbacks;
1369#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001370
1371 return 0;
1372}
1373
1374/* capture mixer elements */
1375static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1376 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
1377 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
1378 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
1379 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
1380 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
1381 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
1382 {
1383 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1384 /* The multiple "Capture Source" controls confuse alsamixer
1385 * So call somewhat different..
Joseph Chanc577b8a2006-11-29 15:29:40 +01001386 */
1387 /* .name = "Capture Source", */
1388 .name = "Input Source",
1389 .count = 1,
1390 .info = via_mux_enum_info,
1391 .get = via_mux_enum_get,
1392 .put = via_mux_enum_put,
1393 },
1394 { } /* end */
1395};
1396
Harald Welte69e52a82008-09-09 15:57:32 +08001397static struct hda_verb vt1709_uniwill_init_verbs[] = {
1398 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
1399 { }
1400};
1401
Joseph Chanc577b8a2006-11-29 15:29:40 +01001402/*
1403 * generic initialization of ADC, input mixers and output mixers
1404 */
1405static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1406 /*
1407 * Unmute ADC0-2 and set the default input to mic-in
1408 */
1409 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1410 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1411 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1412
1413
Josepch Chanf7278fd2007-12-13 16:40:40 +01001414 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
Joseph Chanc577b8a2006-11-29 15:29:40 +01001415 * mixer widget
1416 */
1417 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
Josepch Chanf7278fd2007-12-13 16:40:40 +01001418 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1419 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1420 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1421 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1422 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001423
1424 /*
1425 * Set up output selector (0x1a, 0x1b, 0x29)
1426 */
1427 /* set vol=0 to output mixers */
1428 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1429 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1430 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1431
1432 /*
1433 * Unmute PW3 and PW4
1434 */
1435 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1436 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1437
1438 /* Set input of PW4 as AOW4 */
1439 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001440 /* PW9 Output enable */
1441 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1442 { }
1443};
1444
1445static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1446 .substreams = 1,
1447 .channels_min = 2,
1448 .channels_max = 10,
1449 .nid = 0x10, /* NID to query formats and rates */
1450 .ops = {
1451 .open = via_playback_pcm_open,
1452 .prepare = via_playback_pcm_prepare,
1453 .cleanup = via_playback_pcm_cleanup
1454 },
1455};
1456
1457static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1458 .substreams = 1,
1459 .channels_min = 2,
1460 .channels_max = 6,
1461 .nid = 0x10, /* NID to query formats and rates */
1462 .ops = {
1463 .open = via_playback_pcm_open,
1464 .prepare = via_playback_pcm_prepare,
1465 .cleanup = via_playback_pcm_cleanup
1466 },
1467};
1468
1469static struct hda_pcm_stream vt1709_pcm_analog_capture = {
1470 .substreams = 2,
1471 .channels_min = 2,
1472 .channels_max = 2,
1473 .nid = 0x14, /* NID to query formats and rates */
1474 .ops = {
1475 .prepare = via_capture_pcm_prepare,
1476 .cleanup = via_capture_pcm_cleanup
1477 },
1478};
1479
1480static struct hda_pcm_stream vt1709_pcm_digital_playback = {
1481 .substreams = 1,
1482 .channels_min = 2,
1483 .channels_max = 2,
1484 /* NID is set in via_build_pcms */
1485 .ops = {
1486 .open = via_dig_playback_pcm_open,
1487 .close = via_dig_playback_pcm_close
1488 },
1489};
1490
1491static struct hda_pcm_stream vt1709_pcm_digital_capture = {
1492 .substreams = 1,
1493 .channels_min = 2,
1494 .channels_max = 2,
1495};
1496
1497static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1498 const struct auto_pin_cfg *cfg)
1499{
1500 int i;
1501 hda_nid_t nid;
1502
1503 if (cfg->line_outs == 4) /* 10 channels */
1504 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
1505 else if (cfg->line_outs == 3) /* 6 channels */
1506 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
1507
1508 spec->multiout.dac_nids = spec->private_dac_nids;
1509
1510 if (cfg->line_outs == 4) { /* 10 channels */
1511 for (i = 0; i < cfg->line_outs; i++) {
1512 nid = cfg->line_out_pins[i];
1513 if (nid) {
1514 /* config dac list */
1515 switch (i) {
1516 case AUTO_SEQ_FRONT:
1517 /* AOW0 */
1518 spec->multiout.dac_nids[i] = 0x10;
1519 break;
1520 case AUTO_SEQ_CENLFE:
1521 /* AOW2 */
1522 spec->multiout.dac_nids[i] = 0x12;
1523 break;
1524 case AUTO_SEQ_SURROUND:
1525 /* AOW3 */
Harald Weltefb4cb772008-09-09 15:53:36 +08001526 spec->multiout.dac_nids[i] = 0x11;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001527 break;
1528 case AUTO_SEQ_SIDE:
1529 /* AOW1 */
Harald Weltefb4cb772008-09-09 15:53:36 +08001530 spec->multiout.dac_nids[i] = 0x27;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001531 break;
1532 default:
1533 break;
1534 }
1535 }
1536 }
1537 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1538
1539 } else if (cfg->line_outs == 3) { /* 6 channels */
1540 for(i = 0; i < cfg->line_outs; i++) {
1541 nid = cfg->line_out_pins[i];
1542 if (nid) {
1543 /* config dac list */
1544 switch(i) {
1545 case AUTO_SEQ_FRONT:
1546 /* AOW0 */
1547 spec->multiout.dac_nids[i] = 0x10;
1548 break;
1549 case AUTO_SEQ_CENLFE:
1550 /* AOW2 */
1551 spec->multiout.dac_nids[i] = 0x12;
1552 break;
1553 case AUTO_SEQ_SURROUND:
1554 /* AOW1 */
1555 spec->multiout.dac_nids[i] = 0x11;
1556 break;
1557 default:
1558 break;
1559 }
1560 }
1561 }
1562 }
1563
1564 return 0;
1565}
1566
1567/* add playback controls from the parsed DAC table */
1568static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1569 const struct auto_pin_cfg *cfg)
1570{
1571 char name[32];
1572 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1573 hda_nid_t nid = 0;
1574 int i, err;
1575
1576 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1577 nid = cfg->line_out_pins[i];
1578
1579 if (!nid)
1580 continue;
1581
1582 if (i == AUTO_SEQ_CENLFE) {
1583 /* Center/LFE */
1584 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1585 "Center Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001586 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1587 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001588 if (err < 0)
1589 return err;
1590 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1591 "LFE Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001592 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1593 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001594 if (err < 0)
1595 return err;
1596 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1597 "Center Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001598 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1599 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001600 if (err < 0)
1601 return err;
1602 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1603 "LFE Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001604 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1605 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001606 if (err < 0)
1607 return err;
1608 } else if (i == AUTO_SEQ_FRONT){
1609 /* add control to mixer index 0 */
1610 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1611 "Master Front Playback Volume",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001612 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1613 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001614 if (err < 0)
1615 return err;
1616 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1617 "Master Front Playback Switch",
Josepch Chanf7278fd2007-12-13 16:40:40 +01001618 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1619 HDA_INPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001620 if (err < 0)
1621 return err;
1622
1623 /* add control to PW3 */
1624 sprintf(name, "%s Playback Volume", chname[i]);
1625 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001626 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1627 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001628 if (err < 0)
1629 return err;
1630 sprintf(name, "%s Playback Switch", chname[i]);
1631 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001632 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1633 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001634 if (err < 0)
1635 return err;
1636 } else if (i == AUTO_SEQ_SURROUND) {
1637 sprintf(name, "%s Playback Volume", chname[i]);
1638 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Harald Weltefb4cb772008-09-09 15:53:36 +08001639 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001640 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001641 if (err < 0)
1642 return err;
1643 sprintf(name, "%s Playback Switch", chname[i]);
1644 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Harald Weltefb4cb772008-09-09 15:53:36 +08001645 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001646 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001647 if (err < 0)
1648 return err;
1649 } else if (i == AUTO_SEQ_SIDE) {
1650 sprintf(name, "%s Playback Volume", chname[i]);
1651 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
Harald Weltefb4cb772008-09-09 15:53:36 +08001652 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001653 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001654 if (err < 0)
1655 return err;
1656 sprintf(name, "%s Playback Switch", chname[i]);
1657 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
Harald Weltefb4cb772008-09-09 15:53:36 +08001658 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
Josepch Chanf7278fd2007-12-13 16:40:40 +01001659 HDA_OUTPUT));
Joseph Chanc577b8a2006-11-29 15:29:40 +01001660 if (err < 0)
1661 return err;
1662 }
1663 }
1664
1665 return 0;
1666}
1667
1668static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1669{
1670 int err;
1671
1672 if (!pin)
1673 return 0;
1674
1675 if (spec->multiout.num_dacs == 5) /* 10 channels */
1676 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1677 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1678 spec->multiout.hp_nid = 0;
1679
1680 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1681 "Headphone Playback Volume",
1682 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1683 if (err < 0)
1684 return err;
1685 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1686 "Headphone Playback Switch",
1687 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1688 if (err < 0)
1689 return err;
1690
1691 return 0;
1692}
1693
1694/* create playback/capture controls for input pins */
1695static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1696 const struct auto_pin_cfg *cfg)
1697{
1698 static char *labels[] = {
1699 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1700 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08001701 struct hda_input_mux *imux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001702 int i, err, idx = 0;
1703
1704 /* for internal loopback recording select */
1705 imux->items[imux->num_items].label = "Stereo Mixer";
1706 imux->items[imux->num_items].index = idx;
1707 imux->num_items++;
1708
1709 for (i = 0; i < AUTO_PIN_LAST; i++) {
1710 if (!cfg->input_pins[i])
1711 continue;
1712
1713 switch (cfg->input_pins[i]) {
1714 case 0x1d: /* Mic */
1715 idx = 2;
1716 break;
1717
1718 case 0x1e: /* Line In */
1719 idx = 3;
1720 break;
1721
1722 case 0x21: /* Front Mic */
1723 idx = 4;
1724 break;
1725
1726 case 0x23: /* CD */
1727 idx = 1;
1728 break;
1729 }
1730 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1731 idx, 0x18);
1732 if (err < 0)
1733 return err;
1734 imux->items[imux->num_items].label = labels[i];
1735 imux->items[imux->num_items].index = idx;
1736 imux->num_items++;
1737 }
1738 return 0;
1739}
1740
1741static int vt1709_parse_auto_config(struct hda_codec *codec)
1742{
1743 struct via_spec *spec = codec->spec;
1744 int err;
1745
1746 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1747 if (err < 0)
1748 return err;
1749 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
1750 if (err < 0)
1751 return err;
1752 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1753 return 0; /* can't find valid BIOS pin config */
1754
1755 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
1756 if (err < 0)
1757 return err;
1758 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1759 if (err < 0)
1760 return err;
1761 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
1762 if (err < 0)
1763 return err;
1764
1765 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1766
1767 if (spec->autocfg.dig_out_pin)
1768 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
1769 if (spec->autocfg.dig_in_pin)
1770 spec->dig_in_nid = VT1709_DIGIN_NID;
1771
1772 if (spec->kctl_alloc)
1773 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1774
Harald Welte0aa62ae2008-09-09 15:58:27 +08001775 spec->input_mux = &spec->private_imux[0];
Joseph Chanc577b8a2006-11-29 15:29:40 +01001776
Harald Weltef8fdd492008-09-15 22:41:31 +08001777 if (spec->hp_mux)
1778 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1779
Joseph Chanc577b8a2006-11-29 15:29:40 +01001780 return 1;
1781}
1782
Takashi Iwaicb53c622007-08-10 17:21:45 +02001783#ifdef CONFIG_SND_HDA_POWER_SAVE
1784static struct hda_amp_list vt1709_loopbacks[] = {
1785 { 0x18, HDA_INPUT, 1 },
1786 { 0x18, HDA_INPUT, 2 },
1787 { 0x18, HDA_INPUT, 3 },
1788 { 0x18, HDA_INPUT, 4 },
1789 { } /* end */
1790};
1791#endif
1792
Joseph Chanc577b8a2006-11-29 15:29:40 +01001793static int patch_vt1709_10ch(struct hda_codec *codec)
1794{
1795 struct via_spec *spec;
1796 int err;
1797
1798 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08001799 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001800 if (spec == NULL)
1801 return -ENOMEM;
1802
1803 codec->spec = spec;
1804
1805 err = vt1709_parse_auto_config(codec);
1806 if (err < 0) {
1807 via_free(codec);
1808 return err;
1809 } else if (!err) {
1810 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1811 "Using genenic mode...\n");
1812 }
1813
Harald Welte69e52a82008-09-09 15:57:32 +08001814 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
1815 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001816
1817 spec->stream_name_analog = "VT1709 Analog";
1818 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
1819 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1820
1821 spec->stream_name_digital = "VT1709 Digital";
1822 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1823 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1824
1825
1826 if (!spec->adc_nids && spec->input_mux) {
1827 spec->adc_nids = vt1709_adc_nids;
1828 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1829 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1830 spec->num_mixers++;
1831 }
1832
1833 codec->patch_ops = via_patch_ops;
1834
1835 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08001836 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001837#ifdef CONFIG_SND_HDA_POWER_SAVE
1838 spec->loopback.amplist = vt1709_loopbacks;
1839#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01001840
1841 return 0;
1842}
1843/*
1844 * generic initialization of ADC, input mixers and output mixers
1845 */
1846static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
1847 /*
1848 * Unmute ADC0-2 and set the default input to mic-in
1849 */
1850 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1851 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1852 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1853
1854
1855 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1856 * mixer widget
1857 */
1858 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1859 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1860 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1861 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1862 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1863 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1864
1865 /*
1866 * Set up output selector (0x1a, 0x1b, 0x29)
1867 */
1868 /* set vol=0 to output mixers */
1869 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1870 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1871 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1872
1873 /*
1874 * Unmute PW3 and PW4
1875 */
1876 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1877 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1878
1879 /* Set input of PW4 as MW0 */
1880 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
Joseph Chanc577b8a2006-11-29 15:29:40 +01001881 /* PW9 Output enable */
1882 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1883 { }
1884};
1885
1886static int patch_vt1709_6ch(struct hda_codec *codec)
1887{
1888 struct via_spec *spec;
1889 int err;
1890
1891 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08001892 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Joseph Chanc577b8a2006-11-29 15:29:40 +01001893 if (spec == NULL)
1894 return -ENOMEM;
1895
1896 codec->spec = spec;
1897
1898 err = vt1709_parse_auto_config(codec);
1899 if (err < 0) {
1900 via_free(codec);
1901 return err;
1902 } else if (!err) {
1903 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1904 "Using genenic mode...\n");
1905 }
1906
Harald Welte69e52a82008-09-09 15:57:32 +08001907 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
1908 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
Joseph Chanc577b8a2006-11-29 15:29:40 +01001909
1910 spec->stream_name_analog = "VT1709 Analog";
1911 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
1912 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1913
1914 spec->stream_name_digital = "VT1709 Digital";
1915 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1916 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1917
1918
1919 if (!spec->adc_nids && spec->input_mux) {
1920 spec->adc_nids = vt1709_adc_nids;
1921 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1922 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1923 spec->num_mixers++;
1924 }
1925
1926 codec->patch_ops = via_patch_ops;
1927
1928 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08001929 codec->patch_ops.unsol_event = via_unsol_event;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001930#ifdef CONFIG_SND_HDA_POWER_SAVE
1931 spec->loopback.amplist = vt1709_loopbacks;
1932#endif
Josepch Chanf7278fd2007-12-13 16:40:40 +01001933 return 0;
1934}
1935
1936/* capture mixer elements */
1937static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
1938 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
1939 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
1940 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
1941 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
1942 {
1943 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1944 /* The multiple "Capture Source" controls confuse alsamixer
1945 * So call somewhat different..
Josepch Chanf7278fd2007-12-13 16:40:40 +01001946 */
1947 /* .name = "Capture Source", */
1948 .name = "Input Source",
1949 .count = 1,
1950 .info = via_mux_enum_info,
1951 .get = via_mux_enum_get,
1952 .put = via_mux_enum_put,
1953 },
1954 { } /* end */
1955};
1956/*
1957 * generic initialization of ADC, input mixers and output mixers
1958 */
1959static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
1960 /*
1961 * Unmute ADC0-1 and set the default input to mic-in
1962 */
1963 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1964 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1965
1966
1967 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1968 * mixer widget
1969 */
1970 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1971 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1972 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1973 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1974 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1975 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1976
1977 /*
1978 * Set up output mixers
1979 */
1980 /* set vol=0 to output mixers */
1981 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1982 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1983 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1984
1985 /* Setup default input to PW4 */
1986 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
1987 /* PW9 Output enable */
1988 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1989 /* PW10 Input enable */
1990 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
1991 { }
1992};
1993
1994static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
1995 /*
1996 * Unmute ADC0-1 and set the default input to mic-in
1997 */
1998 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1999 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2000
2001
2002 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2003 * mixer widget
2004 */
2005 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2006 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2007 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2008 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2009 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2010 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2011
2012 /*
2013 * Set up output mixers
2014 */
2015 /* set vol=0 to output mixers */
2016 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2017 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2018 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2019
2020 /* Setup default input of PW4 to MW0 */
2021 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2022 /* PW9 Output enable */
2023 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2024 /* PW10 Input enable */
2025 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2026 { }
2027};
2028
Harald Welte69e52a82008-09-09 15:57:32 +08002029static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2030 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2031 { }
2032};
2033
Josepch Chanf7278fd2007-12-13 16:40:40 +01002034static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002035 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002036 .channels_min = 2,
2037 .channels_max = 8,
2038 .nid = 0x10, /* NID to query formats and rates */
2039 .ops = {
2040 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002041 .prepare = via_playback_multi_pcm_prepare,
2042 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002043 },
2044};
2045
2046static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002047 .substreams = 2,
Josepch Chanf7278fd2007-12-13 16:40:40 +01002048 .channels_min = 2,
2049 .channels_max = 4,
2050 .nid = 0x10, /* NID to query formats and rates */
2051 .ops = {
2052 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002053 .prepare = via_playback_multi_pcm_prepare,
2054 .cleanup = via_playback_multi_pcm_cleanup
Josepch Chanf7278fd2007-12-13 16:40:40 +01002055 },
2056};
2057
2058static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2059 .substreams = 2,
2060 .channels_min = 2,
2061 .channels_max = 2,
2062 .nid = 0x13, /* NID to query formats and rates */
2063 .ops = {
2064 .prepare = via_capture_pcm_prepare,
2065 .cleanup = via_capture_pcm_cleanup
2066 },
2067};
2068
2069static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2070 .substreams = 1,
2071 .channels_min = 2,
2072 .channels_max = 2,
2073 /* NID is set in via_build_pcms */
2074 .ops = {
2075 .open = via_dig_playback_pcm_open,
2076 .close = via_dig_playback_pcm_close,
2077 .prepare = via_dig_playback_pcm_prepare
2078 },
2079};
2080
2081static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
2082 .substreams = 1,
2083 .channels_min = 2,
2084 .channels_max = 2,
2085};
2086
2087/* fill in the dac_nids table from the parsed pin configuration */
2088static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
2089 const struct auto_pin_cfg *cfg)
2090{
2091 int i;
2092 hda_nid_t nid;
2093
2094 spec->multiout.num_dacs = cfg->line_outs;
2095
2096 spec->multiout.dac_nids = spec->private_dac_nids;
2097
2098 for (i = 0; i < 4; i++) {
2099 nid = cfg->line_out_pins[i];
2100 if (nid) {
2101 /* config dac list */
2102 switch (i) {
2103 case AUTO_SEQ_FRONT:
2104 spec->multiout.dac_nids[i] = 0x10;
2105 break;
2106 case AUTO_SEQ_CENLFE:
2107 spec->multiout.dac_nids[i] = 0x24;
2108 break;
2109 case AUTO_SEQ_SURROUND:
Harald Weltefb4cb772008-09-09 15:53:36 +08002110 spec->multiout.dac_nids[i] = 0x11;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002111 break;
2112 case AUTO_SEQ_SIDE:
Harald Weltefb4cb772008-09-09 15:53:36 +08002113 spec->multiout.dac_nids[i] = 0x25;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002114 break;
2115 }
2116 }
2117 }
2118
2119 return 0;
2120}
2121
2122/* add playback controls from the parsed DAC table */
2123static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
2124 const struct auto_pin_cfg *cfg)
2125{
2126 char name[32];
2127 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
Harald Weltefb4cb772008-09-09 15:53:36 +08002128 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
Josepch Chanf7278fd2007-12-13 16:40:40 +01002129 hda_nid_t nid, nid_vol = 0;
2130 int i, err;
2131
2132 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2133 nid = cfg->line_out_pins[i];
2134
2135 if (!nid)
2136 continue;
2137
2138 nid_vol = nid_vols[i];
2139
2140 if (i == AUTO_SEQ_CENLFE) {
2141 /* Center/LFE */
2142 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2143 "Center Playback Volume",
2144 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2145 HDA_OUTPUT));
2146 if (err < 0)
2147 return err;
2148 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2149 "LFE Playback Volume",
2150 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2151 HDA_OUTPUT));
2152 if (err < 0)
2153 return err;
2154 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2155 "Center Playback Switch",
2156 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2157 HDA_OUTPUT));
2158 if (err < 0)
2159 return err;
2160 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2161 "LFE Playback Switch",
2162 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2163 HDA_OUTPUT));
2164 if (err < 0)
2165 return err;
2166 } else if (i == AUTO_SEQ_FRONT) {
2167 /* add control to mixer index 0 */
2168 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2169 "Master Front Playback Volume",
2170 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2171 HDA_INPUT));
2172 if (err < 0)
2173 return err;
2174 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2175 "Master Front Playback Switch",
2176 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2177 HDA_INPUT));
2178 if (err < 0)
2179 return err;
2180
2181 /* add control to PW3 */
2182 sprintf(name, "%s Playback Volume", chname[i]);
2183 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2184 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2185 HDA_OUTPUT));
2186 if (err < 0)
2187 return err;
2188 sprintf(name, "%s Playback Switch", chname[i]);
2189 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2190 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2191 HDA_OUTPUT));
2192 if (err < 0)
2193 return err;
2194 } else {
2195 sprintf(name, "%s Playback Volume", chname[i]);
2196 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2197 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2198 HDA_OUTPUT));
2199 if (err < 0)
2200 return err;
2201 sprintf(name, "%s Playback Switch", chname[i]);
2202 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2203 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2204 HDA_OUTPUT));
2205 if (err < 0)
2206 return err;
2207 }
2208 }
2209
2210 return 0;
2211}
2212
2213static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2214{
2215 int err;
2216
2217 if (!pin)
2218 return 0;
2219
2220 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
2221
2222 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2223 "Headphone Playback Volume",
2224 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2225 if (err < 0)
2226 return err;
2227 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2228 "Headphone Playback Switch",
2229 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2230 if (err < 0)
2231 return err;
2232
Harald Welte0aa62ae2008-09-09 15:58:27 +08002233 create_hp_imux(spec);
2234
Josepch Chanf7278fd2007-12-13 16:40:40 +01002235 return 0;
2236}
2237
2238/* create playback/capture controls for input pins */
2239static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2240 const struct auto_pin_cfg *cfg)
2241{
2242 static char *labels[] = {
2243 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2244 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08002245 struct hda_input_mux *imux = &spec->private_imux[0];
Josepch Chanf7278fd2007-12-13 16:40:40 +01002246 int i, err, idx = 0;
2247
2248 /* for internal loopback recording select */
2249 imux->items[imux->num_items].label = "Stereo Mixer";
2250 imux->items[imux->num_items].index = idx;
2251 imux->num_items++;
2252
2253 for (i = 0; i < AUTO_PIN_LAST; i++) {
2254 if (!cfg->input_pins[i])
2255 continue;
2256
2257 switch (cfg->input_pins[i]) {
2258 case 0x1a: /* Mic */
2259 idx = 2;
2260 break;
2261
2262 case 0x1b: /* Line In */
2263 idx = 3;
2264 break;
2265
2266 case 0x1e: /* Front Mic */
2267 idx = 4;
2268 break;
2269
2270 case 0x1f: /* CD */
2271 idx = 1;
2272 break;
2273 }
2274 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2275 idx, 0x16);
2276 if (err < 0)
2277 return err;
2278 imux->items[imux->num_items].label = labels[i];
2279 imux->items[imux->num_items].index = idx;
2280 imux->num_items++;
2281 }
2282 return 0;
2283}
2284
2285static int vt1708B_parse_auto_config(struct hda_codec *codec)
2286{
2287 struct via_spec *spec = codec->spec;
2288 int err;
2289
2290 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2291 if (err < 0)
2292 return err;
2293 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
2294 if (err < 0)
2295 return err;
2296 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2297 return 0; /* can't find valid BIOS pin config */
2298
2299 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
2300 if (err < 0)
2301 return err;
2302 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2303 if (err < 0)
2304 return err;
2305 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
2306 if (err < 0)
2307 return err;
2308
2309 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2310
2311 if (spec->autocfg.dig_out_pin)
2312 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
2313 if (spec->autocfg.dig_in_pin)
2314 spec->dig_in_nid = VT1708B_DIGIN_NID;
2315
2316 if (spec->kctl_alloc)
2317 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2318
Harald Welte0aa62ae2008-09-09 15:58:27 +08002319 spec->input_mux = &spec->private_imux[0];
2320
Harald Weltef8fdd492008-09-15 22:41:31 +08002321 if (spec->hp_mux)
2322 spec->mixers[spec->num_mixers++] = via_hp_mixer;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002323
2324 return 1;
2325}
2326
2327#ifdef CONFIG_SND_HDA_POWER_SAVE
2328static struct hda_amp_list vt1708B_loopbacks[] = {
2329 { 0x16, HDA_INPUT, 1 },
2330 { 0x16, HDA_INPUT, 2 },
2331 { 0x16, HDA_INPUT, 3 },
2332 { 0x16, HDA_INPUT, 4 },
2333 { } /* end */
2334};
2335#endif
2336
2337static int patch_vt1708B_8ch(struct hda_codec *codec)
2338{
2339 struct via_spec *spec;
2340 int err;
2341
2342 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08002343 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002344 if (spec == NULL)
2345 return -ENOMEM;
2346
2347 codec->spec = spec;
2348
2349 /* automatic parse from the BIOS config */
2350 err = vt1708B_parse_auto_config(codec);
2351 if (err < 0) {
2352 via_free(codec);
2353 return err;
2354 } else if (!err) {
2355 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2356 "from BIOS. Using genenic mode...\n");
2357 }
2358
Harald Welte69e52a82008-09-09 15:57:32 +08002359 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
2360 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002361
2362 spec->stream_name_analog = "VT1708B Analog";
2363 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
2364 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2365
2366 spec->stream_name_digital = "VT1708B Digital";
2367 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2368 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2369
2370 if (!spec->adc_nids && spec->input_mux) {
2371 spec->adc_nids = vt1708B_adc_nids;
2372 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2373 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2374 spec->num_mixers++;
2375 }
2376
2377 codec->patch_ops = via_patch_ops;
2378
2379 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002380 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002381#ifdef CONFIG_SND_HDA_POWER_SAVE
2382 spec->loopback.amplist = vt1708B_loopbacks;
2383#endif
2384
2385 return 0;
2386}
2387
2388static int patch_vt1708B_4ch(struct hda_codec *codec)
2389{
2390 struct via_spec *spec;
2391 int err;
2392
2393 /* create a codec specific record */
Harald Welteeb14a462008-09-09 15:40:38 +08002394 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Josepch Chanf7278fd2007-12-13 16:40:40 +01002395 if (spec == NULL)
2396 return -ENOMEM;
2397
2398 codec->spec = spec;
2399
2400 /* automatic parse from the BIOS config */
2401 err = vt1708B_parse_auto_config(codec);
2402 if (err < 0) {
2403 via_free(codec);
2404 return err;
2405 } else if (!err) {
2406 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2407 "from BIOS. Using genenic mode...\n");
2408 }
2409
Harald Welte69e52a82008-09-09 15:57:32 +08002410 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
2411 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002412
2413 spec->stream_name_analog = "VT1708B Analog";
2414 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
2415 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2416
2417 spec->stream_name_digital = "VT1708B Digital";
2418 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2419 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2420
2421 if (!spec->adc_nids && spec->input_mux) {
2422 spec->adc_nids = vt1708B_adc_nids;
2423 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2424 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2425 spec->num_mixers++;
2426 }
2427
2428 codec->patch_ops = via_patch_ops;
2429
2430 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002431 codec->patch_ops.unsol_event = via_unsol_event;
Josepch Chanf7278fd2007-12-13 16:40:40 +01002432#ifdef CONFIG_SND_HDA_POWER_SAVE
2433 spec->loopback.amplist = vt1708B_loopbacks;
2434#endif
Joseph Chanc577b8a2006-11-29 15:29:40 +01002435
2436 return 0;
2437}
2438
Harald Welted949cac2008-09-09 15:56:01 +08002439/* Patch for VT1708S */
2440
2441/* capture mixer elements */
2442static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2443 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2444 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2445 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2446 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2447 HDA_CODEC_VOLUME("Mic Boost", 0x1A, 0x0, HDA_INPUT),
2448 HDA_CODEC_VOLUME("Front Mic Boost", 0x1E, 0x0, HDA_INPUT),
2449 {
2450 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2451 /* The multiple "Capture Source" controls confuse alsamixer
2452 * So call somewhat different..
2453 */
2454 /* .name = "Capture Source", */
2455 .name = "Input Source",
2456 .count = 1,
2457 .info = via_mux_enum_info,
2458 .get = via_mux_enum_get,
2459 .put = via_mux_enum_put,
2460 },
2461 { } /* end */
2462};
2463
2464static struct hda_verb vt1708S_volume_init_verbs[] = {
2465 /* Unmute ADC0-1 and set the default input to mic-in */
2466 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2467 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2468
2469 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2470 * analog-loopback mixer widget */
2471 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2472 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2473 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2474 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2475 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2476 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2477
2478 /* Setup default input of PW4 to MW0 */
2479 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2480 /* PW9 Output enable */
2481 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2482 { }
2483};
2484
Harald Welte69e52a82008-09-09 15:57:32 +08002485static struct hda_verb vt1708S_uniwill_init_verbs[] = {
2486 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2487 { }
2488};
2489
Harald Welted949cac2008-09-09 15:56:01 +08002490static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2491 .substreams = 2,
2492 .channels_min = 2,
2493 .channels_max = 8,
2494 .nid = 0x10, /* NID to query formats and rates */
2495 .ops = {
2496 .open = via_playback_pcm_open,
2497 .prepare = via_playback_pcm_prepare,
2498 .cleanup = via_playback_pcm_cleanup
2499 },
2500};
2501
2502static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2503 .substreams = 2,
2504 .channels_min = 2,
2505 .channels_max = 2,
2506 .nid = 0x13, /* NID to query formats and rates */
2507 .ops = {
2508 .prepare = via_capture_pcm_prepare,
2509 .cleanup = via_capture_pcm_cleanup
2510 },
2511};
2512
2513static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
2514 .substreams = 1,
2515 .channels_min = 2,
2516 .channels_max = 2,
2517 /* NID is set in via_build_pcms */
2518 .ops = {
2519 .open = via_dig_playback_pcm_open,
2520 .close = via_dig_playback_pcm_close,
2521 .prepare = via_dig_playback_pcm_prepare
2522 },
2523};
2524
Harald Welte98aa34c2008-09-09 16:02:09 +08002525static struct hda_pcm_stream vt1708S_pcm_extra_digital_playback = {
2526 .substreams = 1,
2527 .channels_min = 2,
2528 .channels_max = 2,
2529 /* NID is set in via_build_pcms */
2530 .ops = {
2531 .prepare = via_extra_dig_playback_pcm_prepare
2532 },
2533};
2534
Harald Welted949cac2008-09-09 15:56:01 +08002535/* fill in the dac_nids table from the parsed pin configuration */
2536static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
2537 const struct auto_pin_cfg *cfg)
2538{
2539 int i;
2540 hda_nid_t nid;
2541
2542 spec->multiout.num_dacs = cfg->line_outs;
2543
2544 spec->multiout.dac_nids = spec->private_dac_nids;
2545
2546 for (i = 0; i < 4; i++) {
2547 nid = cfg->line_out_pins[i];
2548 if (nid) {
2549 /* config dac list */
2550 switch (i) {
2551 case AUTO_SEQ_FRONT:
2552 spec->multiout.dac_nids[i] = 0x10;
2553 break;
2554 case AUTO_SEQ_CENLFE:
2555 spec->multiout.dac_nids[i] = 0x24;
2556 break;
2557 case AUTO_SEQ_SURROUND:
2558 spec->multiout.dac_nids[i] = 0x11;
2559 break;
2560 case AUTO_SEQ_SIDE:
2561 spec->multiout.dac_nids[i] = 0x25;
2562 break;
2563 }
2564 }
2565 }
2566
2567 return 0;
2568}
2569
2570/* add playback controls from the parsed DAC table */
2571static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
2572 const struct auto_pin_cfg *cfg)
2573{
2574 char name[32];
2575 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2576 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
2577 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
2578 hda_nid_t nid, nid_vol, nid_mute;
2579 int i, err;
2580
2581 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2582 nid = cfg->line_out_pins[i];
2583
2584 if (!nid)
2585 continue;
2586
2587 nid_vol = nid_vols[i];
2588 nid_mute = nid_mutes[i];
2589
2590 if (i == AUTO_SEQ_CENLFE) {
2591 /* Center/LFE */
2592 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2593 "Center Playback Volume",
2594 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2595 HDA_OUTPUT));
2596 if (err < 0)
2597 return err;
2598 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2599 "LFE Playback Volume",
2600 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2601 HDA_OUTPUT));
2602 if (err < 0)
2603 return err;
2604 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2605 "Center Playback Switch",
2606 HDA_COMPOSE_AMP_VAL(nid_mute,
2607 1, 0,
2608 HDA_OUTPUT));
2609 if (err < 0)
2610 return err;
2611 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2612 "LFE Playback Switch",
2613 HDA_COMPOSE_AMP_VAL(nid_mute,
2614 2, 0,
2615 HDA_OUTPUT));
2616 if (err < 0)
2617 return err;
2618 } else if (i == AUTO_SEQ_FRONT) {
2619 /* add control to mixer index 0 */
2620 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2621 "Master Front Playback Volume",
2622 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2623 HDA_INPUT));
2624 if (err < 0)
2625 return err;
2626 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2627 "Master Front Playback Switch",
2628 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2629 HDA_INPUT));
2630 if (err < 0)
2631 return err;
2632
2633 /* Front */
2634 sprintf(name, "%s Playback Volume", chname[i]);
2635 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2636 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2637 HDA_OUTPUT));
2638 if (err < 0)
2639 return err;
2640 sprintf(name, "%s Playback Switch", chname[i]);
2641 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2642 HDA_COMPOSE_AMP_VAL(nid_mute,
2643 3, 0,
2644 HDA_OUTPUT));
2645 if (err < 0)
2646 return err;
2647 } else {
2648 sprintf(name, "%s Playback Volume", chname[i]);
2649 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2650 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2651 HDA_OUTPUT));
2652 if (err < 0)
2653 return err;
2654 sprintf(name, "%s Playback Switch", chname[i]);
2655 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2656 HDA_COMPOSE_AMP_VAL(nid_mute,
2657 3, 0,
2658 HDA_OUTPUT));
2659 if (err < 0)
2660 return err;
2661 }
2662 }
2663
2664 return 0;
2665}
2666
2667static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2668{
2669 int err;
2670
2671 if (!pin)
2672 return 0;
2673
2674 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
2675
2676 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2677 "Headphone Playback Volume",
2678 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
2679 if (err < 0)
2680 return err;
2681
2682 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2683 "Headphone Playback Switch",
2684 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2685 if (err < 0)
2686 return err;
2687
Harald Welte0aa62ae2008-09-09 15:58:27 +08002688 create_hp_imux(spec);
2689
Harald Welted949cac2008-09-09 15:56:01 +08002690 return 0;
2691}
2692
2693/* create playback/capture controls for input pins */
2694static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2695 const struct auto_pin_cfg *cfg)
2696{
2697 static char *labels[] = {
2698 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2699 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08002700 struct hda_input_mux *imux = &spec->private_imux[0];
Harald Welted949cac2008-09-09 15:56:01 +08002701 int i, err, idx = 0;
2702
2703 /* for internal loopback recording select */
2704 imux->items[imux->num_items].label = "Stereo Mixer";
2705 imux->items[imux->num_items].index = 5;
2706 imux->num_items++;
2707
2708 for (i = 0; i < AUTO_PIN_LAST; i++) {
2709 if (!cfg->input_pins[i])
2710 continue;
2711
2712 switch (cfg->input_pins[i]) {
2713 case 0x1a: /* Mic */
2714 idx = 2;
2715 break;
2716
2717 case 0x1b: /* Line In */
2718 idx = 3;
2719 break;
2720
2721 case 0x1e: /* Front Mic */
2722 idx = 4;
2723 break;
2724
2725 case 0x1f: /* CD */
2726 idx = 1;
2727 break;
2728 }
2729 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2730 idx, 0x16);
2731 if (err < 0)
2732 return err;
2733 imux->items[imux->num_items].label = labels[i];
2734 imux->items[imux->num_items].index = idx-1;
2735 imux->num_items++;
2736 }
2737 return 0;
2738}
2739
2740static int vt1708S_parse_auto_config(struct hda_codec *codec)
2741{
2742 struct via_spec *spec = codec->spec;
2743 int err;
2744 static hda_nid_t vt1708s_ignore[] = {0x21, 0};
2745
2746 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
2747 vt1708s_ignore);
2748 if (err < 0)
2749 return err;
2750 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
2751 if (err < 0)
2752 return err;
2753 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2754 return 0; /* can't find valid BIOS pin config */
2755
2756 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
2757 if (err < 0)
2758 return err;
2759 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2760 if (err < 0)
2761 return err;
2762 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
2763 if (err < 0)
2764 return err;
2765
2766 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2767
2768 if (spec->autocfg.dig_out_pin)
2769 spec->multiout.dig_out_nid = VT1708S_DIGOUT_NID;
2770
Harald Welte98aa34c2008-09-09 16:02:09 +08002771 spec->extra_dig_out_nid = 0x15;
2772
Harald Welted949cac2008-09-09 15:56:01 +08002773 if (spec->kctl_alloc)
2774 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2775
Harald Welte0aa62ae2008-09-09 15:58:27 +08002776 spec->input_mux = &spec->private_imux[0];
2777
Harald Weltef8fdd492008-09-15 22:41:31 +08002778 if (spec->hp_mux)
2779 spec->mixers[spec->num_mixers++] = via_hp_mixer;
Harald Welted949cac2008-09-09 15:56:01 +08002780
2781 return 1;
2782}
2783
2784#ifdef CONFIG_SND_HDA_POWER_SAVE
2785static struct hda_amp_list vt1708S_loopbacks[] = {
2786 { 0x16, HDA_INPUT, 1 },
2787 { 0x16, HDA_INPUT, 2 },
2788 { 0x16, HDA_INPUT, 3 },
2789 { 0x16, HDA_INPUT, 4 },
2790 { } /* end */
2791};
2792#endif
2793
2794static int patch_vt1708S(struct hda_codec *codec)
2795{
2796 struct via_spec *spec;
2797 int err;
2798
2799 /* create a codec specific record */
2800 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2801 if (spec == NULL)
2802 return -ENOMEM;
2803
2804 codec->spec = spec;
2805
2806 /* automatic parse from the BIOS config */
2807 err = vt1708S_parse_auto_config(codec);
2808 if (err < 0) {
2809 via_free(codec);
2810 return err;
2811 } else if (!err) {
2812 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2813 "from BIOS. Using genenic mode...\n");
2814 }
2815
Harald Welte69e52a82008-09-09 15:57:32 +08002816 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
2817 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08002818
2819 spec->stream_name_analog = "VT1708S Analog";
2820 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2821 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2822
2823 spec->stream_name_digital = "VT1708S Digital";
2824 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
Harald Welte98aa34c2008-09-09 16:02:09 +08002825 spec->stream_extra_digital_playback =
2826 &vt1708S_pcm_extra_digital_playback;
Harald Welted949cac2008-09-09 15:56:01 +08002827
2828 if (!spec->adc_nids && spec->input_mux) {
2829 spec->adc_nids = vt1708S_adc_nids;
2830 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2831 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2832 spec->num_mixers++;
2833 }
2834
2835 codec->patch_ops = via_patch_ops;
2836
2837 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08002838 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08002839#ifdef CONFIG_SND_HDA_POWER_SAVE
2840 spec->loopback.amplist = vt1708S_loopbacks;
2841#endif
2842
2843 return 0;
2844}
2845
2846/* Patch for VT1702 */
2847
2848/* capture mixer elements */
2849static struct snd_kcontrol_new vt1702_capture_mixer[] = {
2850 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
2851 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
2852 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
2853 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
2854 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
2855 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
2856 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2857 HDA_INPUT),
2858 {
2859 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2860 /* The multiple "Capture Source" controls confuse alsamixer
2861 * So call somewhat different..
2862 */
2863 /* .name = "Capture Source", */
2864 .name = "Input Source",
2865 .count = 1,
2866 .info = via_mux_enum_info,
2867 .get = via_mux_enum_get,
2868 .put = via_mux_enum_put,
2869 },
2870 { } /* end */
2871};
2872
2873static struct hda_verb vt1702_volume_init_verbs[] = {
2874 /*
2875 * Unmute ADC0-1 and set the default input to mic-in
2876 */
2877 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2878 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2879 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2880
2881
2882 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2883 * mixer widget
2884 */
2885 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2886 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2887 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2888 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2889 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2890 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2891
2892 /* Setup default input of PW4 to MW0 */
2893 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
2894 /* PW6 PW7 Output enable */
2895 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2896 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2897 { }
2898};
2899
Harald Welte69e52a82008-09-09 15:57:32 +08002900static struct hda_verb vt1702_uniwill_init_verbs[] = {
2901 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
2902 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2903 { }
2904};
2905
Harald Welted949cac2008-09-09 15:56:01 +08002906static struct hda_pcm_stream vt1702_pcm_analog_playback = {
Harald Welte0aa62ae2008-09-09 15:58:27 +08002907 .substreams = 2,
Harald Welted949cac2008-09-09 15:56:01 +08002908 .channels_min = 2,
2909 .channels_max = 2,
2910 .nid = 0x10, /* NID to query formats and rates */
2911 .ops = {
2912 .open = via_playback_pcm_open,
Harald Welte0aa62ae2008-09-09 15:58:27 +08002913 .prepare = via_playback_multi_pcm_prepare,
2914 .cleanup = via_playback_multi_pcm_cleanup
Harald Welted949cac2008-09-09 15:56:01 +08002915 },
2916};
2917
2918static struct hda_pcm_stream vt1702_pcm_analog_capture = {
2919 .substreams = 3,
2920 .channels_min = 2,
2921 .channels_max = 2,
2922 .nid = 0x12, /* NID to query formats and rates */
2923 .ops = {
2924 .prepare = via_capture_pcm_prepare,
2925 .cleanup = via_capture_pcm_cleanup
2926 },
2927};
2928
2929static struct hda_pcm_stream vt1702_pcm_digital_playback = {
2930 .substreams = 1,
2931 .channels_min = 2,
2932 .channels_max = 2,
2933 /* NID is set in via_build_pcms */
2934 .ops = {
2935 .open = via_dig_playback_pcm_open,
2936 .close = via_dig_playback_pcm_close,
2937 .prepare = via_dig_playback_pcm_prepare
2938 },
2939};
2940
Harald Welte98aa34c2008-09-09 16:02:09 +08002941static struct hda_pcm_stream vt1702_pcm_extra_digital_playback = {
2942 .substreams = 1,
2943 .channels_min = 2,
2944 .channels_max = 2,
2945 /* NID is set in via_build_pcms */
2946 .ops = {
2947 .prepare = via_extra_dig_playback_pcm_prepare
2948 },
2949};
2950
Harald Welted949cac2008-09-09 15:56:01 +08002951/* fill in the dac_nids table from the parsed pin configuration */
2952static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
2953 const struct auto_pin_cfg *cfg)
2954{
2955 spec->multiout.num_dacs = 1;
2956 spec->multiout.dac_nids = spec->private_dac_nids;
2957
2958 if (cfg->line_out_pins[0]) {
2959 /* config dac list */
2960 spec->multiout.dac_nids[0] = 0x10;
2961 }
2962
2963 return 0;
2964}
2965
2966/* add playback controls from the parsed DAC table */
2967static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
2968 const struct auto_pin_cfg *cfg)
2969{
2970 int err;
2971
2972 if (!cfg->line_out_pins[0])
2973 return -1;
2974
2975 /* add control to mixer index 0 */
2976 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2977 "Master Front Playback Volume",
2978 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
2979 if (err < 0)
2980 return err;
2981 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2982 "Master Front Playback Switch",
2983 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
2984 if (err < 0)
2985 return err;
2986
2987 /* Front */
2988 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2989 "Front Playback Volume",
2990 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
2991 if (err < 0)
2992 return err;
2993 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2994 "Front Playback Switch",
2995 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
2996 if (err < 0)
2997 return err;
2998
2999 return 0;
3000}
3001
3002static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3003{
3004 int err;
3005
3006 if (!pin)
3007 return 0;
3008
3009 spec->multiout.hp_nid = 0x1D;
3010
3011 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3012 "Headphone Playback Volume",
3013 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
3014 if (err < 0)
3015 return err;
3016
3017 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3018 "Headphone Playback Switch",
3019 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3020 if (err < 0)
3021 return err;
3022
Harald Welte0aa62ae2008-09-09 15:58:27 +08003023 create_hp_imux(spec);
3024
Harald Welted949cac2008-09-09 15:56:01 +08003025 return 0;
3026}
3027
3028/* create playback/capture controls for input pins */
3029static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3030 const struct auto_pin_cfg *cfg)
3031{
3032 static char *labels[] = {
3033 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3034 };
Harald Welte0aa62ae2008-09-09 15:58:27 +08003035 struct hda_input_mux *imux = &spec->private_imux[0];
Harald Welted949cac2008-09-09 15:56:01 +08003036 int i, err, idx = 0;
3037
3038 /* for internal loopback recording select */
3039 imux->items[imux->num_items].label = "Stereo Mixer";
3040 imux->items[imux->num_items].index = 3;
3041 imux->num_items++;
3042
3043 for (i = 0; i < AUTO_PIN_LAST; i++) {
3044 if (!cfg->input_pins[i])
3045 continue;
3046
3047 switch (cfg->input_pins[i]) {
3048 case 0x14: /* Mic */
3049 idx = 1;
3050 break;
3051
3052 case 0x15: /* Line In */
3053 idx = 2;
3054 break;
3055
3056 case 0x18: /* Front Mic */
3057 idx = 3;
3058 break;
3059 }
3060 err = via_new_analog_input(spec, cfg->input_pins[i],
3061 labels[i], idx, 0x1A);
3062 if (err < 0)
3063 return err;
3064 imux->items[imux->num_items].label = labels[i];
3065 imux->items[imux->num_items].index = idx-1;
3066 imux->num_items++;
3067 }
3068 return 0;
3069}
3070
3071static int vt1702_parse_auto_config(struct hda_codec *codec)
3072{
3073 struct via_spec *spec = codec->spec;
3074 int err;
3075 static hda_nid_t vt1702_ignore[] = {0x1C, 0};
3076
3077 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3078 vt1702_ignore);
3079 if (err < 0)
3080 return err;
3081 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
3082 if (err < 0)
3083 return err;
3084 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3085 return 0; /* can't find valid BIOS pin config */
3086
3087 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
3088 if (err < 0)
3089 return err;
3090 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3091 if (err < 0)
3092 return err;
3093 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3094 if (err < 0)
3095 return err;
3096
3097 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3098
3099 if (spec->autocfg.dig_out_pin)
3100 spec->multiout.dig_out_nid = VT1702_DIGOUT_NID;
3101
Harald Welte98aa34c2008-09-09 16:02:09 +08003102 spec->extra_dig_out_nid = 0x1B;
3103
Harald Welted949cac2008-09-09 15:56:01 +08003104 if (spec->kctl_alloc)
3105 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3106
Harald Welte0aa62ae2008-09-09 15:58:27 +08003107 spec->input_mux = &spec->private_imux[0];
3108
Harald Weltef8fdd492008-09-15 22:41:31 +08003109 if (spec->hp_mux)
3110 spec->mixers[spec->num_mixers++] = via_hp_mixer;
Harald Welted949cac2008-09-09 15:56:01 +08003111
3112 return 1;
3113}
3114
3115#ifdef CONFIG_SND_HDA_POWER_SAVE
3116static struct hda_amp_list vt1702_loopbacks[] = {
3117 { 0x1A, HDA_INPUT, 1 },
3118 { 0x1A, HDA_INPUT, 2 },
3119 { 0x1A, HDA_INPUT, 3 },
3120 { 0x1A, HDA_INPUT, 4 },
3121 { } /* end */
3122};
3123#endif
3124
3125static int patch_vt1702(struct hda_codec *codec)
3126{
3127 struct via_spec *spec;
3128 int err;
3129 unsigned int response;
3130 unsigned char control;
3131
3132 /* create a codec specific record */
3133 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3134 if (spec == NULL)
3135 return -ENOMEM;
3136
3137 codec->spec = spec;
3138
3139 /* automatic parse from the BIOS config */
3140 err = vt1702_parse_auto_config(codec);
3141 if (err < 0) {
3142 via_free(codec);
3143 return err;
3144 } else if (!err) {
3145 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3146 "from BIOS. Using genenic mode...\n");
3147 }
3148
Harald Welte69e52a82008-09-09 15:57:32 +08003149 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
3150 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
Harald Welted949cac2008-09-09 15:56:01 +08003151
3152 spec->stream_name_analog = "VT1702 Analog";
3153 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
3154 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
3155
3156 spec->stream_name_digital = "VT1702 Digital";
3157 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
Harald Welte98aa34c2008-09-09 16:02:09 +08003158 spec->stream_extra_digital_playback =
3159 &vt1702_pcm_extra_digital_playback;
Harald Welted949cac2008-09-09 15:56:01 +08003160
3161 if (!spec->adc_nids && spec->input_mux) {
3162 spec->adc_nids = vt1702_adc_nids;
3163 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
3164 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3165 spec->num_mixers++;
3166 }
3167
3168 codec->patch_ops = via_patch_ops;
3169
3170 codec->patch_ops.init = via_auto_init;
Harald Welte69e52a82008-09-09 15:57:32 +08003171 codec->patch_ops.unsol_event = via_unsol_event;
Harald Welted949cac2008-09-09 15:56:01 +08003172#ifdef CONFIG_SND_HDA_POWER_SAVE
3173 spec->loopback.amplist = vt1702_loopbacks;
3174#endif
3175
3176 /* Open backdoor */
3177 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
3178 control = (unsigned char)(response & 0xff);
3179 control |= 0x3;
3180 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control);
3181
3182 /* Enable GPIO 0&1 for volume&mute control */
3183 /* Enable GPIO 2 for DMIC-DATA */
3184 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
3185 control = (unsigned char)((response >> 16) & 0x3f);
3186 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control);
3187
3188 return 0;
3189}
3190
Joseph Chanc577b8a2006-11-29 15:29:40 +01003191/*
3192 * patch entries
3193 */
3194struct hda_codec_preset snd_hda_preset_via[] = {
3195 { .id = 0x11061708, .name = "VIA VT1708", .patch = patch_vt1708},
3196 { .id = 0x11061709, .name = "VIA VT1708", .patch = patch_vt1708},
3197 { .id = 0x1106170A, .name = "VIA VT1708", .patch = patch_vt1708},
3198 { .id = 0x1106170B, .name = "VIA VT1708", .patch = patch_vt1708},
Josepch Chanf7278fd2007-12-13 16:40:40 +01003199 { .id = 0x1106E710, .name = "VIA VT1709 10-Ch",
3200 .patch = patch_vt1709_10ch},
3201 { .id = 0x1106E711, .name = "VIA VT1709 10-Ch",
3202 .patch = patch_vt1709_10ch},
3203 { .id = 0x1106E712, .name = "VIA VT1709 10-Ch",
3204 .patch = patch_vt1709_10ch},
3205 { .id = 0x1106E713, .name = "VIA VT1709 10-Ch",
3206 .patch = patch_vt1709_10ch},
3207 { .id = 0x1106E714, .name = "VIA VT1709 6-Ch",
3208 .patch = patch_vt1709_6ch},
3209 { .id = 0x1106E715, .name = "VIA VT1709 6-Ch",
3210 .patch = patch_vt1709_6ch},
3211 { .id = 0x1106E716, .name = "VIA VT1709 6-Ch",
3212 .patch = patch_vt1709_6ch},
3213 { .id = 0x1106E717, .name = "VIA VT1709 6-Ch",
3214 .patch = patch_vt1709_6ch},
3215 { .id = 0x1106E720, .name = "VIA VT1708B 8-Ch",
3216 .patch = patch_vt1708B_8ch},
3217 { .id = 0x1106E721, .name = "VIA VT1708B 8-Ch",
3218 .patch = patch_vt1708B_8ch},
3219 { .id = 0x1106E722, .name = "VIA VT1708B 8-Ch",
3220 .patch = patch_vt1708B_8ch},
3221 { .id = 0x1106E723, .name = "VIA VT1708B 8-Ch",
3222 .patch = patch_vt1708B_8ch},
3223 { .id = 0x1106E724, .name = "VIA VT1708B 4-Ch",
3224 .patch = patch_vt1708B_4ch},
3225 { .id = 0x1106E725, .name = "VIA VT1708B 4-Ch",
3226 .patch = patch_vt1708B_4ch},
3227 { .id = 0x1106E726, .name = "VIA VT1708B 4-Ch",
3228 .patch = patch_vt1708B_4ch},
3229 { .id = 0x1106E727, .name = "VIA VT1708B 4-Ch",
3230 .patch = patch_vt1708B_4ch},
Harald Welted949cac2008-09-09 15:56:01 +08003231 { .id = 0x11060397, .name = "VIA VT1708S",
3232 .patch = patch_vt1708S},
3233 { .id = 0x11061397, .name = "VIA VT1708S",
3234 .patch = patch_vt1708S},
3235 { .id = 0x11062397, .name = "VIA VT1708S",
3236 .patch = patch_vt1708S},
3237 { .id = 0x11063397, .name = "VIA VT1708S",
3238 .patch = patch_vt1708S},
3239 { .id = 0x11064397, .name = "VIA VT1708S",
3240 .patch = patch_vt1708S},
3241 { .id = 0x11065397, .name = "VIA VT1708S",
3242 .patch = patch_vt1708S},
3243 { .id = 0x11066397, .name = "VIA VT1708S",
3244 .patch = patch_vt1708S},
3245 { .id = 0x11067397, .name = "VIA VT1708S",
3246 .patch = patch_vt1708S},
3247 { .id = 0x11060398, .name = "VIA VT1702",
3248 .patch = patch_vt1702},
3249 { .id = 0x11061398, .name = "VIA VT1702",
3250 .patch = patch_vt1702},
3251 { .id = 0x11062398, .name = "VIA VT1702",
3252 .patch = patch_vt1702},
3253 { .id = 0x11063398, .name = "VIA VT1702",
3254 .patch = patch_vt1702},
3255 { .id = 0x11064398, .name = "VIA VT1702",
3256 .patch = patch_vt1702},
3257 { .id = 0x11065398, .name = "VIA VT1702",
3258 .patch = patch_vt1702},
3259 { .id = 0x11066398, .name = "VIA VT1702",
3260 .patch = patch_vt1702},
3261 { .id = 0x11067398, .name = "VIA VT1702",
3262 .patch = patch_vt1702},
Joseph Chanc577b8a2006-11-29 15:29:40 +01003263 {} /* terminator */
3264};