2 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
5 * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/init.h>
23 #include <linux/delay.h>
24 #include <linux/slab.h>
25 #include <linux/pci.h>
27 #include <sound/core.h>
28 #include "hda_codec.h"
29 #include "hda_local.h"
33 struct snd_kcontrol_new *mixers[5];
35 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
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;
47 unsigned int need_dac_fix;
50 unsigned int num_adc_nids;
52 hda_nid_t dig_in_nid; /* digital-in NID; optional */
55 const struct hda_input_mux *input_mux;
56 hda_nid_t *capsrc_nids;
57 unsigned int cur_mux[3];
60 const struct hda_channel_mode *channel_mode;
64 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
66 unsigned int spdif_route;
68 /* dynamic controls, init_verbs and input_mux */
69 struct auto_pin_cfg autocfg;
70 struct snd_array kctls;
71 struct hda_input_mux private_imux;
72 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
74 unsigned int jack_present :1;
75 unsigned int inv_jack_detect:1;
77 #ifdef CONFIG_SND_HDA_POWER_SAVE
78 struct hda_loopback_check loopback;
80 /* for virtual master */
81 hda_nid_t vmaster_nid;
82 const char **slave_vols;
83 const char **slave_sws;
87 * input MUX handling (common part)
89 static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
91 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
92 struct ad198x_spec *spec = codec->spec;
94 return snd_hda_input_mux_info(spec->input_mux, uinfo);
97 static int ad198x_mux_enum_get(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 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
107 static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
109 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
110 struct ad198x_spec *spec = codec->spec;
111 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
113 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
114 spec->capsrc_nids[adc_idx],
115 &spec->cur_mux[adc_idx]);
119 * initialization (common callbacks)
121 static int ad198x_init(struct hda_codec *codec)
123 struct ad198x_spec *spec = codec->spec;
126 for (i = 0; i < spec->num_init_verbs; i++)
127 snd_hda_sequence_write(codec, spec->init_verbs[i]);
131 static const char *ad_slave_vols[] = {
132 "Front Playback Volume",
133 "Surround Playback Volume",
134 "Center Playback Volume",
135 "LFE Playback Volume",
136 "Side Playback Volume",
137 "Headphone Playback Volume",
138 "Mono Playback Volume",
139 "Speaker Playback Volume",
140 "IEC958 Playback Volume",
144 static const char *ad_slave_sws[] = {
145 "Front Playback Switch",
146 "Surround Playback Switch",
147 "Center Playback Switch",
148 "LFE Playback Switch",
149 "Side Playback Switch",
150 "Headphone Playback Switch",
151 "Mono Playback Switch",
152 "Speaker Playback Switch",
153 "IEC958 Playback Switch",
157 static void ad198x_free_kctls(struct hda_codec *codec);
159 /* additional beep mixers; the actual parameters are overwritten at build */
160 static struct snd_kcontrol_new ad_beep_mixer[] = {
161 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
162 HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_OUTPUT),
166 #define set_beep_amp(spec, nid, idx, dir) \
167 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
169 static int ad198x_build_controls(struct hda_codec *codec)
171 struct ad198x_spec *spec = codec->spec;
175 for (i = 0; i < spec->num_mixers; i++) {
176 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
180 if (spec->multiout.dig_out_nid) {
181 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
184 err = snd_hda_create_spdif_share_sw(codec,
188 spec->multiout.share_spdif = 1;
190 if (spec->dig_in_nid) {
191 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
196 /* create beep controls if needed */
197 if (spec->beep_amp) {
198 struct snd_kcontrol_new *knew;
199 for (knew = ad_beep_mixer; knew->name; knew++) {
200 struct snd_kcontrol *kctl;
201 kctl = snd_ctl_new1(knew, codec);
204 kctl->private_value = spec->beep_amp;
205 err = snd_hda_ctl_add(codec, kctl);
211 /* if we have no master control, let's create it */
212 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
213 unsigned int vmaster_tlv[4];
214 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
215 HDA_OUTPUT, vmaster_tlv);
216 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
219 spec->slave_vols : ad_slave_vols));
223 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
224 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
227 spec->slave_sws : ad_slave_sws));
232 ad198x_free_kctls(codec); /* no longer needed */
236 #ifdef CONFIG_SND_HDA_POWER_SAVE
237 static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
239 struct ad198x_spec *spec = codec->spec;
240 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
245 * Analog playback callbacks
247 static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
248 struct hda_codec *codec,
249 struct snd_pcm_substream *substream)
251 struct ad198x_spec *spec = codec->spec;
252 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
256 static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
257 struct hda_codec *codec,
258 unsigned int stream_tag,
260 struct snd_pcm_substream *substream)
262 struct ad198x_spec *spec = codec->spec;
263 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
267 static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
268 struct hda_codec *codec,
269 struct snd_pcm_substream *substream)
271 struct ad198x_spec *spec = codec->spec;
272 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
278 static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
279 struct hda_codec *codec,
280 struct snd_pcm_substream *substream)
282 struct ad198x_spec *spec = codec->spec;
283 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
286 static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
287 struct hda_codec *codec,
288 struct snd_pcm_substream *substream)
290 struct ad198x_spec *spec = codec->spec;
291 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
294 static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
295 struct hda_codec *codec,
296 unsigned int stream_tag,
298 struct snd_pcm_substream *substream)
300 struct ad198x_spec *spec = codec->spec;
301 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
305 static int ad198x_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
306 struct hda_codec *codec,
307 struct snd_pcm_substream *substream)
309 struct ad198x_spec *spec = codec->spec;
310 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
316 static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
317 struct hda_codec *codec,
318 unsigned int stream_tag,
320 struct snd_pcm_substream *substream)
322 struct ad198x_spec *spec = codec->spec;
323 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
324 stream_tag, 0, format);
328 static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
329 struct hda_codec *codec,
330 struct snd_pcm_substream *substream)
332 struct ad198x_spec *spec = codec->spec;
333 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
340 static struct hda_pcm_stream ad198x_pcm_analog_playback = {
343 .channels_max = 6, /* changed later */
344 .nid = 0, /* fill later */
346 .open = ad198x_playback_pcm_open,
347 .prepare = ad198x_playback_pcm_prepare,
348 .cleanup = ad198x_playback_pcm_cleanup
352 static struct hda_pcm_stream ad198x_pcm_analog_capture = {
356 .nid = 0, /* fill later */
358 .prepare = ad198x_capture_pcm_prepare,
359 .cleanup = ad198x_capture_pcm_cleanup
363 static struct hda_pcm_stream ad198x_pcm_digital_playback = {
367 .nid = 0, /* fill later */
369 .open = ad198x_dig_playback_pcm_open,
370 .close = ad198x_dig_playback_pcm_close,
371 .prepare = ad198x_dig_playback_pcm_prepare,
372 .cleanup = ad198x_dig_playback_pcm_cleanup
376 static struct hda_pcm_stream ad198x_pcm_digital_capture = {
380 /* NID is set in alc_build_pcms */
383 static int ad198x_build_pcms(struct hda_codec *codec)
385 struct ad198x_spec *spec = codec->spec;
386 struct hda_pcm *info = spec->pcm_rec;
389 codec->pcm_info = info;
391 info->name = "AD198x Analog";
392 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
393 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
394 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
395 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
396 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
397 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
399 if (spec->multiout.dig_out_nid) {
402 info->name = "AD198x Digital";
403 info->pcm_type = HDA_PCM_TYPE_SPDIF;
404 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
405 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
406 if (spec->dig_in_nid) {
407 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
408 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
415 static void ad198x_free_kctls(struct hda_codec *codec)
417 struct ad198x_spec *spec = codec->spec;
419 if (spec->kctls.list) {
420 struct snd_kcontrol_new *kctl = spec->kctls.list;
422 for (i = 0; i < spec->kctls.used; i++)
425 snd_array_free(&spec->kctls);
428 static void ad198x_free(struct hda_codec *codec)
430 struct ad198x_spec *spec = codec->spec;
435 ad198x_free_kctls(codec);
437 snd_hda_detach_beep_device(codec);
440 static struct hda_codec_ops ad198x_patch_ops = {
441 .build_controls = ad198x_build_controls,
442 .build_pcms = ad198x_build_pcms,
445 #ifdef CONFIG_SND_HDA_POWER_SAVE
446 .check_power_status = ad198x_check_power_status,
453 * the private value = nid | (invert << 8)
455 #define ad198x_eapd_info snd_ctl_boolean_mono_info
457 static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
458 struct snd_ctl_elem_value *ucontrol)
460 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
461 struct ad198x_spec *spec = codec->spec;
462 int invert = (kcontrol->private_value >> 8) & 1;
464 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
466 ucontrol->value.integer.value[0] = spec->cur_eapd;
470 static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
471 struct snd_ctl_elem_value *ucontrol)
473 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
474 struct ad198x_spec *spec = codec->spec;
475 int invert = (kcontrol->private_value >> 8) & 1;
476 hda_nid_t nid = kcontrol->private_value & 0xff;
478 eapd = !!ucontrol->value.integer.value[0];
481 if (eapd == spec->cur_eapd)
483 spec->cur_eapd = eapd;
484 snd_hda_codec_write_cache(codec, nid,
485 0, AC_VERB_SET_EAPD_BTLENABLE,
490 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
491 struct snd_ctl_elem_info *uinfo);
492 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
493 struct snd_ctl_elem_value *ucontrol);
494 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
495 struct snd_ctl_elem_value *ucontrol);
502 #define AD1986A_SPDIF_OUT 0x02
503 #define AD1986A_FRONT_DAC 0x03
504 #define AD1986A_SURR_DAC 0x04
505 #define AD1986A_CLFE_DAC 0x05
506 #define AD1986A_ADC 0x06
508 static hda_nid_t ad1986a_dac_nids[3] = {
509 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
511 static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
512 static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
514 static struct hda_input_mux ad1986a_capture_source = {
528 static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
529 .ops = &snd_hda_bind_vol,
531 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
532 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
533 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
538 static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
539 .ops = &snd_hda_bind_sw,
541 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
542 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
543 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
551 static struct snd_kcontrol_new ad1986a_mixers[] = {
553 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
555 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
556 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
557 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
558 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
559 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
560 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
561 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
562 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
563 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
564 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
565 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
566 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
567 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
568 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
569 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
570 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
571 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
572 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
573 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
574 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
575 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
576 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
577 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
578 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
579 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
581 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
582 .name = "Capture Source",
583 .info = ad198x_mux_enum_info,
584 .get = ad198x_mux_enum_get,
585 .put = ad198x_mux_enum_put,
587 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
591 /* additional mixers for 3stack mode */
592 static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
594 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
595 .name = "Channel Mode",
596 .info = ad198x_ch_mode_info,
597 .get = ad198x_ch_mode_get,
598 .put = ad198x_ch_mode_put,
603 /* laptop model - 2ch only */
604 static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
606 /* master controls both pins 0x1a and 0x1b */
607 static struct hda_bind_ctls ad1986a_laptop_master_vol = {
608 .ops = &snd_hda_bind_vol,
610 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
611 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
616 static struct hda_bind_ctls ad1986a_laptop_master_sw = {
617 .ops = &snd_hda_bind_sw,
619 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
620 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
625 static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
626 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
627 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
628 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
629 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
630 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
631 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
632 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
633 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
634 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
635 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
636 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
637 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
638 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
640 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
641 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
642 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
643 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
645 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
646 .name = "Capture Source",
647 .info = ad198x_mux_enum_info,
648 .get = ad198x_mux_enum_get,
649 .put = ad198x_mux_enum_put,
654 /* laptop-eapd model - 2ch only */
656 static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
660 { "Internal Mic", 0x4 },
665 static struct hda_input_mux ad1986a_automic_capture_source = {
673 static struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
674 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
675 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
679 static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
680 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
681 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
682 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
683 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
684 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
685 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
686 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
688 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
689 .name = "Capture Source",
690 .info = ad198x_mux_enum_info,
691 .get = ad198x_mux_enum_get,
692 .put = ad198x_mux_enum_put,
695 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
696 .name = "External Amplifier",
697 .info = ad198x_eapd_info,
698 .get = ad198x_eapd_get,
699 .put = ad198x_eapd_put,
700 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
705 static struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
706 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
707 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
711 /* re-connect the mic boost input according to the jack sensing */
712 static void ad1986a_automic(struct hda_codec *codec)
714 unsigned int present;
715 present = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_PIN_SENSE, 0);
716 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
717 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
718 (present & AC_PINSENSE_PRESENCE) ? 0 : 2);
721 #define AD1986A_MIC_EVENT 0x36
723 static void ad1986a_automic_unsol_event(struct hda_codec *codec,
726 if ((res >> 26) != AD1986A_MIC_EVENT)
728 ad1986a_automic(codec);
731 static int ad1986a_automic_init(struct hda_codec *codec)
734 ad1986a_automic(codec);
738 /* laptop-automute - 2ch only */
740 static void ad1986a_update_hp(struct hda_codec *codec)
742 struct ad198x_spec *spec = codec->spec;
745 if (spec->jack_present)
746 mute = HDA_AMP_MUTE; /* mute internal speaker */
748 /* unmute internal speaker if necessary */
749 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
750 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
754 static void ad1986a_hp_automute(struct hda_codec *codec)
756 struct ad198x_spec *spec = codec->spec;
757 unsigned int present;
759 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0);
760 spec->jack_present = !!(present & 0x80000000);
761 if (spec->inv_jack_detect)
762 spec->jack_present = !spec->jack_present;
763 ad1986a_update_hp(codec);
766 #define AD1986A_HP_EVENT 0x37
768 static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
770 if ((res >> 26) != AD1986A_HP_EVENT)
772 ad1986a_hp_automute(codec);
775 static int ad1986a_hp_init(struct hda_codec *codec)
778 ad1986a_hp_automute(codec);
782 /* bind hp and internal speaker mute (with plug check) */
783 static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
784 struct snd_ctl_elem_value *ucontrol)
786 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
787 long *valp = ucontrol->value.integer.value;
790 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
792 valp[0] ? 0 : HDA_AMP_MUTE);
793 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
795 valp[1] ? 0 : HDA_AMP_MUTE);
797 ad1986a_update_hp(codec);
801 static struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
802 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
805 .name = "Master Playback Switch",
806 .info = snd_hda_mixer_amp_switch_info,
807 .get = snd_hda_mixer_amp_switch_get,
808 .put = ad1986a_hp_master_sw_put,
809 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
816 * initialization verbs
818 static struct hda_verb ad1986a_init_verbs[] = {
819 /* Front, Surround, CLFE DAC; mute as default */
820 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
821 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
822 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
824 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
825 /* HP, Line-Out, Surround, CLFE selectors */
826 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
827 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
828 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
829 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
831 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
832 /* Mic selector: Mic 1/2 pin */
833 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
834 /* Line-in selector: Line-in */
835 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
837 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
838 /* Record selector: mic */
839 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
840 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
841 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
842 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
843 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
844 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
845 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
847 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
848 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
849 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
850 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
851 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
852 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
853 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
855 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
856 /* Front, Surround, CLFE Pins */
857 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
858 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
859 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
861 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
863 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
864 /* Line, Aux, CD, Beep-In Pin */
865 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
866 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
867 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
868 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
869 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
873 static struct hda_verb ad1986a_ch2_init[] = {
874 /* Surround out -> Line In */
875 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
876 /* Line-in selectors */
877 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
879 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
880 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
881 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
885 static struct hda_verb ad1986a_ch4_init[] = {
886 /* Surround out -> Surround */
887 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
888 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
890 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
891 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
895 static struct hda_verb ad1986a_ch6_init[] = {
896 /* Surround out -> Surround out */
897 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
898 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
900 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
901 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
905 static struct hda_channel_mode ad1986a_modes[3] = {
906 { 2, ad1986a_ch2_init },
907 { 4, ad1986a_ch4_init },
908 { 6, ad1986a_ch6_init },
911 /* eapd initialization */
912 static struct hda_verb ad1986a_eapd_init_verbs[] = {
913 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
917 static struct hda_verb ad1986a_automic_verbs[] = {
918 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
919 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
920 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
921 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
922 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
926 /* Ultra initialization */
927 static struct hda_verb ad1986a_ultra_init[] = {
928 /* eapd initialization */
929 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
931 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
932 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
933 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
937 /* pin sensing on HP jack */
938 static struct hda_verb ad1986a_hp_init_verbs[] = {
939 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
950 AD1986A_LAPTOP_AUTOMUTE,
956 static const char *ad1986a_models[AD1986A_MODELS] = {
957 [AD1986A_6STACK] = "6stack",
958 [AD1986A_3STACK] = "3stack",
959 [AD1986A_LAPTOP] = "laptop",
960 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
961 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
962 [AD1986A_ULTRA] = "ultra",
963 [AD1986A_SAMSUNG] = "samsung",
966 static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
967 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
968 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
969 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
970 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
971 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
972 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
973 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
974 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
975 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
976 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
977 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
978 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
979 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
980 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
981 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
982 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
983 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
984 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
985 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
986 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
987 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
988 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
989 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
990 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
991 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
992 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
996 #ifdef CONFIG_SND_HDA_POWER_SAVE
997 static struct hda_amp_list ad1986a_loopbacks[] = {
998 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
999 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
1000 { 0x15, HDA_OUTPUT, 0 }, /* CD */
1001 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
1002 { 0x17, HDA_OUTPUT, 0 }, /* Line */
1007 static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1009 unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
1010 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1013 static int patch_ad1986a(struct hda_codec *codec)
1015 struct ad198x_spec *spec;
1016 int err, board_config;
1018 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1024 err = snd_hda_attach_beep_device(codec, 0x19);
1029 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1031 spec->multiout.max_channels = 6;
1032 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
1033 spec->multiout.dac_nids = ad1986a_dac_nids;
1034 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
1035 spec->num_adc_nids = 1;
1036 spec->adc_nids = ad1986a_adc_nids;
1037 spec->capsrc_nids = ad1986a_capsrc_nids;
1038 spec->input_mux = &ad1986a_capture_source;
1039 spec->num_mixers = 1;
1040 spec->mixers[0] = ad1986a_mixers;
1041 spec->num_init_verbs = 1;
1042 spec->init_verbs[0] = ad1986a_init_verbs;
1043 #ifdef CONFIG_SND_HDA_POWER_SAVE
1044 spec->loopback.amplist = ad1986a_loopbacks;
1046 spec->vmaster_nid = 0x1b;
1048 codec->patch_ops = ad198x_patch_ops;
1050 /* override some parameters */
1051 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1054 switch (board_config) {
1055 case AD1986A_3STACK:
1056 spec->num_mixers = 2;
1057 spec->mixers[1] = ad1986a_3st_mixers;
1058 spec->num_init_verbs = 2;
1059 spec->init_verbs[1] = ad1986a_ch2_init;
1060 spec->channel_mode = ad1986a_modes;
1061 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
1062 spec->need_dac_fix = 1;
1063 spec->multiout.max_channels = 2;
1064 spec->multiout.num_dacs = 1;
1066 case AD1986A_LAPTOP:
1067 spec->mixers[0] = ad1986a_laptop_mixers;
1068 spec->multiout.max_channels = 2;
1069 spec->multiout.num_dacs = 1;
1070 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1072 case AD1986A_LAPTOP_EAPD:
1073 spec->num_mixers = 3;
1074 spec->mixers[0] = ad1986a_laptop_master_mixers;
1075 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1076 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
1077 spec->num_init_verbs = 2;
1078 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1079 spec->multiout.max_channels = 2;
1080 spec->multiout.num_dacs = 1;
1081 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1082 if (!is_jack_available(codec, 0x25))
1083 spec->multiout.dig_out_nid = 0;
1084 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1086 case AD1986A_SAMSUNG:
1087 spec->num_mixers = 2;
1088 spec->mixers[0] = ad1986a_laptop_master_mixers;
1089 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1090 spec->num_init_verbs = 3;
1091 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1092 spec->init_verbs[2] = ad1986a_automic_verbs;
1093 spec->multiout.max_channels = 2;
1094 spec->multiout.num_dacs = 1;
1095 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1096 if (!is_jack_available(codec, 0x25))
1097 spec->multiout.dig_out_nid = 0;
1098 spec->input_mux = &ad1986a_automic_capture_source;
1099 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1100 codec->patch_ops.init = ad1986a_automic_init;
1102 case AD1986A_LAPTOP_AUTOMUTE:
1103 spec->num_mixers = 3;
1104 spec->mixers[0] = ad1986a_automute_master_mixers;
1105 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1106 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
1107 spec->num_init_verbs = 3;
1108 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1109 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1110 spec->multiout.max_channels = 2;
1111 spec->multiout.num_dacs = 1;
1112 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1113 if (!is_jack_available(codec, 0x25))
1114 spec->multiout.dig_out_nid = 0;
1115 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1116 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1117 codec->patch_ops.init = ad1986a_hp_init;
1118 /* Lenovo N100 seems to report the reversed bit
1119 * for HP jack-sensing
1121 spec->inv_jack_detect = 1;
1124 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1125 spec->num_init_verbs = 2;
1126 spec->init_verbs[1] = ad1986a_ultra_init;
1127 spec->multiout.max_channels = 2;
1128 spec->multiout.num_dacs = 1;
1129 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1130 spec->multiout.dig_out_nid = 0;
1134 /* AD1986A has a hardware problem that it can't share a stream
1135 * with multiple output pins. The copy of front to surrounds
1136 * causes noisy or silent outputs at a certain timing, e.g.
1137 * changing the volume.
1138 * So, let's disable the shared stream.
1140 spec->multiout.no_share_stream = 1;
1149 #define AD1983_SPDIF_OUT 0x02
1150 #define AD1983_DAC 0x03
1151 #define AD1983_ADC 0x04
1153 static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
1154 static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
1155 static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
1157 static struct hda_input_mux ad1983_capture_source = {
1163 { "Mix Mono", 0x3 },
1168 * SPDIF playback route
1170 static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1172 static char *texts[] = { "PCM", "ADC" };
1174 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1176 uinfo->value.enumerated.items = 2;
1177 if (uinfo->value.enumerated.item > 1)
1178 uinfo->value.enumerated.item = 1;
1179 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1183 static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1185 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1186 struct ad198x_spec *spec = codec->spec;
1188 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1192 static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1194 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1195 struct ad198x_spec *spec = codec->spec;
1197 if (ucontrol->value.enumerated.item[0] > 1)
1199 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1200 spec->spdif_route = ucontrol->value.enumerated.item[0];
1201 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1202 AC_VERB_SET_CONNECT_SEL,
1209 static struct snd_kcontrol_new ad1983_mixers[] = {
1210 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1211 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1212 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1213 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1214 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1215 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1216 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1217 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1218 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1219 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1220 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1221 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1222 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1223 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1224 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1226 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1227 .name = "Capture Source",
1228 .info = ad198x_mux_enum_info,
1229 .get = ad198x_mux_enum_get,
1230 .put = ad198x_mux_enum_put,
1233 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1234 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1235 .info = ad1983_spdif_route_info,
1236 .get = ad1983_spdif_route_get,
1237 .put = ad1983_spdif_route_put,
1242 static struct hda_verb ad1983_init_verbs[] = {
1243 /* Front, HP, Mono; mute as default */
1244 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1245 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1246 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1247 /* Beep, PCM, Mic, Line-In: mute */
1248 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1249 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1250 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1251 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1252 /* Front, HP selectors; from Mix */
1253 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1254 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1255 /* Mono selector; from Mix */
1256 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1257 /* Mic selector; Mic */
1258 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1259 /* Line-in selector: Line-in */
1260 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1261 /* Mic boost: 0dB */
1262 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1263 /* Record selector: mic */
1264 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1265 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1266 /* SPDIF route: PCM */
1267 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1269 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1271 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1273 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1275 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1277 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1281 #ifdef CONFIG_SND_HDA_POWER_SAVE
1282 static struct hda_amp_list ad1983_loopbacks[] = {
1283 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1284 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1289 static int patch_ad1983(struct hda_codec *codec)
1291 struct ad198x_spec *spec;
1294 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1300 err = snd_hda_attach_beep_device(codec, 0x10);
1305 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1307 spec->multiout.max_channels = 2;
1308 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1309 spec->multiout.dac_nids = ad1983_dac_nids;
1310 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
1311 spec->num_adc_nids = 1;
1312 spec->adc_nids = ad1983_adc_nids;
1313 spec->capsrc_nids = ad1983_capsrc_nids;
1314 spec->input_mux = &ad1983_capture_source;
1315 spec->num_mixers = 1;
1316 spec->mixers[0] = ad1983_mixers;
1317 spec->num_init_verbs = 1;
1318 spec->init_verbs[0] = ad1983_init_verbs;
1319 spec->spdif_route = 0;
1320 #ifdef CONFIG_SND_HDA_POWER_SAVE
1321 spec->loopback.amplist = ad1983_loopbacks;
1323 spec->vmaster_nid = 0x05;
1325 codec->patch_ops = ad198x_patch_ops;
1332 * AD1981 HD specific
1335 #define AD1981_SPDIF_OUT 0x02
1336 #define AD1981_DAC 0x03
1337 #define AD1981_ADC 0x04
1339 static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
1340 static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
1341 static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
1343 /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1344 static struct hda_input_mux ad1981_capture_source = {
1347 { "Front Mic", 0x0 },
1350 { "Mix Mono", 0x3 },
1357 static struct snd_kcontrol_new ad1981_mixers[] = {
1358 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1359 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1360 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1361 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1362 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1364 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1365 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1366 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1367 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1368 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1369 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1370 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1371 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1372 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1373 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1374 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1375 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1376 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1377 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1378 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1379 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1381 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1382 .name = "Capture Source",
1383 .info = ad198x_mux_enum_info,
1384 .get = ad198x_mux_enum_get,
1385 .put = ad198x_mux_enum_put,
1387 /* identical with AD1983 */
1389 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1390 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1391 .info = ad1983_spdif_route_info,
1392 .get = ad1983_spdif_route_get,
1393 .put = ad1983_spdif_route_put,
1398 static struct hda_verb ad1981_init_verbs[] = {
1399 /* Front, HP, Mono; mute as default */
1400 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1401 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1402 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1403 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1404 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1405 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1406 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1407 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1408 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1409 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1410 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1411 /* Front, HP selectors; from Mix */
1412 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1413 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1414 /* Mono selector; from Mix */
1415 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1416 /* Mic Mixer; select Front Mic */
1417 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1418 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1419 /* Mic boost: 0dB */
1420 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1421 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1422 /* Record selector: Front mic */
1423 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1424 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1425 /* SPDIF route: PCM */
1426 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1428 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1430 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1432 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1433 /* Front & Rear Mic Pins */
1434 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1435 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1437 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1439 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1440 /* Line-Out as Input: disabled */
1441 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1445 #ifdef CONFIG_SND_HDA_POWER_SAVE
1446 static struct hda_amp_list ad1981_loopbacks[] = {
1447 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1448 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1449 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1450 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1451 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1457 * Patch for HP nx6320
1459 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
1460 * speaker output enabled _and_ mute-LED off.
1463 #define AD1981_HP_EVENT 0x37
1464 #define AD1981_MIC_EVENT 0x38
1466 static struct hda_verb ad1981_hp_init_verbs[] = {
1467 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1468 /* pin sensing on HP and Mic jacks */
1469 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1470 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1474 /* turn on/off EAPD (+ mute HP) as a master switch */
1475 static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1476 struct snd_ctl_elem_value *ucontrol)
1478 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1479 struct ad198x_spec *spec = codec->spec;
1481 if (! ad198x_eapd_put(kcontrol, ucontrol))
1483 /* change speaker pin appropriately */
1484 snd_hda_codec_write(codec, 0x05, 0,
1485 AC_VERB_SET_PIN_WIDGET_CONTROL,
1486 spec->cur_eapd ? PIN_OUT : 0);
1487 /* toggle HP mute appropriately */
1488 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1490 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
1494 /* bind volumes of both NID 0x05 and 0x06 */
1495 static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1496 .ops = &snd_hda_bind_vol,
1498 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1499 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1504 /* mute internal speaker if HP is plugged */
1505 static void ad1981_hp_automute(struct hda_codec *codec)
1507 unsigned int present;
1509 present = snd_hda_codec_read(codec, 0x06, 0,
1510 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1511 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1512 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1515 /* toggle input of built-in and mic jack appropriately */
1516 static void ad1981_hp_automic(struct hda_codec *codec)
1518 static struct hda_verb mic_jack_on[] = {
1519 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1520 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1523 static struct hda_verb mic_jack_off[] = {
1524 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1525 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1528 unsigned int present;
1530 present = snd_hda_codec_read(codec, 0x08, 0,
1531 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1533 snd_hda_sequence_write(codec, mic_jack_on);
1535 snd_hda_sequence_write(codec, mic_jack_off);
1538 /* unsolicited event for HP jack sensing */
1539 static void ad1981_hp_unsol_event(struct hda_codec *codec,
1544 case AD1981_HP_EVENT:
1545 ad1981_hp_automute(codec);
1547 case AD1981_MIC_EVENT:
1548 ad1981_hp_automic(codec);
1553 static struct hda_input_mux ad1981_hp_capture_source = {
1557 { "Docking-Station", 0x1 },
1562 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1563 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
1565 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1566 .name = "Master Playback Switch",
1567 .info = ad198x_eapd_info,
1568 .get = ad198x_eapd_get,
1569 .put = ad1981_hp_master_sw_put,
1570 .private_value = 0x05,
1572 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1573 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1575 /* FIXME: analog mic/line loopback doesn't work with my tests...
1576 * (although recording is OK)
1578 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1579 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1580 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1581 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1582 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1583 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1584 /* FIXME: does this laptop have analog CD connection? */
1585 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1586 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1588 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1589 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1590 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1591 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1593 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1594 .name = "Capture Source",
1595 .info = ad198x_mux_enum_info,
1596 .get = ad198x_mux_enum_get,
1597 .put = ad198x_mux_enum_put,
1602 /* initialize jack-sensing, too */
1603 static int ad1981_hp_init(struct hda_codec *codec)
1606 ad1981_hp_automute(codec);
1607 ad1981_hp_automic(codec);
1611 /* configuration for Toshiba Laptops */
1612 static struct hda_verb ad1981_toshiba_init_verbs[] = {
1613 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1614 /* pin sensing on HP and Mic jacks */
1615 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1616 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1620 static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1621 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1622 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1626 /* configuration for Lenovo Thinkpad T60 */
1627 static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1628 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1629 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1630 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1631 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1632 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1633 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1634 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1635 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1636 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1637 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1638 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1640 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1641 .name = "Capture Source",
1642 .info = ad198x_mux_enum_info,
1643 .get = ad198x_mux_enum_get,
1644 .put = ad198x_mux_enum_put,
1646 /* identical with AD1983 */
1648 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1649 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1650 .info = ad1983_spdif_route_info,
1651 .get = ad1983_spdif_route_get,
1652 .put = ad1983_spdif_route_put,
1657 static struct hda_input_mux ad1981_thinkpad_capture_source = {
1675 static const char *ad1981_models[AD1981_MODELS] = {
1677 [AD1981_THINKPAD] = "thinkpad",
1678 [AD1981_BASIC] = "basic",
1679 [AD1981_TOSHIBA] = "toshiba"
1682 static struct snd_pci_quirk ad1981_cfg_tbl[] = {
1683 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
1684 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
1686 SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
1687 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
1688 /* Lenovo Thinkpad T60/X60/Z6xx */
1689 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
1690 /* HP nx6320 (reversed SSID, H/W bug) */
1691 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
1695 static int patch_ad1981(struct hda_codec *codec)
1697 struct ad198x_spec *spec;
1698 int err, board_config;
1700 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1706 err = snd_hda_attach_beep_device(codec, 0x10);
1711 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
1713 spec->multiout.max_channels = 2;
1714 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1715 spec->multiout.dac_nids = ad1981_dac_nids;
1716 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
1717 spec->num_adc_nids = 1;
1718 spec->adc_nids = ad1981_adc_nids;
1719 spec->capsrc_nids = ad1981_capsrc_nids;
1720 spec->input_mux = &ad1981_capture_source;
1721 spec->num_mixers = 1;
1722 spec->mixers[0] = ad1981_mixers;
1723 spec->num_init_verbs = 1;
1724 spec->init_verbs[0] = ad1981_init_verbs;
1725 spec->spdif_route = 0;
1726 #ifdef CONFIG_SND_HDA_POWER_SAVE
1727 spec->loopback.amplist = ad1981_loopbacks;
1729 spec->vmaster_nid = 0x05;
1731 codec->patch_ops = ad198x_patch_ops;
1733 /* override some parameters */
1734 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1737 switch (board_config) {
1739 spec->mixers[0] = ad1981_hp_mixers;
1740 spec->num_init_verbs = 2;
1741 spec->init_verbs[1] = ad1981_hp_init_verbs;
1742 spec->multiout.dig_out_nid = 0;
1743 spec->input_mux = &ad1981_hp_capture_source;
1745 codec->patch_ops.init = ad1981_hp_init;
1746 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1748 case AD1981_THINKPAD:
1749 spec->mixers[0] = ad1981_thinkpad_mixers;
1750 spec->input_mux = &ad1981_thinkpad_capture_source;
1752 case AD1981_TOSHIBA:
1753 spec->mixers[0] = ad1981_hp_mixers;
1754 spec->mixers[1] = ad1981_toshiba_mixers;
1755 spec->num_init_verbs = 2;
1756 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1757 spec->multiout.dig_out_nid = 0;
1758 spec->input_mux = &ad1981_hp_capture_source;
1759 codec->patch_ops.init = ad1981_hp_init;
1760 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1770 * Output pins and routes
1772 * Pin Mix Sel DAC (*)
1773 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1774 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1775 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1776 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1777 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1778 * port-F 0x16 (mute) <- 0x2a <- 06
1779 * port-G 0x24 (mute) <- 0x27 <- 05
1780 * port-H 0x25 (mute) <- 0x28 <- 0a
1781 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1783 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1784 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
1786 * Input pins and routes
1788 * pin boost mix input # / adc input #
1789 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1790 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1791 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1792 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1793 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1794 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1795 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1796 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1800 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
1801 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
1803 * Inputs of Analog Mix (0x20)
1804 * 0:Port-B (front mic)
1805 * 1:Port-C/G/H (line-in)
1807 * 3:Port-D (line-in/2)
1808 * 4:Port-E/G/H (mic-in)
1809 * 5:Port-F (mic2-in)
1815 * 1:Port-B (front mic-in)
1816 * 2:Port-C (line-in)
1817 * 3:Port-F (mic2-in)
1822 * 8:Port-D (line-in/2)
1825 * Proposed pin assignments by the datasheet
1828 * Port-A front headphone
1838 * Port-A front headphone
1840 * C rear line-in/surround
1842 * E rear mic-in/CLFE
1848 * D internal speaker (with EAPD)
1849 * E/F quad mic array
1865 /* reivision id to check workarounds */
1866 #define AD1988A_REV2 0x100200
1868 #define is_rev2(codec) \
1869 ((codec)->vendor_id == 0x11d41988 && \
1870 (codec)->revision_id == AD1988A_REV2)
1876 static hda_nid_t ad1988_6stack_dac_nids[4] = {
1877 0x04, 0x06, 0x05, 0x0a
1880 static hda_nid_t ad1988_3stack_dac_nids[3] = {
1884 /* for AD1988A revision-2, DAC2-4 are swapped */
1885 static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1886 0x04, 0x05, 0x0a, 0x06
1889 static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
1893 static hda_nid_t ad1988_adc_nids[3] = {
1897 static hda_nid_t ad1988_capsrc_nids[3] = {
1901 #define AD1988_SPDIF_OUT 0x02
1902 #define AD1988_SPDIF_OUT_HDMI 0x0b
1903 #define AD1988_SPDIF_IN 0x07
1905 static hda_nid_t ad1989b_slave_dig_outs[] = {
1906 AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
1909 static struct hda_input_mux ad1988_6stack_capture_source = {
1912 { "Front Mic", 0x1 }, /* port-B */
1913 { "Line", 0x2 }, /* port-C */
1914 { "Mic", 0x4 }, /* port-E */
1920 static struct hda_input_mux ad1988_laptop_capture_source = {
1923 { "Mic/Line", 0x1 }, /* port-B */
1931 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1932 struct snd_ctl_elem_info *uinfo)
1934 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1935 struct ad198x_spec *spec = codec->spec;
1936 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1937 spec->num_channel_mode);
1940 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1941 struct snd_ctl_elem_value *ucontrol)
1943 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1944 struct ad198x_spec *spec = codec->spec;
1945 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1946 spec->num_channel_mode, spec->multiout.max_channels);
1949 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1950 struct snd_ctl_elem_value *ucontrol)
1952 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1953 struct ad198x_spec *spec = codec->spec;
1954 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1955 spec->num_channel_mode,
1956 &spec->multiout.max_channels);
1957 if (err >= 0 && spec->need_dac_fix)
1958 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
1963 static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
1964 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1965 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1966 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1967 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1968 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1972 static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1973 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1974 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1975 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1976 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1977 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1981 static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
1982 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1983 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1984 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1985 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1986 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1987 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1988 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1990 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1991 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1992 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1993 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1994 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1995 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1996 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1997 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1999 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2000 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2002 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2003 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2009 static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
2010 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2011 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2012 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2013 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2017 static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
2018 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2019 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2020 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
2021 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
2025 static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
2026 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2027 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
2028 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
2029 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
2030 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2031 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2033 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2034 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2035 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2036 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2037 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2038 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2039 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2040 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2042 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2043 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2045 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2046 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2048 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2049 .name = "Channel Mode",
2050 .info = ad198x_ch_mode_info,
2051 .get = ad198x_ch_mode_get,
2052 .put = ad198x_ch_mode_put,
2059 static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2060 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2061 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
2062 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2064 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2065 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2066 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2067 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2068 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2069 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2071 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2072 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2074 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2077 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2078 .name = "External Amplifier",
2079 .info = ad198x_eapd_info,
2080 .get = ad198x_eapd_get,
2081 .put = ad198x_eapd_put,
2082 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
2089 static struct snd_kcontrol_new ad1988_capture_mixers[] = {
2090 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2091 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2092 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2093 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2094 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2095 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2097 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2098 /* The multiple "Capture Source" controls confuse alsamixer
2099 * So call somewhat different..
2101 /* .name = "Capture Source", */
2102 .name = "Input Source",
2104 .info = ad198x_mux_enum_info,
2105 .get = ad198x_mux_enum_get,
2106 .put = ad198x_mux_enum_put,
2111 static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2112 struct snd_ctl_elem_info *uinfo)
2114 static char *texts[] = {
2115 "PCM", "ADC1", "ADC2", "ADC3"
2117 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2119 uinfo->value.enumerated.items = 4;
2120 if (uinfo->value.enumerated.item >= 4)
2121 uinfo->value.enumerated.item = 3;
2122 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2126 static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2127 struct snd_ctl_elem_value *ucontrol)
2129 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2132 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2135 ucontrol->value.enumerated.item[0] = 0;
2137 sel = snd_hda_codec_read(codec, 0x0b, 0,
2138 AC_VERB_GET_CONNECT_SEL, 0);
2143 ucontrol->value.enumerated.item[0] = sel;
2148 static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2149 struct snd_ctl_elem_value *ucontrol)
2151 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2152 unsigned int val, sel;
2155 val = ucontrol->value.enumerated.item[0];
2159 sel = snd_hda_codec_read(codec, 0x1d, 0,
2160 AC_VERB_GET_AMP_GAIN_MUTE,
2162 change = sel & 0x80;
2164 snd_hda_codec_write_cache(codec, 0x1d, 0,
2165 AC_VERB_SET_AMP_GAIN_MUTE,
2167 snd_hda_codec_write_cache(codec, 0x1d, 0,
2168 AC_VERB_SET_AMP_GAIN_MUTE,
2172 sel = snd_hda_codec_read(codec, 0x1d, 0,
2173 AC_VERB_GET_AMP_GAIN_MUTE,
2174 AC_AMP_GET_INPUT | 0x01);
2175 change = sel & 0x80;
2177 snd_hda_codec_write_cache(codec, 0x1d, 0,
2178 AC_VERB_SET_AMP_GAIN_MUTE,
2180 snd_hda_codec_write_cache(codec, 0x1d, 0,
2181 AC_VERB_SET_AMP_GAIN_MUTE,
2184 sel = snd_hda_codec_read(codec, 0x0b, 0,
2185 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2186 change |= sel != val;
2188 snd_hda_codec_write_cache(codec, 0x0b, 0,
2189 AC_VERB_SET_CONNECT_SEL,
2195 static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2196 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2198 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2199 .name = "IEC958 Playback Source",
2200 .info = ad1988_spdif_playback_source_info,
2201 .get = ad1988_spdif_playback_source_get,
2202 .put = ad1988_spdif_playback_source_put,
2207 static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2208 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2212 static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2213 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2214 HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
2219 * initialization verbs
2223 * for 6-stack (+dig)
2225 static struct hda_verb ad1988_6stack_init_verbs[] = {
2226 /* Front, Surround, CLFE, side DAC; unmute as default */
2227 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2228 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2229 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2230 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2231 /* Port-A front headphon path */
2232 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2233 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2234 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2235 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2236 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2237 /* Port-D line-out path */
2238 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2239 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2240 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2241 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2242 /* Port-F surround path */
2243 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2244 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2245 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2246 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2247 /* Port-G CLFE path */
2248 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2249 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2250 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2251 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2252 /* Port-H side path */
2253 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2254 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2255 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2256 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2258 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2259 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2260 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2261 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2262 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2263 /* Port-B front mic-in path */
2264 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2265 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2266 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2267 /* Port-C line-in path */
2268 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2269 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2270 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2271 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2272 /* Port-E mic-in path */
2273 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2274 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2275 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2276 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2277 /* Analog CD Input */
2278 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2279 /* Analog Mix output amp */
2280 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2285 static struct hda_verb ad1988_capture_init_verbs[] = {
2286 /* mute analog mix */
2287 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2288 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2289 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2290 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2291 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2292 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2293 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2294 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2295 /* select ADCs - front-mic */
2296 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2297 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2298 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2303 static struct hda_verb ad1988_spdif_init_verbs[] = {
2305 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2306 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2307 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2308 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2310 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2315 /* AD1989 has no ADC -> SPDIF route */
2316 static struct hda_verb ad1989_spdif_init_verbs[] = {
2317 /* SPDIF-1 out pin */
2318 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2319 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2320 /* SPDIF-2/HDMI out pin */
2321 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2322 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2327 * verbs for 3stack (+dig)
2329 static struct hda_verb ad1988_3stack_ch2_init[] = {
2330 /* set port-C to line-in */
2331 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2332 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2333 /* set port-E to mic-in */
2334 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2335 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2339 static struct hda_verb ad1988_3stack_ch6_init[] = {
2340 /* set port-C to surround out */
2341 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2342 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2343 /* set port-E to CLFE out */
2344 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2345 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2349 static struct hda_channel_mode ad1988_3stack_modes[2] = {
2350 { 2, ad1988_3stack_ch2_init },
2351 { 6, ad1988_3stack_ch6_init },
2354 static struct hda_verb ad1988_3stack_init_verbs[] = {
2355 /* Front, Surround, CLFE, side DAC; unmute as default */
2356 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2357 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2358 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2359 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2360 /* Port-A front headphon path */
2361 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2362 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2363 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2364 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2365 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2366 /* Port-D line-out path */
2367 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2368 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2369 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2370 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2372 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2373 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2374 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2375 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2376 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2377 /* Port-B front mic-in path */
2378 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2379 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2380 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2381 /* Port-C line-in/surround path - 6ch mode as default */
2382 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2383 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2384 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2385 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
2386 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2387 /* Port-E mic-in/CLFE path - 6ch mode as default */
2388 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2389 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2390 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2391 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
2392 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2393 /* mute analog mix */
2394 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2395 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2396 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2397 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2398 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2399 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2400 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2401 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2402 /* select ADCs - front-mic */
2403 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2404 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2405 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2406 /* Analog Mix output amp */
2407 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2412 * verbs for laptop mode (+dig)
2414 static struct hda_verb ad1988_laptop_hp_on[] = {
2415 /* unmute port-A and mute port-D */
2416 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2417 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2420 static struct hda_verb ad1988_laptop_hp_off[] = {
2421 /* mute port-A and unmute port-D */
2422 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2423 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2427 #define AD1988_HP_EVENT 0x01
2429 static struct hda_verb ad1988_laptop_init_verbs[] = {
2430 /* Front, Surround, CLFE, side DAC; unmute as default */
2431 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2432 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2433 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2434 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2435 /* Port-A front headphon path */
2436 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2437 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2438 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2439 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2440 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2441 /* unsolicited event for pin-sense */
2442 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2443 /* Port-D line-out path + EAPD */
2444 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2445 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2446 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2447 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2448 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2450 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2451 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2452 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2453 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2454 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2455 /* Port-B mic-in path */
2456 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2457 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2458 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2459 /* Port-C docking station - try to output */
2460 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2461 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2462 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2463 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2464 /* mute analog mix */
2465 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2466 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2467 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2468 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2469 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2470 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2471 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2472 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2473 /* select ADCs - mic */
2474 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2475 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2476 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2477 /* Analog Mix output amp */
2478 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2482 static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2484 if ((res >> 26) != AD1988_HP_EVENT)
2486 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2487 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2489 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2492 #ifdef CONFIG_SND_HDA_POWER_SAVE
2493 static struct hda_amp_list ad1988_loopbacks[] = {
2494 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2495 { 0x20, HDA_INPUT, 1 }, /* Line */
2496 { 0x20, HDA_INPUT, 4 }, /* Mic */
2497 { 0x20, HDA_INPUT, 6 }, /* CD */
2503 * Automatic parse of I/O pins from the BIOS configuration
2511 static struct snd_kcontrol_new ad1988_control_templates[] = {
2512 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2513 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2514 HDA_BIND_MUTE(NULL, 0, 0, 0),
2517 /* add dynamic controls */
2518 static int add_control(struct ad198x_spec *spec, int type, const char *name,
2521 struct snd_kcontrol_new *knew;
2523 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2524 knew = snd_array_new(&spec->kctls);
2527 *knew = ad1988_control_templates[type];
2528 knew->name = kstrdup(name, GFP_KERNEL);
2531 knew->private_value = val;
2535 #define AD1988_PIN_CD_NID 0x18
2536 #define AD1988_PIN_BEEP_NID 0x10
2538 static hda_nid_t ad1988_mixer_nids[8] = {
2539 /* A B C D E F G H */
2540 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2543 static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2545 static hda_nid_t idx_to_dac[8] = {
2546 /* A B C D E F G H */
2547 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
2549 static hda_nid_t idx_to_dac_rev2[8] = {
2550 /* A B C D E F G H */
2551 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
2554 return idx_to_dac_rev2[idx];
2556 return idx_to_dac[idx];
2559 static hda_nid_t ad1988_boost_nids[8] = {
2560 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2563 static int ad1988_pin_idx(hda_nid_t nid)
2565 static hda_nid_t ad1988_io_pins[8] = {
2566 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2569 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2570 if (ad1988_io_pins[i] == nid)
2572 return 0; /* should be -1 */
2575 static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2577 static int loopback_idx[8] = {
2578 2, 0, 1, 3, 4, 5, 1, 4
2581 case AD1988_PIN_CD_NID:
2584 return loopback_idx[ad1988_pin_idx(nid)];
2588 static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2590 static int adc_idx[8] = {
2591 0, 1, 2, 8, 4, 3, 6, 7
2594 case AD1988_PIN_CD_NID:
2597 return adc_idx[ad1988_pin_idx(nid)];
2601 /* fill in the dac_nids table from the parsed pin configuration */
2602 static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2603 const struct auto_pin_cfg *cfg)
2605 struct ad198x_spec *spec = codec->spec;
2608 spec->multiout.dac_nids = spec->private_dac_nids;
2610 /* check the pins hardwired to audio widget */
2611 for (i = 0; i < cfg->line_outs; i++) {
2612 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2613 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2615 spec->multiout.num_dacs = cfg->line_outs;
2619 /* add playback controls from the parsed DAC table */
2620 static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2621 const struct auto_pin_cfg *cfg)
2624 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2628 for (i = 0; i < cfg->line_outs; i++) {
2629 hda_nid_t dac = spec->multiout.dac_nids[i];
2632 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2635 err = add_control(spec, AD_CTL_WIDGET_VOL,
2636 "Center Playback Volume",
2637 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2640 err = add_control(spec, AD_CTL_WIDGET_VOL,
2641 "LFE Playback Volume",
2642 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2645 err = add_control(spec, AD_CTL_BIND_MUTE,
2646 "Center Playback Switch",
2647 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2650 err = add_control(spec, AD_CTL_BIND_MUTE,
2651 "LFE Playback Switch",
2652 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2656 sprintf(name, "%s Playback Volume", chname[i]);
2657 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2658 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2661 sprintf(name, "%s Playback Switch", chname[i]);
2662 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2663 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2671 /* add playback controls for speaker and HP outputs */
2672 static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2675 struct ad198x_spec *spec = codec->spec;
2683 idx = ad1988_pin_idx(pin);
2684 nid = ad1988_idx_to_dac(codec, idx);
2685 /* check whether the corresponding DAC was already taken */
2686 for (i = 0; i < spec->autocfg.line_outs; i++) {
2687 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2688 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
2692 if (i >= spec->autocfg.line_outs) {
2693 /* specify the DAC as the extra output */
2694 if (!spec->multiout.hp_nid)
2695 spec->multiout.hp_nid = nid;
2697 spec->multiout.extra_out_nid[0] = nid;
2698 /* control HP volume/switch on the output mixer amp */
2699 sprintf(name, "%s Playback Volume", pfx);
2700 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2701 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2705 nid = ad1988_mixer_nids[idx];
2706 sprintf(name, "%s Playback Switch", pfx);
2707 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2708 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2713 /* create input playback/capture controls for the given pin */
2714 static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2715 const char *ctlname, int boost)
2720 sprintf(name, "%s Playback Volume", ctlname);
2721 idx = ad1988_pin_to_loopback_idx(pin);
2722 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2723 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2725 sprintf(name, "%s Playback Switch", ctlname);
2726 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2727 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2731 idx = ad1988_pin_idx(pin);
2732 bnid = ad1988_boost_nids[idx];
2734 sprintf(name, "%s Boost", ctlname);
2735 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2736 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2743 /* create playback/capture controls for input pins */
2744 static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2745 const struct auto_pin_cfg *cfg)
2747 struct hda_input_mux *imux = &spec->private_imux;
2750 for (i = 0; i < AUTO_PIN_LAST; i++) {
2751 err = new_analog_input(spec, cfg->input_pins[i],
2752 auto_pin_cfg_labels[i],
2753 i <= AUTO_PIN_FRONT_MIC);
2756 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2757 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2760 imux->items[imux->num_items].label = "Mix";
2761 imux->items[imux->num_items].index = 9;
2764 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2765 "Analog Mix Playback Volume",
2766 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2768 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2769 "Analog Mix Playback Switch",
2770 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2776 static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2777 hda_nid_t nid, int pin_type,
2781 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2782 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2784 case 0x11: /* port-A - DAC 04 */
2785 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2787 case 0x14: /* port-B - DAC 06 */
2788 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2790 case 0x15: /* port-C - DAC 05 */
2791 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2793 case 0x17: /* port-E - DAC 0a */
2794 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2796 case 0x13: /* mono - DAC 04 */
2797 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2802 static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2804 struct ad198x_spec *spec = codec->spec;
2807 for (i = 0; i < spec->autocfg.line_outs; i++) {
2808 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2809 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2813 static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2815 struct ad198x_spec *spec = codec->spec;
2818 pin = spec->autocfg.speaker_pins[0];
2819 if (pin) /* connect to front */
2820 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2821 pin = spec->autocfg.hp_pins[0];
2822 if (pin) /* connect to front */
2823 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2826 static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2828 struct ad198x_spec *spec = codec->spec;
2831 for (i = 0; i < AUTO_PIN_LAST; i++) {
2832 hda_nid_t nid = spec->autocfg.input_pins[i];
2836 case 0x15: /* port-C */
2837 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2839 case 0x17: /* port-E */
2840 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2843 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2844 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2845 if (nid != AD1988_PIN_CD_NID)
2846 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2848 idx = ad1988_pin_idx(nid);
2849 if (ad1988_boost_nids[idx])
2850 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2851 AC_VERB_SET_AMP_GAIN_MUTE,
2856 /* parse the BIOS configuration and set up the alc_spec */
2857 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2858 static int ad1988_parse_auto_config(struct hda_codec *codec)
2860 struct ad198x_spec *spec = codec->spec;
2863 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2865 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2867 if (! spec->autocfg.line_outs)
2868 return 0; /* can't find valid BIOS pin config */
2869 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2870 (err = ad1988_auto_create_extra_out(codec,
2871 spec->autocfg.speaker_pins[0],
2873 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
2874 "Headphone")) < 0 ||
2875 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2878 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2880 if (spec->autocfg.dig_outs)
2881 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2882 if (spec->autocfg.dig_in_pin)
2883 spec->dig_in_nid = AD1988_SPDIF_IN;
2885 if (spec->kctls.list)
2886 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2888 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2890 spec->input_mux = &spec->private_imux;
2895 /* init callback for auto-configuration model -- overriding the default init */
2896 static int ad1988_auto_init(struct hda_codec *codec)
2899 ad1988_auto_init_multi_out(codec);
2900 ad1988_auto_init_extra_out(codec);
2901 ad1988_auto_init_analog_input(codec);
2909 static const char *ad1988_models[AD1988_MODEL_LAST] = {
2910 [AD1988_6STACK] = "6stack",
2911 [AD1988_6STACK_DIG] = "6stack-dig",
2912 [AD1988_3STACK] = "3stack",
2913 [AD1988_3STACK_DIG] = "3stack-dig",
2914 [AD1988_LAPTOP] = "laptop",
2915 [AD1988_LAPTOP_DIG] = "laptop-dig",
2916 [AD1988_AUTO] = "auto",
2919 static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2920 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
2921 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
2922 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
2923 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
2927 static int patch_ad1988(struct hda_codec *codec)
2929 struct ad198x_spec *spec;
2930 int err, board_config;
2932 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2939 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2941 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
2942 ad1988_models, ad1988_cfg_tbl);
2943 if (board_config < 0) {
2944 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2945 board_config = AD1988_AUTO;
2948 if (board_config == AD1988_AUTO) {
2949 /* automatic parse from the BIOS config */
2950 err = ad1988_parse_auto_config(codec);
2955 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2956 board_config = AD1988_6STACK;
2960 err = snd_hda_attach_beep_device(codec, 0x10);
2965 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
2967 switch (board_config) {
2969 case AD1988_6STACK_DIG:
2970 spec->multiout.max_channels = 8;
2971 spec->multiout.num_dacs = 4;
2973 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2975 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
2976 spec->input_mux = &ad1988_6stack_capture_source;
2977 spec->num_mixers = 2;
2979 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2981 spec->mixers[0] = ad1988_6stack_mixers1;
2982 spec->mixers[1] = ad1988_6stack_mixers2;
2983 spec->num_init_verbs = 1;
2984 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2985 if (board_config == AD1988_6STACK_DIG) {
2986 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2987 spec->dig_in_nid = AD1988_SPDIF_IN;
2991 case AD1988_3STACK_DIG:
2992 spec->multiout.max_channels = 6;
2993 spec->multiout.num_dacs = 3;
2995 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2997 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2998 spec->input_mux = &ad1988_6stack_capture_source;
2999 spec->channel_mode = ad1988_3stack_modes;
3000 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
3001 spec->num_mixers = 2;
3003 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
3005 spec->mixers[0] = ad1988_3stack_mixers1;
3006 spec->mixers[1] = ad1988_3stack_mixers2;
3007 spec->num_init_verbs = 1;
3008 spec->init_verbs[0] = ad1988_3stack_init_verbs;
3009 if (board_config == AD1988_3STACK_DIG)
3010 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3013 case AD1988_LAPTOP_DIG:
3014 spec->multiout.max_channels = 2;
3015 spec->multiout.num_dacs = 1;
3016 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
3017 spec->input_mux = &ad1988_laptop_capture_source;
3018 spec->num_mixers = 1;
3019 spec->mixers[0] = ad1988_laptop_mixers;
3020 spec->num_init_verbs = 1;
3021 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3022 if (board_config == AD1988_LAPTOP_DIG)
3023 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3027 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3028 spec->adc_nids = ad1988_adc_nids;
3029 spec->capsrc_nids = ad1988_capsrc_nids;
3030 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
3031 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
3032 if (spec->multiout.dig_out_nid) {
3033 if (codec->vendor_id >= 0x11d4989a) {
3034 spec->mixers[spec->num_mixers++] =
3035 ad1989_spdif_out_mixers;
3036 spec->init_verbs[spec->num_init_verbs++] =
3037 ad1989_spdif_init_verbs;
3038 codec->slave_dig_outs = ad1989b_slave_dig_outs;
3040 spec->mixers[spec->num_mixers++] =
3041 ad1988_spdif_out_mixers;
3042 spec->init_verbs[spec->num_init_verbs++] =
3043 ad1988_spdif_init_verbs;
3046 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
3047 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
3049 codec->patch_ops = ad198x_patch_ops;
3050 switch (board_config) {
3052 codec->patch_ops.init = ad1988_auto_init;
3055 case AD1988_LAPTOP_DIG:
3056 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
3059 #ifdef CONFIG_SND_HDA_POWER_SAVE
3060 spec->loopback.amplist = ad1988_loopbacks;
3062 spec->vmaster_nid = 0x04;
3071 * port-B - front line/mic-in
3072 * port-E - aux in/out
3073 * port-F - aux in/out
3074 * port-C - rear line/mic-in
3075 * port-D - rear line/hp-out
3076 * port-A - front line/hp-out
3078 * AD1984 = AD1884 + two digital mic-ins
3081 * For simplicity, we share the single DAC for both HP and line-outs
3082 * right now. The inidividual playbacks could be easily implemented,
3083 * but no build-up framework is given, so far.
3086 static hda_nid_t ad1884_dac_nids[1] = {
3090 static hda_nid_t ad1884_adc_nids[2] = {
3094 static hda_nid_t ad1884_capsrc_nids[2] = {
3098 #define AD1884_SPDIF_OUT 0x02
3100 static struct hda_input_mux ad1884_capture_source = {
3103 { "Front Mic", 0x0 },
3110 static struct snd_kcontrol_new ad1884_base_mixers[] = {
3111 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3112 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3113 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3114 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3115 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3116 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3117 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3118 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3119 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3120 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3121 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3122 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3123 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3124 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3125 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3126 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3127 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3128 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3130 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3131 /* The multiple "Capture Source" controls confuse alsamixer
3132 * So call somewhat different..
3134 /* .name = "Capture Source", */
3135 .name = "Input Source",
3137 .info = ad198x_mux_enum_info,
3138 .get = ad198x_mux_enum_get,
3139 .put = ad198x_mux_enum_put,
3141 /* SPDIF controls */
3142 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3144 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3145 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3146 /* identical with ad1983 */
3147 .info = ad1983_spdif_route_info,
3148 .get = ad1983_spdif_route_get,
3149 .put = ad1983_spdif_route_put,
3154 static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3155 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3156 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3157 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
3159 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
3165 * initialization verbs
3167 static struct hda_verb ad1884_init_verbs[] = {
3168 /* DACs; mute as default */
3169 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3170 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3171 /* Port-A (HP) mixer */
3172 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3173 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3175 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3176 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3177 /* HP selector - select DAC2 */
3178 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3179 /* Port-D (Line-out) mixer */
3180 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3181 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3183 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3184 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3185 /* Mono-out mixer */
3186 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3187 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3189 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3190 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3192 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3193 /* Port-B (front mic) pin */
3194 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3195 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3196 /* Port-C (rear mic) pin */
3197 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3198 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3199 /* Analog mixer; mute as default */
3200 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3201 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3202 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3203 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3204 /* Analog Mix output amp */
3205 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3206 /* SPDIF output selector */
3207 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3208 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3212 #ifdef CONFIG_SND_HDA_POWER_SAVE
3213 static struct hda_amp_list ad1884_loopbacks[] = {
3214 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3215 { 0x20, HDA_INPUT, 1 }, /* Mic */
3216 { 0x20, HDA_INPUT, 2 }, /* CD */
3217 { 0x20, HDA_INPUT, 4 }, /* Docking */
3222 static const char *ad1884_slave_vols[] = {
3223 "PCM Playback Volume",
3224 "Mic Playback Volume",
3225 "Mono Playback Volume",
3226 "Front Mic Playback Volume",
3227 "Mic Playback Volume",
3228 "CD Playback Volume",
3229 "Internal Mic Playback Volume",
3230 "Docking Mic Playback Volume",
3231 /* "Beep Playback Volume", */
3232 "IEC958 Playback Volume",
3236 static int patch_ad1884(struct hda_codec *codec)
3238 struct ad198x_spec *spec;
3241 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3247 err = snd_hda_attach_beep_device(codec, 0x10);
3252 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3254 spec->multiout.max_channels = 2;
3255 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3256 spec->multiout.dac_nids = ad1884_dac_nids;
3257 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3258 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3259 spec->adc_nids = ad1884_adc_nids;
3260 spec->capsrc_nids = ad1884_capsrc_nids;
3261 spec->input_mux = &ad1884_capture_source;
3262 spec->num_mixers = 1;
3263 spec->mixers[0] = ad1884_base_mixers;
3264 spec->num_init_verbs = 1;
3265 spec->init_verbs[0] = ad1884_init_verbs;
3266 spec->spdif_route = 0;
3267 #ifdef CONFIG_SND_HDA_POWER_SAVE
3268 spec->loopback.amplist = ad1884_loopbacks;
3270 spec->vmaster_nid = 0x04;
3271 /* we need to cover all playback volumes */
3272 spec->slave_vols = ad1884_slave_vols;
3274 codec->patch_ops = ad198x_patch_ops;
3280 * Lenovo Thinkpad T61/X61
3282 static struct hda_input_mux ad1984_thinkpad_capture_source = {
3286 { "Internal Mic", 0x1 },
3288 { "Docking-Station", 0x4 },
3294 * Dell Precision T3400
3296 static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3299 { "Front Mic", 0x0 },
3306 static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3307 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3308 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3309 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3310 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3311 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3312 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3313 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3314 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3315 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3316 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3317 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3318 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3319 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3320 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3321 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3322 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3323 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3325 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3326 /* The multiple "Capture Source" controls confuse alsamixer
3327 * So call somewhat different..
3329 /* .name = "Capture Source", */
3330 .name = "Input Source",
3332 .info = ad198x_mux_enum_info,
3333 .get = ad198x_mux_enum_get,
3334 .put = ad198x_mux_enum_put,
3336 /* SPDIF controls */
3337 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3339 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3340 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3341 /* identical with ad1983 */
3342 .info = ad1983_spdif_route_info,
3343 .get = ad1983_spdif_route_get,
3344 .put = ad1983_spdif_route_put,
3349 /* additional verbs */
3350 static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3351 /* Port-E (docking station mic) pin */
3352 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3353 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3354 /* docking mic boost */
3355 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3356 /* Analog mixer - docking mic; mute as default */
3357 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3358 /* enable EAPD bit */
3359 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3364 * Dell Precision T3400
3366 static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3367 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3368 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3369 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3370 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3371 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3372 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3373 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3374 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3375 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
3376 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3377 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3378 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3379 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3380 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3381 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3383 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3384 /* The multiple "Capture Source" controls confuse alsamixer
3385 * So call somewhat different..
3387 /* .name = "Capture Source", */
3388 .name = "Input Source",
3390 .info = ad198x_mux_enum_info,
3391 .get = ad198x_mux_enum_get,
3392 .put = ad198x_mux_enum_put,
3397 /* Digial MIC ADC NID 0x05 + 0x06 */
3398 static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3399 struct hda_codec *codec,
3400 unsigned int stream_tag,
3401 unsigned int format,
3402 struct snd_pcm_substream *substream)
3404 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3405 stream_tag, 0, format);
3409 static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3410 struct hda_codec *codec,
3411 struct snd_pcm_substream *substream)
3413 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
3417 static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3423 .prepare = ad1984_pcm_dmic_prepare,
3424 .cleanup = ad1984_pcm_dmic_cleanup
3428 static int ad1984_build_pcms(struct hda_codec *codec)
3430 struct ad198x_spec *spec = codec->spec;
3431 struct hda_pcm *info;
3434 err = ad198x_build_pcms(codec);
3438 info = spec->pcm_rec + codec->num_pcms;
3440 info->name = "AD1984 Digital Mic";
3441 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3449 AD1984_DELL_DESKTOP,
3453 static const char *ad1984_models[AD1984_MODELS] = {
3454 [AD1984_BASIC] = "basic",
3455 [AD1984_THINKPAD] = "thinkpad",
3456 [AD1984_DELL_DESKTOP] = "dell_desktop",
3459 static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3460 /* Lenovo Thinkpad T61/X61 */
3461 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
3462 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
3466 static int patch_ad1984(struct hda_codec *codec)
3468 struct ad198x_spec *spec;
3469 int board_config, err;
3471 err = patch_ad1884(codec);
3475 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3476 ad1984_models, ad1984_cfg_tbl);
3477 switch (board_config) {
3479 /* additional digital mics */
3480 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3481 codec->patch_ops.build_pcms = ad1984_build_pcms;
3483 case AD1984_THINKPAD:
3484 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3485 spec->input_mux = &ad1984_thinkpad_capture_source;
3486 spec->mixers[0] = ad1984_thinkpad_mixers;
3487 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3489 case AD1984_DELL_DESKTOP:
3490 spec->multiout.dig_out_nid = 0;
3491 spec->input_mux = &ad1984_dell_desktop_capture_source;
3492 spec->mixers[0] = ad1984_dell_desktop_mixers;
3500 * AD1883 / AD1884A / AD1984A / AD1984B
3502 * port-B (0x14) - front mic-in
3503 * port-E (0x1c) - rear mic-in
3504 * port-F (0x16) - CD / ext out
3505 * port-C (0x15) - rear line-in
3506 * port-D (0x12) - rear line-out
3507 * port-A (0x11) - front hp-out
3509 * AD1984A = AD1884A + digital-mic
3510 * AD1883 = equivalent with AD1984A
3511 * AD1984B = AD1984A + extra SPDIF-out
3514 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3517 static hda_nid_t ad1884a_dac_nids[1] = {
3521 #define ad1884a_adc_nids ad1884_adc_nids
3522 #define ad1884a_capsrc_nids ad1884_capsrc_nids
3524 #define AD1884A_SPDIF_OUT 0x02
3526 static struct hda_input_mux ad1884a_capture_source = {
3529 { "Front Mic", 0x0 },
3537 static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3538 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3539 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3540 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3541 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3542 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3543 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3544 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3545 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3546 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3547 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3548 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3549 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3550 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3551 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3552 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3553 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3554 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3555 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3556 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3557 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3558 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3559 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3560 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3562 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3563 /* The multiple "Capture Source" controls confuse alsamixer
3564 * So call somewhat different..
3566 /* .name = "Capture Source", */
3567 .name = "Input Source",
3569 .info = ad198x_mux_enum_info,
3570 .get = ad198x_mux_enum_get,
3571 .put = ad198x_mux_enum_put,
3573 /* SPDIF controls */
3574 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3576 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3577 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3578 /* identical with ad1983 */
3579 .info = ad1983_spdif_route_info,
3580 .get = ad1983_spdif_route_get,
3581 .put = ad1983_spdif_route_put,
3587 * initialization verbs
3589 static struct hda_verb ad1884a_init_verbs[] = {
3590 /* DACs; unmute as default */
3591 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3592 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3593 /* Port-A (HP) mixer - route only from analog mixer */
3594 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3595 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3597 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3598 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3599 /* Port-D (Line-out) mixer - route only from analog mixer */
3600 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3601 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3603 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3604 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3605 /* Mono-out mixer - route only from analog mixer */
3606 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3607 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3609 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3610 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3611 /* Port-B (front mic) pin */
3612 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3613 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3614 /* Port-C (rear line-in) pin */
3615 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3616 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3617 /* Port-E (rear mic) pin */
3618 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3619 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3620 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3621 /* Port-F (CD) pin */
3622 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3623 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3624 /* Analog mixer; mute as default */
3625 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3626 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3627 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3628 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3629 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3630 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3631 /* Analog Mix output amp */
3632 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3633 /* capture sources */
3634 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3635 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3636 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3637 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3638 /* SPDIF output amp */
3639 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3643 #ifdef CONFIG_SND_HDA_POWER_SAVE
3644 static struct hda_amp_list ad1884a_loopbacks[] = {
3645 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3646 { 0x20, HDA_INPUT, 1 }, /* Mic */
3647 { 0x20, HDA_INPUT, 2 }, /* CD */
3648 { 0x20, HDA_INPUT, 4 }, /* Docking */
3656 * Port A: Headphone jack
3658 * Port C: Internal MIC
3659 * Port D: Dock Line Out (if enabled)
3660 * Port E: Dock Line In (if enabled)
3661 * Port F: Internal speakers
3664 static struct hda_input_mux ad1884a_laptop_capture_source = {
3667 { "Mic", 0x0 }, /* port-B */
3668 { "Internal Mic", 0x1 }, /* port-C */
3669 { "Dock Mic", 0x4 }, /* port-E */
3674 static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3675 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3676 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3677 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3678 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3679 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3680 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3681 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3682 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3683 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3684 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3685 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3686 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3687 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3688 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3689 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3690 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3691 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3692 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3694 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3695 /* The multiple "Capture Source" controls confuse alsamixer
3696 * So call somewhat different..
3698 /* .name = "Capture Source", */
3699 .name = "Input Source",
3701 .info = ad198x_mux_enum_info,
3702 .get = ad198x_mux_enum_get,
3703 .put = ad198x_mux_enum_put,
3708 static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3709 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3710 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3711 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3712 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3713 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
3714 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
3715 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3716 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3720 /* mute internal speaker if HP is plugged */
3721 static void ad1884a_hp_automute(struct hda_codec *codec)
3723 unsigned int present;
3725 present = snd_hda_codec_read(codec, 0x11, 0,
3726 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3727 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3728 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3729 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3730 present ? 0x00 : 0x02);
3733 /* switch to external mic if plugged */
3734 static void ad1884a_hp_automic(struct hda_codec *codec)
3736 unsigned int present;
3738 present = snd_hda_codec_read(codec, 0x14, 0,
3739 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3740 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3744 #define AD1884A_HP_EVENT 0x37
3745 #define AD1884A_MIC_EVENT 0x36
3747 /* unsolicited event for HP jack sensing */
3748 static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3750 switch (res >> 26) {
3751 case AD1884A_HP_EVENT:
3752 ad1884a_hp_automute(codec);
3754 case AD1884A_MIC_EVENT:
3755 ad1884a_hp_automic(codec);
3760 /* initialize jack-sensing, too */
3761 static int ad1884a_hp_init(struct hda_codec *codec)
3764 ad1884a_hp_automute(codec);
3765 ad1884a_hp_automic(codec);
3769 /* additional verbs for laptop model */
3770 static struct hda_verb ad1884a_laptop_verbs[] = {
3771 /* Port-A (HP) pin - always unmuted */
3772 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3773 /* Port-F (int speaker) mixer - route only from analog mixer */
3774 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3775 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3777 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3778 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3779 /* Port-C pin - internal mic-in */
3780 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3781 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3782 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3784 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3785 /* unsolicited event for pin-sense */
3786 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3787 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3791 static struct hda_verb ad1884a_mobile_verbs[] = {
3792 /* DACs; unmute as default */
3793 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3794 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3795 /* Port-A (HP) mixer - route only from analog mixer */
3796 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3797 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3799 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3800 /* Port-A (HP) pin - always unmuted */
3801 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3802 /* Port-B (mic jack) pin */
3803 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3804 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3805 /* Port-C (int mic) pin */
3806 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3807 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3808 /* Port-F (int speaker) mixer - route only from analog mixer */
3809 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3810 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3812 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3813 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3814 /* Analog mixer; mute as default */
3815 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3816 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3817 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3818 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3819 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3820 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3821 /* Analog Mix output amp */
3822 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3823 /* capture sources */
3824 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
3825 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3826 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3827 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3828 /* unsolicited event for pin-sense */
3829 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3830 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3839 * 0x17 - built-in mic
3842 static struct hda_verb ad1984a_thinkpad_verbs[] = {
3844 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3846 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3848 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3849 /* unsolicited event for pin-sense */
3850 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3851 /* internal mic - dmic */
3852 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3853 /* set magic COEFs for dmic */
3854 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3855 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
3859 static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3860 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3861 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3862 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3863 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3864 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3865 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3866 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3867 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3868 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3869 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3871 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3872 .name = "Capture Source",
3873 .info = ad198x_mux_enum_info,
3874 .get = ad198x_mux_enum_get,
3875 .put = ad198x_mux_enum_put,
3880 static struct hda_input_mux ad1984a_thinkpad_capture_source = {
3884 { "Internal Mic", 0x5 },
3889 /* mute internal speaker if HP is plugged */
3890 static void ad1984a_thinkpad_automute(struct hda_codec *codec)
3892 unsigned int present;
3894 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0)
3895 & AC_PINSENSE_PRESENCE;
3896 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
3897 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3900 /* unsolicited event for HP jack sensing */
3901 static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
3904 if ((res >> 26) != AD1884A_HP_EVENT)
3906 ad1984a_thinkpad_automute(codec);
3909 /* initialize jack-sensing, too */
3910 static int ad1984a_thinkpad_init(struct hda_codec *codec)
3913 ad1984a_thinkpad_automute(codec);
3928 static const char *ad1884a_models[AD1884A_MODELS] = {
3929 [AD1884A_DESKTOP] = "desktop",
3930 [AD1884A_LAPTOP] = "laptop",
3931 [AD1884A_MOBILE] = "mobile",
3932 [AD1884A_THINKPAD] = "thinkpad",
3935 static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3936 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
3937 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
3938 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
3939 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
3940 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
3941 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
3942 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
3946 static int patch_ad1884a(struct hda_codec *codec)
3948 struct ad198x_spec *spec;
3949 int err, board_config;
3951 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3957 err = snd_hda_attach_beep_device(codec, 0x10);
3962 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3964 spec->multiout.max_channels = 2;
3965 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
3966 spec->multiout.dac_nids = ad1884a_dac_nids;
3967 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
3968 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
3969 spec->adc_nids = ad1884a_adc_nids;
3970 spec->capsrc_nids = ad1884a_capsrc_nids;
3971 spec->input_mux = &ad1884a_capture_source;
3972 spec->num_mixers = 1;
3973 spec->mixers[0] = ad1884a_base_mixers;
3974 spec->num_init_verbs = 1;
3975 spec->init_verbs[0] = ad1884a_init_verbs;
3976 spec->spdif_route = 0;
3977 #ifdef CONFIG_SND_HDA_POWER_SAVE
3978 spec->loopback.amplist = ad1884a_loopbacks;
3980 codec->patch_ops = ad198x_patch_ops;
3982 /* override some parameters */
3983 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
3986 switch (board_config) {
3987 case AD1884A_LAPTOP:
3988 spec->mixers[0] = ad1884a_laptop_mixers;
3989 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3990 spec->multiout.dig_out_nid = 0;
3991 spec->input_mux = &ad1884a_laptop_capture_source;
3992 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3993 codec->patch_ops.init = ad1884a_hp_init;
3994 /* set the upper-limit for mixer amp to 0dB for avoiding the
3995 * possible damage by overloading
3997 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
3998 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3999 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4000 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4001 (1 << AC_AMPCAP_MUTE_SHIFT));
4003 case AD1884A_MOBILE:
4004 spec->mixers[0] = ad1884a_mobile_mixers;
4005 spec->init_verbs[0] = ad1884a_mobile_verbs;
4006 spec->multiout.dig_out_nid = 0;
4007 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
4008 codec->patch_ops.init = ad1884a_hp_init;
4009 /* set the upper-limit for mixer amp to 0dB for avoiding the
4010 * possible damage by overloading
4012 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4013 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4014 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4015 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4016 (1 << AC_AMPCAP_MUTE_SHIFT));
4018 case AD1884A_THINKPAD:
4019 spec->mixers[0] = ad1984a_thinkpad_mixers;
4020 spec->init_verbs[spec->num_init_verbs++] =
4021 ad1984a_thinkpad_verbs;
4022 spec->multiout.dig_out_nid = 0;
4023 spec->input_mux = &ad1984a_thinkpad_capture_source;
4024 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
4025 codec->patch_ops.init = ad1984a_thinkpad_init;
4036 * port-A - front hp-out
4037 * port-B - front mic-in
4038 * port-C - rear line-in, shared surr-out (3stack)
4039 * port-D - rear line-out
4040 * port-E - rear mic-in, shared clfe-out (3stack)
4041 * port-F - rear surr-out (6stack)
4042 * port-G - rear clfe-out (6stack)
4045 static hda_nid_t ad1882_dac_nids[3] = {
4049 static hda_nid_t ad1882_adc_nids[2] = {
4053 static hda_nid_t ad1882_capsrc_nids[2] = {
4057 #define AD1882_SPDIF_OUT 0x02
4059 /* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
4060 static struct hda_input_mux ad1882_capture_source = {
4063 { "Front Mic", 0x1 },
4071 /* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
4072 static struct hda_input_mux ad1882a_capture_source = {
4075 { "Front Mic", 0x1 },
4078 { "Digital Mic", 0x06 },
4083 static struct snd_kcontrol_new ad1882_base_mixers[] = {
4084 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
4085 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
4086 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
4087 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
4088 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
4089 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4090 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4091 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
4093 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
4094 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
4095 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
4096 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4097 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4098 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
4099 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
4101 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4102 /* The multiple "Capture Source" controls confuse alsamixer
4103 * So call somewhat different..
4105 /* .name = "Capture Source", */
4106 .name = "Input Source",
4108 .info = ad198x_mux_enum_info,
4109 .get = ad198x_mux_enum_get,
4110 .put = ad198x_mux_enum_put,
4112 /* SPDIF controls */
4113 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
4115 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4116 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4117 /* identical with ad1983 */
4118 .info = ad1983_spdif_route_info,
4119 .get = ad1983_spdif_route_get,
4120 .put = ad1983_spdif_route_put,
4125 static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4126 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4127 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4128 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4129 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4130 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4131 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4132 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4133 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4137 static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4138 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4139 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4140 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4141 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4142 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4143 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4144 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4145 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4146 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT),
4150 static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
4151 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4152 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
4153 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
4155 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4156 .name = "Channel Mode",
4157 .info = ad198x_ch_mode_info,
4158 .get = ad198x_ch_mode_get,
4159 .put = ad198x_ch_mode_put,
4164 static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
4165 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4166 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4167 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4171 static struct hda_verb ad1882_ch2_init[] = {
4172 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4173 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4174 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4175 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4176 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4177 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4181 static struct hda_verb ad1882_ch4_init[] = {
4182 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4183 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4184 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4185 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4186 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4187 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4191 static struct hda_verb ad1882_ch6_init[] = {
4192 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4193 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4194 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4195 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4196 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4197 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4201 static struct hda_channel_mode ad1882_modes[3] = {
4202 { 2, ad1882_ch2_init },
4203 { 4, ad1882_ch4_init },
4204 { 6, ad1882_ch6_init },
4208 * initialization verbs
4210 static struct hda_verb ad1882_init_verbs[] = {
4211 /* DACs; mute as default */
4212 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4213 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4214 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4215 /* Port-A (HP) mixer */
4216 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4217 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4219 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4220 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4221 /* HP selector - select DAC2 */
4222 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4223 /* Port-D (Line-out) mixer */
4224 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4225 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4227 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4228 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4229 /* Mono-out mixer */
4230 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4231 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4233 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4234 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4235 /* Port-B (front mic) pin */
4236 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4237 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4238 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4239 /* Port-C (line-in) pin */
4240 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4241 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4242 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4243 /* Port-C mixer - mute as input */
4244 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4245 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4246 /* Port-E (mic-in) pin */
4247 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4248 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4249 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4250 /* Port-E mixer - mute as input */
4251 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4252 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4253 /* Port-F (surround) */
4254 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4255 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4257 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4258 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4259 /* Analog mixer; mute as default */
4260 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4261 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4262 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4263 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4264 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4265 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4266 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4267 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4268 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4269 /* Analog Mix output amp */
4270 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4271 /* SPDIF output selector */
4272 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4273 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4274 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4278 #ifdef CONFIG_SND_HDA_POWER_SAVE
4279 static struct hda_amp_list ad1882_loopbacks[] = {
4280 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4281 { 0x20, HDA_INPUT, 1 }, /* Mic */
4282 { 0x20, HDA_INPUT, 4 }, /* Line */
4283 { 0x20, HDA_INPUT, 6 }, /* CD */
4295 static const char *ad1882_models[AD1986A_MODELS] = {
4296 [AD1882_3STACK] = "3stack",
4297 [AD1882_6STACK] = "6stack",
4301 static int patch_ad1882(struct hda_codec *codec)
4303 struct ad198x_spec *spec;
4304 int err, board_config;
4306 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4312 err = snd_hda_attach_beep_device(codec, 0x10);
4317 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4319 spec->multiout.max_channels = 6;
4320 spec->multiout.num_dacs = 3;
4321 spec->multiout.dac_nids = ad1882_dac_nids;
4322 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4323 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4324 spec->adc_nids = ad1882_adc_nids;
4325 spec->capsrc_nids = ad1882_capsrc_nids;
4326 if (codec->vendor_id == 0x11d41882)
4327 spec->input_mux = &ad1882_capture_source;
4329 spec->input_mux = &ad1882a_capture_source;
4330 spec->num_mixers = 2;
4331 spec->mixers[0] = ad1882_base_mixers;
4332 if (codec->vendor_id == 0x11d41882)
4333 spec->mixers[1] = ad1882_loopback_mixers;
4335 spec->mixers[1] = ad1882a_loopback_mixers;
4336 spec->num_init_verbs = 1;
4337 spec->init_verbs[0] = ad1882_init_verbs;
4338 spec->spdif_route = 0;
4339 #ifdef CONFIG_SND_HDA_POWER_SAVE
4340 spec->loopback.amplist = ad1882_loopbacks;
4342 spec->vmaster_nid = 0x04;
4344 codec->patch_ops = ad198x_patch_ops;
4346 /* override some parameters */
4347 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4348 ad1882_models, NULL);
4349 switch (board_config) {
4352 spec->num_mixers = 3;
4353 spec->mixers[2] = ad1882_3stack_mixers;
4354 spec->channel_mode = ad1882_modes;
4355 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4356 spec->need_dac_fix = 1;
4357 spec->multiout.max_channels = 2;
4358 spec->multiout.num_dacs = 1;
4361 spec->num_mixers = 3;
4362 spec->mixers[2] = ad1882_6stack_mixers;
4372 static struct hda_codec_preset snd_hda_preset_analog[] = {
4373 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
4374 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
4375 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
4376 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
4377 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4378 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
4379 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4380 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
4381 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
4382 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
4383 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
4384 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
4385 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
4386 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4387 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
4391 MODULE_ALIAS("snd-hda-codec-id:11d4*");
4393 MODULE_LICENSE("GPL");
4394 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
4396 static struct hda_codec_preset_list analog_list = {
4397 .preset = snd_hda_preset_analog,
4398 .owner = THIS_MODULE,
4401 static int __init patch_analog_init(void)
4403 return snd_hda_add_codec_preset(&analog_list);
4406 static void __exit patch_analog_exit(void)
4408 snd_hda_delete_codec_preset(&analog_list);
4411 module_init(patch_analog_init)
4412 module_exit(patch_analog_exit)