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,
382 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
383 struct snd_ctl_elem_info *uinfo);
384 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
385 struct snd_ctl_elem_value *ucontrol);
386 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
387 struct snd_ctl_elem_value *ucontrol);
394 #define AD1986A_SPDIF_OUT 0x02
395 #define AD1986A_FRONT_DAC 0x03
396 #define AD1986A_SURR_DAC 0x04
397 #define AD1986A_CLFE_DAC 0x05
398 #define AD1986A_ADC 0x06
400 static hda_nid_t ad1986a_dac_nids[3] = {
401 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
403 static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
404 static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
406 static struct hda_input_mux ad1986a_capture_source = {
422 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
425 #define ad1986a_pcm_amp_vol_info snd_hda_mixer_amp_volume_info
427 static int ad1986a_pcm_amp_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
429 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
430 struct ad198x_spec *ad = codec->spec;
432 mutex_lock(&ad->amp_mutex);
433 snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
434 mutex_unlock(&ad->amp_mutex);
438 static int ad1986a_pcm_amp_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
440 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
441 struct ad198x_spec *ad = codec->spec;
444 mutex_lock(&ad->amp_mutex);
445 for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
446 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
447 change |= snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
449 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
450 mutex_unlock(&ad->amp_mutex);
454 #define ad1986a_pcm_amp_sw_info snd_hda_mixer_amp_switch_info
456 static int ad1986a_pcm_amp_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
458 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
459 struct ad198x_spec *ad = codec->spec;
461 mutex_lock(&ad->amp_mutex);
462 snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
463 mutex_unlock(&ad->amp_mutex);
467 static int ad1986a_pcm_amp_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
469 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
470 struct ad198x_spec *ad = codec->spec;
473 mutex_lock(&ad->amp_mutex);
474 for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
475 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
476 change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
478 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
479 mutex_unlock(&ad->amp_mutex);
486 static struct snd_kcontrol_new ad1986a_mixers[] = {
488 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
489 .name = "PCM Playback Volume",
490 .info = ad1986a_pcm_amp_vol_info,
491 .get = ad1986a_pcm_amp_vol_get,
492 .put = ad1986a_pcm_amp_vol_put,
493 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
496 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
497 .name = "PCM Playback Switch",
498 .info = ad1986a_pcm_amp_sw_info,
499 .get = ad1986a_pcm_amp_sw_get,
500 .put = ad1986a_pcm_amp_sw_put,
501 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
503 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
504 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
505 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
506 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
507 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
508 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
509 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
510 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
511 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
512 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
513 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
514 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
515 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
516 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
517 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
518 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
519 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
520 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
521 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
522 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
523 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
524 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
525 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
526 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
528 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
529 .name = "Capture Source",
530 .info = ad198x_mux_enum_info,
531 .get = ad198x_mux_enum_get,
532 .put = ad198x_mux_enum_put,
534 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
538 /* additional mixers for 3stack mode */
539 static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
541 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
542 .name = "Channel Mode",
543 .info = ad198x_ch_mode_info,
544 .get = ad198x_ch_mode_get,
545 .put = ad198x_ch_mode_put,
550 /* laptop model - 2ch only */
551 static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
553 static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
554 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
555 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
556 HDA_CODEC_VOLUME("Master Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
557 HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
558 /* HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
559 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), */
560 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
561 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
562 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
563 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
564 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
565 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
566 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
567 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
568 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
569 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
570 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
571 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
572 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
573 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
575 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
576 .name = "Capture Source",
577 .info = ad198x_mux_enum_info,
578 .get = ad198x_mux_enum_get,
579 .put = ad198x_mux_enum_put,
585 * initialization verbs
587 static struct hda_verb ad1986a_init_verbs[] = {
588 /* Front, Surround, CLFE DAC; mute as default */
589 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
590 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
591 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
593 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
594 /* HP, Line-Out, Surround, CLFE selectors */
595 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
596 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
597 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
598 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
600 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
601 /* Mic selector: Mic 1/2 pin */
602 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
603 /* Line-in selector: Line-in */
604 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
606 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
607 /* Record selector: mic */
608 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
609 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
610 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
611 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
612 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
613 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
614 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
616 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
617 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
618 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
619 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
620 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
621 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
622 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
624 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
625 /* Front, Surround, CLFE Pins */
626 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
627 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
628 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
630 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
632 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
633 /* Line, Aux, CD, Beep-In Pin */
634 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
635 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
636 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
637 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
638 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
642 /* additional verbs for 3-stack model */
643 static struct hda_verb ad1986a_3st_init_verbs[] = {
644 /* Mic and line-in selectors */
645 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
646 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
650 static struct hda_verb ad1986a_ch2_init[] = {
651 /* Surround out -> Line In */
652 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
653 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
655 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
656 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
660 static struct hda_verb ad1986a_ch4_init[] = {
661 /* Surround out -> Surround */
662 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
663 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
665 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
666 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
670 static struct hda_verb ad1986a_ch6_init[] = {
671 /* Surround out -> Surround out */
672 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
673 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
675 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
676 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
680 static struct hda_channel_mode ad1986a_modes[3] = {
681 { 2, ad1986a_ch2_init },
682 { 4, ad1986a_ch4_init },
683 { 6, ad1986a_ch6_init },
687 enum { AD1986A_6STACK, AD1986A_3STACK, AD1986A_LAPTOP };
689 static struct hda_board_config ad1986a_cfg_tbl[] = {
690 { .modelname = "6stack", .config = AD1986A_6STACK },
691 { .modelname = "3stack", .config = AD1986A_3STACK },
692 { .modelname = "laptop", .config = AD1986A_LAPTOP },
693 { .pci_subvendor = 0x144d, .pci_subdevice = 0xc01e,
694 .config = AD1986A_LAPTOP }, /* FSC V2060 */
695 { .pci_subvendor = 0x17c0, .pci_subdevice = 0x2017,
696 .config = AD1986A_LAPTOP }, /* Samsung M50 */
700 static int patch_ad1986a(struct hda_codec *codec)
702 struct ad198x_spec *spec;
705 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
709 mutex_init(&spec->amp_mutex);
712 spec->multiout.max_channels = 6;
713 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
714 spec->multiout.dac_nids = ad1986a_dac_nids;
715 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
716 spec->num_adc_nids = 1;
717 spec->adc_nids = ad1986a_adc_nids;
718 spec->capsrc_nids = ad1986a_capsrc_nids;
719 spec->input_mux = &ad1986a_capture_source;
720 spec->num_mixers = 1;
721 spec->mixers[0] = ad1986a_mixers;
722 spec->num_init_verbs = 1;
723 spec->init_verbs[0] = ad1986a_init_verbs;
725 codec->patch_ops = ad198x_patch_ops;
727 /* override some parameters */
728 board_config = snd_hda_check_board_config(codec, ad1986a_cfg_tbl);
729 switch (board_config) {
731 spec->num_mixers = 2;
732 spec->mixers[1] = ad1986a_3st_mixers;
733 spec->num_init_verbs = 2;
734 spec->init_verbs[1] = ad1986a_3st_init_verbs;
735 spec->channel_mode = ad1986a_modes;
736 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
739 spec->mixers[0] = ad1986a_laptop_mixers;
740 spec->multiout.max_channels = 2;
741 spec->multiout.num_dacs = 1;
742 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
753 #define AD1983_SPDIF_OUT 0x02
754 #define AD1983_DAC 0x03
755 #define AD1983_ADC 0x04
757 static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
758 static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
759 static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
761 static struct hda_input_mux ad1983_capture_source = {
772 * SPDIF playback route
774 static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
776 static char *texts[] = { "PCM", "ADC" };
778 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
780 uinfo->value.enumerated.items = 2;
781 if (uinfo->value.enumerated.item > 1)
782 uinfo->value.enumerated.item = 1;
783 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
787 static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
789 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
790 struct ad198x_spec *spec = codec->spec;
792 ucontrol->value.enumerated.item[0] = spec->spdif_route;
796 static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
798 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
799 struct ad198x_spec *spec = codec->spec;
801 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
802 spec->spdif_route = ucontrol->value.enumerated.item[0];
803 snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
804 AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
810 static struct snd_kcontrol_new ad1983_mixers[] = {
811 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
812 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
813 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
814 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
815 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
816 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
817 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
818 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
819 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
820 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
821 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
822 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
823 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
824 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
825 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
826 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
827 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
829 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
830 .name = "Capture Source",
831 .info = ad198x_mux_enum_info,
832 .get = ad198x_mux_enum_get,
833 .put = ad198x_mux_enum_put,
836 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
837 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
838 .info = ad1983_spdif_route_info,
839 .get = ad1983_spdif_route_get,
840 .put = ad1983_spdif_route_put,
845 static struct hda_verb ad1983_init_verbs[] = {
846 /* Front, HP, Mono; mute as default */
847 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
848 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
849 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
850 /* Beep, PCM, Mic, Line-In: mute */
851 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
852 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
853 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
854 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
855 /* Front, HP selectors; from Mix */
856 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
857 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
858 /* Mono selector; from Mix */
859 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
860 /* Mic selector; Mic */
861 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
862 /* Line-in selector: Line-in */
863 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
865 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
866 /* Record selector: mic */
867 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
868 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
869 /* SPDIF route: PCM */
870 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
872 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
874 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
876 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
878 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
880 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
885 static int patch_ad1983(struct hda_codec *codec)
887 struct ad198x_spec *spec;
889 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
893 mutex_init(&spec->amp_mutex);
896 spec->multiout.max_channels = 2;
897 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
898 spec->multiout.dac_nids = ad1983_dac_nids;
899 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
900 spec->num_adc_nids = 1;
901 spec->adc_nids = ad1983_adc_nids;
902 spec->capsrc_nids = ad1983_capsrc_nids;
903 spec->input_mux = &ad1983_capture_source;
904 spec->num_mixers = 1;
905 spec->mixers[0] = ad1983_mixers;
906 spec->num_init_verbs = 1;
907 spec->init_verbs[0] = ad1983_init_verbs;
908 spec->spdif_route = 0;
910 codec->patch_ops = ad198x_patch_ops;
920 #define AD1981_SPDIF_OUT 0x02
921 #define AD1981_DAC 0x03
922 #define AD1981_ADC 0x04
924 static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
925 static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
926 static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
928 /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
929 static struct hda_input_mux ad1981_capture_source = {
932 { "Front Mic", 0x0 },
942 static struct snd_kcontrol_new ad1981_mixers[] = {
943 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
944 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
945 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
946 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
947 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
948 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
949 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
950 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
951 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
952 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
953 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
954 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
955 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
956 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
957 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
958 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
959 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
960 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
961 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
962 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
963 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
964 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
965 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
966 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
968 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
969 .name = "Capture Source",
970 .info = ad198x_mux_enum_info,
971 .get = ad198x_mux_enum_get,
972 .put = ad198x_mux_enum_put,
974 /* identical with AD1983 */
976 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
977 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
978 .info = ad1983_spdif_route_info,
979 .get = ad1983_spdif_route_get,
980 .put = ad1983_spdif_route_put,
985 static struct hda_verb ad1981_init_verbs[] = {
986 /* Front, HP, Mono; mute as default */
987 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
988 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
989 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
990 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
991 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
992 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
993 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
994 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
995 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
996 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
997 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
998 /* Front, HP selectors; from Mix */
999 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1000 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1001 /* Mono selector; from Mix */
1002 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1003 /* Mic Mixer; select Front Mic */
1004 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1005 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1006 /* Mic boost: 0dB */
1007 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1008 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1009 /* Record selector: Front mic */
1010 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1011 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1012 /* SPDIF route: PCM */
1013 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1015 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1017 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1019 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1020 /* Front & Rear Mic Pins */
1021 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1022 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1024 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1026 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1027 /* Line-Out as Input: disabled */
1028 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1033 * Patch for HP nx6320
1035 * nx6320 uses EAPD in the reserve way - EAPD-on means the internal
1036 * speaker output enabled _and_ mute-LED off.
1039 #define AD1981_HP_EVENT 0x37
1040 #define AD1981_MIC_EVENT 0x38
1042 static struct hda_verb ad1981_hp_init_verbs[] = {
1043 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1044 /* pin sensing on HP and Mic jacks */
1045 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1046 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1050 /* turn on/off EAPD (+ mute HP) as a master switch */
1051 static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1052 struct snd_ctl_elem_value *ucontrol)
1054 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1055 struct ad198x_spec *spec = codec->spec;
1057 if (! ad198x_eapd_put(kcontrol, ucontrol))
1060 /* toggle HP mute appropriately */
1061 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1062 0x80, spec->cur_eapd ? 0 : 0x80);
1063 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1064 0x80, spec->cur_eapd ? 0 : 0x80);
1068 /* bind volumes of both NID 0x05 and 0x06 */
1069 static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
1070 struct snd_ctl_elem_value *ucontrol)
1072 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1073 long *valp = ucontrol->value.integer.value;
1076 change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1077 0x7f, valp[0] & 0x7f);
1078 change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1079 0x7f, valp[1] & 0x7f);
1080 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1081 0x7f, valp[0] & 0x7f);
1082 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1083 0x7f, valp[1] & 0x7f);
1087 /* mute internal speaker if HP is plugged */
1088 static void ad1981_hp_automute(struct hda_codec *codec)
1090 unsigned int present;
1092 present = snd_hda_codec_read(codec, 0x06, 0,
1093 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1094 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1095 0x80, present ? 0x80 : 0);
1096 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1097 0x80, present ? 0x80 : 0);
1100 /* toggle input of built-in and mic jack appropriately */
1101 static void ad1981_hp_automic(struct hda_codec *codec)
1103 static struct hda_verb mic_jack_on[] = {
1104 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1105 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1108 static struct hda_verb mic_jack_off[] = {
1109 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1110 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1113 unsigned int present;
1115 present = snd_hda_codec_read(codec, 0x08, 0,
1116 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1118 snd_hda_sequence_write(codec, mic_jack_on);
1120 snd_hda_sequence_write(codec, mic_jack_off);
1123 /* unsolicited event for HP jack sensing */
1124 static void ad1981_hp_unsol_event(struct hda_codec *codec,
1129 case AD1981_HP_EVENT:
1130 ad1981_hp_automute(codec);
1132 case AD1981_MIC_EVENT:
1133 ad1981_hp_automic(codec);
1138 static struct hda_input_mux ad1981_hp_capture_source = {
1142 { "Docking-Station", 0x1 },
1147 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1149 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1150 .name = "Master Playback Volume",
1151 .info = snd_hda_mixer_amp_volume_info,
1152 .get = snd_hda_mixer_amp_volume_get,
1153 .put = ad1981_hp_master_vol_put,
1154 .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1157 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1158 .name = "Master Playback Switch",
1159 .info = ad198x_eapd_info,
1160 .get = ad198x_eapd_get,
1161 .put = ad1981_hp_master_sw_put,
1162 .private_value = 0x05,
1164 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1165 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1167 /* FIXME: analog mic/line loopback doesn't work with my tests...
1168 * (although recording is OK)
1170 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1171 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1172 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1173 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1174 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1175 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1176 /* FIXME: does this laptop have analog CD connection? */
1177 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1178 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1180 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1181 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1182 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1183 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1185 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1186 .name = "Capture Source",
1187 .info = ad198x_mux_enum_info,
1188 .get = ad198x_mux_enum_get,
1189 .put = ad198x_mux_enum_put,
1194 /* initialize jack-sensing, too */
1195 static int ad1981_hp_init(struct hda_codec *codec)
1198 ad1981_hp_automute(codec);
1199 ad1981_hp_automic(codec);
1204 enum { AD1981_BASIC, AD1981_HP };
1206 static struct hda_board_config ad1981_cfg_tbl[] = {
1207 { .modelname = "hp", .config = AD1981_HP },
1208 { .pci_subvendor = 0x103c, .pci_subdevice = 0x30aa,
1209 .config = AD1981_HP },
1210 { .modelname = "basic", .config = AD1981_BASIC },
1214 static int patch_ad1981(struct hda_codec *codec)
1216 struct ad198x_spec *spec;
1219 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1223 mutex_init(&spec->amp_mutex);
1226 spec->multiout.max_channels = 2;
1227 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1228 spec->multiout.dac_nids = ad1981_dac_nids;
1229 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
1230 spec->num_adc_nids = 1;
1231 spec->adc_nids = ad1981_adc_nids;
1232 spec->capsrc_nids = ad1981_capsrc_nids;
1233 spec->input_mux = &ad1981_capture_source;
1234 spec->num_mixers = 1;
1235 spec->mixers[0] = ad1981_mixers;
1236 spec->num_init_verbs = 1;
1237 spec->init_verbs[0] = ad1981_init_verbs;
1238 spec->spdif_route = 0;
1240 codec->patch_ops = ad198x_patch_ops;
1242 /* override some parameters */
1243 board_config = snd_hda_check_board_config(codec, ad1981_cfg_tbl);
1244 switch (board_config) {
1246 spec->mixers[0] = ad1981_hp_mixers;
1247 spec->num_init_verbs = 2;
1248 spec->init_verbs[1] = ad1981_hp_init_verbs;
1249 spec->multiout.dig_out_nid = 0;
1250 spec->input_mux = &ad1981_hp_capture_source;
1252 codec->patch_ops.init = ad1981_hp_init;
1253 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1264 * Output pins and routes
1266 * Pin Mix Sel DAC (*)
1267 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1268 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1269 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1270 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1271 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1272 * port-F 0x16 (mute) <- 0x2a <- 06
1273 * port-G 0x24 (mute) <- 0x27 <- 05
1274 * port-H 0x25 (mute) <- 0x28 <- 0a
1275 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1277 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1278 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
1280 * Input pins and routes
1282 * pin boost mix input # / adc input #
1283 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1284 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1285 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1286 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1287 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1288 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1289 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1290 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1294 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
1295 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
1297 * Inputs of Analog Mix (0x20)
1298 * 0:Port-B (front mic)
1299 * 1:Port-C/G/H (line-in)
1301 * 3:Port-D (line-in/2)
1302 * 4:Port-E/G/H (mic-in)
1303 * 5:Port-F (mic2-in)
1309 * 1:Port-B (front mic-in)
1310 * 2:Port-C (line-in)
1311 * 3:Port-F (mic2-in)
1316 * 8:Port-D (line-in/2)
1319 * Proposed pin assignments by the datasheet
1322 * Port-A front headphone
1332 * Port-A front headphone
1334 * C rear line-in/surround
1336 * E rear mic-in/CLFE
1342 * D internal speaker (with EAPD)
1343 * E/F quad mic array
1359 /* reivision id to check workarounds */
1360 #define AD1988A_REV2 0x100200
1367 static hda_nid_t ad1988_6stack_dac_nids[4] = {
1368 0x04, 0x06, 0x05, 0x0a
1371 static hda_nid_t ad1988_3stack_dac_nids[3] = {
1375 /* for AD1988A revision-2, DAC2-4 are swapped */
1376 static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1377 0x04, 0x05, 0x0a, 0x06
1380 static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
1384 static hda_nid_t ad1988_adc_nids[3] = {
1388 static hda_nid_t ad1988_capsrc_nids[3] = {
1392 #define AD1988_SPDIF_OUT 0x02
1393 #define AD1988_SPDIF_IN 0x07
1395 static struct hda_input_mux ad1988_6stack_capture_source = {
1398 { "Front Mic", 0x0 },
1406 static struct hda_input_mux ad1988_laptop_capture_source = {
1409 { "Mic/Line", 0x0 },
1417 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1418 struct snd_ctl_elem_info *uinfo)
1420 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1421 struct ad198x_spec *spec = codec->spec;
1422 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1423 spec->num_channel_mode);
1426 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1427 struct snd_ctl_elem_value *ucontrol)
1429 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1430 struct ad198x_spec *spec = codec->spec;
1431 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1432 spec->num_channel_mode, spec->multiout.max_channels);
1435 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1436 struct snd_ctl_elem_value *ucontrol)
1438 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1439 struct ad198x_spec *spec = codec->spec;
1440 return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1441 spec->num_channel_mode, &spec->multiout.max_channels);
1445 static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
1446 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1447 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1448 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1449 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1450 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1453 static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1454 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1455 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1456 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1457 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1458 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1461 static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
1462 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1463 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1464 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1465 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1466 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1467 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1468 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1470 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1471 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1472 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1473 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1474 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1475 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1476 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1477 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1479 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1480 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1482 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1483 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1485 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1486 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1492 static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
1493 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1494 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1495 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1496 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1499 static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1500 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1501 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1502 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1503 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
1506 static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
1507 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1508 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1509 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1510 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
1511 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1512 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1514 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1515 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1516 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1517 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1518 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1519 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1520 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1521 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1523 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1524 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1526 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1527 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1529 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1530 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1532 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1533 .name = "Channel Mode",
1534 .info = ad198x_ch_mode_info,
1535 .get = ad198x_ch_mode_get,
1536 .put = ad198x_ch_mode_put,
1543 static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1544 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1545 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1546 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1548 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1549 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1550 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1551 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1552 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1553 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1555 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1556 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1558 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1559 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1561 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1564 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1565 .name = "External Amplifier",
1566 .info = ad198x_eapd_info,
1567 .get = ad198x_eapd_get,
1568 .put = ad198x_eapd_put,
1569 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
1576 static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1577 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1578 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1579 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1580 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1581 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1582 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1584 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1585 /* The multiple "Capture Source" controls confuse alsamixer
1586 * So call somewhat different..
1587 * FIXME: the controls appear in the "playback" view!
1589 /* .name = "Capture Source", */
1590 .name = "Input Source",
1592 .info = ad198x_mux_enum_info,
1593 .get = ad198x_mux_enum_get,
1594 .put = ad198x_mux_enum_put,
1599 static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1600 struct snd_ctl_elem_info *uinfo)
1602 static char *texts[] = {
1603 "PCM", "ADC1", "ADC2", "ADC3"
1605 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1607 uinfo->value.enumerated.items = 4;
1608 if (uinfo->value.enumerated.item >= 4)
1609 uinfo->value.enumerated.item = 3;
1610 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1614 static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1615 struct snd_ctl_elem_value *ucontrol)
1617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1620 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1622 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0);
1628 ucontrol->value.enumerated.item[0] = sel;
1632 static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
1633 struct snd_ctl_elem_value *ucontrol)
1635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1639 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1640 if (! ucontrol->value.enumerated.item[0]) {
1643 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 0);
1647 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 1);
1648 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0) + 1;
1649 change |= sel == ucontrol->value.enumerated.item[0];
1651 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL,
1652 ucontrol->value.enumerated.item[0] - 1);
1657 static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
1658 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1660 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1661 .name = "IEC958 Playback Source",
1662 .info = ad1988_spdif_playback_source_info,
1663 .get = ad1988_spdif_playback_source_get,
1664 .put = ad1988_spdif_playback_source_put,
1669 static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
1670 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
1676 * initialization verbs
1680 * for 6-stack (+dig)
1682 static struct hda_verb ad1988_6stack_init_verbs[] = {
1683 /* Front, Surround, CLFE, side DAC; unmute as default */
1684 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1685 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1686 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1687 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1688 /* Port-A front headphon path */
1689 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1690 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1691 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1692 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1693 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1694 /* Port-D line-out path */
1695 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1696 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1697 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1698 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1699 /* Port-F surround path */
1700 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1701 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1702 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1703 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1704 /* Port-G CLFE path */
1705 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1706 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1707 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1708 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1709 /* Port-H side path */
1710 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1711 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1712 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1713 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1715 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1716 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1717 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1718 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1719 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1720 /* Port-B front mic-in path */
1721 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1722 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1723 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1724 /* Port-C line-in path */
1725 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1726 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1727 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1728 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1729 /* Port-E mic-in path */
1730 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1731 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1732 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1733 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
1738 static struct hda_verb ad1988_capture_init_verbs[] = {
1739 /* mute analog mix */
1740 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1741 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1742 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1743 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1744 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1745 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1746 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1747 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1748 /* select ADCs - front-mic */
1749 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1750 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1751 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1753 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1754 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1755 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1760 static struct hda_verb ad1988_spdif_init_verbs[] = {
1762 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
1763 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
1764 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1765 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1767 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
1768 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x17}, /* 0dB */
1774 * verbs for 3stack (+dig)
1776 static struct hda_verb ad1988_3stack_ch2_init[] = {
1777 /* set port-C to line-in */
1778 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1779 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1780 /* set port-E to mic-in */
1781 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1782 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1786 static struct hda_verb ad1988_3stack_ch6_init[] = {
1787 /* set port-C to surround out */
1788 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1789 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1790 /* set port-E to CLFE out */
1791 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1792 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1796 static struct hda_channel_mode ad1988_3stack_modes[2] = {
1797 { 2, ad1988_3stack_ch2_init },
1798 { 6, ad1988_3stack_ch6_init },
1801 static struct hda_verb ad1988_3stack_init_verbs[] = {
1802 /* Front, Surround, CLFE, side DAC; unmute as default */
1803 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1804 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1805 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1806 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1807 /* Port-A front headphon path */
1808 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1809 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1810 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1811 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1812 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1813 /* Port-D line-out path */
1814 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1815 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1816 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1817 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1819 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1820 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1821 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1822 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1823 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1824 /* Port-B front mic-in path */
1825 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1826 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1827 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1828 /* Port-C line-in/surround path - 6ch mode as default */
1829 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1830 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1831 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1832 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
1833 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1834 /* Port-E mic-in/CLFE path - 6ch mode as default */
1835 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1836 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1837 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1838 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
1839 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
1840 /* mute analog mix */
1841 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1842 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1843 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1844 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1845 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1846 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1847 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1848 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1849 /* select ADCs - front-mic */
1850 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1851 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1852 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1854 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1855 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1856 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1861 * verbs for laptop mode (+dig)
1863 static struct hda_verb ad1988_laptop_hp_on[] = {
1864 /* unmute port-A and mute port-D */
1865 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1866 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1869 static struct hda_verb ad1988_laptop_hp_off[] = {
1870 /* mute port-A and unmute port-D */
1871 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1872 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1876 #define AD1988_HP_EVENT 0x01
1878 static struct hda_verb ad1988_laptop_init_verbs[] = {
1879 /* Front, Surround, CLFE, side DAC; unmute as default */
1880 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1881 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1882 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1883 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1884 /* Port-A front headphon path */
1885 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1886 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1887 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1888 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1889 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1890 /* unsolicited event for pin-sense */
1891 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
1892 /* Port-D line-out path + EAPD */
1893 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1894 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1895 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1896 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1897 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
1899 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1900 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1901 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1902 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1903 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1904 /* Port-B mic-in path */
1905 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1906 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1907 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1908 /* Port-C docking station - try to output */
1909 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1910 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1911 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1912 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1913 /* mute analog mix */
1914 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1915 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1916 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1917 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1918 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1919 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1920 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1921 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1922 /* select ADCs - mic */
1923 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1924 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1925 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1927 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1928 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1929 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1933 static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
1935 if ((res >> 26) != AD1988_HP_EVENT)
1937 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
1938 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
1940 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
1945 * Automatic parse of I/O pins from the BIOS configuration
1948 #define NUM_CONTROL_ALLOC 32
1949 #define NUM_VERB_ALLOC 32
1956 static struct snd_kcontrol_new ad1988_control_templates[] = {
1957 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1958 HDA_CODEC_MUTE(NULL, 0, 0, 0),
1959 HDA_BIND_MUTE(NULL, 0, 0, 0),
1962 /* add dynamic controls */
1963 static int add_control(struct ad198x_spec *spec, int type, const char *name,
1966 struct snd_kcontrol_new *knew;
1968 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1969 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1971 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1974 if (spec->kctl_alloc) {
1975 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1976 kfree(spec->kctl_alloc);
1978 spec->kctl_alloc = knew;
1979 spec->num_kctl_alloc = num;
1982 knew = &spec->kctl_alloc[spec->num_kctl_used];
1983 *knew = ad1988_control_templates[type];
1984 knew->name = kstrdup(name, GFP_KERNEL);
1987 knew->private_value = val;
1988 spec->num_kctl_used++;
1992 #define AD1988_PIN_CD_NID 0x18
1993 #define AD1988_PIN_BEEP_NID 0x10
1995 static hda_nid_t ad1988_mixer_nids[8] = {
1996 /* A B C D E F G H */
1997 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2000 static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2002 static hda_nid_t idx_to_dac[8] = {
2003 /* A B C D E F G H */
2004 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
2006 static hda_nid_t idx_to_dac_rev2[8] = {
2007 /* A B C D E F G H */
2008 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
2010 if (codec->revision_id == AD1988A_REV2)
2011 return idx_to_dac_rev2[idx];
2013 return idx_to_dac[idx];
2016 static hda_nid_t ad1988_boost_nids[8] = {
2017 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2020 static int ad1988_pin_idx(hda_nid_t nid)
2022 static hda_nid_t ad1988_io_pins[8] = {
2023 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2026 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2027 if (ad1988_io_pins[i] == nid)
2029 return 0; /* should be -1 */
2032 static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2034 static int loopback_idx[8] = {
2035 2, 0, 1, 3, 4, 5, 1, 4
2038 case AD1988_PIN_CD_NID:
2041 return loopback_idx[ad1988_pin_idx(nid)];
2045 static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2047 static int adc_idx[8] = {
2048 0, 1, 2, 8, 4, 3, 6, 7
2051 case AD1988_PIN_CD_NID:
2054 return adc_idx[ad1988_pin_idx(nid)];
2058 /* fill in the dac_nids table from the parsed pin configuration */
2059 static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2060 const struct auto_pin_cfg *cfg)
2062 struct ad198x_spec *spec = codec->spec;
2065 spec->multiout.dac_nids = spec->private_dac_nids;
2067 /* check the pins hardwired to audio widget */
2068 for (i = 0; i < cfg->line_outs; i++) {
2069 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2070 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2072 spec->multiout.num_dacs = cfg->line_outs;
2076 /* add playback controls from the parsed DAC table */
2077 static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2078 const struct auto_pin_cfg *cfg)
2081 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2085 for (i = 0; i < cfg->line_outs; i++) {
2086 hda_nid_t dac = spec->multiout.dac_nids[i];
2089 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2092 err = add_control(spec, AD_CTL_WIDGET_VOL,
2093 "Center Playback Volume",
2094 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2097 err = add_control(spec, AD_CTL_WIDGET_VOL,
2098 "LFE Playback Volume",
2099 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2102 err = add_control(spec, AD_CTL_BIND_MUTE,
2103 "Center Playback Switch",
2104 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2107 err = add_control(spec, AD_CTL_BIND_MUTE,
2108 "LFE Playback Switch",
2109 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2113 sprintf(name, "%s Playback Volume", chname[i]);
2114 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2115 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2118 sprintf(name, "%s Playback Switch", chname[i]);
2119 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2120 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2128 /* add playback controls for speaker and HP outputs */
2129 static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2132 struct ad198x_spec *spec = codec->spec;
2140 idx = ad1988_pin_idx(pin);
2141 nid = ad1988_idx_to_dac(codec, idx);
2142 if (! spec->multiout.dac_nids[0]) {
2143 /* use this as the primary output */
2144 spec->multiout.dac_nids[0] = nid;
2145 if (! spec->multiout.num_dacs)
2146 spec->multiout.num_dacs = 1;
2148 /* specify the DAC as the extra output */
2149 spec->multiout.hp_nid = nid;
2150 /* control HP volume/switch on the output mixer amp */
2151 sprintf(name, "%s Playback Volume", pfx);
2152 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2153 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2155 nid = ad1988_mixer_nids[idx];
2156 sprintf(name, "%s Playback Switch", pfx);
2157 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2158 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2163 /* create input playback/capture controls for the given pin */
2164 static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2165 const char *ctlname, int boost)
2170 sprintf(name, "%s Playback Volume", ctlname);
2171 idx = ad1988_pin_to_loopback_idx(pin);
2172 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2173 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2175 sprintf(name, "%s Playback Switch", ctlname);
2176 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2177 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2181 idx = ad1988_pin_idx(pin);
2182 bnid = ad1988_boost_nids[idx];
2184 sprintf(name, "%s Boost", ctlname);
2185 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2186 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2193 /* create playback/capture controls for input pins */
2194 static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2195 const struct auto_pin_cfg *cfg)
2197 struct hda_input_mux *imux = &spec->private_imux;
2200 for (i = 0; i < AUTO_PIN_LAST; i++) {
2201 err = new_analog_input(spec, cfg->input_pins[i],
2202 auto_pin_cfg_labels[i],
2203 i <= AUTO_PIN_FRONT_MIC);
2206 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2207 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2210 imux->items[imux->num_items].label = "Mix";
2211 imux->items[imux->num_items].index = 9;
2214 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2215 "Analog Mix Playback Volume",
2216 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2218 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2219 "Analog Mix Playback Switch",
2220 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2226 static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2227 hda_nid_t nid, int pin_type,
2231 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2232 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2234 case 0x11: /* port-A - DAC 04 */
2235 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2237 case 0x14: /* port-B - DAC 06 */
2238 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2240 case 0x15: /* port-C - DAC 05 */
2241 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2243 case 0x17: /* port-E - DAC 0a */
2244 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2246 case 0x13: /* mono - DAC 04 */
2247 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2252 static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2254 struct ad198x_spec *spec = codec->spec;
2257 for (i = 0; i < spec->autocfg.line_outs; i++) {
2258 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2259 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2263 static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2265 struct ad198x_spec *spec = codec->spec;
2268 pin = spec->autocfg.speaker_pin;
2269 if (pin) /* connect to front */
2270 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2271 pin = spec->autocfg.hp_pin;
2272 if (pin) /* connect to front */
2273 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2276 static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2278 struct ad198x_spec *spec = codec->spec;
2281 for (i = 0; i < AUTO_PIN_LAST; i++) {
2282 hda_nid_t nid = spec->autocfg.input_pins[i];
2286 case 0x15: /* port-C */
2287 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2289 case 0x17: /* port-E */
2290 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2293 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2294 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2295 if (nid != AD1988_PIN_CD_NID)
2296 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2298 idx = ad1988_pin_idx(nid);
2299 if (ad1988_boost_nids[idx])
2300 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2301 AC_VERB_SET_AMP_GAIN_MUTE,
2306 /* parse the BIOS configuration and set up the alc_spec */
2307 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2308 static int ad1988_parse_auto_config(struct hda_codec *codec)
2310 struct ad198x_spec *spec = codec->spec;
2313 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2315 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2317 if (! spec->autocfg.line_outs && ! spec->autocfg.speaker_pin &&
2318 ! spec->autocfg.hp_pin)
2319 return 0; /* can't find valid BIOS pin config */
2320 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2321 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.speaker_pin,
2323 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.speaker_pin,
2324 "Headphone")) < 0 ||
2325 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2328 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2330 if (spec->autocfg.dig_out_pin)
2331 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2332 if (spec->autocfg.dig_in_pin)
2333 spec->dig_in_nid = AD1988_SPDIF_IN;
2335 if (spec->kctl_alloc)
2336 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2338 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2340 spec->input_mux = &spec->private_imux;
2345 /* init callback for auto-configuration model -- overriding the default init */
2346 static int ad1988_auto_init(struct hda_codec *codec)
2349 ad1988_auto_init_multi_out(codec);
2350 ad1988_auto_init_extra_out(codec);
2351 ad1988_auto_init_analog_input(codec);
2359 static struct hda_board_config ad1988_cfg_tbl[] = {
2360 { .modelname = "6stack", .config = AD1988_6STACK },
2361 { .modelname = "6stack-dig", .config = AD1988_6STACK_DIG },
2362 { .modelname = "3stack", .config = AD1988_3STACK },
2363 { .modelname = "3stack-dig", .config = AD1988_3STACK_DIG },
2364 { .modelname = "laptop", .config = AD1988_LAPTOP },
2365 { .modelname = "laptop-dig", .config = AD1988_LAPTOP_DIG },
2366 { .modelname = "auto", .config = AD1988_AUTO },
2370 static int patch_ad1988(struct hda_codec *codec)
2372 struct ad198x_spec *spec;
2375 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2379 mutex_init(&spec->amp_mutex);
2382 if (codec->revision_id == AD1988A_REV2)
2383 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2385 board_config = snd_hda_check_board_config(codec, ad1988_cfg_tbl);
2386 if (board_config < 0 || board_config >= AD1988_MODEL_LAST) {
2387 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2388 board_config = AD1988_AUTO;
2391 if (board_config == AD1988_AUTO) {
2392 /* automatic parse from the BIOS config */
2393 int err = ad1988_parse_auto_config(codec);
2398 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2399 board_config = AD1988_6STACK;
2403 switch (board_config) {
2405 case AD1988_6STACK_DIG:
2406 spec->multiout.max_channels = 8;
2407 spec->multiout.num_dacs = 4;
2408 if (codec->revision_id == AD1988A_REV2)
2409 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2411 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
2412 spec->input_mux = &ad1988_6stack_capture_source;
2413 spec->num_mixers = 2;
2414 if (codec->revision_id == AD1988A_REV2)
2415 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2417 spec->mixers[0] = ad1988_6stack_mixers1;
2418 spec->mixers[1] = ad1988_6stack_mixers2;
2419 spec->num_init_verbs = 1;
2420 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2421 if (board_config == AD1988_6STACK_DIG) {
2422 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2423 spec->dig_in_nid = AD1988_SPDIF_IN;
2427 case AD1988_3STACK_DIG:
2428 spec->multiout.max_channels = 6;
2429 spec->multiout.num_dacs = 3;
2430 if (codec->revision_id == AD1988A_REV2)
2431 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2433 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2434 spec->input_mux = &ad1988_6stack_capture_source;
2435 spec->channel_mode = ad1988_3stack_modes;
2436 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
2437 spec->num_mixers = 2;
2438 if (codec->revision_id == AD1988A_REV2)
2439 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2441 spec->mixers[0] = ad1988_3stack_mixers1;
2442 spec->mixers[1] = ad1988_3stack_mixers2;
2443 spec->num_init_verbs = 1;
2444 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2445 if (board_config == AD1988_3STACK_DIG)
2446 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2449 case AD1988_LAPTOP_DIG:
2450 spec->multiout.max_channels = 2;
2451 spec->multiout.num_dacs = 1;
2452 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2453 spec->input_mux = &ad1988_laptop_capture_source;
2454 spec->num_mixers = 1;
2455 spec->mixers[0] = ad1988_laptop_mixers;
2456 spec->num_init_verbs = 1;
2457 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2458 if (board_config == AD1988_LAPTOP_DIG)
2459 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2463 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2464 spec->adc_nids = ad1988_adc_nids;
2465 spec->capsrc_nids = ad1988_capsrc_nids;
2466 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2467 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2468 if (spec->multiout.dig_out_nid) {
2469 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2470 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2472 if (spec->dig_in_nid)
2473 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2475 codec->patch_ops = ad198x_patch_ops;
2476 switch (board_config) {
2478 codec->patch_ops.init = ad1988_auto_init;
2481 case AD1988_LAPTOP_DIG:
2482 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2493 struct hda_codec_preset snd_hda_preset_analog[] = {
2494 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
2495 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
2496 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
2497 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },