2 * HD audio interface patch for AD1981HD, AD1983, AD1986A, AD1988
4 * Copyright (c) 2005 Takashi Iwai <tiwai@suse.de>
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This driver is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <sound/driver.h>
22 #include <linux/init.h>
23 #include <linux/delay.h>
24 #include <linux/slab.h>
25 #include <linux/pci.h>
26 #include <linux/mutex.h>
28 #include <sound/core.h>
29 #include "hda_codec.h"
30 #include "hda_local.h"
33 struct snd_kcontrol_new *mixers[5];
36 const struct hda_verb *init_verbs[5]; /* initialization verbs
37 * don't forget NULL termination!
39 unsigned int num_init_verbs;
42 struct hda_multi_out multiout; /* playback set-up
43 * max_channels, dacs must be set
44 * dig_out_nid and hp_nid are optional
46 unsigned int cur_eapd;
49 unsigned int num_adc_nids;
51 hda_nid_t dig_in_nid; /* digital-in NID; optional */
54 const struct hda_input_mux *input_mux;
55 hda_nid_t *capsrc_nids;
56 unsigned int cur_mux[3];
59 const struct hda_channel_mode *channel_mode;
63 struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */
65 struct mutex amp_mutex; /* PCM volume/mute control mutex */
66 unsigned int spdif_route;
68 /* dynamic controls, init_verbs and input_mux */
69 struct auto_pin_cfg autocfg;
70 unsigned int num_kctl_alloc, num_kctl_used;
71 struct snd_kcontrol_new *kctl_alloc;
72 struct hda_input_mux private_imux;
73 hda_nid_t private_dac_nids[4];
77 * input MUX handling (common part)
79 static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
81 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
82 struct ad198x_spec *spec = codec->spec;
84 return snd_hda_input_mux_info(spec->input_mux, uinfo);
87 static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
89 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
90 struct ad198x_spec *spec = codec->spec;
91 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
93 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
97 static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
99 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
100 struct ad198x_spec *spec = codec->spec;
101 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
103 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
104 spec->capsrc_nids[adc_idx],
105 &spec->cur_mux[adc_idx]);
109 * initialization (common callbacks)
111 static int ad198x_init(struct hda_codec *codec)
113 struct ad198x_spec *spec = codec->spec;
116 for (i = 0; i < spec->num_init_verbs; i++)
117 snd_hda_sequence_write(codec, spec->init_verbs[i]);
121 static int ad198x_build_controls(struct hda_codec *codec)
123 struct ad198x_spec *spec = codec->spec;
127 for (i = 0; i < spec->num_mixers; i++) {
128 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
132 if (spec->multiout.dig_out_nid) {
133 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
137 if (spec->dig_in_nid) {
138 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
146 * Analog playback callbacks
148 static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
149 struct hda_codec *codec,
150 struct snd_pcm_substream *substream)
152 struct ad198x_spec *spec = codec->spec;
153 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
156 static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
157 struct hda_codec *codec,
158 unsigned int stream_tag,
160 struct snd_pcm_substream *substream)
162 struct ad198x_spec *spec = codec->spec;
163 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
167 static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
168 struct hda_codec *codec,
169 struct snd_pcm_substream *substream)
171 struct ad198x_spec *spec = codec->spec;
172 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
178 static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
179 struct hda_codec *codec,
180 struct snd_pcm_substream *substream)
182 struct ad198x_spec *spec = codec->spec;
183 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
186 static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
187 struct hda_codec *codec,
188 struct snd_pcm_substream *substream)
190 struct ad198x_spec *spec = codec->spec;
191 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
197 static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
198 struct hda_codec *codec,
199 unsigned int stream_tag,
201 struct snd_pcm_substream *substream)
203 struct ad198x_spec *spec = codec->spec;
204 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
205 stream_tag, 0, format);
209 static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
210 struct hda_codec *codec,
211 struct snd_pcm_substream *substream)
213 struct ad198x_spec *spec = codec->spec;
214 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
222 static struct hda_pcm_stream ad198x_pcm_analog_playback = {
225 .channels_max = 6, /* changed later */
226 .nid = 0, /* fill later */
228 .open = ad198x_playback_pcm_open,
229 .prepare = ad198x_playback_pcm_prepare,
230 .cleanup = ad198x_playback_pcm_cleanup
234 static struct hda_pcm_stream ad198x_pcm_analog_capture = {
238 .nid = 0, /* fill later */
240 .prepare = ad198x_capture_pcm_prepare,
241 .cleanup = ad198x_capture_pcm_cleanup
245 static struct hda_pcm_stream ad198x_pcm_digital_playback = {
249 .nid = 0, /* fill later */
251 .open = ad198x_dig_playback_pcm_open,
252 .close = ad198x_dig_playback_pcm_close
256 static struct hda_pcm_stream ad198x_pcm_digital_capture = {
260 /* NID is set in alc_build_pcms */
263 static int ad198x_build_pcms(struct hda_codec *codec)
265 struct ad198x_spec *spec = codec->spec;
266 struct hda_pcm *info = spec->pcm_rec;
269 codec->pcm_info = info;
271 info->name = "AD198x Analog";
272 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
273 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
274 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
275 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
276 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
277 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
279 if (spec->multiout.dig_out_nid) {
282 info->name = "AD198x Digital";
283 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
284 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
285 if (spec->dig_in_nid) {
286 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
287 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
294 static void ad198x_free(struct hda_codec *codec)
296 struct ad198x_spec *spec = codec->spec;
299 if (spec->kctl_alloc) {
300 for (i = 0; i < spec->num_kctl_used; i++)
301 kfree(spec->kctl_alloc[i].name);
302 kfree(spec->kctl_alloc);
308 static int ad198x_resume(struct hda_codec *codec)
310 struct ad198x_spec *spec = codec->spec;
313 codec->patch_ops.init(codec);
314 for (i = 0; i < spec->num_mixers; i++)
315 snd_hda_resume_ctls(codec, spec->mixers[i]);
316 if (spec->multiout.dig_out_nid)
317 snd_hda_resume_spdif_out(codec);
318 if (spec->dig_in_nid)
319 snd_hda_resume_spdif_in(codec);
324 static struct hda_codec_ops ad198x_patch_ops = {
325 .build_controls = ad198x_build_controls,
326 .build_pcms = ad198x_build_pcms,
330 .resume = ad198x_resume,
337 * the private value = nid | (invert << 8)
339 static int ad198x_eapd_info(struct snd_kcontrol *kcontrol,
340 struct snd_ctl_elem_info *uinfo)
342 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
344 uinfo->value.integer.min = 0;
345 uinfo->value.integer.max = 1;
349 static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
350 struct snd_ctl_elem_value *ucontrol)
352 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
353 struct ad198x_spec *spec = codec->spec;
354 int invert = (kcontrol->private_value >> 8) & 1;
356 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
358 ucontrol->value.integer.value[0] = spec->cur_eapd;
362 static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
363 struct snd_ctl_elem_value *ucontrol)
365 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
366 struct ad198x_spec *spec = codec->spec;
367 int invert = (kcontrol->private_value >> 8) & 1;
368 hda_nid_t nid = kcontrol->private_value & 0xff;
370 eapd = ucontrol->value.integer.value[0];
373 if (eapd == spec->cur_eapd && ! codec->in_resume)
375 spec->cur_eapd = eapd;
376 snd_hda_codec_write(codec, nid,
377 0, AC_VERB_SET_EAPD_BTLENABLE,
386 #define AD1986A_SPDIF_OUT 0x02
387 #define AD1986A_FRONT_DAC 0x03
388 #define AD1986A_SURR_DAC 0x04
389 #define AD1986A_CLFE_DAC 0x05
390 #define AD1986A_ADC 0x06
392 static hda_nid_t ad1986a_dac_nids[3] = {
393 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
395 static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
396 static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
398 static struct hda_input_mux ad1986a_capture_source = {
414 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
417 #define ad1986a_pcm_amp_vol_info snd_hda_mixer_amp_volume_info
419 static int ad1986a_pcm_amp_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
421 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
422 struct ad198x_spec *ad = codec->spec;
424 mutex_lock(&ad->amp_mutex);
425 snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
426 mutex_unlock(&ad->amp_mutex);
430 static int ad1986a_pcm_amp_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
432 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
433 struct ad198x_spec *ad = codec->spec;
436 mutex_lock(&ad->amp_mutex);
437 for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
438 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
439 change |= snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
441 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
442 mutex_unlock(&ad->amp_mutex);
446 #define ad1986a_pcm_amp_sw_info snd_hda_mixer_amp_switch_info
448 static int ad1986a_pcm_amp_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
450 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
451 struct ad198x_spec *ad = codec->spec;
453 mutex_lock(&ad->amp_mutex);
454 snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
455 mutex_unlock(&ad->amp_mutex);
459 static int ad1986a_pcm_amp_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
461 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
462 struct ad198x_spec *ad = codec->spec;
465 mutex_lock(&ad->amp_mutex);
466 for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
467 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
468 change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
470 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
471 mutex_unlock(&ad->amp_mutex);
478 static struct snd_kcontrol_new ad1986a_mixers[] = {
480 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
481 .name = "PCM Playback Volume",
482 .info = ad1986a_pcm_amp_vol_info,
483 .get = ad1986a_pcm_amp_vol_get,
484 .put = ad1986a_pcm_amp_vol_put,
485 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
488 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
489 .name = "PCM Playback Switch",
490 .info = ad1986a_pcm_amp_sw_info,
491 .get = ad1986a_pcm_amp_sw_get,
492 .put = ad1986a_pcm_amp_sw_put,
493 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
495 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
496 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
497 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
498 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
499 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
500 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
501 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
502 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
503 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
504 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
505 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
506 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
507 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
508 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
509 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
510 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
511 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
512 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
513 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
514 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
515 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
516 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
517 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
518 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
520 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
521 .name = "Capture Source",
522 .info = ad198x_mux_enum_info,
523 .get = ad198x_mux_enum_get,
524 .put = ad198x_mux_enum_put,
526 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
531 * initialization verbs
533 static struct hda_verb ad1986a_init_verbs[] = {
534 /* Front, Surround, CLFE DAC; mute as default */
535 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
536 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
537 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
539 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
540 /* HP, Line-Out, Surround, CLFE selectors */
541 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
542 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
543 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
544 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
546 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
547 /* Mic selector: Mic 1/2 pin */
548 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
549 /* Line-in selector: Line-in */
550 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
552 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
553 /* Record selector: mic */
554 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
555 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
556 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
557 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
558 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
559 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
560 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
562 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
563 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
564 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
565 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
566 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
567 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
568 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
570 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
571 /* Front, Surround, CLFE Pins */
572 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
573 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
574 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
576 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
578 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
579 /* Line, Aux, CD, Beep-In Pin */
580 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
581 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
582 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
583 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
584 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
589 static int patch_ad1986a(struct hda_codec *codec)
591 struct ad198x_spec *spec;
593 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
597 mutex_init(&spec->amp_mutex);
600 spec->multiout.max_channels = 6;
601 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
602 spec->multiout.dac_nids = ad1986a_dac_nids;
603 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
604 spec->num_adc_nids = 1;
605 spec->adc_nids = ad1986a_adc_nids;
606 spec->capsrc_nids = ad1986a_capsrc_nids;
607 spec->input_mux = &ad1986a_capture_source;
608 spec->num_mixers = 1;
609 spec->mixers[0] = ad1986a_mixers;
610 spec->num_init_verbs = 1;
611 spec->init_verbs[0] = ad1986a_init_verbs;
613 codec->patch_ops = ad198x_patch_ops;
622 #define AD1983_SPDIF_OUT 0x02
623 #define AD1983_DAC 0x03
624 #define AD1983_ADC 0x04
626 static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
627 static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
628 static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
630 static struct hda_input_mux ad1983_capture_source = {
641 * SPDIF playback route
643 static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
645 static char *texts[] = { "PCM", "ADC" };
647 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
649 uinfo->value.enumerated.items = 2;
650 if (uinfo->value.enumerated.item > 1)
651 uinfo->value.enumerated.item = 1;
652 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
656 static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
658 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
659 struct ad198x_spec *spec = codec->spec;
661 ucontrol->value.enumerated.item[0] = spec->spdif_route;
665 static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
667 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
668 struct ad198x_spec *spec = codec->spec;
670 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
671 spec->spdif_route = ucontrol->value.enumerated.item[0];
672 snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
673 AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
679 static struct snd_kcontrol_new ad1983_mixers[] = {
680 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
681 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
682 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
683 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
684 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
685 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
686 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
687 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
688 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
689 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
690 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
691 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
692 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
693 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
694 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
695 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
696 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
698 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
699 .name = "Capture Source",
700 .info = ad198x_mux_enum_info,
701 .get = ad198x_mux_enum_get,
702 .put = ad198x_mux_enum_put,
705 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
706 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
707 .info = ad1983_spdif_route_info,
708 .get = ad1983_spdif_route_get,
709 .put = ad1983_spdif_route_put,
714 static struct hda_verb ad1983_init_verbs[] = {
715 /* Front, HP, Mono; mute as default */
716 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
717 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
718 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
719 /* Beep, PCM, Mic, Line-In: mute */
720 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
721 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
722 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
723 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
724 /* Front, HP selectors; from Mix */
725 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
726 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
727 /* Mono selector; from Mix */
728 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
729 /* Mic selector; Mic */
730 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
731 /* Line-in selector: Line-in */
732 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
734 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
735 /* Record selector: mic */
736 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
737 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
738 /* SPDIF route: PCM */
739 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
741 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
743 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
745 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
747 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
749 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
754 static int patch_ad1983(struct hda_codec *codec)
756 struct ad198x_spec *spec;
758 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
762 mutex_init(&spec->amp_mutex);
765 spec->multiout.max_channels = 2;
766 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
767 spec->multiout.dac_nids = ad1983_dac_nids;
768 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
769 spec->num_adc_nids = 1;
770 spec->adc_nids = ad1983_adc_nids;
771 spec->capsrc_nids = ad1983_capsrc_nids;
772 spec->input_mux = &ad1983_capture_source;
773 spec->num_mixers = 1;
774 spec->mixers[0] = ad1983_mixers;
775 spec->num_init_verbs = 1;
776 spec->init_verbs[0] = ad1983_init_verbs;
777 spec->spdif_route = 0;
779 codec->patch_ops = ad198x_patch_ops;
789 #define AD1981_SPDIF_OUT 0x02
790 #define AD1981_DAC 0x03
791 #define AD1981_ADC 0x04
793 static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
794 static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
795 static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
797 /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
798 static struct hda_input_mux ad1981_capture_source = {
801 { "Front Mic", 0x0 },
811 static struct snd_kcontrol_new ad1981_mixers[] = {
812 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
813 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
814 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
815 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
816 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
817 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
818 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
819 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
820 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
821 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
822 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
823 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
824 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
825 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
826 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
827 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
828 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
829 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
830 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
831 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
832 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
833 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
834 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
835 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
837 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
838 .name = "Capture Source",
839 .info = ad198x_mux_enum_info,
840 .get = ad198x_mux_enum_get,
841 .put = ad198x_mux_enum_put,
843 /* identical with AD1983 */
845 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
846 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
847 .info = ad1983_spdif_route_info,
848 .get = ad1983_spdif_route_get,
849 .put = ad1983_spdif_route_put,
854 static struct hda_verb ad1981_init_verbs[] = {
855 /* Front, HP, Mono; mute as default */
856 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
857 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
858 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
859 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
860 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
861 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
862 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
863 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
864 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
865 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
866 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
867 /* Front, HP selectors; from Mix */
868 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
869 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
870 /* Mono selector; from Mix */
871 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
872 /* Mic Mixer; select Front Mic */
873 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
874 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
876 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
877 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
878 /* Record selector: Front mic */
879 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
880 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
881 /* SPDIF route: PCM */
882 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
884 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
886 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
888 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
889 /* Front & Rear Mic Pins */
890 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
891 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
893 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
895 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
896 /* Line-Out as Input: disabled */
897 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
902 * Patch for HP nx6320
904 * nx6320 uses EAPD in the reserve way - EAPD-on means the internal
905 * speaker output enabled _and_ mute-LED off.
908 #define AD1981_HP_EVENT 0x37
909 #define AD1981_MIC_EVENT 0x38
911 static struct hda_verb ad1981_hp_init_verbs[] = {
912 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
913 /* pin sensing on HP and Mic jacks */
914 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
915 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
919 /* turn on/off EAPD (+ mute HP) as a master switch */
920 static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
921 struct snd_ctl_elem_value *ucontrol)
923 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
924 struct ad198x_spec *spec = codec->spec;
926 if (! ad198x_eapd_put(kcontrol, ucontrol))
929 /* toggle HP mute appropriately */
930 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
931 0x80, spec->cur_eapd ? 0 : 0x80);
932 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
933 0x80, spec->cur_eapd ? 0 : 0x80);
937 /* bind volumes of both NID 0x05 and 0x06 */
938 static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
939 struct snd_ctl_elem_value *ucontrol)
941 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
942 long *valp = ucontrol->value.integer.value;
945 change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
946 0x7f, valp[0] & 0x7f);
947 change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
948 0x7f, valp[1] & 0x7f);
949 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
950 0x7f, valp[0] & 0x7f);
951 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
952 0x7f, valp[1] & 0x7f);
956 /* mute internal speaker if HP is plugged */
957 static void ad1981_hp_automute(struct hda_codec *codec)
959 unsigned int present;
961 present = snd_hda_codec_read(codec, 0x06, 0,
962 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
963 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
964 0x80, present ? 0x80 : 0);
965 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
966 0x80, present ? 0x80 : 0);
969 /* toggle input of built-in and mic jack appropriately */
970 static void ad1981_hp_automic(struct hda_codec *codec)
972 static struct hda_verb mic_jack_on[] = {
973 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
974 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
977 static struct hda_verb mic_jack_off[] = {
978 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
979 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
982 unsigned int present;
984 present = snd_hda_codec_read(codec, 0x08, 0,
985 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
987 snd_hda_sequence_write(codec, mic_jack_on);
989 snd_hda_sequence_write(codec, mic_jack_off);
992 /* unsolicited event for HP jack sensing */
993 static void ad1981_hp_unsol_event(struct hda_codec *codec,
998 case AD1981_HP_EVENT:
999 ad1981_hp_automute(codec);
1001 case AD1981_MIC_EVENT:
1002 ad1981_hp_automic(codec);
1007 static struct hda_input_mux ad1981_hp_capture_source = {
1011 { "Docking-Station", 0x1 },
1016 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1018 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1019 .name = "Master Playback Volume",
1020 .info = snd_hda_mixer_amp_volume_info,
1021 .get = snd_hda_mixer_amp_volume_get,
1022 .put = ad1981_hp_master_vol_put,
1023 .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1026 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1027 .name = "Master Playback Switch",
1028 .info = ad198x_eapd_info,
1029 .get = ad198x_eapd_get,
1030 .put = ad1981_hp_master_sw_put,
1031 .private_value = 0x05,
1033 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1034 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1036 /* FIXME: analog mic/line loopback doesn't work with my tests...
1037 * (although recording is OK)
1039 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1040 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1041 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1042 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1043 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1044 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1045 /* FIXME: does this laptop have analog CD connection? */
1046 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1047 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1049 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1050 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1051 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1052 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1054 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1055 .name = "Capture Source",
1056 .info = ad198x_mux_enum_info,
1057 .get = ad198x_mux_enum_get,
1058 .put = ad198x_mux_enum_put,
1063 /* initialize jack-sensing, too */
1064 static int ad1981_hp_init(struct hda_codec *codec)
1067 ad1981_hp_automute(codec);
1068 ad1981_hp_automic(codec);
1073 enum { AD1981_BASIC, AD1981_HP };
1075 static struct hda_board_config ad1981_cfg_tbl[] = {
1076 { .modelname = "hp", .config = AD1981_HP },
1077 { .pci_subvendor = 0x103c, .pci_subdevice = 0x30aa,
1078 .config = AD1981_HP },
1079 { .modelname = "basic", .config = AD1981_BASIC },
1083 static int patch_ad1981(struct hda_codec *codec)
1085 struct ad198x_spec *spec;
1088 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1092 mutex_init(&spec->amp_mutex);
1095 spec->multiout.max_channels = 2;
1096 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1097 spec->multiout.dac_nids = ad1981_dac_nids;
1098 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
1099 spec->num_adc_nids = 1;
1100 spec->adc_nids = ad1981_adc_nids;
1101 spec->capsrc_nids = ad1981_capsrc_nids;
1102 spec->input_mux = &ad1981_capture_source;
1103 spec->num_mixers = 1;
1104 spec->mixers[0] = ad1981_mixers;
1105 spec->num_init_verbs = 1;
1106 spec->init_verbs[0] = ad1981_init_verbs;
1107 spec->spdif_route = 0;
1109 codec->patch_ops = ad198x_patch_ops;
1111 /* override some parameters */
1112 board_config = snd_hda_check_board_config(codec, ad1981_cfg_tbl);
1113 switch (board_config) {
1115 spec->mixers[0] = ad1981_hp_mixers;
1116 spec->num_init_verbs = 2;
1117 spec->init_verbs[1] = ad1981_hp_init_verbs;
1118 spec->multiout.dig_out_nid = 0;
1119 spec->input_mux = &ad1981_hp_capture_source;
1121 codec->patch_ops.init = ad1981_hp_init;
1122 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1133 * Output pins and routes
1135 * Pin Mix Sel DAC (*)
1136 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1137 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1138 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1139 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1140 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1141 * port-F 0x16 (mute) <- 0x2a <- 06
1142 * port-G 0x24 (mute) <- 0x27 <- 05
1143 * port-H 0x25 (mute) <- 0x28 <- 0a
1144 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1146 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1147 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
1149 * Input pins and routes
1151 * pin boost mix input # / adc input #
1152 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1153 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1154 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1155 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1156 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1157 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1158 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1159 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1163 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
1164 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
1166 * Inputs of Analog Mix (0x20)
1167 * 0:Port-B (front mic)
1168 * 1:Port-C/G/H (line-in)
1170 * 3:Port-D (line-in/2)
1171 * 4:Port-E/G/H (mic-in)
1172 * 5:Port-F (mic2-in)
1178 * 1:Port-B (front mic-in)
1179 * 2:Port-C (line-in)
1180 * 3:Port-F (mic2-in)
1185 * 8:Port-D (line-in/2)
1188 * Proposed pin assignments by the datasheet
1191 * Port-A front headphone
1201 * Port-A front headphone
1203 * C rear line-in/surround
1205 * E rear mic-in/CLFE
1211 * D internal speaker (with EAPD)
1212 * E/F quad mic array
1228 /* reivision id to check workarounds */
1229 #define AD1988A_REV2 0x100200
1236 static hda_nid_t ad1988_6stack_dac_nids[4] = {
1237 0x04, 0x06, 0x05, 0x0a
1240 static hda_nid_t ad1988_3stack_dac_nids[3] = {
1244 /* for AD1988A revision-2, DAC2-4 are swapped */
1245 static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1246 0x04, 0x05, 0x0a, 0x06
1249 static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
1253 static hda_nid_t ad1988_adc_nids[3] = {
1257 static hda_nid_t ad1988_capsrc_nids[3] = {
1261 #define AD1988_SPDIF_OUT 0x02
1262 #define AD1988_SPDIF_IN 0x07
1264 static struct hda_input_mux ad1988_6stack_capture_source = {
1267 { "Front Mic", 0x0 },
1275 static struct hda_input_mux ad1988_laptop_capture_source = {
1278 { "Mic/Line", 0x0 },
1286 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1287 struct snd_ctl_elem_info *uinfo)
1289 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1290 struct ad198x_spec *spec = codec->spec;
1291 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1292 spec->num_channel_mode);
1295 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1296 struct snd_ctl_elem_value *ucontrol)
1298 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1299 struct ad198x_spec *spec = codec->spec;
1300 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1301 spec->num_channel_mode, spec->multiout.max_channels);
1304 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1305 struct snd_ctl_elem_value *ucontrol)
1307 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1308 struct ad198x_spec *spec = codec->spec;
1309 return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1310 spec->num_channel_mode, &spec->multiout.max_channels);
1314 static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
1315 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1316 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1317 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1318 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1319 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1322 static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1323 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1324 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1325 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1326 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1327 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1330 static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
1331 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1332 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1333 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1334 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1335 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1336 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1337 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1339 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1340 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1341 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1342 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1343 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1344 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1345 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1346 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1348 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1349 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1351 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1352 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1354 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1355 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1361 static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
1362 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1364 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1365 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1368 static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1369 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1370 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1371 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1372 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
1375 static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
1376 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1377 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1378 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1379 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
1380 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1381 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1383 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1384 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1385 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1386 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1387 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1388 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1389 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1390 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1392 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1393 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1395 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1396 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1398 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1401 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1402 .name = "Channel Mode",
1403 .info = ad198x_ch_mode_info,
1404 .get = ad198x_ch_mode_get,
1405 .put = ad198x_ch_mode_put,
1412 static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1413 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1414 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1415 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1417 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1418 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1419 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1420 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1421 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1422 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1424 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1425 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1427 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1428 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1433 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1434 .name = "External Amplifier",
1435 .info = ad198x_eapd_info,
1436 .get = ad198x_eapd_get,
1437 .put = ad198x_eapd_put,
1438 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
1445 static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1446 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1447 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1448 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1449 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1450 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1451 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1453 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1454 /* The multiple "Capture Source" controls confuse alsamixer
1455 * So call somewhat different..
1456 * FIXME: the controls appear in the "playback" view!
1458 /* .name = "Capture Source", */
1459 .name = "Input Source",
1461 .info = ad198x_mux_enum_info,
1462 .get = ad198x_mux_enum_get,
1463 .put = ad198x_mux_enum_put,
1468 static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1469 struct snd_ctl_elem_info *uinfo)
1471 static char *texts[] = {
1472 "PCM", "ADC1", "ADC2", "ADC3"
1474 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1476 uinfo->value.enumerated.items = 4;
1477 if (uinfo->value.enumerated.item >= 4)
1478 uinfo->value.enumerated.item = 3;
1479 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1483 static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1484 struct snd_ctl_elem_value *ucontrol)
1486 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1489 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1491 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0);
1497 ucontrol->value.enumerated.item[0] = sel;
1501 static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
1502 struct snd_ctl_elem_value *ucontrol)
1504 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1508 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1509 if (! ucontrol->value.enumerated.item[0]) {
1512 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 0);
1516 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 1);
1517 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0) + 1;
1518 change |= sel == ucontrol->value.enumerated.item[0];
1520 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL,
1521 ucontrol->value.enumerated.item[0] - 1);
1526 static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
1527 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1529 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1530 .name = "IEC958 Playback Source",
1531 .info = ad1988_spdif_playback_source_info,
1532 .get = ad1988_spdif_playback_source_get,
1533 .put = ad1988_spdif_playback_source_put,
1538 static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
1539 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
1545 * initialization verbs
1549 * for 6-stack (+dig)
1551 static struct hda_verb ad1988_6stack_init_verbs[] = {
1552 /* Front, Surround, CLFE, side DAC; unmute as default */
1553 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1554 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1555 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1556 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1557 /* Port-A front headphon path */
1558 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1559 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1560 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1561 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1562 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1563 /* Port-D line-out path */
1564 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1565 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1566 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1567 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1568 /* Port-F surround path */
1569 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1570 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1571 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1572 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1573 /* Port-G CLFE path */
1574 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1575 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1576 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1577 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1578 /* Port-H side path */
1579 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1580 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1581 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1582 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1584 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1585 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1586 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1587 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1588 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1589 /* Port-B front mic-in path */
1590 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1591 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1592 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1593 /* Port-C line-in path */
1594 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1595 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1596 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1597 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1598 /* Port-E mic-in path */
1599 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1600 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1601 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1602 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
1607 static struct hda_verb ad1988_capture_init_verbs[] = {
1608 /* mute analog mix */
1609 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1610 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1611 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1612 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1613 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1614 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1615 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1616 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1617 /* select ADCs - front-mic */
1618 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1619 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1620 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1622 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1623 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1624 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1629 static struct hda_verb ad1988_spdif_init_verbs[] = {
1631 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
1632 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
1633 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1634 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1636 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
1637 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x17}, /* 0dB */
1643 * verbs for 3stack (+dig)
1645 static struct hda_verb ad1988_3stack_ch2_init[] = {
1646 /* set port-C to line-in */
1647 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1648 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1649 /* set port-E to mic-in */
1650 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1651 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1655 static struct hda_verb ad1988_3stack_ch6_init[] = {
1656 /* set port-C to surround out */
1657 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1658 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1659 /* set port-E to CLFE out */
1660 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1661 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1665 static struct hda_channel_mode ad1988_3stack_modes[2] = {
1666 { 2, ad1988_3stack_ch2_init },
1667 { 6, ad1988_3stack_ch6_init },
1670 static struct hda_verb ad1988_3stack_init_verbs[] = {
1671 /* Front, Surround, CLFE, side DAC; unmute as default */
1672 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1673 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1674 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1675 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1676 /* Port-A front headphon path */
1677 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1678 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1679 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1680 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1681 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1682 /* Port-D line-out path */
1683 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1684 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1685 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1686 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1688 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1689 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1690 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1691 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1692 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1693 /* Port-B front mic-in path */
1694 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1695 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1696 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1697 /* Port-C line-in/surround path - 6ch mode as default */
1698 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1699 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1700 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1701 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
1702 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1703 /* Port-E mic-in/CLFE path - 6ch mode as default */
1704 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1705 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1706 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1707 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
1708 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
1709 /* mute analog mix */
1710 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1711 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1712 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1713 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1714 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1715 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1716 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1717 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1718 /* select ADCs - front-mic */
1719 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1720 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1721 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1723 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1724 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1725 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1730 * verbs for laptop mode (+dig)
1732 static struct hda_verb ad1988_laptop_hp_on[] = {
1733 /* unmute port-A and mute port-D */
1734 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1735 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1738 static struct hda_verb ad1988_laptop_hp_off[] = {
1739 /* mute port-A and unmute port-D */
1740 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1741 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1745 #define AD1988_HP_EVENT 0x01
1747 static struct hda_verb ad1988_laptop_init_verbs[] = {
1748 /* Front, Surround, CLFE, side DAC; unmute as default */
1749 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1750 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1751 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1752 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1753 /* Port-A front headphon path */
1754 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1755 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1756 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1757 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1758 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1759 /* unsolicited event for pin-sense */
1760 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
1761 /* Port-D line-out path + EAPD */
1762 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1763 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1764 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1765 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1766 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
1768 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1769 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1770 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1771 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1772 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1773 /* Port-B mic-in path */
1774 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1775 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1776 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1777 /* Port-C docking station - try to output */
1778 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1779 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1780 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1781 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1782 /* mute analog mix */
1783 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1784 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1785 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1786 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1787 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1788 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1789 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1790 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1791 /* select ADCs - mic */
1792 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1793 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1794 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1796 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1797 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1798 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1802 static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
1804 if ((res >> 26) != AD1988_HP_EVENT)
1806 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
1807 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
1809 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
1814 * Automatic parse of I/O pins from the BIOS configuration
1817 #define NUM_CONTROL_ALLOC 32
1818 #define NUM_VERB_ALLOC 32
1825 static struct snd_kcontrol_new ad1988_control_templates[] = {
1826 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1827 HDA_CODEC_MUTE(NULL, 0, 0, 0),
1828 HDA_BIND_MUTE(NULL, 0, 0, 0),
1831 /* add dynamic controls */
1832 static int add_control(struct ad198x_spec *spec, int type, const char *name,
1835 struct snd_kcontrol_new *knew;
1837 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1838 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1840 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1843 if (spec->kctl_alloc) {
1844 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1845 kfree(spec->kctl_alloc);
1847 spec->kctl_alloc = knew;
1848 spec->num_kctl_alloc = num;
1851 knew = &spec->kctl_alloc[spec->num_kctl_used];
1852 *knew = ad1988_control_templates[type];
1853 knew->name = kstrdup(name, GFP_KERNEL);
1856 knew->private_value = val;
1857 spec->num_kctl_used++;
1861 #define AD1988_PIN_CD_NID 0x18
1862 #define AD1988_PIN_BEEP_NID 0x10
1864 static hda_nid_t ad1988_mixer_nids[8] = {
1865 /* A B C D E F G H */
1866 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
1869 static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
1871 static hda_nid_t idx_to_dac[8] = {
1872 /* A B C D E F G H */
1873 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
1875 static hda_nid_t idx_to_dac_rev2[8] = {
1876 /* A B C D E F G H */
1877 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
1879 if (codec->revision_id == AD1988A_REV2)
1880 return idx_to_dac_rev2[idx];
1882 return idx_to_dac[idx];
1885 static hda_nid_t ad1988_boost_nids[8] = {
1886 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
1889 static int ad1988_pin_idx(hda_nid_t nid)
1891 static hda_nid_t ad1988_io_pins[8] = {
1892 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
1895 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
1896 if (ad1988_io_pins[i] == nid)
1898 return 0; /* should be -1 */
1901 static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
1903 static int loopback_idx[8] = {
1904 2, 0, 1, 3, 4, 5, 1, 4
1907 case AD1988_PIN_CD_NID:
1910 return loopback_idx[ad1988_pin_idx(nid)];
1914 static int ad1988_pin_to_adc_idx(hda_nid_t nid)
1916 static int adc_idx[8] = {
1917 0, 1, 2, 8, 4, 3, 6, 7
1920 case AD1988_PIN_CD_NID:
1923 return adc_idx[ad1988_pin_idx(nid)];
1927 /* fill in the dac_nids table from the parsed pin configuration */
1928 static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
1929 const struct auto_pin_cfg *cfg)
1931 struct ad198x_spec *spec = codec->spec;
1934 spec->multiout.dac_nids = spec->private_dac_nids;
1936 /* check the pins hardwired to audio widget */
1937 for (i = 0; i < cfg->line_outs; i++) {
1938 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
1939 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
1941 spec->multiout.num_dacs = cfg->line_outs;
1945 /* add playback controls from the parsed DAC table */
1946 static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
1947 const struct auto_pin_cfg *cfg)
1950 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
1954 for (i = 0; i < cfg->line_outs; i++) {
1955 hda_nid_t dac = spec->multiout.dac_nids[i];
1958 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
1961 err = add_control(spec, AD_CTL_WIDGET_VOL,
1962 "Center Playback Volume",
1963 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
1966 err = add_control(spec, AD_CTL_WIDGET_VOL,
1967 "LFE Playback Volume",
1968 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
1971 err = add_control(spec, AD_CTL_BIND_MUTE,
1972 "Center Playback Switch",
1973 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
1976 err = add_control(spec, AD_CTL_BIND_MUTE,
1977 "LFE Playback Switch",
1978 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
1982 sprintf(name, "%s Playback Volume", chname[i]);
1983 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
1984 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
1987 sprintf(name, "%s Playback Switch", chname[i]);
1988 err = add_control(spec, AD_CTL_BIND_MUTE, name,
1989 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
1997 /* add playback controls for speaker and HP outputs */
1998 static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2001 struct ad198x_spec *spec = codec->spec;
2009 idx = ad1988_pin_idx(pin);
2010 nid = ad1988_idx_to_dac(codec, idx);
2011 if (! spec->multiout.dac_nids[0]) {
2012 /* use this as the primary output */
2013 spec->multiout.dac_nids[0] = nid;
2014 if (! spec->multiout.num_dacs)
2015 spec->multiout.num_dacs = 1;
2017 /* specify the DAC as the extra output */
2018 spec->multiout.hp_nid = nid;
2019 /* control HP volume/switch on the output mixer amp */
2020 sprintf(name, "%s Playback Volume", pfx);
2021 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2022 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2024 nid = ad1988_mixer_nids[idx];
2025 sprintf(name, "%s Playback Switch", pfx);
2026 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2027 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2032 /* create input playback/capture controls for the given pin */
2033 static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2034 const char *ctlname, int boost)
2039 sprintf(name, "%s Playback Volume", ctlname);
2040 idx = ad1988_pin_to_loopback_idx(pin);
2041 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2042 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2044 sprintf(name, "%s Playback Switch", ctlname);
2045 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2046 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2050 idx = ad1988_pin_idx(pin);
2051 bnid = ad1988_boost_nids[idx];
2053 sprintf(name, "%s Boost", ctlname);
2054 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2055 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2062 /* create playback/capture controls for input pins */
2063 static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2064 const struct auto_pin_cfg *cfg)
2066 struct hda_input_mux *imux = &spec->private_imux;
2069 for (i = 0; i < AUTO_PIN_LAST; i++) {
2070 err = new_analog_input(spec, cfg->input_pins[i],
2071 auto_pin_cfg_labels[i],
2072 i <= AUTO_PIN_FRONT_MIC);
2075 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2076 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2079 imux->items[imux->num_items].label = "Mix";
2080 imux->items[imux->num_items].index = 9;
2083 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2084 "Analog Mix Playback Volume",
2085 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2087 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2088 "Analog Mix Playback Switch",
2089 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2095 static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2096 hda_nid_t nid, int pin_type,
2100 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2101 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2103 case 0x11: /* port-A - DAC 04 */
2104 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2106 case 0x14: /* port-B - DAC 06 */
2107 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2109 case 0x15: /* port-C - DAC 05 */
2110 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2112 case 0x17: /* port-E - DAC 0a */
2113 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2115 case 0x13: /* mono - DAC 04 */
2116 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2121 static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2123 struct ad198x_spec *spec = codec->spec;
2126 for (i = 0; i < spec->autocfg.line_outs; i++) {
2127 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2128 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2132 static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2134 struct ad198x_spec *spec = codec->spec;
2137 pin = spec->autocfg.speaker_pin;
2138 if (pin) /* connect to front */
2139 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2140 pin = spec->autocfg.hp_pin;
2141 if (pin) /* connect to front */
2142 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2145 static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2147 struct ad198x_spec *spec = codec->spec;
2150 for (i = 0; i < AUTO_PIN_LAST; i++) {
2151 hda_nid_t nid = spec->autocfg.input_pins[i];
2155 case 0x15: /* port-C */
2156 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2158 case 0x17: /* port-E */
2159 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2162 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2163 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2164 if (nid != AD1988_PIN_CD_NID)
2165 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2167 idx = ad1988_pin_idx(nid);
2168 if (ad1988_boost_nids[idx])
2169 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2170 AC_VERB_SET_AMP_GAIN_MUTE,
2175 /* parse the BIOS configuration and set up the alc_spec */
2176 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2177 static int ad1988_parse_auto_config(struct hda_codec *codec)
2179 struct ad198x_spec *spec = codec->spec;
2182 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2184 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2186 if (! spec->autocfg.line_outs && ! spec->autocfg.speaker_pin &&
2187 ! spec->autocfg.hp_pin)
2188 return 0; /* can't find valid BIOS pin config */
2189 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2190 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.speaker_pin,
2192 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.speaker_pin,
2193 "Headphone")) < 0 ||
2194 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2197 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2199 if (spec->autocfg.dig_out_pin)
2200 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2201 if (spec->autocfg.dig_in_pin)
2202 spec->dig_in_nid = AD1988_SPDIF_IN;
2204 if (spec->kctl_alloc)
2205 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2207 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2209 spec->input_mux = &spec->private_imux;
2214 /* init callback for auto-configuration model -- overriding the default init */
2215 static int ad1988_auto_init(struct hda_codec *codec)
2218 ad1988_auto_init_multi_out(codec);
2219 ad1988_auto_init_extra_out(codec);
2220 ad1988_auto_init_analog_input(codec);
2228 static struct hda_board_config ad1988_cfg_tbl[] = {
2229 { .modelname = "6stack", .config = AD1988_6STACK },
2230 { .modelname = "6stack-dig", .config = AD1988_6STACK_DIG },
2231 { .modelname = "3stack", .config = AD1988_3STACK },
2232 { .modelname = "3stack-dig", .config = AD1988_3STACK_DIG },
2233 { .modelname = "laptop", .config = AD1988_LAPTOP },
2234 { .modelname = "laptop-dig", .config = AD1988_LAPTOP_DIG },
2235 { .modelname = "auto", .config = AD1988_AUTO },
2239 static int patch_ad1988(struct hda_codec *codec)
2241 struct ad198x_spec *spec;
2244 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2248 mutex_init(&spec->amp_mutex);
2251 if (codec->revision_id == AD1988A_REV2)
2252 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2254 board_config = snd_hda_check_board_config(codec, ad1988_cfg_tbl);
2255 if (board_config < 0 || board_config >= AD1988_MODEL_LAST) {
2256 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2257 board_config = AD1988_AUTO;
2260 if (board_config == AD1988_AUTO) {
2261 /* automatic parse from the BIOS config */
2262 int err = ad1988_parse_auto_config(codec);
2267 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2268 board_config = AD1988_6STACK;
2272 switch (board_config) {
2274 case AD1988_6STACK_DIG:
2275 spec->multiout.max_channels = 8;
2276 spec->multiout.num_dacs = 4;
2277 if (codec->revision_id == AD1988A_REV2)
2278 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2280 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
2281 spec->input_mux = &ad1988_6stack_capture_source;
2282 spec->num_mixers = 2;
2283 if (codec->revision_id == AD1988A_REV2)
2284 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2286 spec->mixers[0] = ad1988_6stack_mixers1;
2287 spec->mixers[1] = ad1988_6stack_mixers2;
2288 spec->num_init_verbs = 1;
2289 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2290 if (board_config == AD1988_6STACK_DIG) {
2291 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2292 spec->dig_in_nid = AD1988_SPDIF_IN;
2296 case AD1988_3STACK_DIG:
2297 spec->multiout.max_channels = 6;
2298 spec->multiout.num_dacs = 3;
2299 if (codec->revision_id == AD1988A_REV2)
2300 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2302 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2303 spec->input_mux = &ad1988_6stack_capture_source;
2304 spec->channel_mode = ad1988_3stack_modes;
2305 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
2306 spec->num_mixers = 2;
2307 if (codec->revision_id == AD1988A_REV2)
2308 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2310 spec->mixers[0] = ad1988_3stack_mixers1;
2311 spec->mixers[1] = ad1988_3stack_mixers2;
2312 spec->num_init_verbs = 1;
2313 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2314 if (board_config == AD1988_3STACK_DIG)
2315 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2318 case AD1988_LAPTOP_DIG:
2319 spec->multiout.max_channels = 2;
2320 spec->multiout.num_dacs = 1;
2321 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2322 spec->input_mux = &ad1988_laptop_capture_source;
2323 spec->num_mixers = 1;
2324 spec->mixers[0] = ad1988_laptop_mixers;
2325 spec->num_init_verbs = 1;
2326 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2327 if (board_config == AD1988_LAPTOP_DIG)
2328 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2332 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2333 spec->adc_nids = ad1988_adc_nids;
2334 spec->capsrc_nids = ad1988_capsrc_nids;
2335 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2336 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2337 if (spec->multiout.dig_out_nid) {
2338 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2339 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2341 if (spec->dig_in_nid)
2342 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2344 codec->patch_ops = ad198x_patch_ops;
2345 switch (board_config) {
2347 codec->patch_ops.init = ad1988_auto_init;
2350 case AD1988_LAPTOP_DIG:
2351 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2362 struct hda_codec_preset snd_hda_preset_analog[] = {
2363 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
2364 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
2365 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
2366 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },