mm-only debug patch...
[mmotm.git] / sound / pci / hda / patch_via.c
bloba294060ed68470d2a1e22b669f33c8da0f314447
1 /*
2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
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.
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.
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
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 */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* */
45 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
48 #include <linux/init.h>
49 #include <linux/delay.h>
50 #include <linux/slab.h>
51 #include <sound/core.h>
52 #include <sound/asoundef.h>
53 #include "hda_codec.h"
54 #include "hda_local.h"
56 /* amp values */
57 #define AMP_VAL_IDX_SHIFT 19
58 #define AMP_VAL_IDX_MASK (0x0f<<19)
60 /* Pin Widget NID */
61 #define VT1708_HP_NID 0x13
62 #define VT1708_DIGOUT_NID 0x14
63 #define VT1708_DIGIN_NID 0x16
64 #define VT1708_DIGIN_PIN 0x26
65 #define VT1708_HP_PIN_NID 0x20
66 #define VT1708_CD_PIN_NID 0x24
68 #define VT1709_HP_DAC_NID 0x28
69 #define VT1709_DIGOUT_NID 0x13
70 #define VT1709_DIGIN_NID 0x17
71 #define VT1709_DIGIN_PIN 0x25
73 #define VT1708B_HP_NID 0x25
74 #define VT1708B_DIGOUT_NID 0x12
75 #define VT1708B_DIGIN_NID 0x15
76 #define VT1708B_DIGIN_PIN 0x21
78 #define VT1708S_HP_NID 0x25
79 #define VT1708S_DIGOUT_NID 0x12
81 #define VT1702_HP_NID 0x17
82 #define VT1702_DIGOUT_NID 0x11
84 enum VIA_HDA_CODEC {
85 UNKNOWN = -1,
86 VT1708,
87 VT1709_10CH,
88 VT1709_6CH,
89 VT1708B_8CH,
90 VT1708B_4CH,
91 VT1708S,
92 VT1708BCE,
93 VT1702,
94 VT1718S,
95 VT1716S,
96 VT2002P,
97 VT1812,
98 CODEC_TYPES,
101 struct via_spec {
102 /* codec parameterization */
103 struct snd_kcontrol_new *mixers[6];
104 unsigned int num_mixers;
106 struct hda_verb *init_verbs[5];
107 unsigned int num_iverbs;
109 char *stream_name_analog;
110 struct hda_pcm_stream *stream_analog_playback;
111 struct hda_pcm_stream *stream_analog_capture;
113 char *stream_name_digital;
114 struct hda_pcm_stream *stream_digital_playback;
115 struct hda_pcm_stream *stream_digital_capture;
117 /* playback */
118 struct hda_multi_out multiout;
119 hda_nid_t slave_dig_outs[2];
121 /* capture */
122 unsigned int num_adc_nids;
123 hda_nid_t *adc_nids;
124 hda_nid_t mux_nids[3];
125 hda_nid_t dig_in_nid;
126 hda_nid_t dig_in_pin;
128 /* capture source */
129 const struct hda_input_mux *input_mux;
130 unsigned int cur_mux[3];
132 /* PCM information */
133 struct hda_pcm pcm_rec[3];
135 /* dynamic controls, init_verbs and input_mux */
136 struct auto_pin_cfg autocfg;
137 struct snd_array kctls;
138 struct hda_input_mux private_imux[2];
139 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
141 /* HP mode source */
142 const struct hda_input_mux *hp_mux;
143 unsigned int hp_independent_mode;
144 unsigned int hp_independent_mode_index;
145 unsigned int smart51_enabled;
146 unsigned int dmic_enabled;
147 enum VIA_HDA_CODEC codec_type;
149 /* work to check hp jack state */
150 struct hda_codec *codec;
151 struct delayed_work vt1708_hp_work;
152 int vt1708_jack_detectect;
153 int vt1708_hp_present;
154 #ifdef CONFIG_SND_HDA_POWER_SAVE
155 struct hda_loopback_check loopback;
156 #endif
159 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
161 u32 vendor_id = codec->vendor_id;
162 u16 ven_id = vendor_id >> 16;
163 u16 dev_id = vendor_id & 0xffff;
164 enum VIA_HDA_CODEC codec_type;
166 /* get codec type */
167 if (ven_id != 0x1106)
168 codec_type = UNKNOWN;
169 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
170 codec_type = VT1708;
171 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
172 codec_type = VT1709_10CH;
173 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
174 codec_type = VT1709_6CH;
175 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
176 codec_type = VT1708B_8CH;
177 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
178 codec_type = VT1708BCE;
179 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
180 codec_type = VT1708B_4CH;
181 else if ((dev_id & 0xfff) == 0x397
182 && (dev_id >> 12) < 8)
183 codec_type = VT1708S;
184 else if ((dev_id & 0xfff) == 0x398
185 && (dev_id >> 12) < 8)
186 codec_type = VT1702;
187 else if ((dev_id & 0xfff) == 0x428
188 && (dev_id >> 12) < 8)
189 codec_type = VT1718S;
190 else if (dev_id == 0x0433 || dev_id == 0xa721)
191 codec_type = VT1716S;
192 else if (dev_id == 0x0441 || dev_id == 0x4441)
193 codec_type = VT1718S;
194 else if (dev_id == 0x0438 || dev_id == 0x4438)
195 codec_type = VT2002P;
196 else if (dev_id == 0x0448)
197 codec_type = VT1812;
198 else
199 codec_type = UNKNOWN;
200 return codec_type;
203 #define VIA_HP_EVENT 0x01
204 #define VIA_GPIO_EVENT 0x02
205 #define VIA_JACK_EVENT 0x04
206 #define VIA_MONO_EVENT 0x08
207 #define VIA_SPEAKER_EVENT 0x10
208 #define VIA_BIND_HP_EVENT 0x20
210 enum {
211 VIA_CTL_WIDGET_VOL,
212 VIA_CTL_WIDGET_MUTE,
213 VIA_CTL_WIDGET_ANALOG_MUTE,
214 VIA_CTL_WIDGET_BIND_PIN_MUTE,
217 enum {
218 AUTO_SEQ_FRONT = 0,
219 AUTO_SEQ_SURROUND,
220 AUTO_SEQ_CENLFE,
221 AUTO_SEQ_SIDE
224 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
225 static void set_jack_power_state(struct hda_codec *codec);
226 static int is_aa_path_mute(struct hda_codec *codec);
228 static void vt1708_start_hp_work(struct via_spec *spec)
230 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
231 return;
232 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
233 !spec->vt1708_jack_detectect);
234 if (!delayed_work_pending(&spec->vt1708_hp_work))
235 schedule_delayed_work(&spec->vt1708_hp_work,
236 msecs_to_jiffies(100));
239 static void vt1708_stop_hp_work(struct via_spec *spec)
241 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
242 return;
243 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
244 && !is_aa_path_mute(spec->codec))
245 return;
246 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
247 !spec->vt1708_jack_detectect);
248 cancel_delayed_work(&spec->vt1708_hp_work);
249 flush_scheduled_work();
253 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
254 struct snd_ctl_elem_value *ucontrol)
256 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
257 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
259 set_jack_power_state(codec);
260 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
261 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
262 if (is_aa_path_mute(codec))
263 vt1708_start_hp_work(codec->spec);
264 else
265 vt1708_stop_hp_work(codec->spec);
267 return change;
270 /* modify .put = snd_hda_mixer_amp_switch_put */
271 #define ANALOG_INPUT_MUTE \
272 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
273 .name = NULL, \
274 .index = 0, \
275 .info = snd_hda_mixer_amp_switch_info, \
276 .get = snd_hda_mixer_amp_switch_get, \
277 .put = analog_input_switch_put, \
278 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
280 static void via_hp_bind_automute(struct hda_codec *codec);
282 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
283 struct snd_ctl_elem_value *ucontrol)
285 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
286 struct via_spec *spec = codec->spec;
287 int i;
288 int change = 0;
290 long *valp = ucontrol->value.integer.value;
291 int lmute, rmute;
292 if (strstr(kcontrol->id.name, "Switch") == NULL) {
293 snd_printd("Invalid control!\n");
294 return change;
296 change = snd_hda_mixer_amp_switch_put(kcontrol,
297 ucontrol);
298 /* Get mute value */
299 lmute = *valp ? 0 : HDA_AMP_MUTE;
300 valp++;
301 rmute = *valp ? 0 : HDA_AMP_MUTE;
303 /* Set hp pins */
304 if (!spec->hp_independent_mode) {
305 for (i = 0; i < spec->autocfg.hp_outs; i++) {
306 snd_hda_codec_amp_update(
307 codec, spec->autocfg.hp_pins[i],
308 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
309 lmute);
310 snd_hda_codec_amp_update(
311 codec, spec->autocfg.hp_pins[i],
312 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
313 rmute);
317 if (!lmute && !rmute) {
318 /* Line Outs */
319 for (i = 0; i < spec->autocfg.line_outs; i++)
320 snd_hda_codec_amp_stereo(
321 codec, spec->autocfg.line_out_pins[i],
322 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
323 /* Speakers */
324 for (i = 0; i < spec->autocfg.speaker_outs; i++)
325 snd_hda_codec_amp_stereo(
326 codec, spec->autocfg.speaker_pins[i],
327 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
328 /* unmute */
329 via_hp_bind_automute(codec);
331 } else {
332 if (lmute) {
333 /* Mute all left channels */
334 for (i = 1; i < spec->autocfg.line_outs; i++)
335 snd_hda_codec_amp_update(
336 codec,
337 spec->autocfg.line_out_pins[i],
338 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
339 lmute);
340 for (i = 0; i < spec->autocfg.speaker_outs; i++)
341 snd_hda_codec_amp_update(
342 codec,
343 spec->autocfg.speaker_pins[i],
344 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
345 lmute);
347 if (rmute) {
348 /* mute all right channels */
349 for (i = 1; i < spec->autocfg.line_outs; i++)
350 snd_hda_codec_amp_update(
351 codec,
352 spec->autocfg.line_out_pins[i],
353 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
354 rmute);
355 for (i = 0; i < spec->autocfg.speaker_outs; i++)
356 snd_hda_codec_amp_update(
357 codec,
358 spec->autocfg.speaker_pins[i],
359 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
360 rmute);
363 return change;
366 #define BIND_PIN_MUTE \
367 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
368 .name = NULL, \
369 .index = 0, \
370 .info = snd_hda_mixer_amp_switch_info, \
371 .get = snd_hda_mixer_amp_switch_get, \
372 .put = bind_pin_switch_put, \
373 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
375 static struct snd_kcontrol_new via_control_templates[] = {
376 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
377 HDA_CODEC_MUTE(NULL, 0, 0, 0),
378 ANALOG_INPUT_MUTE,
379 BIND_PIN_MUTE,
382 static hda_nid_t vt1708_adc_nids[2] = {
383 /* ADC1-2 */
384 0x15, 0x27
387 static hda_nid_t vt1709_adc_nids[3] = {
388 /* ADC1-2 */
389 0x14, 0x15, 0x16
392 static hda_nid_t vt1708B_adc_nids[2] = {
393 /* ADC1-2 */
394 0x13, 0x14
397 static hda_nid_t vt1708S_adc_nids[2] = {
398 /* ADC1-2 */
399 0x13, 0x14
402 static hda_nid_t vt1702_adc_nids[3] = {
403 /* ADC1-2 */
404 0x12, 0x20, 0x1F
407 static hda_nid_t vt1718S_adc_nids[2] = {
408 /* ADC1-2 */
409 0x10, 0x11
412 static hda_nid_t vt1716S_adc_nids[2] = {
413 /* ADC1-2 */
414 0x13, 0x14
417 static hda_nid_t vt2002P_adc_nids[2] = {
418 /* ADC1-2 */
419 0x10, 0x11
422 static hda_nid_t vt1812_adc_nids[2] = {
423 /* ADC1-2 */
424 0x10, 0x11
428 /* add dynamic controls */
429 static int via_add_control(struct via_spec *spec, int type, const char *name,
430 unsigned long val)
432 struct snd_kcontrol_new *knew;
434 snd_array_init(&spec->kctls, sizeof(*knew), 32);
435 knew = snd_array_new(&spec->kctls);
436 if (!knew)
437 return -ENOMEM;
438 *knew = via_control_templates[type];
439 knew->name = kstrdup(name, GFP_KERNEL);
440 if (!knew->name)
441 return -ENOMEM;
442 knew->private_value = val;
443 return 0;
446 static void via_free_kctls(struct hda_codec *codec)
448 struct via_spec *spec = codec->spec;
450 if (spec->kctls.list) {
451 struct snd_kcontrol_new *kctl = spec->kctls.list;
452 int i;
453 for (i = 0; i < spec->kctls.used; i++)
454 kfree(kctl[i].name);
456 snd_array_free(&spec->kctls);
459 /* create input playback/capture controls for the given pin */
460 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
461 int idx, int mix_nid)
463 char name[32];
464 int err;
466 sprintf(name, "%s Playback Volume", ctlname);
467 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
468 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
469 if (err < 0)
470 return err;
471 sprintf(name, "%s Playback Switch", ctlname);
472 err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name,
473 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
474 if (err < 0)
475 return err;
476 return 0;
479 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
480 hda_nid_t nid, int pin_type,
481 int dac_idx)
483 /* set as output */
484 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
485 pin_type);
486 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
487 AMP_OUT_UNMUTE);
488 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
489 snd_hda_codec_write(codec, nid, 0,
490 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
494 static void via_auto_init_multi_out(struct hda_codec *codec)
496 struct via_spec *spec = codec->spec;
497 int i;
499 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
500 hda_nid_t nid = spec->autocfg.line_out_pins[i];
501 if (nid)
502 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
506 static void via_auto_init_hp_out(struct hda_codec *codec)
508 struct via_spec *spec = codec->spec;
509 hda_nid_t pin;
510 int i;
512 for (i = 0; i < spec->autocfg.hp_outs; i++) {
513 pin = spec->autocfg.hp_pins[i];
514 if (pin) /* connect to front */
515 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
519 static void via_auto_init_analog_input(struct hda_codec *codec)
521 struct via_spec *spec = codec->spec;
522 int i;
524 for (i = 0; i < AUTO_PIN_LAST; i++) {
525 hda_nid_t nid = spec->autocfg.input_pins[i];
527 snd_hda_codec_write(codec, nid, 0,
528 AC_VERB_SET_PIN_WIDGET_CONTROL,
529 (i <= AUTO_PIN_FRONT_MIC ?
530 PIN_VREF50 : PIN_IN));
535 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
537 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
538 unsigned int *affected_parm)
540 unsigned parm;
541 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
542 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
543 >> AC_DEFCFG_MISC_SHIFT
544 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
545 unsigned present = snd_hda_codec_read(codec, nid, 0,
546 AC_VERB_GET_PIN_SENSE, 0) >> 31;
547 struct via_spec *spec = codec->spec;
548 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
549 || ((no_presence || present)
550 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
551 *affected_parm = AC_PWRST_D0; /* if it's connected */
552 parm = AC_PWRST_D0;
553 } else
554 parm = AC_PWRST_D3;
556 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
559 static void set_jack_power_state(struct hda_codec *codec)
561 struct via_spec *spec = codec->spec;
562 int imux_is_smixer;
563 unsigned int parm;
565 if (spec->codec_type == VT1702) {
566 imux_is_smixer = snd_hda_codec_read(
567 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
568 /* inputs */
569 /* PW 1/2/5 (14h/15h/18h) */
570 parm = AC_PWRST_D3;
571 set_pin_power_state(codec, 0x14, &parm);
572 set_pin_power_state(codec, 0x15, &parm);
573 set_pin_power_state(codec, 0x18, &parm);
574 if (imux_is_smixer)
575 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
576 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
577 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
578 parm);
579 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
580 parm);
581 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
582 parm);
583 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
584 parm);
586 /* outputs */
587 /* PW 3/4 (16h/17h) */
588 parm = AC_PWRST_D3;
589 set_pin_power_state(codec, 0x16, &parm);
590 set_pin_power_state(codec, 0x17, &parm);
591 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
592 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
593 imux_is_smixer ? AC_PWRST_D0 : parm);
594 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
595 parm);
596 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
597 parm);
598 } else if (spec->codec_type == VT1708B_8CH
599 || spec->codec_type == VT1708B_4CH
600 || spec->codec_type == VT1708S) {
601 /* SW0 (17h) = stereo mixer */
602 int is_8ch = spec->codec_type != VT1708B_4CH;
603 imux_is_smixer = snd_hda_codec_read(
604 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
605 == ((spec->codec_type == VT1708S) ? 5 : 0);
606 /* inputs */
607 /* PW 1/2/5 (1ah/1bh/1eh) */
608 parm = AC_PWRST_D3;
609 set_pin_power_state(codec, 0x1a, &parm);
610 set_pin_power_state(codec, 0x1b, &parm);
611 set_pin_power_state(codec, 0x1e, &parm);
612 if (imux_is_smixer)
613 parm = AC_PWRST_D0;
614 /* SW0 (17h), AIW 0/1 (13h/14h) */
615 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
616 parm);
617 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
618 parm);
619 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
620 parm);
622 /* outputs */
623 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
624 parm = AC_PWRST_D3;
625 set_pin_power_state(codec, 0x19, &parm);
626 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
627 parm);
628 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
629 parm);
631 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
632 if (is_8ch) {
633 parm = AC_PWRST_D3;
634 set_pin_power_state(codec, 0x22, &parm);
635 snd_hda_codec_write(codec, 0x26, 0,
636 AC_VERB_SET_POWER_STATE, parm);
637 snd_hda_codec_write(codec, 0x24, 0,
638 AC_VERB_SET_POWER_STATE, parm);
641 /* PW 3/4/7 (1ch/1dh/23h) */
642 parm = AC_PWRST_D3;
643 /* force to D0 for internal Speaker */
644 set_pin_power_state(codec, 0x1c, &parm);
645 set_pin_power_state(codec, 0x1d, &parm);
646 if (is_8ch)
647 set_pin_power_state(codec, 0x23, &parm);
648 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
649 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
650 imux_is_smixer ? AC_PWRST_D0 : parm);
651 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
652 parm);
653 if (is_8ch) {
654 snd_hda_codec_write(codec, 0x25, 0,
655 AC_VERB_SET_POWER_STATE, parm);
656 snd_hda_codec_write(codec, 0x27, 0,
657 AC_VERB_SET_POWER_STATE, parm);
659 } else if (spec->codec_type == VT1718S) {
660 /* MUX6 (1eh) = stereo mixer */
661 imux_is_smixer = snd_hda_codec_read(
662 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
663 /* inputs */
664 /* PW 5/6/7 (29h/2ah/2bh) */
665 parm = AC_PWRST_D3;
666 set_pin_power_state(codec, 0x29, &parm);
667 set_pin_power_state(codec, 0x2a, &parm);
668 set_pin_power_state(codec, 0x2b, &parm);
669 if (imux_is_smixer)
670 parm = AC_PWRST_D0;
671 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
672 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
673 parm);
674 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
675 parm);
676 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
677 parm);
678 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
679 parm);
681 /* outputs */
682 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
683 parm = AC_PWRST_D3;
684 set_pin_power_state(codec, 0x27, &parm);
685 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
686 parm);
687 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
688 parm);
690 /* PW2 (26h), AOW2 (ah) */
691 parm = AC_PWRST_D3;
692 set_pin_power_state(codec, 0x26, &parm);
693 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
694 parm);
696 /* PW0/1 (24h/25h) */
697 parm = AC_PWRST_D3;
698 set_pin_power_state(codec, 0x24, &parm);
699 set_pin_power_state(codec, 0x25, &parm);
700 if (!spec->hp_independent_mode) /* check for redirected HP */
701 set_pin_power_state(codec, 0x28, &parm);
702 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
703 parm);
704 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
705 parm);
706 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
707 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
708 imux_is_smixer ? AC_PWRST_D0 : parm);
709 if (spec->hp_independent_mode) {
710 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
711 parm = AC_PWRST_D3;
712 set_pin_power_state(codec, 0x28, &parm);
713 snd_hda_codec_write(codec, 0x1b, 0,
714 AC_VERB_SET_POWER_STATE, parm);
715 snd_hda_codec_write(codec, 0x34, 0,
716 AC_VERB_SET_POWER_STATE, parm);
717 snd_hda_codec_write(codec, 0xc, 0,
718 AC_VERB_SET_POWER_STATE, parm);
720 } else if (spec->codec_type == VT1716S) {
721 unsigned int mono_out, present;
722 /* SW0 (17h) = stereo mixer */
723 imux_is_smixer = snd_hda_codec_read(
724 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
725 /* inputs */
726 /* PW 1/2/5 (1ah/1bh/1eh) */
727 parm = AC_PWRST_D3;
728 set_pin_power_state(codec, 0x1a, &parm);
729 set_pin_power_state(codec, 0x1b, &parm);
730 set_pin_power_state(codec, 0x1e, &parm);
731 if (imux_is_smixer)
732 parm = AC_PWRST_D0;
733 /* SW0 (17h), AIW0(13h) */
734 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
735 parm);
736 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
737 parm);
739 parm = AC_PWRST_D3;
740 set_pin_power_state(codec, 0x1e, &parm);
741 /* PW11 (22h) */
742 if (spec->dmic_enabled)
743 set_pin_power_state(codec, 0x22, &parm);
744 else
745 snd_hda_codec_write(
746 codec, 0x22, 0,
747 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
749 /* SW2(26h), AIW1(14h) */
750 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
751 parm);
752 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
753 parm);
755 /* outputs */
756 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
757 parm = AC_PWRST_D3;
758 set_pin_power_state(codec, 0x19, &parm);
759 /* Smart 5.1 PW2(1bh) */
760 if (spec->smart51_enabled)
761 set_pin_power_state(codec, 0x1b, &parm);
762 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
763 parm);
764 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
765 parm);
767 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
768 parm = AC_PWRST_D3;
769 set_pin_power_state(codec, 0x23, &parm);
770 /* Smart 5.1 PW1(1ah) */
771 if (spec->smart51_enabled)
772 set_pin_power_state(codec, 0x1a, &parm);
773 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
774 parm);
776 /* Smart 5.1 PW5(1eh) */
777 if (spec->smart51_enabled)
778 set_pin_power_state(codec, 0x1e, &parm);
779 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
780 parm);
782 /* Mono out */
783 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
784 present = snd_hda_codec_read(
785 codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
786 if (present)
787 mono_out = 0;
788 else {
789 present = snd_hda_codec_read(
790 codec, 0x1d, 0, AC_VERB_GET_PIN_SENSE, 0)
791 & 0x80000000;
792 if (!spec->hp_independent_mode && present)
793 mono_out = 0;
794 else
795 mono_out = 1;
797 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
798 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
799 parm);
800 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
801 parm);
802 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
803 parm);
805 /* PW 3/4 (1ch/1dh) */
806 parm = AC_PWRST_D3;
807 set_pin_power_state(codec, 0x1c, &parm);
808 set_pin_power_state(codec, 0x1d, &parm);
809 /* HP Independent Mode, power on AOW3 */
810 if (spec->hp_independent_mode)
811 snd_hda_codec_write(codec, 0x25, 0,
812 AC_VERB_SET_POWER_STATE, parm);
814 /* force to D0 for internal Speaker */
815 /* MW0 (16h), AOW0 (10h) */
816 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
817 imux_is_smixer ? AC_PWRST_D0 : parm);
818 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
819 mono_out ? AC_PWRST_D0 : parm);
820 } else if (spec->codec_type == VT2002P) {
821 unsigned int present;
822 /* MUX9 (1eh) = stereo mixer */
823 imux_is_smixer = snd_hda_codec_read(
824 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
825 /* inputs */
826 /* PW 5/6/7 (29h/2ah/2bh) */
827 parm = AC_PWRST_D3;
828 set_pin_power_state(codec, 0x29, &parm);
829 set_pin_power_state(codec, 0x2a, &parm);
830 set_pin_power_state(codec, 0x2b, &parm);
831 if (imux_is_smixer)
832 parm = AC_PWRST_D0;
833 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
834 snd_hda_codec_write(codec, 0x1e, 0,
835 AC_VERB_SET_POWER_STATE, parm);
836 snd_hda_codec_write(codec, 0x1f, 0,
837 AC_VERB_SET_POWER_STATE, parm);
838 snd_hda_codec_write(codec, 0x10, 0,
839 AC_VERB_SET_POWER_STATE, parm);
840 snd_hda_codec_write(codec, 0x11, 0,
841 AC_VERB_SET_POWER_STATE, parm);
843 /* outputs */
844 /* AOW0 (8h)*/
845 snd_hda_codec_write(codec, 0x8, 0,
846 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
848 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
849 parm = AC_PWRST_D3;
850 set_pin_power_state(codec, 0x26, &parm);
851 snd_hda_codec_write(codec, 0x1c, 0,
852 AC_VERB_SET_POWER_STATE, parm);
853 snd_hda_codec_write(codec, 0x37,
854 0, AC_VERB_SET_POWER_STATE, parm);
856 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
857 parm = AC_PWRST_D3;
858 set_pin_power_state(codec, 0x25, &parm);
859 snd_hda_codec_write(codec, 0x19, 0,
860 AC_VERB_SET_POWER_STATE, parm);
861 snd_hda_codec_write(codec, 0x35, 0,
862 AC_VERB_SET_POWER_STATE, parm);
863 if (spec->hp_independent_mode) {
864 snd_hda_codec_write(codec, 0x9, 0,
865 AC_VERB_SET_POWER_STATE, parm);
868 /* Class-D */
869 /* PW0 (24h), MW0(18h), MUX0(34h) */
870 present = snd_hda_codec_read(
871 codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
872 parm = AC_PWRST_D3;
873 set_pin_power_state(codec, 0x24, &parm);
874 if (present) {
875 snd_hda_codec_write(
876 codec, 0x18, 0,
877 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
878 snd_hda_codec_write(
879 codec, 0x34, 0,
880 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
881 } else {
882 snd_hda_codec_write(
883 codec, 0x18, 0,
884 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
885 snd_hda_codec_write(
886 codec, 0x34, 0,
887 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
890 /* Mono Out */
891 /* PW15 (31h), MW8(17h), MUX8(3bh) */
892 present = snd_hda_codec_read(
893 codec, 0x26, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
894 parm = AC_PWRST_D3;
895 set_pin_power_state(codec, 0x31, &parm);
896 if (present) {
897 snd_hda_codec_write(
898 codec, 0x17, 0,
899 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
900 snd_hda_codec_write(
901 codec, 0x3b, 0,
902 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
903 } else {
904 snd_hda_codec_write(
905 codec, 0x17, 0,
906 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
907 snd_hda_codec_write(
908 codec, 0x3b, 0,
909 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
912 /* MW9 (21h) */
913 if (imux_is_smixer || !is_aa_path_mute(codec))
914 snd_hda_codec_write(
915 codec, 0x21, 0,
916 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
917 else
918 snd_hda_codec_write(
919 codec, 0x21, 0,
920 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
921 } else if (spec->codec_type == VT1812) {
922 unsigned int present;
923 /* MUX10 (1eh) = stereo mixer */
924 imux_is_smixer = snd_hda_codec_read(
925 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
926 /* inputs */
927 /* PW 5/6/7 (29h/2ah/2bh) */
928 parm = AC_PWRST_D3;
929 set_pin_power_state(codec, 0x29, &parm);
930 set_pin_power_state(codec, 0x2a, &parm);
931 set_pin_power_state(codec, 0x2b, &parm);
932 if (imux_is_smixer)
933 parm = AC_PWRST_D0;
934 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
935 snd_hda_codec_write(codec, 0x1e, 0,
936 AC_VERB_SET_POWER_STATE, parm);
937 snd_hda_codec_write(codec, 0x1f, 0,
938 AC_VERB_SET_POWER_STATE, parm);
939 snd_hda_codec_write(codec, 0x10, 0,
940 AC_VERB_SET_POWER_STATE, parm);
941 snd_hda_codec_write(codec, 0x11, 0,
942 AC_VERB_SET_POWER_STATE, parm);
944 /* outputs */
945 /* AOW0 (8h)*/
946 snd_hda_codec_write(codec, 0x8, 0,
947 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
949 /* PW4 (28h), MW4 (18h), MUX4(38h) */
950 parm = AC_PWRST_D3;
951 set_pin_power_state(codec, 0x28, &parm);
952 snd_hda_codec_write(codec, 0x18, 0,
953 AC_VERB_SET_POWER_STATE, parm);
954 snd_hda_codec_write(codec, 0x38, 0,
955 AC_VERB_SET_POWER_STATE, parm);
957 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
958 parm = AC_PWRST_D3;
959 set_pin_power_state(codec, 0x25, &parm);
960 snd_hda_codec_write(codec, 0x15, 0,
961 AC_VERB_SET_POWER_STATE, parm);
962 snd_hda_codec_write(codec, 0x35, 0,
963 AC_VERB_SET_POWER_STATE, parm);
964 if (spec->hp_independent_mode) {
965 snd_hda_codec_write(codec, 0x9, 0,
966 AC_VERB_SET_POWER_STATE, parm);
969 /* Internal Speaker */
970 /* PW0 (24h), MW0(14h), MUX0(34h) */
971 present = snd_hda_codec_read(
972 codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
973 parm = AC_PWRST_D3;
974 set_pin_power_state(codec, 0x24, &parm);
975 if (present) {
976 snd_hda_codec_write(codec, 0x14, 0,
977 AC_VERB_SET_POWER_STATE,
978 AC_PWRST_D3);
979 snd_hda_codec_write(codec, 0x34, 0,
980 AC_VERB_SET_POWER_STATE,
981 AC_PWRST_D3);
982 } else {
983 snd_hda_codec_write(codec, 0x14, 0,
984 AC_VERB_SET_POWER_STATE,
985 AC_PWRST_D0);
986 snd_hda_codec_write(codec, 0x34, 0,
987 AC_VERB_SET_POWER_STATE,
988 AC_PWRST_D0);
990 /* Mono Out */
991 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
992 present = snd_hda_codec_read(
993 codec, 0x28, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
994 parm = AC_PWRST_D3;
995 set_pin_power_state(codec, 0x31, &parm);
996 if (present) {
997 snd_hda_codec_write(codec, 0x1c, 0,
998 AC_VERB_SET_POWER_STATE,
999 AC_PWRST_D3);
1000 snd_hda_codec_write(codec, 0x3c, 0,
1001 AC_VERB_SET_POWER_STATE,
1002 AC_PWRST_D3);
1003 snd_hda_codec_write(codec, 0x3e, 0,
1004 AC_VERB_SET_POWER_STATE,
1005 AC_PWRST_D3);
1006 } else {
1007 snd_hda_codec_write(codec, 0x1c, 0,
1008 AC_VERB_SET_POWER_STATE,
1009 AC_PWRST_D0);
1010 snd_hda_codec_write(codec, 0x3c, 0,
1011 AC_VERB_SET_POWER_STATE,
1012 AC_PWRST_D0);
1013 snd_hda_codec_write(codec, 0x3e, 0,
1014 AC_VERB_SET_POWER_STATE,
1015 AC_PWRST_D0);
1018 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1019 parm = AC_PWRST_D3;
1020 set_pin_power_state(codec, 0x33, &parm);
1021 snd_hda_codec_write(codec, 0x1d, 0,
1022 AC_VERB_SET_POWER_STATE, parm);
1023 snd_hda_codec_write(codec, 0x3d, 0,
1024 AC_VERB_SET_POWER_STATE, parm);
1026 /* MW9 (21h) */
1027 if (imux_is_smixer || !is_aa_path_mute(codec))
1028 snd_hda_codec_write(
1029 codec, 0x21, 0,
1030 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1031 else
1032 snd_hda_codec_write(
1033 codec, 0x21, 0,
1034 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1039 * input MUX handling
1041 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1042 struct snd_ctl_elem_info *uinfo)
1044 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1045 struct via_spec *spec = codec->spec;
1046 return snd_hda_input_mux_info(spec->input_mux, uinfo);
1049 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1050 struct snd_ctl_elem_value *ucontrol)
1052 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1053 struct via_spec *spec = codec->spec;
1054 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1056 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
1057 return 0;
1060 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1061 struct snd_ctl_elem_value *ucontrol)
1063 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1064 struct via_spec *spec = codec->spec;
1065 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1067 if (!spec->mux_nids[adc_idx])
1068 return -EINVAL;
1069 /* switch to D0 beofre change index */
1070 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1071 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1072 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1073 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1074 /* update jack power state */
1075 set_jack_power_state(codec);
1077 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1078 spec->mux_nids[adc_idx],
1079 &spec->cur_mux[adc_idx]);
1082 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
1083 struct snd_ctl_elem_info *uinfo)
1085 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1086 struct via_spec *spec = codec->spec;
1087 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
1090 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
1091 struct snd_ctl_elem_value *ucontrol)
1093 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1094 struct via_spec *spec = codec->spec;
1095 hda_nid_t nid;
1096 unsigned int pinsel;
1098 switch (spec->codec_type) {
1099 case VT1718S:
1100 nid = 0x34;
1101 break;
1102 case VT2002P:
1103 nid = 0x35;
1104 break;
1105 case VT1812:
1106 nid = 0x3d;
1107 break;
1108 default:
1109 nid = spec->autocfg.hp_pins[0];
1110 break;
1112 /* use !! to translate conn sel 2 for VT1718S */
1113 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1114 AC_VERB_GET_CONNECT_SEL,
1115 0x00);
1116 ucontrol->value.enumerated.item[0] = pinsel;
1118 return 0;
1121 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1123 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1124 if (ctl) {
1125 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1126 ctl->vd[0].access |= active
1127 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1128 snd_ctl_notify(codec->bus->card,
1129 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1133 static int update_side_mute_status(struct hda_codec *codec)
1135 /* mute side channel */
1136 struct via_spec *spec = codec->spec;
1137 unsigned int parm = spec->hp_independent_mode
1138 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1139 hda_nid_t sw3;
1141 switch (spec->codec_type) {
1142 case VT1708:
1143 sw3 = 0x1b;
1144 break;
1145 case VT1709_10CH:
1146 sw3 = 0x29;
1147 break;
1148 case VT1708B_8CH:
1149 case VT1708S:
1150 sw3 = 0x27;
1151 break;
1152 default:
1153 sw3 = 0;
1154 break;
1157 if (sw3)
1158 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1159 parm);
1160 return 0;
1163 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
1164 struct snd_ctl_elem_value *ucontrol)
1166 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1167 struct via_spec *spec = codec->spec;
1168 hda_nid_t nid = spec->autocfg.hp_pins[0];
1169 unsigned int pinsel = ucontrol->value.enumerated.item[0];
1170 /* Get Independent Mode index of headphone pin widget */
1171 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1172 ? 1 : 0;
1174 switch (spec->codec_type) {
1175 case VT1718S:
1176 nid = 0x34;
1177 pinsel = pinsel ? 2 : 0; /* indep HP use AOW4 (index 2) */
1178 spec->multiout.num_dacs = 4;
1179 break;
1180 case VT2002P:
1181 nid = 0x35;
1182 break;
1183 case VT1812:
1184 nid = 0x3d;
1185 break;
1186 default:
1187 nid = spec->autocfg.hp_pins[0];
1188 break;
1190 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
1192 if (spec->multiout.hp_nid && spec->multiout.hp_nid
1193 != spec->multiout.dac_nids[HDA_FRONT])
1194 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
1195 0, 0, 0);
1197 update_side_mute_status(codec);
1198 /* update HP volume/swtich active state */
1199 if (spec->codec_type == VT1708S
1200 || spec->codec_type == VT1702
1201 || spec->codec_type == VT1718S
1202 || spec->codec_type == VT1716S
1203 || spec->codec_type == VT2002P
1204 || spec->codec_type == VT1812) {
1205 activate_ctl(codec, "Headphone Playback Volume",
1206 spec->hp_independent_mode);
1207 activate_ctl(codec, "Headphone Playback Switch",
1208 spec->hp_independent_mode);
1210 return 0;
1213 static struct snd_kcontrol_new via_hp_mixer[] = {
1215 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1216 .name = "Independent HP",
1217 .count = 1,
1218 .info = via_independent_hp_info,
1219 .get = via_independent_hp_get,
1220 .put = via_independent_hp_put,
1222 { } /* end */
1225 static void notify_aa_path_ctls(struct hda_codec *codec)
1227 int i;
1228 struct snd_ctl_elem_id id;
1229 const char *labels[] = {"Mic", "Front Mic", "Line"};
1231 memset(&id, 0, sizeof(id));
1232 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1233 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1234 sprintf(id.name, "%s Playback Volume", labels[i]);
1235 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1236 &id);
1240 static void mute_aa_path(struct hda_codec *codec, int mute)
1242 struct via_spec *spec = codec->spec;
1243 hda_nid_t nid_mixer;
1244 int start_idx;
1245 int end_idx;
1246 int i;
1247 /* get nid of MW0 and start & end index */
1248 switch (spec->codec_type) {
1249 case VT1708:
1250 nid_mixer = 0x17;
1251 start_idx = 2;
1252 end_idx = 4;
1253 break;
1254 case VT1709_10CH:
1255 case VT1709_6CH:
1256 nid_mixer = 0x18;
1257 start_idx = 2;
1258 end_idx = 4;
1259 break;
1260 case VT1708B_8CH:
1261 case VT1708B_4CH:
1262 case VT1708S:
1263 case VT1716S:
1264 nid_mixer = 0x16;
1265 start_idx = 2;
1266 end_idx = 4;
1267 break;
1268 default:
1269 return;
1271 /* check AA path's mute status */
1272 for (i = start_idx; i <= end_idx; i++) {
1273 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1274 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1275 HDA_AMP_MUTE, val);
1278 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1280 int res = 0;
1281 int index;
1282 for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
1283 if (pin == spec->autocfg.input_pins[index]) {
1284 res = 1;
1285 break;
1288 return res;
1291 static int via_smart51_info(struct snd_kcontrol *kcontrol,
1292 struct snd_ctl_elem_info *uinfo)
1294 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1295 uinfo->count = 1;
1296 uinfo->value.integer.min = 0;
1297 uinfo->value.integer.max = 1;
1298 return 0;
1301 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1302 struct snd_ctl_elem_value *ucontrol)
1304 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1305 struct via_spec *spec = codec->spec;
1306 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1307 int on = 1;
1308 int i;
1310 for (i = 0; i < ARRAY_SIZE(index); i++) {
1311 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1312 if (nid) {
1313 int ctl =
1314 snd_hda_codec_read(codec, nid, 0,
1315 AC_VERB_GET_PIN_WIDGET_CONTROL,
1317 if (i == AUTO_PIN_FRONT_MIC
1318 && spec->hp_independent_mode
1319 && spec->codec_type != VT1718S)
1320 continue; /* ignore FMic for independent HP */
1321 if (ctl & AC_PINCTL_IN_EN
1322 && !(ctl & AC_PINCTL_OUT_EN))
1323 on = 0;
1326 *ucontrol->value.integer.value = on;
1327 return 0;
1330 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1331 struct snd_ctl_elem_value *ucontrol)
1333 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1334 struct via_spec *spec = codec->spec;
1335 int out_in = *ucontrol->value.integer.value
1336 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1337 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1338 int i;
1340 for (i = 0; i < ARRAY_SIZE(index); i++) {
1341 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1342 if (i == AUTO_PIN_FRONT_MIC
1343 && spec->hp_independent_mode
1344 && spec->codec_type != VT1718S)
1345 continue; /* don't retask FMic for independent HP */
1346 if (nid) {
1347 unsigned int parm = snd_hda_codec_read(
1348 codec, nid, 0,
1349 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1350 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1351 parm |= out_in;
1352 snd_hda_codec_write(codec, nid, 0,
1353 AC_VERB_SET_PIN_WIDGET_CONTROL,
1354 parm);
1355 if (out_in == AC_PINCTL_OUT_EN) {
1356 mute_aa_path(codec, 1);
1357 notify_aa_path_ctls(codec);
1359 if (spec->codec_type == VT1718S)
1360 snd_hda_codec_amp_stereo(
1361 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1362 HDA_AMP_UNMUTE);
1364 if (i == AUTO_PIN_FRONT_MIC) {
1365 if (spec->codec_type == VT1708S
1366 || spec->codec_type == VT1716S) {
1367 /* input = index 1 (AOW3) */
1368 snd_hda_codec_write(
1369 codec, nid, 0,
1370 AC_VERB_SET_CONNECT_SEL, 1);
1371 snd_hda_codec_amp_stereo(
1372 codec, nid, HDA_OUTPUT,
1373 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1377 spec->smart51_enabled = *ucontrol->value.integer.value;
1378 set_jack_power_state(codec);
1379 return 1;
1382 static struct snd_kcontrol_new via_smart51_mixer[] = {
1384 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1385 .name = "Smart 5.1",
1386 .count = 1,
1387 .info = via_smart51_info,
1388 .get = via_smart51_get,
1389 .put = via_smart51_put,
1391 {} /* end */
1394 /* capture mixer elements */
1395 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1396 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1397 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1398 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1399 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1401 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1402 /* The multiple "Capture Source" controls confuse alsamixer
1403 * So call somewhat different..
1405 /* .name = "Capture Source", */
1406 .name = "Input Source",
1407 .count = 1,
1408 .info = via_mux_enum_info,
1409 .get = via_mux_enum_get,
1410 .put = via_mux_enum_put,
1412 { } /* end */
1415 /* check AA path's mute statue */
1416 static int is_aa_path_mute(struct hda_codec *codec)
1418 int mute = 1;
1419 hda_nid_t nid_mixer;
1420 int start_idx;
1421 int end_idx;
1422 int i;
1423 struct via_spec *spec = codec->spec;
1424 /* get nid of MW0 and start & end index */
1425 switch (spec->codec_type) {
1426 case VT1708B_8CH:
1427 case VT1708B_4CH:
1428 case VT1708S:
1429 case VT1716S:
1430 nid_mixer = 0x16;
1431 start_idx = 2;
1432 end_idx = 4;
1433 break;
1434 case VT1702:
1435 nid_mixer = 0x1a;
1436 start_idx = 1;
1437 end_idx = 3;
1438 break;
1439 case VT1718S:
1440 nid_mixer = 0x21;
1441 start_idx = 1;
1442 end_idx = 3;
1443 break;
1444 case VT2002P:
1445 case VT1812:
1446 nid_mixer = 0x21;
1447 start_idx = 0;
1448 end_idx = 2;
1449 break;
1450 default:
1451 return 0;
1453 /* check AA path's mute status */
1454 for (i = start_idx; i <= end_idx; i++) {
1455 unsigned int con_list = snd_hda_codec_read(
1456 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1457 int shift = 8 * (i % 4);
1458 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1459 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1460 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1461 /* check mute status while the pin is connected */
1462 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1463 HDA_INPUT, i) >> 7;
1464 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1465 HDA_INPUT, i) >> 7;
1466 if (!mute_l || !mute_r) {
1467 mute = 0;
1468 break;
1472 return mute;
1475 /* enter/exit analog low-current mode */
1476 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1478 struct via_spec *spec = codec->spec;
1479 static int saved_stream_idle = 1; /* saved stream idle status */
1480 int enable = is_aa_path_mute(codec);
1481 unsigned int verb = 0;
1482 unsigned int parm = 0;
1484 if (stream_idle == -1) /* stream status did not change */
1485 enable = enable && saved_stream_idle;
1486 else {
1487 enable = enable && stream_idle;
1488 saved_stream_idle = stream_idle;
1491 /* decide low current mode's verb & parameter */
1492 switch (spec->codec_type) {
1493 case VT1708B_8CH:
1494 case VT1708B_4CH:
1495 verb = 0xf70;
1496 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1497 break;
1498 case VT1708S:
1499 case VT1718S:
1500 case VT1716S:
1501 verb = 0xf73;
1502 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1503 break;
1504 case VT1702:
1505 verb = 0xf73;
1506 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1507 break;
1508 case VT2002P:
1509 case VT1812:
1510 verb = 0xf93;
1511 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1512 break;
1513 default:
1514 return; /* other codecs are not supported */
1516 /* send verb */
1517 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1521 * generic initialization of ADC, input mixers and output mixers
1523 static struct hda_verb vt1708_volume_init_verbs[] = {
1525 * Unmute ADC0-1 and set the default input to mic-in
1527 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1528 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1531 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1532 * mixer widget
1534 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1535 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1536 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1537 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1538 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1539 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1542 * Set up output mixers (0x19 - 0x1b)
1544 /* set vol=0 to output mixers */
1545 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1546 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1547 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1549 /* Setup default input MW0 to PW4 */
1550 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1551 /* PW9 Output enable */
1552 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1556 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1557 struct hda_codec *codec,
1558 struct snd_pcm_substream *substream)
1560 struct via_spec *spec = codec->spec;
1561 int idle = substream->pstr->substream_opened == 1
1562 && substream->ref_count == 0;
1563 analog_low_current_mode(codec, idle);
1564 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1565 hinfo);
1568 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1569 unsigned int stream_tag,
1570 unsigned int format,
1571 struct snd_pcm_substream *substream)
1573 struct via_spec *spec = codec->spec;
1574 struct hda_multi_out *mout = &spec->multiout;
1575 hda_nid_t *nids = mout->dac_nids;
1576 int chs = substream->runtime->channels;
1577 int i;
1579 mutex_lock(&codec->spdif_mutex);
1580 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1581 if (chs == 2 &&
1582 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1583 format) &&
1584 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1585 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1586 /* turn off SPDIF once; otherwise the IEC958 bits won't
1587 * be updated */
1588 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1589 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1590 AC_VERB_SET_DIGI_CONVERT_1,
1591 codec->spdif_ctls &
1592 ~AC_DIG1_ENABLE & 0xff);
1593 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1594 stream_tag, 0, format);
1595 /* turn on again (if needed) */
1596 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1597 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1598 AC_VERB_SET_DIGI_CONVERT_1,
1599 codec->spdif_ctls & 0xff);
1600 } else {
1601 mout->dig_out_used = 0;
1602 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1603 0, 0, 0);
1606 mutex_unlock(&codec->spdif_mutex);
1608 /* front */
1609 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1610 0, format);
1612 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1613 && !spec->hp_independent_mode)
1614 /* headphone out will just decode front left/right (stereo) */
1615 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1616 0, format);
1618 /* extra outputs copied from front */
1619 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1620 if (mout->extra_out_nid[i])
1621 snd_hda_codec_setup_stream(codec,
1622 mout->extra_out_nid[i],
1623 stream_tag, 0, format);
1625 /* surrounds */
1626 for (i = 1; i < mout->num_dacs; i++) {
1627 if (chs >= (i + 1) * 2) /* independent out */
1628 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1629 i * 2, format);
1630 else /* copy front */
1631 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1632 0, format);
1636 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1637 struct hda_codec *codec,
1638 unsigned int stream_tag,
1639 unsigned int format,
1640 struct snd_pcm_substream *substream)
1642 struct via_spec *spec = codec->spec;
1643 struct hda_multi_out *mout = &spec->multiout;
1644 hda_nid_t *nids = mout->dac_nids;
1646 if (substream->number == 0)
1647 playback_multi_pcm_prep_0(codec, stream_tag, format,
1648 substream);
1649 else {
1650 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1651 spec->hp_independent_mode)
1652 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1653 stream_tag, 0, format);
1655 vt1708_start_hp_work(spec);
1656 return 0;
1659 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1660 struct hda_codec *codec,
1661 struct snd_pcm_substream *substream)
1663 struct via_spec *spec = codec->spec;
1664 struct hda_multi_out *mout = &spec->multiout;
1665 hda_nid_t *nids = mout->dac_nids;
1666 int i;
1668 if (substream->number == 0) {
1669 for (i = 0; i < mout->num_dacs; i++)
1670 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1672 if (mout->hp_nid && !spec->hp_independent_mode)
1673 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1674 0, 0, 0);
1676 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1677 if (mout->extra_out_nid[i])
1678 snd_hda_codec_setup_stream(codec,
1679 mout->extra_out_nid[i],
1680 0, 0, 0);
1681 mutex_lock(&codec->spdif_mutex);
1682 if (mout->dig_out_nid &&
1683 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1684 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1685 0, 0, 0);
1686 mout->dig_out_used = 0;
1688 mutex_unlock(&codec->spdif_mutex);
1689 } else {
1690 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1691 spec->hp_independent_mode)
1692 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1693 0, 0, 0);
1695 vt1708_stop_hp_work(spec);
1696 return 0;
1700 * Digital out
1702 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1703 struct hda_codec *codec,
1704 struct snd_pcm_substream *substream)
1706 struct via_spec *spec = codec->spec;
1707 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1710 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1711 struct hda_codec *codec,
1712 struct snd_pcm_substream *substream)
1714 struct via_spec *spec = codec->spec;
1715 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1718 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1719 struct hda_codec *codec,
1720 unsigned int stream_tag,
1721 unsigned int format,
1722 struct snd_pcm_substream *substream)
1724 struct via_spec *spec = codec->spec;
1725 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1726 stream_tag, format, substream);
1729 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1730 struct hda_codec *codec,
1731 struct snd_pcm_substream *substream)
1733 struct via_spec *spec = codec->spec;
1734 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1735 return 0;
1739 * Analog capture
1741 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1742 struct hda_codec *codec,
1743 unsigned int stream_tag,
1744 unsigned int format,
1745 struct snd_pcm_substream *substream)
1747 struct via_spec *spec = codec->spec;
1749 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1750 stream_tag, 0, format);
1751 return 0;
1754 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1755 struct hda_codec *codec,
1756 struct snd_pcm_substream *substream)
1758 struct via_spec *spec = codec->spec;
1759 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1760 return 0;
1763 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1764 .substreams = 2,
1765 .channels_min = 2,
1766 .channels_max = 8,
1767 .nid = 0x10, /* NID to query formats and rates */
1768 .ops = {
1769 .open = via_playback_pcm_open,
1770 .prepare = via_playback_multi_pcm_prepare,
1771 .cleanup = via_playback_multi_pcm_cleanup
1775 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1776 .substreams = 2,
1777 .channels_min = 2,
1778 .channels_max = 8,
1779 .nid = 0x10, /* NID to query formats and rates */
1780 /* We got noisy outputs on the right channel on VT1708 when
1781 * 24bit samples are used. Until any workaround is found,
1782 * disable the 24bit format, so far.
1784 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1785 .ops = {
1786 .open = via_playback_pcm_open,
1787 .prepare = via_playback_multi_pcm_prepare,
1788 .cleanup = via_playback_multi_pcm_cleanup
1792 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1793 .substreams = 2,
1794 .channels_min = 2,
1795 .channels_max = 2,
1796 .nid = 0x15, /* NID to query formats and rates */
1797 .ops = {
1798 .prepare = via_capture_pcm_prepare,
1799 .cleanup = via_capture_pcm_cleanup
1803 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1804 .substreams = 1,
1805 .channels_min = 2,
1806 .channels_max = 2,
1807 /* NID is set in via_build_pcms */
1808 .ops = {
1809 .open = via_dig_playback_pcm_open,
1810 .close = via_dig_playback_pcm_close,
1811 .prepare = via_dig_playback_pcm_prepare,
1812 .cleanup = via_dig_playback_pcm_cleanup
1816 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1817 .substreams = 1,
1818 .channels_min = 2,
1819 .channels_max = 2,
1822 static int via_build_controls(struct hda_codec *codec)
1824 struct via_spec *spec = codec->spec;
1825 int err;
1826 int i;
1828 for (i = 0; i < spec->num_mixers; i++) {
1829 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1830 if (err < 0)
1831 return err;
1834 if (spec->multiout.dig_out_nid) {
1835 err = snd_hda_create_spdif_out_ctls(codec,
1836 spec->multiout.dig_out_nid);
1837 if (err < 0)
1838 return err;
1839 err = snd_hda_create_spdif_share_sw(codec,
1840 &spec->multiout);
1841 if (err < 0)
1842 return err;
1843 spec->multiout.share_spdif = 1;
1845 if (spec->dig_in_nid) {
1846 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1847 if (err < 0)
1848 return err;
1851 /* init power states */
1852 set_jack_power_state(codec);
1853 analog_low_current_mode(codec, 1);
1855 via_free_kctls(codec); /* no longer needed */
1856 return 0;
1859 static int via_build_pcms(struct hda_codec *codec)
1861 struct via_spec *spec = codec->spec;
1862 struct hda_pcm *info = spec->pcm_rec;
1864 codec->num_pcms = 1;
1865 codec->pcm_info = info;
1867 info->name = spec->stream_name_analog;
1868 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1869 *(spec->stream_analog_playback);
1870 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1871 spec->multiout.dac_nids[0];
1872 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1873 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1875 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1876 spec->multiout.max_channels;
1878 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1879 codec->num_pcms++;
1880 info++;
1881 info->name = spec->stream_name_digital;
1882 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1883 if (spec->multiout.dig_out_nid) {
1884 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1885 *(spec->stream_digital_playback);
1886 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1887 spec->multiout.dig_out_nid;
1889 if (spec->dig_in_nid) {
1890 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1891 *(spec->stream_digital_capture);
1892 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1893 spec->dig_in_nid;
1897 return 0;
1900 static void via_free(struct hda_codec *codec)
1902 struct via_spec *spec = codec->spec;
1904 if (!spec)
1905 return;
1907 via_free_kctls(codec);
1908 vt1708_stop_hp_work(spec);
1909 kfree(codec->spec);
1912 /* mute internal speaker if HP is plugged */
1913 static void via_hp_automute(struct hda_codec *codec)
1915 unsigned int present = 0;
1916 struct via_spec *spec = codec->spec;
1918 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
1919 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1921 if (!spec->hp_independent_mode) {
1922 struct snd_ctl_elem_id id;
1923 /* auto mute */
1924 snd_hda_codec_amp_stereo(
1925 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1926 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1927 /* notify change */
1928 memset(&id, 0, sizeof(id));
1929 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1930 strcpy(id.name, "Front Playback Switch");
1931 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1932 &id);
1936 /* mute mono out if HP or Line out is plugged */
1937 static void via_mono_automute(struct hda_codec *codec)
1939 unsigned int hp_present, lineout_present;
1940 struct via_spec *spec = codec->spec;
1942 if (spec->codec_type != VT1716S)
1943 return;
1945 lineout_present = snd_hda_codec_read(
1946 codec, spec->autocfg.line_out_pins[0], 0,
1947 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1949 /* Mute Mono Out if Line Out is plugged */
1950 if (lineout_present) {
1951 snd_hda_codec_amp_stereo(
1952 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1953 return;
1956 hp_present = snd_hda_codec_read(
1957 codec, spec->autocfg.hp_pins[0], 0,
1958 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1960 if (!spec->hp_independent_mode)
1961 snd_hda_codec_amp_stereo(
1962 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1963 hp_present ? HDA_AMP_MUTE : 0);
1966 static void via_gpio_control(struct hda_codec *codec)
1968 unsigned int gpio_data;
1969 unsigned int vol_counter;
1970 unsigned int vol;
1971 unsigned int master_vol;
1973 struct via_spec *spec = codec->spec;
1975 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1976 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1978 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1979 0xF84, 0) & 0x3F0000) >> 16;
1981 vol = vol_counter & 0x1F;
1982 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1983 AC_VERB_GET_AMP_GAIN_MUTE,
1984 AC_AMP_GET_INPUT);
1986 if (gpio_data == 0x02) {
1987 /* unmute line out */
1988 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1989 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1991 if (vol_counter & 0x20) {
1992 /* decrease volume */
1993 if (vol > master_vol)
1994 vol = master_vol;
1995 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1996 0, HDA_AMP_VOLMASK,
1997 master_vol-vol);
1998 } else {
1999 /* increase volume */
2000 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
2001 HDA_AMP_VOLMASK,
2002 ((master_vol+vol) > 0x2A) ? 0x2A :
2003 (master_vol+vol));
2005 } else if (!(gpio_data & 0x02)) {
2006 /* mute line out */
2007 snd_hda_codec_amp_stereo(codec,
2008 spec->autocfg.line_out_pins[0],
2009 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2010 HDA_AMP_MUTE);
2014 /* mute Internal-Speaker if HP is plugged */
2015 static void via_speaker_automute(struct hda_codec *codec)
2017 unsigned int hp_present;
2018 struct via_spec *spec = codec->spec;
2020 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2021 return;
2023 hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
2024 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2026 if (!spec->hp_independent_mode) {
2027 struct snd_ctl_elem_id id;
2028 snd_hda_codec_amp_stereo(
2029 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2030 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2031 /* notify change */
2032 memset(&id, 0, sizeof(id));
2033 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2034 strcpy(id.name, "Speaker Playback Switch");
2035 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2036 &id);
2040 /* mute line-out and internal speaker if HP is plugged */
2041 static void via_hp_bind_automute(struct hda_codec *codec)
2043 unsigned int hp_present, present = 0;
2044 struct via_spec *spec = codec->spec;
2045 int i;
2047 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2048 return;
2050 hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
2051 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2053 present = snd_hda_codec_read(codec, spec->autocfg.line_out_pins[0], 0,
2054 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2056 if (!spec->hp_independent_mode) {
2057 /* Mute Line-Outs */
2058 for (i = 0; i < spec->autocfg.line_outs; i++)
2059 snd_hda_codec_amp_stereo(
2060 codec, spec->autocfg.line_out_pins[i],
2061 HDA_OUTPUT, 0,
2062 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2063 if (hp_present)
2064 present = hp_present;
2066 /* Speakers */
2067 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2068 snd_hda_codec_amp_stereo(
2069 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2070 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2074 /* unsolicited event for jack sensing */
2075 static void via_unsol_event(struct hda_codec *codec,
2076 unsigned int res)
2078 res >>= 26;
2079 if (res & VIA_HP_EVENT)
2080 via_hp_automute(codec);
2081 if (res & VIA_GPIO_EVENT)
2082 via_gpio_control(codec);
2083 if (res & VIA_JACK_EVENT)
2084 set_jack_power_state(codec);
2085 if (res & VIA_MONO_EVENT)
2086 via_mono_automute(codec);
2087 if (res & VIA_SPEAKER_EVENT)
2088 via_speaker_automute(codec);
2089 if (res & VIA_BIND_HP_EVENT)
2090 via_hp_bind_automute(codec);
2093 static int via_init(struct hda_codec *codec)
2095 struct via_spec *spec = codec->spec;
2096 int i;
2097 for (i = 0; i < spec->num_iverbs; i++)
2098 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2100 spec->codec_type = get_codec_type(codec);
2101 if (spec->codec_type == VT1708BCE)
2102 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2103 same */
2104 /* Lydia Add for EAPD enable */
2105 if (!spec->dig_in_nid) { /* No Digital In connection */
2106 if (spec->dig_in_pin) {
2107 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2108 AC_VERB_SET_PIN_WIDGET_CONTROL,
2109 PIN_OUT);
2110 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2111 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2113 } else /* enable SPDIF-input pin */
2114 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2115 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2117 /* assign slave outs */
2118 if (spec->slave_dig_outs[0])
2119 codec->slave_dig_outs = spec->slave_dig_outs;
2121 return 0;
2124 #ifdef SND_HDA_NEEDS_RESUME
2125 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2127 struct via_spec *spec = codec->spec;
2128 vt1708_stop_hp_work(spec);
2129 return 0;
2131 #endif
2133 #ifdef CONFIG_SND_HDA_POWER_SAVE
2134 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2136 struct via_spec *spec = codec->spec;
2137 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2139 #endif
2143 static struct hda_codec_ops via_patch_ops = {
2144 .build_controls = via_build_controls,
2145 .build_pcms = via_build_pcms,
2146 .init = via_init,
2147 .free = via_free,
2148 #ifdef SND_HDA_NEEDS_RESUME
2149 .suspend = via_suspend,
2150 #endif
2151 #ifdef CONFIG_SND_HDA_POWER_SAVE
2152 .check_power_status = via_check_power_status,
2153 #endif
2156 /* fill in the dac_nids table from the parsed pin configuration */
2157 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2158 const struct auto_pin_cfg *cfg)
2160 int i;
2161 hda_nid_t nid;
2163 spec->multiout.num_dacs = cfg->line_outs;
2165 spec->multiout.dac_nids = spec->private_dac_nids;
2167 for (i = 0; i < 4; i++) {
2168 nid = cfg->line_out_pins[i];
2169 if (nid) {
2170 /* config dac list */
2171 switch (i) {
2172 case AUTO_SEQ_FRONT:
2173 spec->multiout.dac_nids[i] = 0x10;
2174 break;
2175 case AUTO_SEQ_CENLFE:
2176 spec->multiout.dac_nids[i] = 0x12;
2177 break;
2178 case AUTO_SEQ_SURROUND:
2179 spec->multiout.dac_nids[i] = 0x11;
2180 break;
2181 case AUTO_SEQ_SIDE:
2182 spec->multiout.dac_nids[i] = 0x13;
2183 break;
2188 return 0;
2191 /* add playback controls from the parsed DAC table */
2192 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2193 const struct auto_pin_cfg *cfg)
2195 char name[32];
2196 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2197 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2198 int i, err;
2200 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2201 nid = cfg->line_out_pins[i];
2203 if (!nid)
2204 continue;
2206 nid_vol = nid_vols[i];
2208 if (i == AUTO_SEQ_CENLFE) {
2209 /* Center/LFE */
2210 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2211 "Center Playback Volume",
2212 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2213 HDA_OUTPUT));
2214 if (err < 0)
2215 return err;
2216 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2217 "LFE Playback Volume",
2218 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2219 HDA_OUTPUT));
2220 if (err < 0)
2221 return err;
2222 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2223 "Center Playback Switch",
2224 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2225 HDA_OUTPUT));
2226 if (err < 0)
2227 return err;
2228 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2229 "LFE Playback Switch",
2230 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2231 HDA_OUTPUT));
2232 if (err < 0)
2233 return err;
2234 } else if (i == AUTO_SEQ_FRONT) {
2235 /* add control to mixer index 0 */
2236 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2237 "Master Front Playback Volume",
2238 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2239 HDA_INPUT));
2240 if (err < 0)
2241 return err;
2242 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2243 "Master Front Playback Switch",
2244 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2245 HDA_INPUT));
2246 if (err < 0)
2247 return err;
2249 /* add control to PW3 */
2250 sprintf(name, "%s Playback Volume", chname[i]);
2251 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2252 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2253 HDA_OUTPUT));
2254 if (err < 0)
2255 return err;
2256 sprintf(name, "%s Playback Switch", chname[i]);
2257 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2258 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2259 HDA_OUTPUT));
2260 if (err < 0)
2261 return err;
2262 } else {
2263 sprintf(name, "%s Playback Volume", chname[i]);
2264 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2265 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2266 HDA_OUTPUT));
2267 if (err < 0)
2268 return err;
2269 sprintf(name, "%s Playback Switch", chname[i]);
2270 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2271 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2272 HDA_OUTPUT));
2273 if (err < 0)
2274 return err;
2278 return 0;
2281 static void create_hp_imux(struct via_spec *spec)
2283 int i;
2284 struct hda_input_mux *imux = &spec->private_imux[1];
2285 static const char *texts[] = { "OFF", "ON", NULL};
2287 /* for hp mode select */
2288 i = 0;
2289 while (texts[i] != NULL) {
2290 imux->items[imux->num_items].label = texts[i];
2291 imux->items[imux->num_items].index = i;
2292 imux->num_items++;
2293 i++;
2296 spec->hp_mux = &spec->private_imux[1];
2299 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2301 int err;
2303 if (!pin)
2304 return 0;
2306 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2307 spec->hp_independent_mode_index = 1;
2309 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2310 "Headphone Playback Volume",
2311 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2312 if (err < 0)
2313 return err;
2314 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2315 "Headphone Playback Switch",
2316 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2317 if (err < 0)
2318 return err;
2320 create_hp_imux(spec);
2322 return 0;
2325 /* create playback/capture controls for input pins */
2326 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
2327 const struct auto_pin_cfg *cfg)
2329 static char *labels[] = {
2330 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2332 struct hda_input_mux *imux = &spec->private_imux[0];
2333 int i, err, idx = 0;
2335 /* for internal loopback recording select */
2336 imux->items[imux->num_items].label = "Stereo Mixer";
2337 imux->items[imux->num_items].index = idx;
2338 imux->num_items++;
2340 for (i = 0; i < AUTO_PIN_LAST; i++) {
2341 if (!cfg->input_pins[i])
2342 continue;
2344 switch (cfg->input_pins[i]) {
2345 case 0x1d: /* Mic */
2346 idx = 2;
2347 break;
2349 case 0x1e: /* Line In */
2350 idx = 3;
2351 break;
2353 case 0x21: /* Front Mic */
2354 idx = 4;
2355 break;
2357 case 0x24: /* CD */
2358 idx = 1;
2359 break;
2361 err = via_new_analog_input(spec, labels[i], idx, 0x17);
2362 if (err < 0)
2363 return err;
2364 imux->items[imux->num_items].label = labels[i];
2365 imux->items[imux->num_items].index = idx;
2366 imux->num_items++;
2368 return 0;
2371 #ifdef CONFIG_SND_HDA_POWER_SAVE
2372 static struct hda_amp_list vt1708_loopbacks[] = {
2373 { 0x17, HDA_INPUT, 1 },
2374 { 0x17, HDA_INPUT, 2 },
2375 { 0x17, HDA_INPUT, 3 },
2376 { 0x17, HDA_INPUT, 4 },
2377 { } /* end */
2379 #endif
2381 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2383 unsigned int def_conf;
2384 unsigned char seqassoc;
2386 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2387 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2388 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2389 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2390 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2391 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2392 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2395 return;
2398 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2399 struct snd_ctl_elem_value *ucontrol)
2401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2402 struct via_spec *spec = codec->spec;
2404 if (spec->codec_type != VT1708)
2405 return 0;
2406 spec->vt1708_jack_detectect =
2407 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2408 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2409 return 0;
2412 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2413 struct snd_ctl_elem_value *ucontrol)
2415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2416 struct via_spec *spec = codec->spec;
2417 int change;
2419 if (spec->codec_type != VT1708)
2420 return 0;
2421 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2422 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2423 == !spec->vt1708_jack_detectect;
2424 if (spec->vt1708_jack_detectect) {
2425 mute_aa_path(codec, 1);
2426 notify_aa_path_ctls(codec);
2428 return change;
2431 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2433 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2434 .name = "Jack Detect",
2435 .count = 1,
2436 .info = snd_ctl_boolean_mono_info,
2437 .get = vt1708_jack_detectect_get,
2438 .put = vt1708_jack_detectect_put,
2440 {} /* end */
2443 static int vt1708_parse_auto_config(struct hda_codec *codec)
2445 struct via_spec *spec = codec->spec;
2446 int err;
2448 /* Add HP and CD pin config connect bit re-config action */
2449 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2450 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2452 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2453 if (err < 0)
2454 return err;
2455 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2456 if (err < 0)
2457 return err;
2458 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2459 return 0; /* can't find valid BIOS pin config */
2461 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2462 if (err < 0)
2463 return err;
2464 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2465 if (err < 0)
2466 return err;
2467 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
2468 if (err < 0)
2469 return err;
2470 /* add jack detect on/off control */
2471 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2472 if (err < 0)
2473 return err;
2475 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2477 if (spec->autocfg.dig_outs)
2478 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2479 spec->dig_in_pin = VT1708_DIGIN_PIN;
2480 if (spec->autocfg.dig_in_pin)
2481 spec->dig_in_nid = VT1708_DIGIN_NID;
2483 if (spec->kctls.list)
2484 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2486 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2488 spec->input_mux = &spec->private_imux[0];
2490 if (spec->hp_mux)
2491 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2493 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2494 return 1;
2497 /* init callback for auto-configuration model -- overriding the default init */
2498 static int via_auto_init(struct hda_codec *codec)
2500 struct via_spec *spec = codec->spec;
2502 via_init(codec);
2503 via_auto_init_multi_out(codec);
2504 via_auto_init_hp_out(codec);
2505 via_auto_init_analog_input(codec);
2506 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2507 via_hp_bind_automute(codec);
2508 } else {
2509 via_hp_automute(codec);
2510 via_speaker_automute(codec);
2513 return 0;
2516 static void vt1708_update_hp_jack_state(struct work_struct *work)
2518 struct via_spec *spec = container_of(work, struct via_spec,
2519 vt1708_hp_work.work);
2520 if (spec->codec_type != VT1708)
2521 return;
2522 /* if jack state toggled */
2523 if (spec->vt1708_hp_present
2524 != (snd_hda_codec_read(spec->codec, spec->autocfg.hp_pins[0], 0,
2525 AC_VERB_GET_PIN_SENSE, 0) >> 31)) {
2526 spec->vt1708_hp_present ^= 1;
2527 via_hp_automute(spec->codec);
2529 vt1708_start_hp_work(spec);
2532 static int get_mux_nids(struct hda_codec *codec)
2534 struct via_spec *spec = codec->spec;
2535 hda_nid_t nid, conn[8];
2536 unsigned int type;
2537 int i, n;
2539 for (i = 0; i < spec->num_adc_nids; i++) {
2540 nid = spec->adc_nids[i];
2541 while (nid) {
2542 type = get_wcaps_type(get_wcaps(codec, nid));
2543 if (type == AC_WID_PIN)
2544 break;
2545 n = snd_hda_get_connections(codec, nid, conn,
2546 ARRAY_SIZE(conn));
2547 if (n <= 0)
2548 break;
2549 if (n > 1) {
2550 spec->mux_nids[i] = nid;
2551 break;
2553 nid = conn[0];
2556 return 0;
2559 static int patch_vt1708(struct hda_codec *codec)
2561 struct via_spec *spec;
2562 int err;
2564 /* create a codec specific record */
2565 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2566 if (spec == NULL)
2567 return -ENOMEM;
2569 codec->spec = spec;
2571 /* automatic parse from the BIOS config */
2572 err = vt1708_parse_auto_config(codec);
2573 if (err < 0) {
2574 via_free(codec);
2575 return err;
2576 } else if (!err) {
2577 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2578 "from BIOS. Using genenic mode...\n");
2582 spec->stream_name_analog = "VT1708 Analog";
2583 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2584 /* disable 32bit format on VT1708 */
2585 if (codec->vendor_id == 0x11061708)
2586 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2587 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2589 spec->stream_name_digital = "VT1708 Digital";
2590 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2591 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2594 if (!spec->adc_nids && spec->input_mux) {
2595 spec->adc_nids = vt1708_adc_nids;
2596 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2597 get_mux_nids(codec);
2598 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2599 spec->num_mixers++;
2602 codec->patch_ops = via_patch_ops;
2604 codec->patch_ops.init = via_auto_init;
2605 #ifdef CONFIG_SND_HDA_POWER_SAVE
2606 spec->loopback.amplist = vt1708_loopbacks;
2607 #endif
2608 spec->codec = codec;
2609 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2610 return 0;
2613 /* capture mixer elements */
2614 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2615 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2616 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2617 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2618 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2619 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2620 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2622 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2623 /* The multiple "Capture Source" controls confuse alsamixer
2624 * So call somewhat different..
2626 /* .name = "Capture Source", */
2627 .name = "Input Source",
2628 .count = 1,
2629 .info = via_mux_enum_info,
2630 .get = via_mux_enum_get,
2631 .put = via_mux_enum_put,
2633 { } /* end */
2636 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2637 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2638 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2643 * generic initialization of ADC, input mixers and output mixers
2645 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2647 * Unmute ADC0-2 and set the default input to mic-in
2649 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2650 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2651 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2654 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2655 * mixer widget
2657 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2658 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2659 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2660 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2661 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2662 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2665 * Set up output selector (0x1a, 0x1b, 0x29)
2667 /* set vol=0 to output mixers */
2668 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2669 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2670 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2673 * Unmute PW3 and PW4
2675 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2676 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2678 /* Set input of PW4 as MW0 */
2679 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2680 /* PW9 Output enable */
2681 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2685 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2686 .substreams = 1,
2687 .channels_min = 2,
2688 .channels_max = 10,
2689 .nid = 0x10, /* NID to query formats and rates */
2690 .ops = {
2691 .open = via_playback_pcm_open,
2692 .prepare = via_playback_multi_pcm_prepare,
2693 .cleanup = via_playback_multi_pcm_cleanup,
2697 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2698 .substreams = 1,
2699 .channels_min = 2,
2700 .channels_max = 6,
2701 .nid = 0x10, /* NID to query formats and rates */
2702 .ops = {
2703 .open = via_playback_pcm_open,
2704 .prepare = via_playback_multi_pcm_prepare,
2705 .cleanup = via_playback_multi_pcm_cleanup,
2709 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2710 .substreams = 2,
2711 .channels_min = 2,
2712 .channels_max = 2,
2713 .nid = 0x14, /* NID to query formats and rates */
2714 .ops = {
2715 .prepare = via_capture_pcm_prepare,
2716 .cleanup = via_capture_pcm_cleanup
2720 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2721 .substreams = 1,
2722 .channels_min = 2,
2723 .channels_max = 2,
2724 /* NID is set in via_build_pcms */
2725 .ops = {
2726 .open = via_dig_playback_pcm_open,
2727 .close = via_dig_playback_pcm_close
2731 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2732 .substreams = 1,
2733 .channels_min = 2,
2734 .channels_max = 2,
2737 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2738 const struct auto_pin_cfg *cfg)
2740 int i;
2741 hda_nid_t nid;
2743 if (cfg->line_outs == 4) /* 10 channels */
2744 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2745 else if (cfg->line_outs == 3) /* 6 channels */
2746 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2748 spec->multiout.dac_nids = spec->private_dac_nids;
2750 if (cfg->line_outs == 4) { /* 10 channels */
2751 for (i = 0; i < cfg->line_outs; i++) {
2752 nid = cfg->line_out_pins[i];
2753 if (nid) {
2754 /* config dac list */
2755 switch (i) {
2756 case AUTO_SEQ_FRONT:
2757 /* AOW0 */
2758 spec->multiout.dac_nids[i] = 0x10;
2759 break;
2760 case AUTO_SEQ_CENLFE:
2761 /* AOW2 */
2762 spec->multiout.dac_nids[i] = 0x12;
2763 break;
2764 case AUTO_SEQ_SURROUND:
2765 /* AOW3 */
2766 spec->multiout.dac_nids[i] = 0x11;
2767 break;
2768 case AUTO_SEQ_SIDE:
2769 /* AOW1 */
2770 spec->multiout.dac_nids[i] = 0x27;
2771 break;
2772 default:
2773 break;
2777 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2779 } else if (cfg->line_outs == 3) { /* 6 channels */
2780 for (i = 0; i < cfg->line_outs; i++) {
2781 nid = cfg->line_out_pins[i];
2782 if (nid) {
2783 /* config dac list */
2784 switch (i) {
2785 case AUTO_SEQ_FRONT:
2786 /* AOW0 */
2787 spec->multiout.dac_nids[i] = 0x10;
2788 break;
2789 case AUTO_SEQ_CENLFE:
2790 /* AOW2 */
2791 spec->multiout.dac_nids[i] = 0x12;
2792 break;
2793 case AUTO_SEQ_SURROUND:
2794 /* AOW1 */
2795 spec->multiout.dac_nids[i] = 0x11;
2796 break;
2797 default:
2798 break;
2804 return 0;
2807 /* add playback controls from the parsed DAC table */
2808 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2809 const struct auto_pin_cfg *cfg)
2811 char name[32];
2812 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2813 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2814 int i, err;
2816 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2817 nid = cfg->line_out_pins[i];
2819 if (!nid)
2820 continue;
2822 nid_vol = nid_vols[i];
2824 if (i == AUTO_SEQ_CENLFE) {
2825 /* Center/LFE */
2826 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2827 "Center Playback Volume",
2828 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2829 HDA_OUTPUT));
2830 if (err < 0)
2831 return err;
2832 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2833 "LFE Playback Volume",
2834 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2835 HDA_OUTPUT));
2836 if (err < 0)
2837 return err;
2838 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2839 "Center Playback Switch",
2840 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2841 HDA_OUTPUT));
2842 if (err < 0)
2843 return err;
2844 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2845 "LFE Playback Switch",
2846 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2847 HDA_OUTPUT));
2848 if (err < 0)
2849 return err;
2850 } else if (i == AUTO_SEQ_FRONT) {
2851 /* ADD control to mixer index 0 */
2852 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2853 "Master Front Playback Volume",
2854 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2855 HDA_INPUT));
2856 if (err < 0)
2857 return err;
2858 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2859 "Master Front Playback Switch",
2860 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2861 HDA_INPUT));
2862 if (err < 0)
2863 return err;
2865 /* add control to PW3 */
2866 sprintf(name, "%s Playback Volume", chname[i]);
2867 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2868 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2869 HDA_OUTPUT));
2870 if (err < 0)
2871 return err;
2872 sprintf(name, "%s Playback Switch", chname[i]);
2873 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2874 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2875 HDA_OUTPUT));
2876 if (err < 0)
2877 return err;
2878 } else if (i == AUTO_SEQ_SURROUND) {
2879 sprintf(name, "%s Playback Volume", chname[i]);
2880 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2881 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2882 HDA_OUTPUT));
2883 if (err < 0)
2884 return err;
2885 sprintf(name, "%s Playback Switch", chname[i]);
2886 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2887 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2888 HDA_OUTPUT));
2889 if (err < 0)
2890 return err;
2891 } else if (i == AUTO_SEQ_SIDE) {
2892 sprintf(name, "%s Playback Volume", chname[i]);
2893 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2894 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2895 HDA_OUTPUT));
2896 if (err < 0)
2897 return err;
2898 sprintf(name, "%s Playback Switch", chname[i]);
2899 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2900 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2901 HDA_OUTPUT));
2902 if (err < 0)
2903 return err;
2907 return 0;
2910 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2912 int err;
2914 if (!pin)
2915 return 0;
2917 if (spec->multiout.num_dacs == 5) /* 10 channels */
2918 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2919 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2920 spec->multiout.hp_nid = 0;
2921 spec->hp_independent_mode_index = 1;
2923 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2924 "Headphone Playback Volume",
2925 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2926 if (err < 0)
2927 return err;
2928 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2929 "Headphone Playback Switch",
2930 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2931 if (err < 0)
2932 return err;
2934 return 0;
2937 /* create playback/capture controls for input pins */
2938 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
2939 const struct auto_pin_cfg *cfg)
2941 static char *labels[] = {
2942 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2944 struct hda_input_mux *imux = &spec->private_imux[0];
2945 int i, err, idx = 0;
2947 /* for internal loopback recording select */
2948 imux->items[imux->num_items].label = "Stereo Mixer";
2949 imux->items[imux->num_items].index = idx;
2950 imux->num_items++;
2952 for (i = 0; i < AUTO_PIN_LAST; i++) {
2953 if (!cfg->input_pins[i])
2954 continue;
2956 switch (cfg->input_pins[i]) {
2957 case 0x1d: /* Mic */
2958 idx = 2;
2959 break;
2961 case 0x1e: /* Line In */
2962 idx = 3;
2963 break;
2965 case 0x21: /* Front Mic */
2966 idx = 4;
2967 break;
2969 case 0x23: /* CD */
2970 idx = 1;
2971 break;
2973 err = via_new_analog_input(spec, labels[i], idx, 0x18);
2974 if (err < 0)
2975 return err;
2976 imux->items[imux->num_items].label = labels[i];
2977 imux->items[imux->num_items].index = idx;
2978 imux->num_items++;
2980 return 0;
2983 static int vt1709_parse_auto_config(struct hda_codec *codec)
2985 struct via_spec *spec = codec->spec;
2986 int err;
2988 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2989 if (err < 0)
2990 return err;
2991 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2992 if (err < 0)
2993 return err;
2994 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2995 return 0; /* can't find valid BIOS pin config */
2997 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2998 if (err < 0)
2999 return err;
3000 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3001 if (err < 0)
3002 return err;
3003 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
3004 if (err < 0)
3005 return err;
3007 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3009 if (spec->autocfg.dig_outs)
3010 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3011 spec->dig_in_pin = VT1709_DIGIN_PIN;
3012 if (spec->autocfg.dig_in_pin)
3013 spec->dig_in_nid = VT1709_DIGIN_NID;
3015 if (spec->kctls.list)
3016 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3018 spec->input_mux = &spec->private_imux[0];
3020 if (spec->hp_mux)
3021 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3023 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
3024 return 1;
3027 #ifdef CONFIG_SND_HDA_POWER_SAVE
3028 static struct hda_amp_list vt1709_loopbacks[] = {
3029 { 0x18, HDA_INPUT, 1 },
3030 { 0x18, HDA_INPUT, 2 },
3031 { 0x18, HDA_INPUT, 3 },
3032 { 0x18, HDA_INPUT, 4 },
3033 { } /* end */
3035 #endif
3037 static int patch_vt1709_10ch(struct hda_codec *codec)
3039 struct via_spec *spec;
3040 int err;
3042 /* create a codec specific record */
3043 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3044 if (spec == NULL)
3045 return -ENOMEM;
3047 codec->spec = spec;
3049 err = vt1709_parse_auto_config(codec);
3050 if (err < 0) {
3051 via_free(codec);
3052 return err;
3053 } else if (!err) {
3054 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3055 "Using genenic mode...\n");
3058 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3059 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3061 spec->stream_name_analog = "VT1709 Analog";
3062 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3063 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3065 spec->stream_name_digital = "VT1709 Digital";
3066 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3067 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3070 if (!spec->adc_nids && spec->input_mux) {
3071 spec->adc_nids = vt1709_adc_nids;
3072 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3073 get_mux_nids(codec);
3074 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3075 spec->num_mixers++;
3078 codec->patch_ops = via_patch_ops;
3080 codec->patch_ops.init = via_auto_init;
3081 codec->patch_ops.unsol_event = via_unsol_event;
3082 #ifdef CONFIG_SND_HDA_POWER_SAVE
3083 spec->loopback.amplist = vt1709_loopbacks;
3084 #endif
3086 return 0;
3089 * generic initialization of ADC, input mixers and output mixers
3091 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3093 * Unmute ADC0-2 and set the default input to mic-in
3095 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3096 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3097 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3100 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3101 * mixer widget
3103 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3104 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3105 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3106 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3107 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3108 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3111 * Set up output selector (0x1a, 0x1b, 0x29)
3113 /* set vol=0 to output mixers */
3114 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3115 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3116 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3119 * Unmute PW3 and PW4
3121 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3122 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3124 /* Set input of PW4 as MW0 */
3125 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3126 /* PW9 Output enable */
3127 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3131 static int patch_vt1709_6ch(struct hda_codec *codec)
3133 struct via_spec *spec;
3134 int err;
3136 /* create a codec specific record */
3137 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3138 if (spec == NULL)
3139 return -ENOMEM;
3141 codec->spec = spec;
3143 err = vt1709_parse_auto_config(codec);
3144 if (err < 0) {
3145 via_free(codec);
3146 return err;
3147 } else if (!err) {
3148 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3149 "Using genenic mode...\n");
3152 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3153 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3155 spec->stream_name_analog = "VT1709 Analog";
3156 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3157 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3159 spec->stream_name_digital = "VT1709 Digital";
3160 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3161 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3164 if (!spec->adc_nids && spec->input_mux) {
3165 spec->adc_nids = vt1709_adc_nids;
3166 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3167 get_mux_nids(codec);
3168 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3169 spec->num_mixers++;
3172 codec->patch_ops = via_patch_ops;
3174 codec->patch_ops.init = via_auto_init;
3175 codec->patch_ops.unsol_event = via_unsol_event;
3176 #ifdef CONFIG_SND_HDA_POWER_SAVE
3177 spec->loopback.amplist = vt1709_loopbacks;
3178 #endif
3179 return 0;
3182 /* capture mixer elements */
3183 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3184 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3185 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3186 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3187 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3189 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3190 /* The multiple "Capture Source" controls confuse alsamixer
3191 * So call somewhat different..
3193 /* .name = "Capture Source", */
3194 .name = "Input Source",
3195 .count = 1,
3196 .info = via_mux_enum_info,
3197 .get = via_mux_enum_get,
3198 .put = via_mux_enum_put,
3200 { } /* end */
3203 * generic initialization of ADC, input mixers and output mixers
3205 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3207 * Unmute ADC0-1 and set the default input to mic-in
3209 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3210 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3213 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3214 * mixer widget
3216 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3217 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3218 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3219 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3220 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3221 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3224 * Set up output mixers
3226 /* set vol=0 to output mixers */
3227 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3228 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3229 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3231 /* Setup default input to PW4 */
3232 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3233 /* PW9 Output enable */
3234 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3235 /* PW10 Input enable */
3236 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3240 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3242 * Unmute ADC0-1 and set the default input to mic-in
3244 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3245 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3248 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3249 * mixer widget
3251 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3252 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3253 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3254 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3255 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3256 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3259 * Set up output mixers
3261 /* set vol=0 to output mixers */
3262 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3263 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3264 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3266 /* Setup default input of PW4 to MW0 */
3267 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3268 /* PW9 Output enable */
3269 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3270 /* PW10 Input enable */
3271 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3275 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3276 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3277 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3278 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3279 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3280 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3281 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3282 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3283 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3284 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3288 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3289 struct hda_codec *codec,
3290 struct snd_pcm_substream *substream)
3292 int idle = substream->pstr->substream_opened == 1
3293 && substream->ref_count == 0;
3295 analog_low_current_mode(codec, idle);
3296 return 0;
3299 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3300 .substreams = 2,
3301 .channels_min = 2,
3302 .channels_max = 8,
3303 .nid = 0x10, /* NID to query formats and rates */
3304 .ops = {
3305 .open = via_playback_pcm_open,
3306 .prepare = via_playback_multi_pcm_prepare,
3307 .cleanup = via_playback_multi_pcm_cleanup,
3308 .close = via_pcm_open_close
3312 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3313 .substreams = 2,
3314 .channels_min = 2,
3315 .channels_max = 4,
3316 .nid = 0x10, /* NID to query formats and rates */
3317 .ops = {
3318 .open = via_playback_pcm_open,
3319 .prepare = via_playback_multi_pcm_prepare,
3320 .cleanup = via_playback_multi_pcm_cleanup
3324 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3325 .substreams = 2,
3326 .channels_min = 2,
3327 .channels_max = 2,
3328 .nid = 0x13, /* NID to query formats and rates */
3329 .ops = {
3330 .open = via_pcm_open_close,
3331 .prepare = via_capture_pcm_prepare,
3332 .cleanup = via_capture_pcm_cleanup,
3333 .close = via_pcm_open_close
3337 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3338 .substreams = 1,
3339 .channels_min = 2,
3340 .channels_max = 2,
3341 /* NID is set in via_build_pcms */
3342 .ops = {
3343 .open = via_dig_playback_pcm_open,
3344 .close = via_dig_playback_pcm_close,
3345 .prepare = via_dig_playback_pcm_prepare,
3346 .cleanup = via_dig_playback_pcm_cleanup
3350 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3351 .substreams = 1,
3352 .channels_min = 2,
3353 .channels_max = 2,
3356 /* fill in the dac_nids table from the parsed pin configuration */
3357 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3358 const struct auto_pin_cfg *cfg)
3360 int i;
3361 hda_nid_t nid;
3363 spec->multiout.num_dacs = cfg->line_outs;
3365 spec->multiout.dac_nids = spec->private_dac_nids;
3367 for (i = 0; i < 4; i++) {
3368 nid = cfg->line_out_pins[i];
3369 if (nid) {
3370 /* config dac list */
3371 switch (i) {
3372 case AUTO_SEQ_FRONT:
3373 spec->multiout.dac_nids[i] = 0x10;
3374 break;
3375 case AUTO_SEQ_CENLFE:
3376 spec->multiout.dac_nids[i] = 0x24;
3377 break;
3378 case AUTO_SEQ_SURROUND:
3379 spec->multiout.dac_nids[i] = 0x11;
3380 break;
3381 case AUTO_SEQ_SIDE:
3382 spec->multiout.dac_nids[i] = 0x25;
3383 break;
3388 return 0;
3391 /* add playback controls from the parsed DAC table */
3392 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3393 const struct auto_pin_cfg *cfg)
3395 char name[32];
3396 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3397 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3398 hda_nid_t nid, nid_vol = 0;
3399 int i, err;
3401 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3402 nid = cfg->line_out_pins[i];
3404 if (!nid)
3405 continue;
3407 nid_vol = nid_vols[i];
3409 if (i == AUTO_SEQ_CENLFE) {
3410 /* Center/LFE */
3411 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3412 "Center Playback Volume",
3413 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3414 HDA_OUTPUT));
3415 if (err < 0)
3416 return err;
3417 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3418 "LFE Playback Volume",
3419 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3420 HDA_OUTPUT));
3421 if (err < 0)
3422 return err;
3423 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3424 "Center Playback Switch",
3425 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3426 HDA_OUTPUT));
3427 if (err < 0)
3428 return err;
3429 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3430 "LFE Playback Switch",
3431 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3432 HDA_OUTPUT));
3433 if (err < 0)
3434 return err;
3435 } else if (i == AUTO_SEQ_FRONT) {
3436 /* add control to mixer index 0 */
3437 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3438 "Master Front Playback Volume",
3439 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3440 HDA_INPUT));
3441 if (err < 0)
3442 return err;
3443 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3444 "Master Front Playback Switch",
3445 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3446 HDA_INPUT));
3447 if (err < 0)
3448 return err;
3450 /* add control to PW3 */
3451 sprintf(name, "%s Playback Volume", chname[i]);
3452 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3453 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3454 HDA_OUTPUT));
3455 if (err < 0)
3456 return err;
3457 sprintf(name, "%s Playback Switch", chname[i]);
3458 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3459 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3460 HDA_OUTPUT));
3461 if (err < 0)
3462 return err;
3463 } else {
3464 sprintf(name, "%s Playback Volume", chname[i]);
3465 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3466 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3467 HDA_OUTPUT));
3468 if (err < 0)
3469 return err;
3470 sprintf(name, "%s Playback Switch", chname[i]);
3471 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3472 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3473 HDA_OUTPUT));
3474 if (err < 0)
3475 return err;
3479 return 0;
3482 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3484 int err;
3486 if (!pin)
3487 return 0;
3489 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3490 spec->hp_independent_mode_index = 1;
3492 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3493 "Headphone Playback Volume",
3494 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3495 if (err < 0)
3496 return err;
3497 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3498 "Headphone Playback Switch",
3499 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3500 if (err < 0)
3501 return err;
3503 create_hp_imux(spec);
3505 return 0;
3508 /* create playback/capture controls for input pins */
3509 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
3510 const struct auto_pin_cfg *cfg)
3512 static char *labels[] = {
3513 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3515 struct hda_input_mux *imux = &spec->private_imux[0];
3516 int i, err, idx = 0;
3518 /* for internal loopback recording select */
3519 imux->items[imux->num_items].label = "Stereo Mixer";
3520 imux->items[imux->num_items].index = idx;
3521 imux->num_items++;
3523 for (i = 0; i < AUTO_PIN_LAST; i++) {
3524 if (!cfg->input_pins[i])
3525 continue;
3527 switch (cfg->input_pins[i]) {
3528 case 0x1a: /* Mic */
3529 idx = 2;
3530 break;
3532 case 0x1b: /* Line In */
3533 idx = 3;
3534 break;
3536 case 0x1e: /* Front Mic */
3537 idx = 4;
3538 break;
3540 case 0x1f: /* CD */
3541 idx = 1;
3542 break;
3544 err = via_new_analog_input(spec, labels[i], idx, 0x16);
3545 if (err < 0)
3546 return err;
3547 imux->items[imux->num_items].label = labels[i];
3548 imux->items[imux->num_items].index = idx;
3549 imux->num_items++;
3551 return 0;
3554 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3556 struct via_spec *spec = codec->spec;
3557 int err;
3559 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3560 if (err < 0)
3561 return err;
3562 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3563 if (err < 0)
3564 return err;
3565 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3566 return 0; /* can't find valid BIOS pin config */
3568 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3569 if (err < 0)
3570 return err;
3571 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3572 if (err < 0)
3573 return err;
3574 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
3575 if (err < 0)
3576 return err;
3578 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3580 if (spec->autocfg.dig_outs)
3581 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3582 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3583 if (spec->autocfg.dig_in_pin)
3584 spec->dig_in_nid = VT1708B_DIGIN_NID;
3586 if (spec->kctls.list)
3587 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3589 spec->input_mux = &spec->private_imux[0];
3591 if (spec->hp_mux)
3592 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3594 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
3595 return 1;
3598 #ifdef CONFIG_SND_HDA_POWER_SAVE
3599 static struct hda_amp_list vt1708B_loopbacks[] = {
3600 { 0x16, HDA_INPUT, 1 },
3601 { 0x16, HDA_INPUT, 2 },
3602 { 0x16, HDA_INPUT, 3 },
3603 { 0x16, HDA_INPUT, 4 },
3604 { } /* end */
3606 #endif
3607 static int patch_vt1708S(struct hda_codec *codec);
3608 static int patch_vt1708B_8ch(struct hda_codec *codec)
3610 struct via_spec *spec;
3611 int err;
3613 if (get_codec_type(codec) == VT1708BCE)
3614 return patch_vt1708S(codec);
3615 /* create a codec specific record */
3616 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3617 if (spec == NULL)
3618 return -ENOMEM;
3620 codec->spec = spec;
3622 /* automatic parse from the BIOS config */
3623 err = vt1708B_parse_auto_config(codec);
3624 if (err < 0) {
3625 via_free(codec);
3626 return err;
3627 } else if (!err) {
3628 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3629 "from BIOS. Using genenic mode...\n");
3632 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3633 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3635 spec->stream_name_analog = "VT1708B Analog";
3636 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3637 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3639 spec->stream_name_digital = "VT1708B Digital";
3640 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3641 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3643 if (!spec->adc_nids && spec->input_mux) {
3644 spec->adc_nids = vt1708B_adc_nids;
3645 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3646 get_mux_nids(codec);
3647 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3648 spec->num_mixers++;
3651 codec->patch_ops = via_patch_ops;
3653 codec->patch_ops.init = via_auto_init;
3654 codec->patch_ops.unsol_event = via_unsol_event;
3655 #ifdef CONFIG_SND_HDA_POWER_SAVE
3656 spec->loopback.amplist = vt1708B_loopbacks;
3657 #endif
3659 return 0;
3662 static int patch_vt1708B_4ch(struct hda_codec *codec)
3664 struct via_spec *spec;
3665 int err;
3667 /* create a codec specific record */
3668 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3669 if (spec == NULL)
3670 return -ENOMEM;
3672 codec->spec = spec;
3674 /* automatic parse from the BIOS config */
3675 err = vt1708B_parse_auto_config(codec);
3676 if (err < 0) {
3677 via_free(codec);
3678 return err;
3679 } else if (!err) {
3680 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3681 "from BIOS. Using genenic mode...\n");
3684 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3685 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3687 spec->stream_name_analog = "VT1708B Analog";
3688 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3689 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3691 spec->stream_name_digital = "VT1708B Digital";
3692 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3693 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3695 if (!spec->adc_nids && spec->input_mux) {
3696 spec->adc_nids = vt1708B_adc_nids;
3697 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3698 get_mux_nids(codec);
3699 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3700 spec->num_mixers++;
3703 codec->patch_ops = via_patch_ops;
3705 codec->patch_ops.init = via_auto_init;
3706 codec->patch_ops.unsol_event = via_unsol_event;
3707 #ifdef CONFIG_SND_HDA_POWER_SAVE
3708 spec->loopback.amplist = vt1708B_loopbacks;
3709 #endif
3711 return 0;
3714 /* Patch for VT1708S */
3716 /* capture mixer elements */
3717 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3718 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3719 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3720 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3721 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3722 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3723 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3724 HDA_INPUT),
3726 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3727 /* The multiple "Capture Source" controls confuse alsamixer
3728 * So call somewhat different..
3730 /* .name = "Capture Source", */
3731 .name = "Input Source",
3732 .count = 1,
3733 .info = via_mux_enum_info,
3734 .get = via_mux_enum_get,
3735 .put = via_mux_enum_put,
3737 { } /* end */
3740 static struct hda_verb vt1708S_volume_init_verbs[] = {
3741 /* Unmute ADC0-1 and set the default input to mic-in */
3742 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3743 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3745 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3746 * analog-loopback mixer widget */
3747 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3748 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3749 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3750 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3751 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3752 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3754 /* Setup default input of PW4 to MW0 */
3755 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3756 /* PW9, PW10 Output enable */
3757 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3758 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3759 /* Enable Mic Boost Volume backdoor */
3760 {0x1, 0xf98, 0x1},
3761 /* don't bybass mixer */
3762 {0x1, 0xf88, 0xc0},
3766 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3767 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3768 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3769 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3770 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3771 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3772 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3773 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3774 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3775 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3779 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3780 .substreams = 2,
3781 .channels_min = 2,
3782 .channels_max = 8,
3783 .nid = 0x10, /* NID to query formats and rates */
3784 .ops = {
3785 .open = via_playback_pcm_open,
3786 .prepare = via_playback_multi_pcm_prepare,
3787 .cleanup = via_playback_multi_pcm_cleanup,
3788 .close = via_pcm_open_close
3792 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3793 .substreams = 2,
3794 .channels_min = 2,
3795 .channels_max = 2,
3796 .nid = 0x13, /* NID to query formats and rates */
3797 .ops = {
3798 .open = via_pcm_open_close,
3799 .prepare = via_capture_pcm_prepare,
3800 .cleanup = via_capture_pcm_cleanup,
3801 .close = via_pcm_open_close
3805 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3806 .substreams = 1,
3807 .channels_min = 2,
3808 .channels_max = 2,
3809 /* NID is set in via_build_pcms */
3810 .ops = {
3811 .open = via_dig_playback_pcm_open,
3812 .close = via_dig_playback_pcm_close,
3813 .prepare = via_dig_playback_pcm_prepare,
3814 .cleanup = via_dig_playback_pcm_cleanup
3818 /* fill in the dac_nids table from the parsed pin configuration */
3819 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3820 const struct auto_pin_cfg *cfg)
3822 int i;
3823 hda_nid_t nid;
3825 spec->multiout.num_dacs = cfg->line_outs;
3827 spec->multiout.dac_nids = spec->private_dac_nids;
3829 for (i = 0; i < 4; i++) {
3830 nid = cfg->line_out_pins[i];
3831 if (nid) {
3832 /* config dac list */
3833 switch (i) {
3834 case AUTO_SEQ_FRONT:
3835 spec->multiout.dac_nids[i] = 0x10;
3836 break;
3837 case AUTO_SEQ_CENLFE:
3838 spec->multiout.dac_nids[i] = 0x24;
3839 break;
3840 case AUTO_SEQ_SURROUND:
3841 spec->multiout.dac_nids[i] = 0x11;
3842 break;
3843 case AUTO_SEQ_SIDE:
3844 spec->multiout.dac_nids[i] = 0x25;
3845 break;
3850 return 0;
3853 /* add playback controls from the parsed DAC table */
3854 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3855 const struct auto_pin_cfg *cfg)
3857 char name[32];
3858 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3859 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3860 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3861 hda_nid_t nid, nid_vol, nid_mute;
3862 int i, err;
3864 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3865 nid = cfg->line_out_pins[i];
3867 if (!nid)
3868 continue;
3870 nid_vol = nid_vols[i];
3871 nid_mute = nid_mutes[i];
3873 if (i == AUTO_SEQ_CENLFE) {
3874 /* Center/LFE */
3875 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3876 "Center Playback Volume",
3877 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3878 HDA_OUTPUT));
3879 if (err < 0)
3880 return err;
3881 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3882 "LFE Playback Volume",
3883 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3884 HDA_OUTPUT));
3885 if (err < 0)
3886 return err;
3887 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3888 "Center Playback Switch",
3889 HDA_COMPOSE_AMP_VAL(nid_mute,
3890 1, 0,
3891 HDA_OUTPUT));
3892 if (err < 0)
3893 return err;
3894 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3895 "LFE Playback Switch",
3896 HDA_COMPOSE_AMP_VAL(nid_mute,
3897 2, 0,
3898 HDA_OUTPUT));
3899 if (err < 0)
3900 return err;
3901 } else if (i == AUTO_SEQ_FRONT) {
3902 /* add control to mixer index 0 */
3903 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3904 "Master Front Playback Volume",
3905 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3906 HDA_INPUT));
3907 if (err < 0)
3908 return err;
3909 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3910 "Master Front Playback Switch",
3911 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3912 HDA_INPUT));
3913 if (err < 0)
3914 return err;
3916 /* Front */
3917 sprintf(name, "%s Playback Volume", chname[i]);
3918 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3919 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3920 HDA_OUTPUT));
3921 if (err < 0)
3922 return err;
3923 sprintf(name, "%s Playback Switch", chname[i]);
3924 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3925 HDA_COMPOSE_AMP_VAL(nid_mute,
3926 3, 0,
3927 HDA_OUTPUT));
3928 if (err < 0)
3929 return err;
3930 } else {
3931 sprintf(name, "%s Playback Volume", chname[i]);
3932 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3933 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3934 HDA_OUTPUT));
3935 if (err < 0)
3936 return err;
3937 sprintf(name, "%s Playback Switch", chname[i]);
3938 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3939 HDA_COMPOSE_AMP_VAL(nid_mute,
3940 3, 0,
3941 HDA_OUTPUT));
3942 if (err < 0)
3943 return err;
3947 return 0;
3950 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3952 int err;
3954 if (!pin)
3955 return 0;
3957 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3958 spec->hp_independent_mode_index = 1;
3960 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3961 "Headphone Playback Volume",
3962 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3963 if (err < 0)
3964 return err;
3966 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3967 "Headphone Playback Switch",
3968 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3969 if (err < 0)
3970 return err;
3972 create_hp_imux(spec);
3974 return 0;
3977 /* create playback/capture controls for input pins */
3978 static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
3979 const struct auto_pin_cfg *cfg)
3981 static char *labels[] = {
3982 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3984 struct hda_input_mux *imux = &spec->private_imux[0];
3985 int i, err, idx = 0;
3987 /* for internal loopback recording select */
3988 imux->items[imux->num_items].label = "Stereo Mixer";
3989 imux->items[imux->num_items].index = 5;
3990 imux->num_items++;
3992 for (i = 0; i < AUTO_PIN_LAST; i++) {
3993 if (!cfg->input_pins[i])
3994 continue;
3996 switch (cfg->input_pins[i]) {
3997 case 0x1a: /* Mic */
3998 idx = 2;
3999 break;
4001 case 0x1b: /* Line In */
4002 idx = 3;
4003 break;
4005 case 0x1e: /* Front Mic */
4006 idx = 4;
4007 break;
4009 case 0x1f: /* CD */
4010 idx = 1;
4011 break;
4013 err = via_new_analog_input(spec, labels[i], idx, 0x16);
4014 if (err < 0)
4015 return err;
4016 imux->items[imux->num_items].label = labels[i];
4017 imux->items[imux->num_items].index = idx-1;
4018 imux->num_items++;
4020 return 0;
4023 /* fill out digital output widgets; one for master and one for slave outputs */
4024 static void fill_dig_outs(struct hda_codec *codec)
4026 struct via_spec *spec = codec->spec;
4027 int i;
4029 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4030 hda_nid_t nid;
4031 int conn;
4033 nid = spec->autocfg.dig_out_pins[i];
4034 if (!nid)
4035 continue;
4036 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4037 if (conn < 1)
4038 continue;
4039 if (!spec->multiout.dig_out_nid)
4040 spec->multiout.dig_out_nid = nid;
4041 else {
4042 spec->slave_dig_outs[0] = nid;
4043 break; /* at most two dig outs */
4048 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4050 struct via_spec *spec = codec->spec;
4051 int err;
4053 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4054 if (err < 0)
4055 return err;
4056 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4057 if (err < 0)
4058 return err;
4059 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4060 return 0; /* can't find valid BIOS pin config */
4062 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4063 if (err < 0)
4064 return err;
4065 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4066 if (err < 0)
4067 return err;
4068 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4069 if (err < 0)
4070 return err;
4072 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4074 fill_dig_outs(codec);
4076 if (spec->kctls.list)
4077 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4079 spec->input_mux = &spec->private_imux[0];
4081 if (spec->hp_mux)
4082 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4084 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4085 return 1;
4088 #ifdef CONFIG_SND_HDA_POWER_SAVE
4089 static struct hda_amp_list vt1708S_loopbacks[] = {
4090 { 0x16, HDA_INPUT, 1 },
4091 { 0x16, HDA_INPUT, 2 },
4092 { 0x16, HDA_INPUT, 3 },
4093 { 0x16, HDA_INPUT, 4 },
4094 { } /* end */
4096 #endif
4098 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4099 int offset, int num_steps, int step_size)
4101 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4102 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4103 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4104 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4105 (0 << AC_AMPCAP_MUTE_SHIFT));
4108 static int patch_vt1708S(struct hda_codec *codec)
4110 struct via_spec *spec;
4111 int err;
4113 /* create a codec specific record */
4114 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4115 if (spec == NULL)
4116 return -ENOMEM;
4118 codec->spec = spec;
4120 /* automatic parse from the BIOS config */
4121 err = vt1708S_parse_auto_config(codec);
4122 if (err < 0) {
4123 via_free(codec);
4124 return err;
4125 } else if (!err) {
4126 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4127 "from BIOS. Using genenic mode...\n");
4130 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4131 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4133 spec->stream_name_analog = "VT1708S Analog";
4134 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4135 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4137 spec->stream_name_digital = "VT1708S Digital";
4138 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4140 if (!spec->adc_nids && spec->input_mux) {
4141 spec->adc_nids = vt1708S_adc_nids;
4142 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4143 get_mux_nids(codec);
4144 override_mic_boost(codec, 0x1a, 0, 3, 40);
4145 override_mic_boost(codec, 0x1e, 0, 3, 40);
4146 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4147 spec->num_mixers++;
4150 codec->patch_ops = via_patch_ops;
4152 codec->patch_ops.init = via_auto_init;
4153 codec->patch_ops.unsol_event = via_unsol_event;
4154 #ifdef CONFIG_SND_HDA_POWER_SAVE
4155 spec->loopback.amplist = vt1708S_loopbacks;
4156 #endif
4158 /* correct names for VT1708BCE */
4159 if (get_codec_type(codec) == VT1708BCE) {
4160 kfree(codec->chip_name);
4161 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4162 snprintf(codec->bus->card->mixername,
4163 sizeof(codec->bus->card->mixername),
4164 "%s %s", codec->vendor_name, codec->chip_name);
4165 spec->stream_name_analog = "VT1708BCE Analog";
4166 spec->stream_name_digital = "VT1708BCE Digital";
4168 return 0;
4171 /* Patch for VT1702 */
4173 /* capture mixer elements */
4174 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4175 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4176 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4177 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4178 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4179 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4180 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4181 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4182 HDA_INPUT),
4184 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4185 /* The multiple "Capture Source" controls confuse alsamixer
4186 * So call somewhat different..
4188 /* .name = "Capture Source", */
4189 .name = "Input Source",
4190 .count = 1,
4191 .info = via_mux_enum_info,
4192 .get = via_mux_enum_get,
4193 .put = via_mux_enum_put,
4195 { } /* end */
4198 static struct hda_verb vt1702_volume_init_verbs[] = {
4200 * Unmute ADC0-1 and set the default input to mic-in
4202 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4203 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4204 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4207 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4208 * mixer widget
4210 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4211 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4212 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4213 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4214 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4215 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4217 /* Setup default input of PW4 to MW0 */
4218 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4219 /* PW6 PW7 Output enable */
4220 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4221 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4222 /* mixer enable */
4223 {0x1, 0xF88, 0x3},
4224 /* GPIO 0~2 */
4225 {0x1, 0xF82, 0x3F},
4229 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4230 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4231 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4232 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4233 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4234 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4235 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4239 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4240 .substreams = 2,
4241 .channels_min = 2,
4242 .channels_max = 2,
4243 .nid = 0x10, /* NID to query formats and rates */
4244 .ops = {
4245 .open = via_playback_pcm_open,
4246 .prepare = via_playback_multi_pcm_prepare,
4247 .cleanup = via_playback_multi_pcm_cleanup,
4248 .close = via_pcm_open_close
4252 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4253 .substreams = 3,
4254 .channels_min = 2,
4255 .channels_max = 2,
4256 .nid = 0x12, /* NID to query formats and rates */
4257 .ops = {
4258 .open = via_pcm_open_close,
4259 .prepare = via_capture_pcm_prepare,
4260 .cleanup = via_capture_pcm_cleanup,
4261 .close = via_pcm_open_close
4265 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4266 .substreams = 2,
4267 .channels_min = 2,
4268 .channels_max = 2,
4269 /* NID is set in via_build_pcms */
4270 .ops = {
4271 .open = via_dig_playback_pcm_open,
4272 .close = via_dig_playback_pcm_close,
4273 .prepare = via_dig_playback_pcm_prepare,
4274 .cleanup = via_dig_playback_pcm_cleanup
4278 /* fill in the dac_nids table from the parsed pin configuration */
4279 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4280 const struct auto_pin_cfg *cfg)
4282 spec->multiout.num_dacs = 1;
4283 spec->multiout.dac_nids = spec->private_dac_nids;
4285 if (cfg->line_out_pins[0]) {
4286 /* config dac list */
4287 spec->multiout.dac_nids[0] = 0x10;
4290 return 0;
4293 /* add playback controls from the parsed DAC table */
4294 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4295 const struct auto_pin_cfg *cfg)
4297 int err;
4299 if (!cfg->line_out_pins[0])
4300 return -1;
4302 /* add control to mixer index 0 */
4303 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4304 "Master Front Playback Volume",
4305 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4306 if (err < 0)
4307 return err;
4308 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4309 "Master Front Playback Switch",
4310 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4311 if (err < 0)
4312 return err;
4314 /* Front */
4315 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4316 "Front Playback Volume",
4317 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4318 if (err < 0)
4319 return err;
4320 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4321 "Front Playback Switch",
4322 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4323 if (err < 0)
4324 return err;
4326 return 0;
4329 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4331 int err, i;
4332 struct hda_input_mux *imux;
4333 static const char *texts[] = { "ON", "OFF", NULL};
4334 if (!pin)
4335 return 0;
4336 spec->multiout.hp_nid = 0x1D;
4337 spec->hp_independent_mode_index = 0;
4339 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4340 "Headphone Playback Volume",
4341 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4342 if (err < 0)
4343 return err;
4345 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4346 "Headphone Playback Switch",
4347 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4348 if (err < 0)
4349 return err;
4351 imux = &spec->private_imux[1];
4353 /* for hp mode select */
4354 i = 0;
4355 while (texts[i] != NULL) {
4356 imux->items[imux->num_items].label = texts[i];
4357 imux->items[imux->num_items].index = i;
4358 imux->num_items++;
4359 i++;
4362 spec->hp_mux = &spec->private_imux[1];
4363 return 0;
4366 /* create playback/capture controls for input pins */
4367 static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
4368 const struct auto_pin_cfg *cfg)
4370 static char *labels[] = {
4371 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4373 struct hda_input_mux *imux = &spec->private_imux[0];
4374 int i, err, idx = 0;
4376 /* for internal loopback recording select */
4377 imux->items[imux->num_items].label = "Stereo Mixer";
4378 imux->items[imux->num_items].index = 3;
4379 imux->num_items++;
4381 for (i = 0; i < AUTO_PIN_LAST; i++) {
4382 if (!cfg->input_pins[i])
4383 continue;
4385 switch (cfg->input_pins[i]) {
4386 case 0x14: /* Mic */
4387 idx = 1;
4388 break;
4390 case 0x15: /* Line In */
4391 idx = 2;
4392 break;
4394 case 0x18: /* Front Mic */
4395 idx = 3;
4396 break;
4398 err = via_new_analog_input(spec, labels[i], idx, 0x1A);
4399 if (err < 0)
4400 return err;
4401 imux->items[imux->num_items].label = labels[i];
4402 imux->items[imux->num_items].index = idx-1;
4403 imux->num_items++;
4405 return 0;
4408 static int vt1702_parse_auto_config(struct hda_codec *codec)
4410 struct via_spec *spec = codec->spec;
4411 int err;
4413 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4414 if (err < 0)
4415 return err;
4416 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4417 if (err < 0)
4418 return err;
4419 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4420 return 0; /* can't find valid BIOS pin config */
4422 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4423 if (err < 0)
4424 return err;
4425 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4426 if (err < 0)
4427 return err;
4428 /* limit AA path volume to 0 dB */
4429 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4430 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4431 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4432 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4433 (1 << AC_AMPCAP_MUTE_SHIFT));
4434 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
4435 if (err < 0)
4436 return err;
4438 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4440 fill_dig_outs(codec);
4442 if (spec->kctls.list)
4443 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4445 spec->input_mux = &spec->private_imux[0];
4447 if (spec->hp_mux)
4448 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4450 return 1;
4453 #ifdef CONFIG_SND_HDA_POWER_SAVE
4454 static struct hda_amp_list vt1702_loopbacks[] = {
4455 { 0x1A, HDA_INPUT, 1 },
4456 { 0x1A, HDA_INPUT, 2 },
4457 { 0x1A, HDA_INPUT, 3 },
4458 { 0x1A, HDA_INPUT, 4 },
4459 { } /* end */
4461 #endif
4463 static int patch_vt1702(struct hda_codec *codec)
4465 struct via_spec *spec;
4466 int err;
4468 /* create a codec specific record */
4469 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4470 if (spec == NULL)
4471 return -ENOMEM;
4473 codec->spec = spec;
4475 /* automatic parse from the BIOS config */
4476 err = vt1702_parse_auto_config(codec);
4477 if (err < 0) {
4478 via_free(codec);
4479 return err;
4480 } else if (!err) {
4481 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4482 "from BIOS. Using genenic mode...\n");
4485 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4486 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4488 spec->stream_name_analog = "VT1702 Analog";
4489 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4490 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4492 spec->stream_name_digital = "VT1702 Digital";
4493 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4495 if (!spec->adc_nids && spec->input_mux) {
4496 spec->adc_nids = vt1702_adc_nids;
4497 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4498 get_mux_nids(codec);
4499 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4500 spec->num_mixers++;
4503 codec->patch_ops = via_patch_ops;
4505 codec->patch_ops.init = via_auto_init;
4506 codec->patch_ops.unsol_event = via_unsol_event;
4507 #ifdef CONFIG_SND_HDA_POWER_SAVE
4508 spec->loopback.amplist = vt1702_loopbacks;
4509 #endif
4511 return 0;
4514 /* Patch for VT1718S */
4516 /* capture mixer elements */
4517 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4518 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4519 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4520 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4521 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4522 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4523 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4524 HDA_INPUT),
4526 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4527 /* The multiple "Capture Source" controls confuse alsamixer
4528 * So call somewhat different..
4530 .name = "Input Source",
4531 .count = 2,
4532 .info = via_mux_enum_info,
4533 .get = via_mux_enum_get,
4534 .put = via_mux_enum_put,
4536 { } /* end */
4539 static struct hda_verb vt1718S_volume_init_verbs[] = {
4541 * Unmute ADC0-1 and set the default input to mic-in
4543 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4544 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4547 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4548 * mixer widget
4550 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4551 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4552 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4553 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4554 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4555 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4557 /* Setup default input of Front HP to MW9 */
4558 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4559 /* PW9 PW10 Output enable */
4560 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4561 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4562 /* PW11 Input enable */
4563 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4564 /* Enable Boost Volume backdoor */
4565 {0x1, 0xf88, 0x8},
4566 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4567 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4568 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4569 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4570 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4571 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4572 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4573 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4574 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4575 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4576 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4577 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4578 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4579 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4580 /* Unmute MW4's index 0 */
4581 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4586 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4587 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4588 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4589 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4590 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4591 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4592 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4593 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4594 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4595 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4599 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4600 .substreams = 2,
4601 .channels_min = 2,
4602 .channels_max = 10,
4603 .nid = 0x8, /* NID to query formats and rates */
4604 .ops = {
4605 .open = via_playback_pcm_open,
4606 .prepare = via_playback_multi_pcm_prepare,
4607 .cleanup = via_playback_multi_pcm_cleanup,
4608 .close = via_pcm_open_close,
4612 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4613 .substreams = 2,
4614 .channels_min = 2,
4615 .channels_max = 2,
4616 .nid = 0x10, /* NID to query formats and rates */
4617 .ops = {
4618 .open = via_pcm_open_close,
4619 .prepare = via_capture_pcm_prepare,
4620 .cleanup = via_capture_pcm_cleanup,
4621 .close = via_pcm_open_close,
4625 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4626 .substreams = 2,
4627 .channels_min = 2,
4628 .channels_max = 2,
4629 .rates = SNDRV_PCM_RATE_48000,
4630 /* NID is set in via_build_pcms */
4631 .ops = {
4632 .open = via_dig_playback_pcm_open,
4633 .close = via_dig_playback_pcm_close,
4634 .prepare = via_dig_playback_pcm_prepare,
4635 .cleanup = via_dig_playback_pcm_cleanup
4639 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4640 .substreams = 1,
4641 .channels_min = 2,
4642 .channels_max = 2,
4645 /* fill in the dac_nids table from the parsed pin configuration */
4646 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4647 const struct auto_pin_cfg *cfg)
4649 int i;
4650 hda_nid_t nid;
4652 spec->multiout.num_dacs = cfg->line_outs;
4654 spec->multiout.dac_nids = spec->private_dac_nids;
4656 for (i = 0; i < 4; i++) {
4657 nid = cfg->line_out_pins[i];
4658 if (nid) {
4659 /* config dac list */
4660 switch (i) {
4661 case AUTO_SEQ_FRONT:
4662 spec->multiout.dac_nids[i] = 0x8;
4663 break;
4664 case AUTO_SEQ_CENLFE:
4665 spec->multiout.dac_nids[i] = 0xa;
4666 break;
4667 case AUTO_SEQ_SURROUND:
4668 spec->multiout.dac_nids[i] = 0x9;
4669 break;
4670 case AUTO_SEQ_SIDE:
4671 spec->multiout.dac_nids[i] = 0xb;
4672 break;
4677 return 0;
4680 /* add playback controls from the parsed DAC table */
4681 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4682 const struct auto_pin_cfg *cfg)
4684 char name[32];
4685 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4686 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4687 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4688 hda_nid_t nid, nid_vol, nid_mute = 0;
4689 int i, err;
4691 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4692 nid = cfg->line_out_pins[i];
4694 if (!nid)
4695 continue;
4696 nid_vol = nid_vols[i];
4697 nid_mute = nid_mutes[i];
4699 if (i == AUTO_SEQ_CENLFE) {
4700 /* Center/LFE */
4701 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4702 "Center Playback Volume",
4703 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4704 HDA_OUTPUT));
4705 if (err < 0)
4706 return err;
4707 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4708 "LFE Playback Volume",
4709 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4710 HDA_OUTPUT));
4711 if (err < 0)
4712 return err;
4713 err = via_add_control(
4714 spec, VIA_CTL_WIDGET_MUTE,
4715 "Center Playback Switch",
4716 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4717 HDA_OUTPUT));
4718 if (err < 0)
4719 return err;
4720 err = via_add_control(
4721 spec, VIA_CTL_WIDGET_MUTE,
4722 "LFE Playback Switch",
4723 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4724 HDA_OUTPUT));
4725 if (err < 0)
4726 return err;
4727 } else if (i == AUTO_SEQ_FRONT) {
4728 /* Front */
4729 sprintf(name, "%s Playback Volume", chname[i]);
4730 err = via_add_control(
4731 spec, VIA_CTL_WIDGET_VOL, name,
4732 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4733 if (err < 0)
4734 return err;
4735 sprintf(name, "%s Playback Switch", chname[i]);
4736 err = via_add_control(
4737 spec, VIA_CTL_WIDGET_MUTE, name,
4738 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4739 HDA_OUTPUT));
4740 if (err < 0)
4741 return err;
4742 } else {
4743 sprintf(name, "%s Playback Volume", chname[i]);
4744 err = via_add_control(
4745 spec, VIA_CTL_WIDGET_VOL, name,
4746 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4747 if (err < 0)
4748 return err;
4749 sprintf(name, "%s Playback Switch", chname[i]);
4750 err = via_add_control(
4751 spec, VIA_CTL_WIDGET_MUTE, name,
4752 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4753 HDA_OUTPUT));
4754 if (err < 0)
4755 return err;
4758 return 0;
4761 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4763 int err;
4765 if (!pin)
4766 return 0;
4768 spec->multiout.hp_nid = 0xc; /* AOW4 */
4769 spec->hp_independent_mode_index = 1;
4771 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4772 "Headphone Playback Volume",
4773 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4774 if (err < 0)
4775 return err;
4777 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4778 "Headphone Playback Switch",
4779 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4780 if (err < 0)
4781 return err;
4783 create_hp_imux(spec);
4784 return 0;
4787 /* create playback/capture controls for input pins */
4788 static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4789 const struct auto_pin_cfg *cfg)
4791 static char *labels[] = {
4792 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4794 struct hda_input_mux *imux = &spec->private_imux[0];
4795 int i, err, idx = 0;
4797 /* for internal loopback recording select */
4798 imux->items[imux->num_items].label = "Stereo Mixer";
4799 imux->items[imux->num_items].index = 5;
4800 imux->num_items++;
4802 for (i = 0; i < AUTO_PIN_LAST; i++) {
4803 if (!cfg->input_pins[i])
4804 continue;
4806 switch (cfg->input_pins[i]) {
4807 case 0x2b: /* Mic */
4808 idx = 1;
4809 break;
4811 case 0x2a: /* Line In */
4812 idx = 2;
4813 break;
4815 case 0x29: /* Front Mic */
4816 idx = 3;
4817 break;
4819 case 0x2c: /* CD */
4820 idx = 0;
4821 break;
4823 err = via_new_analog_input(spec, labels[i], idx, 0x21);
4824 if (err < 0)
4825 return err;
4826 imux->items[imux->num_items].label = labels[i];
4827 imux->items[imux->num_items].index = idx;
4828 imux->num_items++;
4830 return 0;
4833 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4835 struct via_spec *spec = codec->spec;
4836 int err;
4838 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4840 if (err < 0)
4841 return err;
4842 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4843 if (err < 0)
4844 return err;
4845 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4846 return 0; /* can't find valid BIOS pin config */
4848 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4849 if (err < 0)
4850 return err;
4851 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4852 if (err < 0)
4853 return err;
4854 err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4855 if (err < 0)
4856 return err;
4858 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4860 fill_dig_outs(codec);
4862 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4863 spec->dig_in_nid = 0x13;
4865 if (spec->kctls.list)
4866 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4868 spec->input_mux = &spec->private_imux[0];
4870 if (spec->hp_mux)
4871 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4873 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4875 return 1;
4878 #ifdef CONFIG_SND_HDA_POWER_SAVE
4879 static struct hda_amp_list vt1718S_loopbacks[] = {
4880 { 0x21, HDA_INPUT, 1 },
4881 { 0x21, HDA_INPUT, 2 },
4882 { 0x21, HDA_INPUT, 3 },
4883 { 0x21, HDA_INPUT, 4 },
4884 { } /* end */
4886 #endif
4888 static int patch_vt1718S(struct hda_codec *codec)
4890 struct via_spec *spec;
4891 int err;
4893 /* create a codec specific record */
4894 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4895 if (spec == NULL)
4896 return -ENOMEM;
4898 codec->spec = spec;
4900 /* automatic parse from the BIOS config */
4901 err = vt1718S_parse_auto_config(codec);
4902 if (err < 0) {
4903 via_free(codec);
4904 return err;
4905 } else if (!err) {
4906 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4907 "from BIOS. Using genenic mode...\n");
4910 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4911 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4913 if (codec->vendor_id == 0x11060441)
4914 spec->stream_name_analog = "VT2020 Analog";
4915 else if (codec->vendor_id == 0x11064441)
4916 spec->stream_name_analog = "VT1828S Analog";
4917 else
4918 spec->stream_name_analog = "VT1718S Analog";
4919 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4920 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4922 if (codec->vendor_id == 0x11060441)
4923 spec->stream_name_digital = "VT2020 Digital";
4924 else if (codec->vendor_id == 0x11064441)
4925 spec->stream_name_digital = "VT1828S Digital";
4926 else
4927 spec->stream_name_digital = "VT1718S Digital";
4928 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4929 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4930 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4932 if (!spec->adc_nids && spec->input_mux) {
4933 spec->adc_nids = vt1718S_adc_nids;
4934 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4935 get_mux_nids(codec);
4936 override_mic_boost(codec, 0x2b, 0, 3, 40);
4937 override_mic_boost(codec, 0x29, 0, 3, 40);
4938 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4939 spec->num_mixers++;
4942 codec->patch_ops = via_patch_ops;
4944 codec->patch_ops.init = via_auto_init;
4945 codec->patch_ops.unsol_event = via_unsol_event;
4947 #ifdef CONFIG_SND_HDA_POWER_SAVE
4948 spec->loopback.amplist = vt1718S_loopbacks;
4949 #endif
4951 return 0;
4954 /* Patch for VT1716S */
4956 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4957 struct snd_ctl_elem_info *uinfo)
4959 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4960 uinfo->count = 1;
4961 uinfo->value.integer.min = 0;
4962 uinfo->value.integer.max = 1;
4963 return 0;
4966 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4967 struct snd_ctl_elem_value *ucontrol)
4969 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4970 int index = 0;
4972 index = snd_hda_codec_read(codec, 0x26, 0,
4973 AC_VERB_GET_CONNECT_SEL, 0);
4974 if (index != -1)
4975 *ucontrol->value.integer.value = index;
4977 return 0;
4980 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4981 struct snd_ctl_elem_value *ucontrol)
4983 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4984 struct via_spec *spec = codec->spec;
4985 int index = *ucontrol->value.integer.value;
4987 snd_hda_codec_write(codec, 0x26, 0,
4988 AC_VERB_SET_CONNECT_SEL, index);
4989 spec->dmic_enabled = index;
4990 set_jack_power_state(codec);
4992 return 1;
4995 /* capture mixer elements */
4996 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4997 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4998 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4999 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
5000 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
5001 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
5002 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5003 HDA_INPUT),
5005 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5006 .name = "Input Source",
5007 .count = 1,
5008 .info = via_mux_enum_info,
5009 .get = via_mux_enum_get,
5010 .put = via_mux_enum_put,
5012 { } /* end */
5015 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
5016 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
5018 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5019 .name = "Digital Mic Capture Switch",
5020 .count = 1,
5021 .info = vt1716s_dmic_info,
5022 .get = vt1716s_dmic_get,
5023 .put = vt1716s_dmic_put,
5025 {} /* end */
5029 /* mono-out mixer elements */
5030 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
5031 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
5032 { } /* end */
5035 static struct hda_verb vt1716S_volume_init_verbs[] = {
5037 * Unmute ADC0-1 and set the default input to mic-in
5039 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5040 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5043 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5044 * mixer widget
5046 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5047 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5048 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5049 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5050 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5051 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5053 /* MUX Indices: Stereo Mixer = 5 */
5054 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
5056 /* Setup default input of PW4 to MW0 */
5057 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
5059 /* Setup default input of SW1 as MW0 */
5060 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5062 /* Setup default input of SW4 as AOW0 */
5063 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5065 /* PW9 PW10 Output enable */
5066 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5067 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5069 /* Unmute SW1, PW12 */
5070 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5071 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5072 /* PW12 Output enable */
5073 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5074 /* Enable Boost Volume backdoor */
5075 {0x1, 0xf8a, 0x80},
5076 /* don't bybass mixer */
5077 {0x1, 0xf88, 0xc0},
5078 /* Enable mono output */
5079 {0x1, 0xf90, 0x08},
5084 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5085 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5086 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5087 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5088 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5089 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5090 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5091 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5092 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5093 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5097 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5098 .substreams = 2,
5099 .channels_min = 2,
5100 .channels_max = 6,
5101 .nid = 0x10, /* NID to query formats and rates */
5102 .ops = {
5103 .open = via_playback_pcm_open,
5104 .prepare = via_playback_multi_pcm_prepare,
5105 .cleanup = via_playback_multi_pcm_cleanup,
5106 .close = via_pcm_open_close,
5110 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5111 .substreams = 2,
5112 .channels_min = 2,
5113 .channels_max = 2,
5114 .nid = 0x13, /* NID to query formats and rates */
5115 .ops = {
5116 .open = via_pcm_open_close,
5117 .prepare = via_capture_pcm_prepare,
5118 .cleanup = via_capture_pcm_cleanup,
5119 .close = via_pcm_open_close,
5123 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5124 .substreams = 2,
5125 .channels_min = 2,
5126 .channels_max = 2,
5127 .rates = SNDRV_PCM_RATE_48000,
5128 /* NID is set in via_build_pcms */
5129 .ops = {
5130 .open = via_dig_playback_pcm_open,
5131 .close = via_dig_playback_pcm_close,
5132 .prepare = via_dig_playback_pcm_prepare,
5133 .cleanup = via_dig_playback_pcm_cleanup
5137 /* fill in the dac_nids table from the parsed pin configuration */
5138 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5139 const struct auto_pin_cfg *cfg)
5140 { int i;
5141 hda_nid_t nid;
5143 spec->multiout.num_dacs = cfg->line_outs;
5145 spec->multiout.dac_nids = spec->private_dac_nids;
5147 for (i = 0; i < 3; i++) {
5148 nid = cfg->line_out_pins[i];
5149 if (nid) {
5150 /* config dac list */
5151 switch (i) {
5152 case AUTO_SEQ_FRONT:
5153 spec->multiout.dac_nids[i] = 0x10;
5154 break;
5155 case AUTO_SEQ_CENLFE:
5156 spec->multiout.dac_nids[i] = 0x25;
5157 break;
5158 case AUTO_SEQ_SURROUND:
5159 spec->multiout.dac_nids[i] = 0x11;
5160 break;
5165 return 0;
5168 /* add playback controls from the parsed DAC table */
5169 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5170 const struct auto_pin_cfg *cfg)
5172 char name[32];
5173 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5174 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5175 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5176 hda_nid_t nid, nid_vol, nid_mute;
5177 int i, err;
5179 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5180 nid = cfg->line_out_pins[i];
5182 if (!nid)
5183 continue;
5185 nid_vol = nid_vols[i];
5186 nid_mute = nid_mutes[i];
5188 if (i == AUTO_SEQ_CENLFE) {
5189 err = via_add_control(
5190 spec, VIA_CTL_WIDGET_VOL,
5191 "Center Playback Volume",
5192 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5193 if (err < 0)
5194 return err;
5195 err = via_add_control(
5196 spec, VIA_CTL_WIDGET_VOL,
5197 "LFE Playback Volume",
5198 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5199 if (err < 0)
5200 return err;
5201 err = via_add_control(
5202 spec, VIA_CTL_WIDGET_MUTE,
5203 "Center Playback Switch",
5204 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5205 HDA_OUTPUT));
5206 if (err < 0)
5207 return err;
5208 err = via_add_control(
5209 spec, VIA_CTL_WIDGET_MUTE,
5210 "LFE Playback Switch",
5211 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5212 HDA_OUTPUT));
5213 if (err < 0)
5214 return err;
5215 } else if (i == AUTO_SEQ_FRONT) {
5217 err = via_add_control(
5218 spec, VIA_CTL_WIDGET_VOL,
5219 "Master Front Playback Volume",
5220 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5221 if (err < 0)
5222 return err;
5223 err = via_add_control(
5224 spec, VIA_CTL_WIDGET_MUTE,
5225 "Master Front Playback Switch",
5226 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5227 if (err < 0)
5228 return err;
5230 sprintf(name, "%s Playback Volume", chname[i]);
5231 err = via_add_control(
5232 spec, VIA_CTL_WIDGET_VOL, name,
5233 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5234 if (err < 0)
5235 return err;
5236 sprintf(name, "%s Playback Switch", chname[i]);
5237 err = via_add_control(
5238 spec, VIA_CTL_WIDGET_MUTE, name,
5239 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5240 HDA_OUTPUT));
5241 if (err < 0)
5242 return err;
5243 } else {
5244 sprintf(name, "%s Playback Volume", chname[i]);
5245 err = via_add_control(
5246 spec, VIA_CTL_WIDGET_VOL, name,
5247 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5248 if (err < 0)
5249 return err;
5250 sprintf(name, "%s Playback Switch", chname[i]);
5251 err = via_add_control(
5252 spec, VIA_CTL_WIDGET_MUTE, name,
5253 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5254 HDA_OUTPUT));
5255 if (err < 0)
5256 return err;
5259 return 0;
5262 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5264 int err;
5266 if (!pin)
5267 return 0;
5269 spec->multiout.hp_nid = 0x25; /* AOW3 */
5270 spec->hp_independent_mode_index = 1;
5272 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5273 "Headphone Playback Volume",
5274 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5275 if (err < 0)
5276 return err;
5278 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5279 "Headphone Playback Switch",
5280 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5281 if (err < 0)
5282 return err;
5284 create_hp_imux(spec);
5285 return 0;
5288 /* create playback/capture controls for input pins */
5289 static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5290 const struct auto_pin_cfg *cfg)
5292 static char *labels[] = {
5293 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5295 struct hda_input_mux *imux = &spec->private_imux[0];
5296 int i, err, idx = 0;
5298 /* for internal loopback recording select */
5299 imux->items[imux->num_items].label = "Stereo Mixer";
5300 imux->items[imux->num_items].index = 5;
5301 imux->num_items++;
5303 for (i = 0; i < AUTO_PIN_LAST; i++) {
5304 if (!cfg->input_pins[i])
5305 continue;
5307 switch (cfg->input_pins[i]) {
5308 case 0x1a: /* Mic */
5309 idx = 2;
5310 break;
5312 case 0x1b: /* Line In */
5313 idx = 3;
5314 break;
5316 case 0x1e: /* Front Mic */
5317 idx = 4;
5318 break;
5320 case 0x1f: /* CD */
5321 idx = 1;
5322 break;
5324 err = via_new_analog_input(spec, labels[i], idx, 0x16);
5325 if (err < 0)
5326 return err;
5327 imux->items[imux->num_items].label = labels[i];
5328 imux->items[imux->num_items].index = idx-1;
5329 imux->num_items++;
5331 return 0;
5334 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5336 struct via_spec *spec = codec->spec;
5337 int err;
5339 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5340 if (err < 0)
5341 return err;
5342 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5343 if (err < 0)
5344 return err;
5345 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5346 return 0; /* can't find valid BIOS pin config */
5348 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5349 if (err < 0)
5350 return err;
5351 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5352 if (err < 0)
5353 return err;
5354 err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
5355 if (err < 0)
5356 return err;
5358 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5360 fill_dig_outs(codec);
5362 if (spec->kctls.list)
5363 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5365 spec->input_mux = &spec->private_imux[0];
5367 if (spec->hp_mux)
5368 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5370 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
5372 return 1;
5375 #ifdef CONFIG_SND_HDA_POWER_SAVE
5376 static struct hda_amp_list vt1716S_loopbacks[] = {
5377 { 0x16, HDA_INPUT, 1 },
5378 { 0x16, HDA_INPUT, 2 },
5379 { 0x16, HDA_INPUT, 3 },
5380 { 0x16, HDA_INPUT, 4 },
5381 { } /* end */
5383 #endif
5385 static int patch_vt1716S(struct hda_codec *codec)
5387 struct via_spec *spec;
5388 int err;
5390 /* create a codec specific record */
5391 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5392 if (spec == NULL)
5393 return -ENOMEM;
5395 codec->spec = spec;
5397 /* automatic parse from the BIOS config */
5398 err = vt1716S_parse_auto_config(codec);
5399 if (err < 0) {
5400 via_free(codec);
5401 return err;
5402 } else if (!err) {
5403 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5404 "from BIOS. Using genenic mode...\n");
5407 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5408 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5410 spec->stream_name_analog = "VT1716S Analog";
5411 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5412 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5414 spec->stream_name_digital = "VT1716S Digital";
5415 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5417 if (!spec->adc_nids && spec->input_mux) {
5418 spec->adc_nids = vt1716S_adc_nids;
5419 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5420 get_mux_nids(codec);
5421 override_mic_boost(codec, 0x1a, 0, 3, 40);
5422 override_mic_boost(codec, 0x1e, 0, 3, 40);
5423 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5424 spec->num_mixers++;
5427 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5428 spec->num_mixers++;
5430 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5432 codec->patch_ops = via_patch_ops;
5434 codec->patch_ops.init = via_auto_init;
5435 codec->patch_ops.unsol_event = via_unsol_event;
5437 #ifdef CONFIG_SND_HDA_POWER_SAVE
5438 spec->loopback.amplist = vt1716S_loopbacks;
5439 #endif
5441 return 0;
5444 /* for vt2002P */
5446 /* capture mixer elements */
5447 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5448 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5449 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5450 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5451 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5452 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5453 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5454 HDA_INPUT),
5456 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5457 /* The multiple "Capture Source" controls confuse alsamixer
5458 * So call somewhat different..
5460 /* .name = "Capture Source", */
5461 .name = "Input Source",
5462 .count = 2,
5463 .info = via_mux_enum_info,
5464 .get = via_mux_enum_get,
5465 .put = via_mux_enum_put,
5467 { } /* end */
5470 static struct hda_verb vt2002P_volume_init_verbs[] = {
5472 * Unmute ADC0-1 and set the default input to mic-in
5474 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5475 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5478 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5479 * mixer widget
5481 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5482 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5483 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5484 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5485 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5486 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5488 /* MUX Indices: Mic = 0 */
5489 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5490 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5492 /* PW9 Output enable */
5493 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5495 /* Enable Boost Volume backdoor */
5496 {0x1, 0xfb9, 0x24},
5498 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5499 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5500 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5501 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5502 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5503 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5504 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5505 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5506 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5508 /* set MUX0/1/4/8 = 0 (AOW0) */
5509 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5510 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5511 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5512 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5514 /* set PW0 index=0 (MW0) */
5515 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5517 /* Enable AOW0 to MW9 */
5518 {0x1, 0xfb8, 0x88},
5523 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5524 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5525 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5526 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5527 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5528 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5529 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5530 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5534 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5535 .substreams = 2,
5536 .channels_min = 2,
5537 .channels_max = 2,
5538 .nid = 0x8, /* NID to query formats and rates */
5539 .ops = {
5540 .open = via_playback_pcm_open,
5541 .prepare = via_playback_multi_pcm_prepare,
5542 .cleanup = via_playback_multi_pcm_cleanup,
5543 .close = via_pcm_open_close,
5547 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5548 .substreams = 2,
5549 .channels_min = 2,
5550 .channels_max = 2,
5551 .nid = 0x10, /* NID to query formats and rates */
5552 .ops = {
5553 .open = via_pcm_open_close,
5554 .prepare = via_capture_pcm_prepare,
5555 .cleanup = via_capture_pcm_cleanup,
5556 .close = via_pcm_open_close,
5560 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5561 .substreams = 1,
5562 .channels_min = 2,
5563 .channels_max = 2,
5564 .rates = SNDRV_PCM_RATE_48000,
5565 /* NID is set in via_build_pcms */
5566 .ops = {
5567 .open = via_dig_playback_pcm_open,
5568 .close = via_dig_playback_pcm_close,
5569 .prepare = via_dig_playback_pcm_prepare,
5570 .cleanup = via_dig_playback_pcm_cleanup
5574 /* fill in the dac_nids table from the parsed pin configuration */
5575 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5576 const struct auto_pin_cfg *cfg)
5578 spec->multiout.num_dacs = 1;
5579 spec->multiout.dac_nids = spec->private_dac_nids;
5580 if (cfg->line_out_pins[0])
5581 spec->multiout.dac_nids[0] = 0x8;
5582 return 0;
5585 /* add playback controls from the parsed DAC table */
5586 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5587 const struct auto_pin_cfg *cfg)
5589 int err;
5591 if (!cfg->line_out_pins[0])
5592 return -1;
5595 /* Line-Out: PortE */
5596 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5597 "Master Front Playback Volume",
5598 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5599 if (err < 0)
5600 return err;
5601 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5602 "Master Front Playback Switch",
5603 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5604 if (err < 0)
5605 return err;
5607 return 0;
5610 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5612 int err;
5614 if (!pin)
5615 return 0;
5617 spec->multiout.hp_nid = 0x9;
5618 spec->hp_independent_mode_index = 1;
5620 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5621 "Headphone Playback Volume",
5622 HDA_COMPOSE_AMP_VAL(
5623 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5624 if (err < 0)
5625 return err;
5627 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5628 "Headphone Playback Switch",
5629 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5630 if (err < 0)
5631 return err;
5633 create_hp_imux(spec);
5634 return 0;
5637 /* create playback/capture controls for input pins */
5638 static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
5639 const struct auto_pin_cfg *cfg)
5641 static char *labels[] = {
5642 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5644 struct hda_input_mux *imux = &spec->private_imux[0];
5645 int i, err, idx = 0;
5647 for (i = 0; i < AUTO_PIN_LAST; i++) {
5648 if (!cfg->input_pins[i])
5649 continue;
5651 switch (cfg->input_pins[i]) {
5652 case 0x2b: /* Mic */
5653 idx = 0;
5654 break;
5656 case 0x2a: /* Line In */
5657 idx = 1;
5658 break;
5660 case 0x29: /* Front Mic */
5661 idx = 2;
5662 break;
5664 err = via_new_analog_input(spec, labels[i], idx, 0x21);
5665 if (err < 0)
5666 return err;
5667 imux->items[imux->num_items].label = labels[i];
5668 imux->items[imux->num_items].index = idx;
5669 imux->num_items++;
5672 /* build volume/mute control of loopback */
5673 err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
5674 if (err < 0)
5675 return err;
5677 /* for internal loopback recording select */
5678 imux->items[imux->num_items].label = "Stereo Mixer";
5679 imux->items[imux->num_items].index = 3;
5680 imux->num_items++;
5682 /* for digital mic select */
5683 imux->items[imux->num_items].label = "Digital Mic";
5684 imux->items[imux->num_items].index = 4;
5685 imux->num_items++;
5687 return 0;
5690 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5692 struct via_spec *spec = codec->spec;
5693 int err;
5696 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5697 if (err < 0)
5698 return err;
5700 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5701 if (err < 0)
5702 return err;
5704 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5705 return 0; /* can't find valid BIOS pin config */
5707 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5708 if (err < 0)
5709 return err;
5710 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5711 if (err < 0)
5712 return err;
5713 err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
5714 if (err < 0)
5715 return err;
5717 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5719 fill_dig_outs(codec);
5721 if (spec->kctls.list)
5722 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5724 spec->input_mux = &spec->private_imux[0];
5726 if (spec->hp_mux)
5727 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5729 return 1;
5732 #ifdef CONFIG_SND_HDA_POWER_SAVE
5733 static struct hda_amp_list vt2002P_loopbacks[] = {
5734 { 0x21, HDA_INPUT, 0 },
5735 { 0x21, HDA_INPUT, 1 },
5736 { 0x21, HDA_INPUT, 2 },
5737 { } /* end */
5739 #endif
5742 /* patch for vt2002P */
5743 static int patch_vt2002P(struct hda_codec *codec)
5745 struct via_spec *spec;
5746 int err;
5748 /* create a codec specific record */
5749 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5750 if (spec == NULL)
5751 return -ENOMEM;
5753 codec->spec = spec;
5755 /* automatic parse from the BIOS config */
5756 err = vt2002P_parse_auto_config(codec);
5757 if (err < 0) {
5758 via_free(codec);
5759 return err;
5760 } else if (!err) {
5761 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5762 "from BIOS. Using genenic mode...\n");
5765 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5766 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5768 spec->stream_name_analog = "VT2002P Analog";
5769 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5770 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5772 spec->stream_name_digital = "VT2002P Digital";
5773 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5775 if (!spec->adc_nids && spec->input_mux) {
5776 spec->adc_nids = vt2002P_adc_nids;
5777 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5778 get_mux_nids(codec);
5779 override_mic_boost(codec, 0x2b, 0, 3, 40);
5780 override_mic_boost(codec, 0x29, 0, 3, 40);
5781 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5782 spec->num_mixers++;
5785 codec->patch_ops = via_patch_ops;
5787 codec->patch_ops.init = via_auto_init;
5788 codec->patch_ops.unsol_event = via_unsol_event;
5790 #ifdef CONFIG_SND_HDA_POWER_SAVE
5791 spec->loopback.amplist = vt2002P_loopbacks;
5792 #endif
5794 return 0;
5797 /* for vt1812 */
5799 /* capture mixer elements */
5800 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5801 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5802 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5803 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5804 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5805 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5806 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5807 HDA_INPUT),
5809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5810 /* The multiple "Capture Source" controls confuse alsamixer
5811 * So call somewhat different..
5813 .name = "Input Source",
5814 .count = 2,
5815 .info = via_mux_enum_info,
5816 .get = via_mux_enum_get,
5817 .put = via_mux_enum_put,
5819 { } /* end */
5822 static struct hda_verb vt1812_volume_init_verbs[] = {
5824 * Unmute ADC0-1 and set the default input to mic-in
5826 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5827 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5830 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5831 * mixer widget
5833 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5834 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5835 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5836 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5837 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5838 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5840 /* MUX Indices: Mic = 0 */
5841 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5842 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5844 /* PW9 Output enable */
5845 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5847 /* Enable Boost Volume backdoor */
5848 {0x1, 0xfb9, 0x24},
5850 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5851 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5852 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5853 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5854 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5855 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5856 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5857 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5858 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5859 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5860 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5862 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5863 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5864 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5865 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5866 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5867 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5869 /* Enable AOW0 to MW9 */
5870 {0x1, 0xfb8, 0xa8},
5875 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5876 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5877 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5878 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5879 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5880 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5881 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5882 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5883 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5887 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5888 .substreams = 2,
5889 .channels_min = 2,
5890 .channels_max = 2,
5891 .nid = 0x8, /* NID to query formats and rates */
5892 .ops = {
5893 .open = via_playback_pcm_open,
5894 .prepare = via_playback_multi_pcm_prepare,
5895 .cleanup = via_playback_multi_pcm_cleanup,
5896 .close = via_pcm_open_close,
5900 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5901 .substreams = 2,
5902 .channels_min = 2,
5903 .channels_max = 2,
5904 .nid = 0x10, /* NID to query formats and rates */
5905 .ops = {
5906 .open = via_pcm_open_close,
5907 .prepare = via_capture_pcm_prepare,
5908 .cleanup = via_capture_pcm_cleanup,
5909 .close = via_pcm_open_close,
5913 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5914 .substreams = 1,
5915 .channels_min = 2,
5916 .channels_max = 2,
5917 .rates = SNDRV_PCM_RATE_48000,
5918 /* NID is set in via_build_pcms */
5919 .ops = {
5920 .open = via_dig_playback_pcm_open,
5921 .close = via_dig_playback_pcm_close,
5922 .prepare = via_dig_playback_pcm_prepare,
5923 .cleanup = via_dig_playback_pcm_cleanup
5926 /* fill in the dac_nids table from the parsed pin configuration */
5927 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5928 const struct auto_pin_cfg *cfg)
5930 spec->multiout.num_dacs = 1;
5931 spec->multiout.dac_nids = spec->private_dac_nids;
5932 if (cfg->line_out_pins[0])
5933 spec->multiout.dac_nids[0] = 0x8;
5934 return 0;
5938 /* add playback controls from the parsed DAC table */
5939 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5940 const struct auto_pin_cfg *cfg)
5942 int err;
5944 if (!cfg->line_out_pins[0])
5945 return -1;
5947 /* Line-Out: PortE */
5948 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5949 "Master Front Playback Volume",
5950 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5951 if (err < 0)
5952 return err;
5953 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5954 "Master Front Playback Switch",
5955 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5956 if (err < 0)
5957 return err;
5959 return 0;
5962 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5964 int err;
5966 if (!pin)
5967 return 0;
5969 spec->multiout.hp_nid = 0x9;
5970 spec->hp_independent_mode_index = 1;
5973 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5974 "Headphone Playback Volume",
5975 HDA_COMPOSE_AMP_VAL(
5976 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5977 if (err < 0)
5978 return err;
5980 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5981 "Headphone Playback Switch",
5982 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5983 if (err < 0)
5984 return err;
5986 create_hp_imux(spec);
5987 return 0;
5990 /* create playback/capture controls for input pins */
5991 static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
5992 const struct auto_pin_cfg *cfg)
5994 static char *labels[] = {
5995 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5997 struct hda_input_mux *imux = &spec->private_imux[0];
5998 int i, err, idx = 0;
6000 for (i = 0; i < AUTO_PIN_LAST; i++) {
6001 if (!cfg->input_pins[i])
6002 continue;
6004 switch (cfg->input_pins[i]) {
6005 case 0x2b: /* Mic */
6006 idx = 0;
6007 break;
6009 case 0x2a: /* Line In */
6010 idx = 1;
6011 break;
6013 case 0x29: /* Front Mic */
6014 idx = 2;
6015 break;
6017 err = via_new_analog_input(spec, labels[i], idx, 0x21);
6018 if (err < 0)
6019 return err;
6020 imux->items[imux->num_items].label = labels[i];
6021 imux->items[imux->num_items].index = idx;
6022 imux->num_items++;
6024 /* build volume/mute control of loopback */
6025 err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
6026 if (err < 0)
6027 return err;
6029 /* for internal loopback recording select */
6030 imux->items[imux->num_items].label = "Stereo Mixer";
6031 imux->items[imux->num_items].index = 5;
6032 imux->num_items++;
6034 /* for digital mic select */
6035 imux->items[imux->num_items].label = "Digital Mic";
6036 imux->items[imux->num_items].index = 6;
6037 imux->num_items++;
6039 return 0;
6042 static int vt1812_parse_auto_config(struct hda_codec *codec)
6044 struct via_spec *spec = codec->spec;
6045 int err;
6048 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6049 if (err < 0)
6050 return err;
6051 fill_dig_outs(codec);
6052 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6053 if (err < 0)
6054 return err;
6056 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6057 return 0; /* can't find valid BIOS pin config */
6059 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6060 if (err < 0)
6061 return err;
6062 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6063 if (err < 0)
6064 return err;
6065 err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
6066 if (err < 0)
6067 return err;
6069 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6071 fill_dig_outs(codec);
6073 if (spec->kctls.list)
6074 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6076 spec->input_mux = &spec->private_imux[0];
6078 if (spec->hp_mux)
6079 spec->mixers[spec->num_mixers++] = via_hp_mixer;
6081 return 1;
6084 #ifdef CONFIG_SND_HDA_POWER_SAVE
6085 static struct hda_amp_list vt1812_loopbacks[] = {
6086 { 0x21, HDA_INPUT, 0 },
6087 { 0x21, HDA_INPUT, 1 },
6088 { 0x21, HDA_INPUT, 2 },
6089 { } /* end */
6091 #endif
6094 /* patch for vt1812 */
6095 static int patch_vt1812(struct hda_codec *codec)
6097 struct via_spec *spec;
6098 int err;
6100 /* create a codec specific record */
6101 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6102 if (spec == NULL)
6103 return -ENOMEM;
6105 codec->spec = spec;
6107 /* automatic parse from the BIOS config */
6108 err = vt1812_parse_auto_config(codec);
6109 if (err < 0) {
6110 via_free(codec);
6111 return err;
6112 } else if (!err) {
6113 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6114 "from BIOS. Using genenic mode...\n");
6118 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6119 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6121 spec->stream_name_analog = "VT1812 Analog";
6122 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6123 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6125 spec->stream_name_digital = "VT1812 Digital";
6126 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6129 if (!spec->adc_nids && spec->input_mux) {
6130 spec->adc_nids = vt1812_adc_nids;
6131 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6132 get_mux_nids(codec);
6133 override_mic_boost(codec, 0x2b, 0, 3, 40);
6134 override_mic_boost(codec, 0x29, 0, 3, 40);
6135 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6136 spec->num_mixers++;
6139 codec->patch_ops = via_patch_ops;
6141 codec->patch_ops.init = via_auto_init;
6142 codec->patch_ops.unsol_event = via_unsol_event;
6144 #ifdef CONFIG_SND_HDA_POWER_SAVE
6145 spec->loopback.amplist = vt1812_loopbacks;
6146 #endif
6148 return 0;
6152 * patch entries
6154 static struct hda_codec_preset snd_hda_preset_via[] = {
6155 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6156 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6157 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6158 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6159 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6160 .patch = patch_vt1709_10ch},
6161 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6162 .patch = patch_vt1709_10ch},
6163 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6164 .patch = patch_vt1709_10ch},
6165 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6166 .patch = patch_vt1709_10ch},
6167 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6168 .patch = patch_vt1709_6ch},
6169 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6170 .patch = patch_vt1709_6ch},
6171 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6172 .patch = patch_vt1709_6ch},
6173 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6174 .patch = patch_vt1709_6ch},
6175 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6176 .patch = patch_vt1708B_8ch},
6177 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6178 .patch = patch_vt1708B_8ch},
6179 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6180 .patch = patch_vt1708B_8ch},
6181 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6182 .patch = patch_vt1708B_8ch},
6183 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6184 .patch = patch_vt1708B_4ch},
6185 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6186 .patch = patch_vt1708B_4ch},
6187 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6188 .patch = patch_vt1708B_4ch},
6189 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6190 .patch = patch_vt1708B_4ch},
6191 { .id = 0x11060397, .name = "VT1708S",
6192 .patch = patch_vt1708S},
6193 { .id = 0x11061397, .name = "VT1708S",
6194 .patch = patch_vt1708S},
6195 { .id = 0x11062397, .name = "VT1708S",
6196 .patch = patch_vt1708S},
6197 { .id = 0x11063397, .name = "VT1708S",
6198 .patch = patch_vt1708S},
6199 { .id = 0x11064397, .name = "VT1708S",
6200 .patch = patch_vt1708S},
6201 { .id = 0x11065397, .name = "VT1708S",
6202 .patch = patch_vt1708S},
6203 { .id = 0x11066397, .name = "VT1708S",
6204 .patch = patch_vt1708S},
6205 { .id = 0x11067397, .name = "VT1708S",
6206 .patch = patch_vt1708S},
6207 { .id = 0x11060398, .name = "VT1702",
6208 .patch = patch_vt1702},
6209 { .id = 0x11061398, .name = "VT1702",
6210 .patch = patch_vt1702},
6211 { .id = 0x11062398, .name = "VT1702",
6212 .patch = patch_vt1702},
6213 { .id = 0x11063398, .name = "VT1702",
6214 .patch = patch_vt1702},
6215 { .id = 0x11064398, .name = "VT1702",
6216 .patch = patch_vt1702},
6217 { .id = 0x11065398, .name = "VT1702",
6218 .patch = patch_vt1702},
6219 { .id = 0x11066398, .name = "VT1702",
6220 .patch = patch_vt1702},
6221 { .id = 0x11067398, .name = "VT1702",
6222 .patch = patch_vt1702},
6223 { .id = 0x11060428, .name = "VT1718S",
6224 .patch = patch_vt1718S},
6225 { .id = 0x11064428, .name = "VT1718S",
6226 .patch = patch_vt1718S},
6227 { .id = 0x11060441, .name = "VT2020",
6228 .patch = patch_vt1718S},
6229 { .id = 0x11064441, .name = "VT1828S",
6230 .patch = patch_vt1718S},
6231 { .id = 0x11060433, .name = "VT1716S",
6232 .patch = patch_vt1716S},
6233 { .id = 0x1106a721, .name = "VT1716S",
6234 .patch = patch_vt1716S},
6235 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6236 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6237 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6238 {} /* terminator */
6241 MODULE_ALIAS("snd-hda-codec-id:1106*");
6243 static struct hda_codec_preset_list via_list = {
6244 .preset = snd_hda_preset_via,
6245 .owner = THIS_MODULE,
6248 MODULE_LICENSE("GPL");
6249 MODULE_DESCRIPTION("VIA HD-audio codec");
6251 static int __init patch_via_init(void)
6253 return snd_hda_add_codec_preset(&via_list);
6256 static void __exit patch_via_exit(void)
6258 snd_hda_delete_codec_preset(&via_list);
6261 module_init(patch_via_init)
6262 module_exit(patch_via_exit)