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"
32 struct snd_kcontrol_new *mixers[5];
35 const struct hda_verb *init_verbs[5]; /* initialization verbs
36 * don't forget NULL termination!
38 unsigned int num_init_verbs;
41 struct hda_multi_out multiout; /* playback set-up
42 * max_channels, dacs must be set
43 * dig_out_nid and hp_nid are optional
45 unsigned int cur_eapd;
46 unsigned int need_dac_fix;
49 unsigned int num_adc_nids;
51 hda_nid_t dig_in_nid; /* digital-in NID; optional */
54 const struct hda_input_mux *input_mux;
55 hda_nid_t *capsrc_nids;
56 unsigned int cur_mux[3];
59 const struct hda_channel_mode *channel_mode;
63 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
65 unsigned int spdif_route;
67 /* dynamic controls, init_verbs and input_mux */
68 struct auto_pin_cfg autocfg;
69 struct snd_array kctls;
70 struct hda_input_mux private_imux;
71 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
73 unsigned int jack_present :1;
75 #ifdef CONFIG_SND_HDA_POWER_SAVE
76 struct hda_loopback_check loopback;
78 /* for virtual master */
79 hda_nid_t vmaster_nid;
80 const char **slave_vols;
81 const char **slave_sws;
85 * input MUX handling (common part)
87 static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
89 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
90 struct ad198x_spec *spec = codec->spec;
92 return snd_hda_input_mux_info(spec->input_mux, uinfo);
95 static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
97 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
98 struct ad198x_spec *spec = codec->spec;
99 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
101 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
105 static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
107 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
108 struct ad198x_spec *spec = codec->spec;
109 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
111 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
112 spec->capsrc_nids[adc_idx],
113 &spec->cur_mux[adc_idx]);
117 * initialization (common callbacks)
119 static int ad198x_init(struct hda_codec *codec)
121 struct ad198x_spec *spec = codec->spec;
124 for (i = 0; i < spec->num_init_verbs; i++)
125 snd_hda_sequence_write(codec, spec->init_verbs[i]);
129 static const char *ad_slave_vols[] = {
130 "Front Playback Volume",
131 "Surround Playback Volume",
132 "Center Playback Volume",
133 "LFE Playback Volume",
134 "Side Playback Volume",
135 "Headphone Playback Volume",
136 "Mono Playback Volume",
137 "Speaker Playback Volume",
138 "IEC958 Playback Volume",
142 static const char *ad_slave_sws[] = {
143 "Front Playback Switch",
144 "Surround Playback Switch",
145 "Center Playback Switch",
146 "LFE Playback Switch",
147 "Side Playback Switch",
148 "Headphone Playback Switch",
149 "Mono Playback Switch",
150 "Speaker Playback Switch",
151 "IEC958 Playback Switch",
155 static void ad198x_free_kctls(struct hda_codec *codec);
157 static int ad198x_build_controls(struct hda_codec *codec)
159 struct ad198x_spec *spec = codec->spec;
163 for (i = 0; i < spec->num_mixers; i++) {
164 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
168 if (spec->multiout.dig_out_nid) {
169 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
172 err = snd_hda_create_spdif_share_sw(codec,
176 spec->multiout.share_spdif = 1;
178 if (spec->dig_in_nid) {
179 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
184 /* if we have no master control, let's create it */
185 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
186 unsigned int vmaster_tlv[4];
187 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
188 HDA_OUTPUT, vmaster_tlv);
189 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
192 spec->slave_vols : ad_slave_vols));
196 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
197 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
200 spec->slave_sws : ad_slave_sws));
205 ad198x_free_kctls(codec); /* no longer needed */
209 #ifdef CONFIG_SND_HDA_POWER_SAVE
210 static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
212 struct ad198x_spec *spec = codec->spec;
213 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
218 * Analog playback callbacks
220 static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
221 struct hda_codec *codec,
222 struct snd_pcm_substream *substream)
224 struct ad198x_spec *spec = codec->spec;
225 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
229 static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
230 struct hda_codec *codec,
231 unsigned int stream_tag,
233 struct snd_pcm_substream *substream)
235 struct ad198x_spec *spec = codec->spec;
236 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
240 static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
241 struct hda_codec *codec,
242 struct snd_pcm_substream *substream)
244 struct ad198x_spec *spec = codec->spec;
245 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
251 static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
252 struct hda_codec *codec,
253 struct snd_pcm_substream *substream)
255 struct ad198x_spec *spec = codec->spec;
256 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
259 static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
260 struct hda_codec *codec,
261 struct snd_pcm_substream *substream)
263 struct ad198x_spec *spec = codec->spec;
264 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
267 static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
268 struct hda_codec *codec,
269 unsigned int stream_tag,
271 struct snd_pcm_substream *substream)
273 struct ad198x_spec *spec = codec->spec;
274 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
281 static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
282 struct hda_codec *codec,
283 unsigned int stream_tag,
285 struct snd_pcm_substream *substream)
287 struct ad198x_spec *spec = codec->spec;
288 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
289 stream_tag, 0, format);
293 static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
294 struct hda_codec *codec,
295 struct snd_pcm_substream *substream)
297 struct ad198x_spec *spec = codec->spec;
298 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
305 static struct hda_pcm_stream ad198x_pcm_analog_playback = {
308 .channels_max = 6, /* changed later */
309 .nid = 0, /* fill later */
311 .open = ad198x_playback_pcm_open,
312 .prepare = ad198x_playback_pcm_prepare,
313 .cleanup = ad198x_playback_pcm_cleanup
317 static struct hda_pcm_stream ad198x_pcm_analog_capture = {
321 .nid = 0, /* fill later */
323 .prepare = ad198x_capture_pcm_prepare,
324 .cleanup = ad198x_capture_pcm_cleanup
328 static struct hda_pcm_stream ad198x_pcm_digital_playback = {
332 .nid = 0, /* fill later */
334 .open = ad198x_dig_playback_pcm_open,
335 .close = ad198x_dig_playback_pcm_close,
336 .prepare = ad198x_dig_playback_pcm_prepare
340 static struct hda_pcm_stream ad198x_pcm_digital_capture = {
344 /* NID is set in alc_build_pcms */
347 static int ad198x_build_pcms(struct hda_codec *codec)
349 struct ad198x_spec *spec = codec->spec;
350 struct hda_pcm *info = spec->pcm_rec;
353 codec->pcm_info = info;
355 info->name = "AD198x Analog";
356 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
357 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
358 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
359 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
360 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
361 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
363 if (spec->multiout.dig_out_nid) {
366 info->name = "AD198x Digital";
367 info->pcm_type = HDA_PCM_TYPE_SPDIF;
368 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
369 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
370 if (spec->dig_in_nid) {
371 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
372 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
379 static void ad198x_free_kctls(struct hda_codec *codec)
381 struct ad198x_spec *spec = codec->spec;
383 if (spec->kctls.list) {
384 struct snd_kcontrol_new *kctl = spec->kctls.list;
386 for (i = 0; i < spec->kctls.used; i++)
389 snd_array_free(&spec->kctls);
392 static void ad198x_free(struct hda_codec *codec)
394 struct ad198x_spec *spec = codec->spec;
399 ad198x_free_kctls(codec);
403 static struct hda_codec_ops ad198x_patch_ops = {
404 .build_controls = ad198x_build_controls,
405 .build_pcms = ad198x_build_pcms,
408 #ifdef CONFIG_SND_HDA_POWER_SAVE
409 .check_power_status = ad198x_check_power_status,
416 * the private value = nid | (invert << 8)
418 #define ad198x_eapd_info snd_ctl_boolean_mono_info
420 static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
421 struct snd_ctl_elem_value *ucontrol)
423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
424 struct ad198x_spec *spec = codec->spec;
425 int invert = (kcontrol->private_value >> 8) & 1;
427 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
429 ucontrol->value.integer.value[0] = spec->cur_eapd;
433 static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
434 struct snd_ctl_elem_value *ucontrol)
436 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
437 struct ad198x_spec *spec = codec->spec;
438 int invert = (kcontrol->private_value >> 8) & 1;
439 hda_nid_t nid = kcontrol->private_value & 0xff;
441 eapd = !!ucontrol->value.integer.value[0];
444 if (eapd == spec->cur_eapd)
446 spec->cur_eapd = eapd;
447 snd_hda_codec_write_cache(codec, nid,
448 0, AC_VERB_SET_EAPD_BTLENABLE,
453 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
454 struct snd_ctl_elem_info *uinfo);
455 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
456 struct snd_ctl_elem_value *ucontrol);
457 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
458 struct snd_ctl_elem_value *ucontrol);
465 #define AD1986A_SPDIF_OUT 0x02
466 #define AD1986A_FRONT_DAC 0x03
467 #define AD1986A_SURR_DAC 0x04
468 #define AD1986A_CLFE_DAC 0x05
469 #define AD1986A_ADC 0x06
471 static hda_nid_t ad1986a_dac_nids[3] = {
472 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
474 static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
475 static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
477 static struct hda_input_mux ad1986a_capture_source = {
491 static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
492 .ops = &snd_hda_bind_vol,
494 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
495 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
496 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
501 static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
502 .ops = &snd_hda_bind_sw,
504 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
505 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
506 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
514 static struct snd_kcontrol_new ad1986a_mixers[] = {
516 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
518 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
519 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
520 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
521 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
522 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
523 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
524 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
525 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
526 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
527 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
528 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
529 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
530 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
531 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
532 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
533 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
534 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
535 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
536 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
537 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
538 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
539 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
540 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
541 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
542 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
543 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
544 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
546 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
547 .name = "Capture Source",
548 .info = ad198x_mux_enum_info,
549 .get = ad198x_mux_enum_get,
550 .put = ad198x_mux_enum_put,
552 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
556 /* additional mixers for 3stack mode */
557 static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
559 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
560 .name = "Channel Mode",
561 .info = ad198x_ch_mode_info,
562 .get = ad198x_ch_mode_get,
563 .put = ad198x_ch_mode_put,
568 /* laptop model - 2ch only */
569 static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
571 /* master controls both pins 0x1a and 0x1b */
572 static struct hda_bind_ctls ad1986a_laptop_master_vol = {
573 .ops = &snd_hda_bind_vol,
575 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
576 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
581 static struct hda_bind_ctls ad1986a_laptop_master_sw = {
582 .ops = &snd_hda_bind_sw,
584 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
585 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
590 static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
591 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
592 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
593 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
594 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
595 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
596 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
597 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
598 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
599 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
600 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
601 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
602 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
603 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
604 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
605 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
606 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
607 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
608 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
609 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
611 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
612 .name = "Capture Source",
613 .info = ad198x_mux_enum_info,
614 .get = ad198x_mux_enum_get,
615 .put = ad198x_mux_enum_put,
620 /* laptop-eapd model - 2ch only */
622 static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
626 { "Internal Mic", 0x4 },
631 static struct hda_input_mux ad1986a_automic_capture_source = {
639 static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
640 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
641 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
642 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
643 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
644 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
645 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
646 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
647 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
648 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
649 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
650 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
652 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
653 .name = "Capture Source",
654 .info = ad198x_mux_enum_info,
655 .get = ad198x_mux_enum_get,
656 .put = ad198x_mux_enum_put,
659 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
660 .name = "External Amplifier",
661 .info = ad198x_eapd_info,
662 .get = ad198x_eapd_get,
663 .put = ad198x_eapd_put,
664 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
669 static struct snd_kcontrol_new ad1986a_samsung_mixers[] = {
670 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
671 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
672 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
673 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
674 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
675 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
676 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
677 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
678 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
680 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
681 .name = "Capture Source",
682 .info = ad198x_mux_enum_info,
683 .get = ad198x_mux_enum_get,
684 .put = ad198x_mux_enum_put,
687 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
688 .name = "External Amplifier",
689 .info = ad198x_eapd_info,
690 .get = ad198x_eapd_get,
691 .put = ad198x_eapd_put,
692 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
697 /* re-connect the mic boost input according to the jack sensing */
698 static void ad1986a_automic(struct hda_codec *codec)
700 unsigned int present;
701 present = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_PIN_SENSE, 0);
702 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
703 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
704 (present & AC_PINSENSE_PRESENCE) ? 0 : 2);
707 #define AD1986A_MIC_EVENT 0x36
709 static void ad1986a_automic_unsol_event(struct hda_codec *codec,
712 if ((res >> 26) != AD1986A_MIC_EVENT)
714 ad1986a_automic(codec);
717 static int ad1986a_automic_init(struct hda_codec *codec)
720 ad1986a_automic(codec);
724 /* laptop-automute - 2ch only */
726 static void ad1986a_update_hp(struct hda_codec *codec)
728 struct ad198x_spec *spec = codec->spec;
731 if (spec->jack_present)
732 mute = HDA_AMP_MUTE; /* mute internal speaker */
734 /* unmute internal speaker if necessary */
735 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
736 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
740 static void ad1986a_hp_automute(struct hda_codec *codec)
742 struct ad198x_spec *spec = codec->spec;
743 unsigned int present;
745 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0);
746 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
747 spec->jack_present = !(present & 0x80000000);
748 ad1986a_update_hp(codec);
751 #define AD1986A_HP_EVENT 0x37
753 static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
755 if ((res >> 26) != AD1986A_HP_EVENT)
757 ad1986a_hp_automute(codec);
760 static int ad1986a_hp_init(struct hda_codec *codec)
763 ad1986a_hp_automute(codec);
767 /* bind hp and internal speaker mute (with plug check) */
768 static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
769 struct snd_ctl_elem_value *ucontrol)
771 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
772 long *valp = ucontrol->value.integer.value;
775 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
777 valp[0] ? 0 : HDA_AMP_MUTE);
778 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
780 valp[1] ? 0 : HDA_AMP_MUTE);
782 ad1986a_update_hp(codec);
786 static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = {
787 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
789 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
790 .name = "Master Playback Switch",
791 .info = snd_hda_mixer_amp_switch_info,
792 .get = snd_hda_mixer_amp_switch_get,
793 .put = ad1986a_hp_master_sw_put,
794 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
796 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
797 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
798 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
799 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
800 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
801 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
802 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
803 HDA_CODEC_VOLUME("Beep Playback Volume", 0x18, 0x0, HDA_OUTPUT),
804 HDA_CODEC_MUTE("Beep Playback Switch", 0x18, 0x0, HDA_OUTPUT),
805 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
806 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
808 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
809 .name = "Capture Source",
810 .info = ad198x_mux_enum_info,
811 .get = ad198x_mux_enum_get,
812 .put = ad198x_mux_enum_put,
815 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
816 .name = "External Amplifier",
817 .info = ad198x_eapd_info,
818 .get = ad198x_eapd_get,
819 .put = ad198x_eapd_put,
820 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
826 * initialization verbs
828 static struct hda_verb ad1986a_init_verbs[] = {
829 /* Front, Surround, CLFE DAC; mute as default */
830 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
831 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
832 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
834 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
835 /* HP, Line-Out, Surround, CLFE selectors */
836 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
837 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
838 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
839 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
841 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
842 /* Mic selector: Mic 1/2 pin */
843 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
844 /* Line-in selector: Line-in */
845 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
847 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
848 /* Record selector: mic */
849 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
850 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
851 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
852 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
853 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
854 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
855 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
857 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
858 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
859 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
860 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
861 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
862 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
863 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
865 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
866 /* Front, Surround, CLFE Pins */
867 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
868 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
869 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
871 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
873 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
874 /* Line, Aux, CD, Beep-In Pin */
875 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
876 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
877 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
878 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
879 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
883 static struct hda_verb ad1986a_ch2_init[] = {
884 /* Surround out -> Line In */
885 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
886 /* Line-in selectors */
887 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
889 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
890 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
891 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
895 static struct hda_verb ad1986a_ch4_init[] = {
896 /* Surround out -> Surround */
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_VREF80 },
901 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
905 static struct hda_verb ad1986a_ch6_init[] = {
906 /* Surround out -> Surround out */
907 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
908 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
910 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
911 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
915 static struct hda_channel_mode ad1986a_modes[3] = {
916 { 2, ad1986a_ch2_init },
917 { 4, ad1986a_ch4_init },
918 { 6, ad1986a_ch6_init },
921 /* eapd initialization */
922 static struct hda_verb ad1986a_eapd_init_verbs[] = {
923 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
927 static struct hda_verb ad1986a_automic_verbs[] = {
928 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
929 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
930 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
931 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
932 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
936 /* Ultra initialization */
937 static struct hda_verb ad1986a_ultra_init[] = {
938 /* eapd initialization */
939 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
941 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
942 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
943 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
947 /* pin sensing on HP jack */
948 static struct hda_verb ad1986a_hp_init_verbs[] = {
949 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
960 AD1986A_LAPTOP_AUTOMUTE,
966 static const char *ad1986a_models[AD1986A_MODELS] = {
967 [AD1986A_6STACK] = "6stack",
968 [AD1986A_3STACK] = "3stack",
969 [AD1986A_LAPTOP] = "laptop",
970 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
971 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
972 [AD1986A_ULTRA] = "ultra",
973 [AD1986A_SAMSUNG] = "samsung",
976 static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
977 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
978 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
979 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
980 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
981 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
982 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
983 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
984 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
985 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
986 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
987 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
988 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
989 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
990 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
991 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
992 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
993 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
994 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
995 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
996 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_SAMSUNG),
997 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_SAMSUNG),
998 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_SAMSUNG),
999 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
1000 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
1001 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
1002 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
1003 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
1004 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
1008 #ifdef CONFIG_SND_HDA_POWER_SAVE
1009 static struct hda_amp_list ad1986a_loopbacks[] = {
1010 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
1011 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
1012 { 0x15, HDA_OUTPUT, 0 }, /* CD */
1013 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
1014 { 0x17, HDA_OUTPUT, 0 }, /* Line */
1019 static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1021 unsigned int conf = snd_hda_codec_read(codec, nid, 0,
1022 AC_VERB_GET_CONFIG_DEFAULT, 0);
1023 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1026 static int patch_ad1986a(struct hda_codec *codec)
1028 struct ad198x_spec *spec;
1031 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1037 spec->multiout.max_channels = 6;
1038 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
1039 spec->multiout.dac_nids = ad1986a_dac_nids;
1040 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
1041 spec->num_adc_nids = 1;
1042 spec->adc_nids = ad1986a_adc_nids;
1043 spec->capsrc_nids = ad1986a_capsrc_nids;
1044 spec->input_mux = &ad1986a_capture_source;
1045 spec->num_mixers = 1;
1046 spec->mixers[0] = ad1986a_mixers;
1047 spec->num_init_verbs = 1;
1048 spec->init_verbs[0] = ad1986a_init_verbs;
1049 #ifdef CONFIG_SND_HDA_POWER_SAVE
1050 spec->loopback.amplist = ad1986a_loopbacks;
1052 spec->vmaster_nid = 0x1b;
1054 codec->patch_ops = ad198x_patch_ops;
1056 /* override some parameters */
1057 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1060 switch (board_config) {
1061 case AD1986A_3STACK:
1062 spec->num_mixers = 2;
1063 spec->mixers[1] = ad1986a_3st_mixers;
1064 spec->num_init_verbs = 2;
1065 spec->init_verbs[1] = ad1986a_ch2_init;
1066 spec->channel_mode = ad1986a_modes;
1067 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
1068 spec->need_dac_fix = 1;
1069 spec->multiout.max_channels = 2;
1070 spec->multiout.num_dacs = 1;
1072 case AD1986A_LAPTOP:
1073 spec->mixers[0] = ad1986a_laptop_mixers;
1074 spec->multiout.max_channels = 2;
1075 spec->multiout.num_dacs = 1;
1076 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1078 case AD1986A_LAPTOP_EAPD:
1079 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1080 spec->num_init_verbs = 2;
1081 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1082 spec->multiout.max_channels = 2;
1083 spec->multiout.num_dacs = 1;
1084 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1085 if (!is_jack_available(codec, 0x25))
1086 spec->multiout.dig_out_nid = 0;
1087 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1089 case AD1986A_SAMSUNG:
1090 spec->mixers[0] = ad1986a_samsung_mixers;
1091 spec->num_init_verbs = 3;
1092 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1093 spec->init_verbs[2] = ad1986a_automic_verbs;
1094 spec->multiout.max_channels = 2;
1095 spec->multiout.num_dacs = 1;
1096 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1097 if (!is_jack_available(codec, 0x25))
1098 spec->multiout.dig_out_nid = 0;
1099 spec->input_mux = &ad1986a_automic_capture_source;
1100 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1101 codec->patch_ops.init = ad1986a_automic_init;
1103 case AD1986A_LAPTOP_AUTOMUTE:
1104 spec->mixers[0] = ad1986a_laptop_automute_mixers;
1105 spec->num_init_verbs = 3;
1106 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1107 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1108 spec->multiout.max_channels = 2;
1109 spec->multiout.num_dacs = 1;
1110 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1111 if (!is_jack_available(codec, 0x25))
1112 spec->multiout.dig_out_nid = 0;
1113 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1114 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1115 codec->patch_ops.init = ad1986a_hp_init;
1118 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1119 spec->num_init_verbs = 2;
1120 spec->init_verbs[1] = ad1986a_ultra_init;
1121 spec->multiout.max_channels = 2;
1122 spec->multiout.num_dacs = 1;
1123 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1124 spec->multiout.dig_out_nid = 0;
1128 /* AD1986A has a hardware problem that it can't share a stream
1129 * with multiple output pins. The copy of front to surrounds
1130 * causes noisy or silent outputs at a certain timing, e.g.
1131 * changing the volume.
1132 * So, let's disable the shared stream.
1134 spec->multiout.no_share_stream = 1;
1143 #define AD1983_SPDIF_OUT 0x02
1144 #define AD1983_DAC 0x03
1145 #define AD1983_ADC 0x04
1147 static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
1148 static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
1149 static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
1151 static struct hda_input_mux ad1983_capture_source = {
1157 { "Mix Mono", 0x3 },
1162 * SPDIF playback route
1164 static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1166 static char *texts[] = { "PCM", "ADC" };
1168 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1170 uinfo->value.enumerated.items = 2;
1171 if (uinfo->value.enumerated.item > 1)
1172 uinfo->value.enumerated.item = 1;
1173 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1177 static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1179 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1180 struct ad198x_spec *spec = codec->spec;
1182 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1186 static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1188 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1189 struct ad198x_spec *spec = codec->spec;
1191 if (ucontrol->value.enumerated.item[0] > 1)
1193 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1194 spec->spdif_route = ucontrol->value.enumerated.item[0];
1195 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1196 AC_VERB_SET_CONNECT_SEL,
1203 static struct snd_kcontrol_new ad1983_mixers[] = {
1204 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1205 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1206 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1207 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1208 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1209 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1210 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1211 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1212 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1213 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1214 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1215 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1216 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
1217 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
1218 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1219 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1220 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1222 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1223 .name = "Capture Source",
1224 .info = ad198x_mux_enum_info,
1225 .get = ad198x_mux_enum_get,
1226 .put = ad198x_mux_enum_put,
1229 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1230 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1231 .info = ad1983_spdif_route_info,
1232 .get = ad1983_spdif_route_get,
1233 .put = ad1983_spdif_route_put,
1238 static struct hda_verb ad1983_init_verbs[] = {
1239 /* Front, HP, Mono; mute as default */
1240 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1241 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1242 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1243 /* Beep, PCM, Mic, Line-In: mute */
1244 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1245 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1246 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1247 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1248 /* Front, HP selectors; from Mix */
1249 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1250 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1251 /* Mono selector; from Mix */
1252 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1253 /* Mic selector; Mic */
1254 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1255 /* Line-in selector: Line-in */
1256 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1257 /* Mic boost: 0dB */
1258 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1259 /* Record selector: mic */
1260 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1261 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1262 /* SPDIF route: PCM */
1263 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1265 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1267 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1269 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1271 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1273 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1277 #ifdef CONFIG_SND_HDA_POWER_SAVE
1278 static struct hda_amp_list ad1983_loopbacks[] = {
1279 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1280 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1285 static int patch_ad1983(struct hda_codec *codec)
1287 struct ad198x_spec *spec;
1289 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1295 spec->multiout.max_channels = 2;
1296 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1297 spec->multiout.dac_nids = ad1983_dac_nids;
1298 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
1299 spec->num_adc_nids = 1;
1300 spec->adc_nids = ad1983_adc_nids;
1301 spec->capsrc_nids = ad1983_capsrc_nids;
1302 spec->input_mux = &ad1983_capture_source;
1303 spec->num_mixers = 1;
1304 spec->mixers[0] = ad1983_mixers;
1305 spec->num_init_verbs = 1;
1306 spec->init_verbs[0] = ad1983_init_verbs;
1307 spec->spdif_route = 0;
1308 #ifdef CONFIG_SND_HDA_POWER_SAVE
1309 spec->loopback.amplist = ad1983_loopbacks;
1311 spec->vmaster_nid = 0x05;
1313 codec->patch_ops = ad198x_patch_ops;
1320 * AD1981 HD specific
1323 #define AD1981_SPDIF_OUT 0x02
1324 #define AD1981_DAC 0x03
1325 #define AD1981_ADC 0x04
1327 static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
1328 static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
1329 static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
1331 /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1332 static struct hda_input_mux ad1981_capture_source = {
1335 { "Front Mic", 0x0 },
1338 { "Mix Mono", 0x3 },
1345 static struct snd_kcontrol_new ad1981_mixers[] = {
1346 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1347 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1348 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1349 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1350 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1351 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1352 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1353 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1354 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1355 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1356 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1357 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1358 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1359 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1360 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1361 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1362 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1364 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1365 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1366 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1367 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1368 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1369 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1371 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1372 .name = "Capture Source",
1373 .info = ad198x_mux_enum_info,
1374 .get = ad198x_mux_enum_get,
1375 .put = ad198x_mux_enum_put,
1377 /* identical with AD1983 */
1379 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1380 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1381 .info = ad1983_spdif_route_info,
1382 .get = ad1983_spdif_route_get,
1383 .put = ad1983_spdif_route_put,
1388 static struct hda_verb ad1981_init_verbs[] = {
1389 /* Front, HP, Mono; mute as default */
1390 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1391 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1392 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1393 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1394 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1395 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1396 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1397 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1398 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1399 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1400 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1401 /* Front, HP selectors; from Mix */
1402 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1403 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1404 /* Mono selector; from Mix */
1405 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1406 /* Mic Mixer; select Front Mic */
1407 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1408 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1409 /* Mic boost: 0dB */
1410 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1411 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1412 /* Record selector: Front mic */
1413 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1414 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1415 /* SPDIF route: PCM */
1416 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1418 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1420 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1422 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1423 /* Front & Rear Mic Pins */
1424 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1425 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1427 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1429 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1430 /* Line-Out as Input: disabled */
1431 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1435 #ifdef CONFIG_SND_HDA_POWER_SAVE
1436 static struct hda_amp_list ad1981_loopbacks[] = {
1437 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1438 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1439 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1440 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1441 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1447 * Patch for HP nx6320
1449 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
1450 * speaker output enabled _and_ mute-LED off.
1453 #define AD1981_HP_EVENT 0x37
1454 #define AD1981_MIC_EVENT 0x38
1456 static struct hda_verb ad1981_hp_init_verbs[] = {
1457 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1458 /* pin sensing on HP and Mic jacks */
1459 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1460 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1464 /* turn on/off EAPD (+ mute HP) as a master switch */
1465 static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1466 struct snd_ctl_elem_value *ucontrol)
1468 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1469 struct ad198x_spec *spec = codec->spec;
1471 if (! ad198x_eapd_put(kcontrol, ucontrol))
1473 /* change speaker pin appropriately */
1474 snd_hda_codec_write(codec, 0x05, 0,
1475 AC_VERB_SET_PIN_WIDGET_CONTROL,
1476 spec->cur_eapd ? PIN_OUT : 0);
1477 /* toggle HP mute appropriately */
1478 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1480 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
1484 /* bind volumes of both NID 0x05 and 0x06 */
1485 static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1486 .ops = &snd_hda_bind_vol,
1488 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1489 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1494 /* mute internal speaker if HP is plugged */
1495 static void ad1981_hp_automute(struct hda_codec *codec)
1497 unsigned int present;
1499 present = snd_hda_codec_read(codec, 0x06, 0,
1500 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1501 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1502 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1505 /* toggle input of built-in and mic jack appropriately */
1506 static void ad1981_hp_automic(struct hda_codec *codec)
1508 static struct hda_verb mic_jack_on[] = {
1509 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1510 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1513 static struct hda_verb mic_jack_off[] = {
1514 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1515 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1518 unsigned int present;
1520 present = snd_hda_codec_read(codec, 0x08, 0,
1521 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1523 snd_hda_sequence_write(codec, mic_jack_on);
1525 snd_hda_sequence_write(codec, mic_jack_off);
1528 /* unsolicited event for HP jack sensing */
1529 static void ad1981_hp_unsol_event(struct hda_codec *codec,
1534 case AD1981_HP_EVENT:
1535 ad1981_hp_automute(codec);
1537 case AD1981_MIC_EVENT:
1538 ad1981_hp_automic(codec);
1543 static struct hda_input_mux ad1981_hp_capture_source = {
1547 { "Docking-Station", 0x1 },
1552 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1553 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
1555 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1556 .name = "Master Playback Switch",
1557 .info = ad198x_eapd_info,
1558 .get = ad198x_eapd_get,
1559 .put = ad1981_hp_master_sw_put,
1560 .private_value = 0x05,
1562 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1563 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1565 /* FIXME: analog mic/line loopback doesn't work with my tests...
1566 * (although recording is OK)
1568 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1569 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1570 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1571 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1572 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1573 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1574 /* FIXME: does this laptop have analog CD connection? */
1575 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1576 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1578 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1579 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1580 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1581 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1583 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1584 .name = "Capture Source",
1585 .info = ad198x_mux_enum_info,
1586 .get = ad198x_mux_enum_get,
1587 .put = ad198x_mux_enum_put,
1592 /* initialize jack-sensing, too */
1593 static int ad1981_hp_init(struct hda_codec *codec)
1596 ad1981_hp_automute(codec);
1597 ad1981_hp_automic(codec);
1601 /* configuration for Toshiba Laptops */
1602 static struct hda_verb ad1981_toshiba_init_verbs[] = {
1603 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1604 /* pin sensing on HP and Mic jacks */
1605 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1606 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1610 static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1611 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1612 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1616 /* configuration for Lenovo Thinkpad T60 */
1617 static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1618 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1619 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1620 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1621 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1622 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1623 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1624 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1625 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1626 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1627 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1628 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1630 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1631 .name = "Capture Source",
1632 .info = ad198x_mux_enum_info,
1633 .get = ad198x_mux_enum_get,
1634 .put = ad198x_mux_enum_put,
1636 /* identical with AD1983 */
1638 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1639 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1640 .info = ad1983_spdif_route_info,
1641 .get = ad1983_spdif_route_get,
1642 .put = ad1983_spdif_route_put,
1647 static struct hda_input_mux ad1981_thinkpad_capture_source = {
1665 static const char *ad1981_models[AD1981_MODELS] = {
1667 [AD1981_THINKPAD] = "thinkpad",
1668 [AD1981_BASIC] = "basic",
1669 [AD1981_TOSHIBA] = "toshiba"
1672 static struct snd_pci_quirk ad1981_cfg_tbl[] = {
1673 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
1674 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
1676 SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
1677 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
1678 /* Lenovo Thinkpad T60/X60/Z6xx */
1679 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
1680 /* HP nx6320 (reversed SSID, H/W bug) */
1681 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
1685 static int patch_ad1981(struct hda_codec *codec)
1687 struct ad198x_spec *spec;
1690 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1696 spec->multiout.max_channels = 2;
1697 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1698 spec->multiout.dac_nids = ad1981_dac_nids;
1699 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
1700 spec->num_adc_nids = 1;
1701 spec->adc_nids = ad1981_adc_nids;
1702 spec->capsrc_nids = ad1981_capsrc_nids;
1703 spec->input_mux = &ad1981_capture_source;
1704 spec->num_mixers = 1;
1705 spec->mixers[0] = ad1981_mixers;
1706 spec->num_init_verbs = 1;
1707 spec->init_verbs[0] = ad1981_init_verbs;
1708 spec->spdif_route = 0;
1709 #ifdef CONFIG_SND_HDA_POWER_SAVE
1710 spec->loopback.amplist = ad1981_loopbacks;
1712 spec->vmaster_nid = 0x05;
1714 codec->patch_ops = ad198x_patch_ops;
1716 /* override some parameters */
1717 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1720 switch (board_config) {
1722 spec->mixers[0] = ad1981_hp_mixers;
1723 spec->num_init_verbs = 2;
1724 spec->init_verbs[1] = ad1981_hp_init_verbs;
1725 spec->multiout.dig_out_nid = 0;
1726 spec->input_mux = &ad1981_hp_capture_source;
1728 codec->patch_ops.init = ad1981_hp_init;
1729 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1731 case AD1981_THINKPAD:
1732 spec->mixers[0] = ad1981_thinkpad_mixers;
1733 spec->input_mux = &ad1981_thinkpad_capture_source;
1735 case AD1981_TOSHIBA:
1736 spec->mixers[0] = ad1981_hp_mixers;
1737 spec->mixers[1] = ad1981_toshiba_mixers;
1738 spec->num_init_verbs = 2;
1739 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1740 spec->multiout.dig_out_nid = 0;
1741 spec->input_mux = &ad1981_hp_capture_source;
1742 codec->patch_ops.init = ad1981_hp_init;
1743 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1753 * Output pins and routes
1755 * Pin Mix Sel DAC (*)
1756 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1757 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1758 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1759 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1760 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1761 * port-F 0x16 (mute) <- 0x2a <- 06
1762 * port-G 0x24 (mute) <- 0x27 <- 05
1763 * port-H 0x25 (mute) <- 0x28 <- 0a
1764 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1766 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1767 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
1769 * Input pins and routes
1771 * pin boost mix input # / adc input #
1772 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1773 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1774 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1775 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1776 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1777 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1778 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1779 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1783 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
1784 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
1786 * Inputs of Analog Mix (0x20)
1787 * 0:Port-B (front mic)
1788 * 1:Port-C/G/H (line-in)
1790 * 3:Port-D (line-in/2)
1791 * 4:Port-E/G/H (mic-in)
1792 * 5:Port-F (mic2-in)
1798 * 1:Port-B (front mic-in)
1799 * 2:Port-C (line-in)
1800 * 3:Port-F (mic2-in)
1805 * 8:Port-D (line-in/2)
1808 * Proposed pin assignments by the datasheet
1811 * Port-A front headphone
1821 * Port-A front headphone
1823 * C rear line-in/surround
1825 * E rear mic-in/CLFE
1831 * D internal speaker (with EAPD)
1832 * E/F quad mic array
1848 /* reivision id to check workarounds */
1849 #define AD1988A_REV2 0x100200
1851 #define is_rev2(codec) \
1852 ((codec)->vendor_id == 0x11d41988 && \
1853 (codec)->revision_id == AD1988A_REV2)
1859 static hda_nid_t ad1988_6stack_dac_nids[4] = {
1860 0x04, 0x06, 0x05, 0x0a
1863 static hda_nid_t ad1988_3stack_dac_nids[3] = {
1867 /* for AD1988A revision-2, DAC2-4 are swapped */
1868 static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1869 0x04, 0x05, 0x0a, 0x06
1872 static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
1876 static hda_nid_t ad1988_adc_nids[3] = {
1880 static hda_nid_t ad1988_capsrc_nids[3] = {
1884 #define AD1988_SPDIF_OUT 0x02
1885 #define AD1988_SPDIF_OUT_HDMI 0x0b
1886 #define AD1988_SPDIF_IN 0x07
1888 static hda_nid_t ad1989b_slave_dig_outs[2] = {
1889 AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI
1892 static struct hda_input_mux ad1988_6stack_capture_source = {
1895 { "Front Mic", 0x1 }, /* port-B */
1896 { "Line", 0x2 }, /* port-C */
1897 { "Mic", 0x4 }, /* port-E */
1903 static struct hda_input_mux ad1988_laptop_capture_source = {
1906 { "Mic/Line", 0x1 }, /* port-B */
1914 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1915 struct snd_ctl_elem_info *uinfo)
1917 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1918 struct ad198x_spec *spec = codec->spec;
1919 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1920 spec->num_channel_mode);
1923 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1924 struct snd_ctl_elem_value *ucontrol)
1926 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1927 struct ad198x_spec *spec = codec->spec;
1928 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1929 spec->num_channel_mode, spec->multiout.max_channels);
1932 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1933 struct snd_ctl_elem_value *ucontrol)
1935 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1936 struct ad198x_spec *spec = codec->spec;
1937 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1938 spec->num_channel_mode,
1939 &spec->multiout.max_channels);
1940 if (err >= 0 && spec->need_dac_fix)
1941 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
1946 static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
1947 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1948 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1949 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1950 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1951 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1955 static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1956 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1957 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1958 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1959 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1960 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1964 static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
1965 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1966 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1967 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1968 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1969 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1970 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1971 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1973 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1974 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1975 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1976 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1977 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1978 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1979 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1980 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1982 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1983 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1985 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1986 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1988 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1989 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1995 static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
1996 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1997 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1998 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1999 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2003 static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
2004 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2005 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2006 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
2007 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
2011 static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
2012 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2013 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
2014 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
2015 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
2016 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2017 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2019 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2020 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2021 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2022 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2023 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2024 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2025 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2026 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2028 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2029 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2031 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2032 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2034 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2035 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2037 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2038 .name = "Channel Mode",
2039 .info = ad198x_ch_mode_info,
2040 .get = ad198x_ch_mode_get,
2041 .put = ad198x_ch_mode_put,
2048 static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2049 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2050 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
2051 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2053 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2054 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2055 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2056 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2057 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2058 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2060 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2061 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2063 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2064 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2066 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2069 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2070 .name = "External Amplifier",
2071 .info = ad198x_eapd_info,
2072 .get = ad198x_eapd_get,
2073 .put = ad198x_eapd_put,
2074 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
2081 static struct snd_kcontrol_new ad1988_capture_mixers[] = {
2082 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2083 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2084 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2085 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2086 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2087 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2089 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2090 /* The multiple "Capture Source" controls confuse alsamixer
2091 * So call somewhat different..
2093 /* .name = "Capture Source", */
2094 .name = "Input Source",
2096 .info = ad198x_mux_enum_info,
2097 .get = ad198x_mux_enum_get,
2098 .put = ad198x_mux_enum_put,
2103 static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2104 struct snd_ctl_elem_info *uinfo)
2106 static char *texts[] = {
2107 "PCM", "ADC1", "ADC2", "ADC3"
2109 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2111 uinfo->value.enumerated.items = 4;
2112 if (uinfo->value.enumerated.item >= 4)
2113 uinfo->value.enumerated.item = 3;
2114 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2118 static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2119 struct snd_ctl_elem_value *ucontrol)
2121 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2124 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2127 ucontrol->value.enumerated.item[0] = 0;
2129 sel = snd_hda_codec_read(codec, 0x0b, 0,
2130 AC_VERB_GET_CONNECT_SEL, 0);
2135 ucontrol->value.enumerated.item[0] = sel;
2140 static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2141 struct snd_ctl_elem_value *ucontrol)
2143 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2144 unsigned int val, sel;
2147 val = ucontrol->value.enumerated.item[0];
2151 sel = snd_hda_codec_read(codec, 0x1d, 0,
2152 AC_VERB_GET_AMP_GAIN_MUTE,
2154 change = sel & 0x80;
2156 snd_hda_codec_write_cache(codec, 0x1d, 0,
2157 AC_VERB_SET_AMP_GAIN_MUTE,
2159 snd_hda_codec_write_cache(codec, 0x1d, 0,
2160 AC_VERB_SET_AMP_GAIN_MUTE,
2164 sel = snd_hda_codec_read(codec, 0x1d, 0,
2165 AC_VERB_GET_AMP_GAIN_MUTE,
2166 AC_AMP_GET_INPUT | 0x01);
2167 change = sel & 0x80;
2169 snd_hda_codec_write_cache(codec, 0x1d, 0,
2170 AC_VERB_SET_AMP_GAIN_MUTE,
2172 snd_hda_codec_write_cache(codec, 0x1d, 0,
2173 AC_VERB_SET_AMP_GAIN_MUTE,
2176 sel = snd_hda_codec_read(codec, 0x0b, 0,
2177 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2178 change |= sel != val;
2180 snd_hda_codec_write_cache(codec, 0x0b, 0,
2181 AC_VERB_SET_CONNECT_SEL,
2187 static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2188 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2190 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2191 .name = "IEC958 Playback Source",
2192 .info = ad1988_spdif_playback_source_info,
2193 .get = ad1988_spdif_playback_source_get,
2194 .put = ad1988_spdif_playback_source_put,
2199 static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2200 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2204 static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2205 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2206 HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
2211 * initialization verbs
2215 * for 6-stack (+dig)
2217 static struct hda_verb ad1988_6stack_init_verbs[] = {
2218 /* Front, Surround, CLFE, side DAC; unmute as default */
2219 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2220 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2221 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2222 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2223 /* Port-A front headphon path */
2224 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2225 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2226 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2227 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2228 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2229 /* Port-D line-out path */
2230 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2231 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2232 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2233 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2234 /* Port-F surround path */
2235 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2236 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2237 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2238 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2239 /* Port-G CLFE path */
2240 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2241 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2242 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2243 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2244 /* Port-H side path */
2245 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2246 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2247 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2248 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2250 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2251 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2252 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2253 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2254 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2255 /* Port-B front mic-in path */
2256 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2257 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2258 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2259 /* Port-C line-in path */
2260 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2261 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2262 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2263 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2264 /* Port-E mic-in path */
2265 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2266 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2267 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2268 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2269 /* Analog CD Input */
2270 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2271 /* Analog Mix output amp */
2272 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2277 static struct hda_verb ad1988_capture_init_verbs[] = {
2278 /* mute analog mix */
2279 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2280 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2281 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2282 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2283 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2284 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2285 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2286 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2287 /* select ADCs - front-mic */
2288 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2289 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2290 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2295 static struct hda_verb ad1988_spdif_init_verbs[] = {
2297 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2298 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2299 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2300 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2302 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2307 /* AD1989 has no ADC -> SPDIF route */
2308 static struct hda_verb ad1989_spdif_init_verbs[] = {
2309 /* SPDIF-1 out pin */
2310 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2311 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2312 /* SPDIF-2/HDMI out pin */
2313 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2314 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2319 * verbs for 3stack (+dig)
2321 static struct hda_verb ad1988_3stack_ch2_init[] = {
2322 /* set port-C to line-in */
2323 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2324 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2325 /* set port-E to mic-in */
2326 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2327 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2331 static struct hda_verb ad1988_3stack_ch6_init[] = {
2332 /* set port-C to surround out */
2333 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2334 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2335 /* set port-E to CLFE out */
2336 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2337 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2341 static struct hda_channel_mode ad1988_3stack_modes[2] = {
2342 { 2, ad1988_3stack_ch2_init },
2343 { 6, ad1988_3stack_ch6_init },
2346 static struct hda_verb ad1988_3stack_init_verbs[] = {
2347 /* Front, Surround, CLFE, side DAC; unmute as default */
2348 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2349 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2350 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2351 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2352 /* Port-A front headphon path */
2353 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2354 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2355 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2356 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2357 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2358 /* Port-D line-out path */
2359 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2360 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2361 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2362 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2364 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2365 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2366 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2367 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2368 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2369 /* Port-B front mic-in path */
2370 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2371 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2372 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2373 /* Port-C line-in/surround path - 6ch mode as default */
2374 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2375 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2376 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2377 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
2378 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2379 /* Port-E mic-in/CLFE path - 6ch mode as default */
2380 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2381 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2382 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2383 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
2384 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2385 /* mute analog mix */
2386 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2387 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2388 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2389 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2390 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2391 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2392 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2393 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2394 /* select ADCs - front-mic */
2395 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2396 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2397 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2398 /* Analog Mix output amp */
2399 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2404 * verbs for laptop mode (+dig)
2406 static struct hda_verb ad1988_laptop_hp_on[] = {
2407 /* unmute port-A and mute port-D */
2408 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2409 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2412 static struct hda_verb ad1988_laptop_hp_off[] = {
2413 /* mute port-A and unmute port-D */
2414 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2415 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2419 #define AD1988_HP_EVENT 0x01
2421 static struct hda_verb ad1988_laptop_init_verbs[] = {
2422 /* Front, Surround, CLFE, side DAC; unmute as default */
2423 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2424 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2425 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2426 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2427 /* Port-A front headphon path */
2428 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2429 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2430 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2431 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2432 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2433 /* unsolicited event for pin-sense */
2434 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2435 /* Port-D line-out path + EAPD */
2436 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2437 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2438 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2439 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2440 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2442 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2443 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2444 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2445 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2446 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2447 /* Port-B mic-in path */
2448 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2449 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2450 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2451 /* Port-C docking station - try to output */
2452 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2453 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2454 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2455 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2456 /* mute analog mix */
2457 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2458 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2459 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2460 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2461 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2462 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2463 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2464 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2465 /* select ADCs - mic */
2466 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2467 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2468 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2469 /* Analog Mix output amp */
2470 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2474 static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2476 if ((res >> 26) != AD1988_HP_EVENT)
2478 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2479 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2481 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2484 #ifdef CONFIG_SND_HDA_POWER_SAVE
2485 static struct hda_amp_list ad1988_loopbacks[] = {
2486 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2487 { 0x20, HDA_INPUT, 1 }, /* Line */
2488 { 0x20, HDA_INPUT, 4 }, /* Mic */
2489 { 0x20, HDA_INPUT, 6 }, /* CD */
2495 * Automatic parse of I/O pins from the BIOS configuration
2503 static struct snd_kcontrol_new ad1988_control_templates[] = {
2504 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2505 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2506 HDA_BIND_MUTE(NULL, 0, 0, 0),
2509 /* add dynamic controls */
2510 static int add_control(struct ad198x_spec *spec, int type, const char *name,
2513 struct snd_kcontrol_new *knew;
2515 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2516 knew = snd_array_new(&spec->kctls);
2519 *knew = ad1988_control_templates[type];
2520 knew->name = kstrdup(name, GFP_KERNEL);
2523 knew->private_value = val;
2527 #define AD1988_PIN_CD_NID 0x18
2528 #define AD1988_PIN_BEEP_NID 0x10
2530 static hda_nid_t ad1988_mixer_nids[8] = {
2531 /* A B C D E F G H */
2532 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2535 static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2537 static hda_nid_t idx_to_dac[8] = {
2538 /* A B C D E F G H */
2539 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
2541 static hda_nid_t idx_to_dac_rev2[8] = {
2542 /* A B C D E F G H */
2543 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
2546 return idx_to_dac_rev2[idx];
2548 return idx_to_dac[idx];
2551 static hda_nid_t ad1988_boost_nids[8] = {
2552 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2555 static int ad1988_pin_idx(hda_nid_t nid)
2557 static hda_nid_t ad1988_io_pins[8] = {
2558 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2561 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2562 if (ad1988_io_pins[i] == nid)
2564 return 0; /* should be -1 */
2567 static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2569 static int loopback_idx[8] = {
2570 2, 0, 1, 3, 4, 5, 1, 4
2573 case AD1988_PIN_CD_NID:
2576 return loopback_idx[ad1988_pin_idx(nid)];
2580 static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2582 static int adc_idx[8] = {
2583 0, 1, 2, 8, 4, 3, 6, 7
2586 case AD1988_PIN_CD_NID:
2589 return adc_idx[ad1988_pin_idx(nid)];
2593 /* fill in the dac_nids table from the parsed pin configuration */
2594 static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2595 const struct auto_pin_cfg *cfg)
2597 struct ad198x_spec *spec = codec->spec;
2600 spec->multiout.dac_nids = spec->private_dac_nids;
2602 /* check the pins hardwired to audio widget */
2603 for (i = 0; i < cfg->line_outs; i++) {
2604 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2605 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2607 spec->multiout.num_dacs = cfg->line_outs;
2611 /* add playback controls from the parsed DAC table */
2612 static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2613 const struct auto_pin_cfg *cfg)
2616 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2620 for (i = 0; i < cfg->line_outs; i++) {
2621 hda_nid_t dac = spec->multiout.dac_nids[i];
2624 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2627 err = add_control(spec, AD_CTL_WIDGET_VOL,
2628 "Center Playback Volume",
2629 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2632 err = add_control(spec, AD_CTL_WIDGET_VOL,
2633 "LFE Playback Volume",
2634 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2637 err = add_control(spec, AD_CTL_BIND_MUTE,
2638 "Center Playback Switch",
2639 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2642 err = add_control(spec, AD_CTL_BIND_MUTE,
2643 "LFE Playback Switch",
2644 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2648 sprintf(name, "%s Playback Volume", chname[i]);
2649 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2650 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2653 sprintf(name, "%s Playback Switch", chname[i]);
2654 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2655 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2663 /* add playback controls for speaker and HP outputs */
2664 static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2667 struct ad198x_spec *spec = codec->spec;
2675 idx = ad1988_pin_idx(pin);
2676 nid = ad1988_idx_to_dac(codec, idx);
2677 /* check whether the corresponding DAC was already taken */
2678 for (i = 0; i < spec->autocfg.line_outs; i++) {
2679 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2680 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
2684 if (i >= spec->autocfg.line_outs) {
2685 /* specify the DAC as the extra output */
2686 if (!spec->multiout.hp_nid)
2687 spec->multiout.hp_nid = nid;
2689 spec->multiout.extra_out_nid[0] = nid;
2690 /* control HP volume/switch on the output mixer amp */
2691 sprintf(name, "%s Playback Volume", pfx);
2692 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2693 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2697 nid = ad1988_mixer_nids[idx];
2698 sprintf(name, "%s Playback Switch", pfx);
2699 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2700 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2705 /* create input playback/capture controls for the given pin */
2706 static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2707 const char *ctlname, int boost)
2712 sprintf(name, "%s Playback Volume", ctlname);
2713 idx = ad1988_pin_to_loopback_idx(pin);
2714 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2715 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2717 sprintf(name, "%s Playback Switch", ctlname);
2718 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2719 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2723 idx = ad1988_pin_idx(pin);
2724 bnid = ad1988_boost_nids[idx];
2726 sprintf(name, "%s Boost", ctlname);
2727 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2728 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2735 /* create playback/capture controls for input pins */
2736 static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2737 const struct auto_pin_cfg *cfg)
2739 struct hda_input_mux *imux = &spec->private_imux;
2742 for (i = 0; i < AUTO_PIN_LAST; i++) {
2743 err = new_analog_input(spec, cfg->input_pins[i],
2744 auto_pin_cfg_labels[i],
2745 i <= AUTO_PIN_FRONT_MIC);
2748 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2749 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2752 imux->items[imux->num_items].label = "Mix";
2753 imux->items[imux->num_items].index = 9;
2756 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2757 "Analog Mix Playback Volume",
2758 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2760 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2761 "Analog Mix Playback Switch",
2762 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2768 static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2769 hda_nid_t nid, int pin_type,
2773 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2774 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2776 case 0x11: /* port-A - DAC 04 */
2777 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2779 case 0x14: /* port-B - DAC 06 */
2780 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2782 case 0x15: /* port-C - DAC 05 */
2783 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2785 case 0x17: /* port-E - DAC 0a */
2786 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2788 case 0x13: /* mono - DAC 04 */
2789 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2794 static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2796 struct ad198x_spec *spec = codec->spec;
2799 for (i = 0; i < spec->autocfg.line_outs; i++) {
2800 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2801 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2805 static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2807 struct ad198x_spec *spec = codec->spec;
2810 pin = spec->autocfg.speaker_pins[0];
2811 if (pin) /* connect to front */
2812 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2813 pin = spec->autocfg.hp_pins[0];
2814 if (pin) /* connect to front */
2815 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2818 static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2820 struct ad198x_spec *spec = codec->spec;
2823 for (i = 0; i < AUTO_PIN_LAST; i++) {
2824 hda_nid_t nid = spec->autocfg.input_pins[i];
2828 case 0x15: /* port-C */
2829 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2831 case 0x17: /* port-E */
2832 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2835 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2836 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2837 if (nid != AD1988_PIN_CD_NID)
2838 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2840 idx = ad1988_pin_idx(nid);
2841 if (ad1988_boost_nids[idx])
2842 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2843 AC_VERB_SET_AMP_GAIN_MUTE,
2848 /* parse the BIOS configuration and set up the alc_spec */
2849 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2850 static int ad1988_parse_auto_config(struct hda_codec *codec)
2852 struct ad198x_spec *spec = codec->spec;
2855 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2857 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2859 if (! spec->autocfg.line_outs)
2860 return 0; /* can't find valid BIOS pin config */
2861 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2862 (err = ad1988_auto_create_extra_out(codec,
2863 spec->autocfg.speaker_pins[0],
2865 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
2866 "Headphone")) < 0 ||
2867 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2870 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2872 if (spec->autocfg.dig_out_pin)
2873 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2874 if (spec->autocfg.dig_in_pin)
2875 spec->dig_in_nid = AD1988_SPDIF_IN;
2877 if (spec->kctls.list)
2878 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2880 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2882 spec->input_mux = &spec->private_imux;
2887 /* init callback for auto-configuration model -- overriding the default init */
2888 static int ad1988_auto_init(struct hda_codec *codec)
2891 ad1988_auto_init_multi_out(codec);
2892 ad1988_auto_init_extra_out(codec);
2893 ad1988_auto_init_analog_input(codec);
2901 static const char *ad1988_models[AD1988_MODEL_LAST] = {
2902 [AD1988_6STACK] = "6stack",
2903 [AD1988_6STACK_DIG] = "6stack-dig",
2904 [AD1988_3STACK] = "3stack",
2905 [AD1988_3STACK_DIG] = "3stack-dig",
2906 [AD1988_LAPTOP] = "laptop",
2907 [AD1988_LAPTOP_DIG] = "laptop-dig",
2908 [AD1988_AUTO] = "auto",
2911 static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2912 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
2913 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
2914 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
2915 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
2919 static int patch_ad1988(struct hda_codec *codec)
2921 struct ad198x_spec *spec;
2924 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2931 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2933 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
2934 ad1988_models, ad1988_cfg_tbl);
2935 if (board_config < 0) {
2936 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2937 board_config = AD1988_AUTO;
2940 if (board_config == AD1988_AUTO) {
2941 /* automatic parse from the BIOS config */
2942 int err = ad1988_parse_auto_config(codec);
2947 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2948 board_config = AD1988_6STACK;
2952 switch (board_config) {
2954 case AD1988_6STACK_DIG:
2955 spec->multiout.max_channels = 8;
2956 spec->multiout.num_dacs = 4;
2958 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2960 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
2961 spec->input_mux = &ad1988_6stack_capture_source;
2962 spec->num_mixers = 2;
2964 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2966 spec->mixers[0] = ad1988_6stack_mixers1;
2967 spec->mixers[1] = ad1988_6stack_mixers2;
2968 spec->num_init_verbs = 1;
2969 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2970 if (board_config == AD1988_6STACK_DIG) {
2971 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2972 spec->dig_in_nid = AD1988_SPDIF_IN;
2976 case AD1988_3STACK_DIG:
2977 spec->multiout.max_channels = 6;
2978 spec->multiout.num_dacs = 3;
2980 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2982 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2983 spec->input_mux = &ad1988_6stack_capture_source;
2984 spec->channel_mode = ad1988_3stack_modes;
2985 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
2986 spec->num_mixers = 2;
2988 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2990 spec->mixers[0] = ad1988_3stack_mixers1;
2991 spec->mixers[1] = ad1988_3stack_mixers2;
2992 spec->num_init_verbs = 1;
2993 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2994 if (board_config == AD1988_3STACK_DIG)
2995 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2998 case AD1988_LAPTOP_DIG:
2999 spec->multiout.max_channels = 2;
3000 spec->multiout.num_dacs = 1;
3001 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
3002 spec->input_mux = &ad1988_laptop_capture_source;
3003 spec->num_mixers = 1;
3004 spec->mixers[0] = ad1988_laptop_mixers;
3005 spec->num_init_verbs = 1;
3006 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3007 if (board_config == AD1988_LAPTOP_DIG)
3008 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3012 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3013 spec->adc_nids = ad1988_adc_nids;
3014 spec->capsrc_nids = ad1988_capsrc_nids;
3015 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
3016 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
3017 if (spec->multiout.dig_out_nid) {
3018 if (codec->vendor_id >= 0x11d4989a) {
3019 spec->mixers[spec->num_mixers++] =
3020 ad1989_spdif_out_mixers;
3021 spec->init_verbs[spec->num_init_verbs++] =
3022 ad1989_spdif_init_verbs;
3023 codec->slave_dig_outs = ad1989b_slave_dig_outs;
3025 spec->mixers[spec->num_mixers++] =
3026 ad1988_spdif_out_mixers;
3027 spec->init_verbs[spec->num_init_verbs++] =
3028 ad1988_spdif_init_verbs;
3031 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
3032 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
3034 codec->patch_ops = ad198x_patch_ops;
3035 switch (board_config) {
3037 codec->patch_ops.init = ad1988_auto_init;
3040 case AD1988_LAPTOP_DIG:
3041 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
3044 #ifdef CONFIG_SND_HDA_POWER_SAVE
3045 spec->loopback.amplist = ad1988_loopbacks;
3047 spec->vmaster_nid = 0x04;
3056 * port-B - front line/mic-in
3057 * port-E - aux in/out
3058 * port-F - aux in/out
3059 * port-C - rear line/mic-in
3060 * port-D - rear line/hp-out
3061 * port-A - front line/hp-out
3063 * AD1984 = AD1884 + two digital mic-ins
3066 * For simplicity, we share the single DAC for both HP and line-outs
3067 * right now. The inidividual playbacks could be easily implemented,
3068 * but no build-up framework is given, so far.
3071 static hda_nid_t ad1884_dac_nids[1] = {
3075 static hda_nid_t ad1884_adc_nids[2] = {
3079 static hda_nid_t ad1884_capsrc_nids[2] = {
3083 #define AD1884_SPDIF_OUT 0x02
3085 static struct hda_input_mux ad1884_capture_source = {
3088 { "Front Mic", 0x0 },
3095 static struct snd_kcontrol_new ad1884_base_mixers[] = {
3096 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3097 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3098 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3099 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3100 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3101 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3102 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3103 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3104 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3105 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3106 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3107 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3109 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
3110 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
3111 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
3112 HDA_CODEC_MUTE("Digital Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3114 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3115 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3116 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3117 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3118 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3119 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3121 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3122 /* The multiple "Capture Source" controls confuse alsamixer
3123 * So call somewhat different..
3125 /* .name = "Capture Source", */
3126 .name = "Input Source",
3128 .info = ad198x_mux_enum_info,
3129 .get = ad198x_mux_enum_get,
3130 .put = ad198x_mux_enum_put,
3132 /* SPDIF controls */
3133 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3135 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3136 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3137 /* identical with ad1983 */
3138 .info = ad1983_spdif_route_info,
3139 .get = ad1983_spdif_route_get,
3140 .put = ad1983_spdif_route_put,
3145 static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3146 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3147 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3148 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
3150 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
3156 * initialization verbs
3158 static struct hda_verb ad1884_init_verbs[] = {
3159 /* DACs; mute as default */
3160 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3161 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3162 /* Port-A (HP) mixer */
3163 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3164 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3166 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3167 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3168 /* HP selector - select DAC2 */
3169 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3170 /* Port-D (Line-out) mixer */
3171 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3172 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3174 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3175 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3176 /* Mono-out mixer */
3177 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3178 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3180 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3181 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3183 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3184 /* Port-B (front mic) pin */
3185 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3186 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3187 /* Port-C (rear mic) pin */
3188 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3189 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3190 /* Analog mixer; mute as default */
3191 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3192 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3193 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3194 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3195 /* Analog Mix output amp */
3196 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3197 /* SPDIF output selector */
3198 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3199 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3203 #ifdef CONFIG_SND_HDA_POWER_SAVE
3204 static struct hda_amp_list ad1884_loopbacks[] = {
3205 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3206 { 0x20, HDA_INPUT, 1 }, /* Mic */
3207 { 0x20, HDA_INPUT, 2 }, /* CD */
3208 { 0x20, HDA_INPUT, 4 }, /* Docking */
3213 static const char *ad1884_slave_vols[] = {
3214 "PCM Playback Volume",
3215 "Mic Playback Volume",
3216 "Mono Playback Volume",
3217 "Front Mic Playback Volume",
3218 "Mic Playback Volume",
3219 "CD Playback Volume",
3220 "Internal Mic Playback Volume",
3221 "Docking Mic Playback Volume"
3222 "Beep Playback Volume",
3223 "IEC958 Playback Volume",
3227 static int patch_ad1884(struct hda_codec *codec)
3229 struct ad198x_spec *spec;
3231 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3237 spec->multiout.max_channels = 2;
3238 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3239 spec->multiout.dac_nids = ad1884_dac_nids;
3240 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3241 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3242 spec->adc_nids = ad1884_adc_nids;
3243 spec->capsrc_nids = ad1884_capsrc_nids;
3244 spec->input_mux = &ad1884_capture_source;
3245 spec->num_mixers = 1;
3246 spec->mixers[0] = ad1884_base_mixers;
3247 spec->num_init_verbs = 1;
3248 spec->init_verbs[0] = ad1884_init_verbs;
3249 spec->spdif_route = 0;
3250 #ifdef CONFIG_SND_HDA_POWER_SAVE
3251 spec->loopback.amplist = ad1884_loopbacks;
3253 spec->vmaster_nid = 0x04;
3254 /* we need to cover all playback volumes */
3255 spec->slave_vols = ad1884_slave_vols;
3257 codec->patch_ops = ad198x_patch_ops;
3263 * Lenovo Thinkpad T61/X61
3265 static struct hda_input_mux ad1984_thinkpad_capture_source = {
3269 { "Internal Mic", 0x1 },
3271 { "Docking-Station", 0x4 },
3277 * Dell Precision T3400
3279 static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3282 { "Front Mic", 0x0 },
3289 static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3290 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3291 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3292 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3293 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3294 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3295 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3296 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3297 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3298 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3299 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3300 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3301 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3302 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3303 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3304 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3305 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3306 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3307 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3308 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3310 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3311 /* The multiple "Capture Source" controls confuse alsamixer
3312 * So call somewhat different..
3314 /* .name = "Capture Source", */
3315 .name = "Input Source",
3317 .info = ad198x_mux_enum_info,
3318 .get = ad198x_mux_enum_get,
3319 .put = ad198x_mux_enum_put,
3321 /* SPDIF controls */
3322 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3324 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3325 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3326 /* identical with ad1983 */
3327 .info = ad1983_spdif_route_info,
3328 .get = ad1983_spdif_route_get,
3329 .put = ad1983_spdif_route_put,
3334 /* additional verbs */
3335 static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3336 /* Port-E (docking station mic) pin */
3337 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3338 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3339 /* docking mic boost */
3340 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3341 /* Analog mixer - docking mic; mute as default */
3342 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3343 /* enable EAPD bit */
3344 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3349 * Dell Precision T3400
3351 static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3352 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3353 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3354 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3355 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3356 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3357 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3358 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3359 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3360 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
3362 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
3363 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
3365 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3366 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3367 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3368 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3369 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3370 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3372 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3373 /* The multiple "Capture Source" controls confuse alsamixer
3374 * So call somewhat different..
3376 /* .name = "Capture Source", */
3377 .name = "Input Source",
3379 .info = ad198x_mux_enum_info,
3380 .get = ad198x_mux_enum_get,
3381 .put = ad198x_mux_enum_put,
3386 /* Digial MIC ADC NID 0x05 + 0x06 */
3387 static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3388 struct hda_codec *codec,
3389 unsigned int stream_tag,
3390 unsigned int format,
3391 struct snd_pcm_substream *substream)
3393 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3394 stream_tag, 0, format);
3398 static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3399 struct hda_codec *codec,
3400 struct snd_pcm_substream *substream)
3402 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
3406 static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3412 .prepare = ad1984_pcm_dmic_prepare,
3413 .cleanup = ad1984_pcm_dmic_cleanup
3417 static int ad1984_build_pcms(struct hda_codec *codec)
3419 struct ad198x_spec *spec = codec->spec;
3420 struct hda_pcm *info;
3423 err = ad198x_build_pcms(codec);
3427 info = spec->pcm_rec + codec->num_pcms;
3429 info->name = "AD1984 Digital Mic";
3430 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3438 AD1984_DELL_DESKTOP,
3442 static const char *ad1984_models[AD1984_MODELS] = {
3443 [AD1984_BASIC] = "basic",
3444 [AD1984_THINKPAD] = "thinkpad",
3445 [AD1984_DELL_DESKTOP] = "dell_desktop",
3448 static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3449 /* Lenovo Thinkpad T61/X61 */
3450 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1984_THINKPAD),
3451 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
3455 static int patch_ad1984(struct hda_codec *codec)
3457 struct ad198x_spec *spec;
3458 int board_config, err;
3460 err = patch_ad1884(codec);
3464 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3465 ad1984_models, ad1984_cfg_tbl);
3466 switch (board_config) {
3468 /* additional digital mics */
3469 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3470 codec->patch_ops.build_pcms = ad1984_build_pcms;
3472 case AD1984_THINKPAD:
3473 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3474 spec->input_mux = &ad1984_thinkpad_capture_source;
3475 spec->mixers[0] = ad1984_thinkpad_mixers;
3476 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3478 case AD1984_DELL_DESKTOP:
3479 spec->multiout.dig_out_nid = 0;
3480 spec->input_mux = &ad1984_dell_desktop_capture_source;
3481 spec->mixers[0] = ad1984_dell_desktop_mixers;
3489 * AD1883 / AD1884A / AD1984A / AD1984B
3491 * port-B (0x14) - front mic-in
3492 * port-E (0x1c) - rear mic-in
3493 * port-F (0x16) - CD / ext out
3494 * port-C (0x15) - rear line-in
3495 * port-D (0x12) - rear line-out
3496 * port-A (0x11) - front hp-out
3498 * AD1984A = AD1884A + digital-mic
3499 * AD1883 = equivalent with AD1984A
3500 * AD1984B = AD1984A + extra SPDIF-out
3503 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3506 static hda_nid_t ad1884a_dac_nids[1] = {
3510 #define ad1884a_adc_nids ad1884_adc_nids
3511 #define ad1884a_capsrc_nids ad1884_capsrc_nids
3513 #define AD1884A_SPDIF_OUT 0x02
3515 static struct hda_input_mux ad1884a_capture_source = {
3518 { "Front Mic", 0x0 },
3526 static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3527 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3528 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3529 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3530 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3531 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3532 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3533 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3534 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3535 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3536 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3537 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3538 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3539 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3540 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3541 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3542 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3543 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3544 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3545 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3546 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3547 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3548 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3549 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3550 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3551 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3553 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3554 /* The multiple "Capture Source" controls confuse alsamixer
3555 * So call somewhat different..
3557 /* .name = "Capture Source", */
3558 .name = "Input Source",
3560 .info = ad198x_mux_enum_info,
3561 .get = ad198x_mux_enum_get,
3562 .put = ad198x_mux_enum_put,
3564 /* SPDIF controls */
3565 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3567 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3568 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3569 /* identical with ad1983 */
3570 .info = ad1983_spdif_route_info,
3571 .get = ad1983_spdif_route_get,
3572 .put = ad1983_spdif_route_put,
3578 * initialization verbs
3580 static struct hda_verb ad1884a_init_verbs[] = {
3581 /* DACs; unmute as default */
3582 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3583 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3584 /* Port-A (HP) mixer - route only from analog mixer */
3585 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3586 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3588 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3589 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3590 /* Port-D (Line-out) mixer - route only from analog mixer */
3591 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3592 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3594 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3595 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3596 /* Mono-out mixer - route only from analog mixer */
3597 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3598 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3600 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3601 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3602 /* Port-B (front mic) pin */
3603 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3604 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3605 /* Port-C (rear line-in) pin */
3606 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3607 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3608 /* Port-E (rear mic) pin */
3609 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3610 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3611 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3612 /* Port-F (CD) pin */
3613 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3614 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3615 /* Analog mixer; mute as default */
3616 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3617 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3618 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3619 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3620 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3621 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3622 /* Analog Mix output amp */
3623 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3624 /* capture sources */
3625 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3626 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3627 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3628 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3629 /* SPDIF output amp */
3630 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3634 #ifdef CONFIG_SND_HDA_POWER_SAVE
3635 static struct hda_amp_list ad1884a_loopbacks[] = {
3636 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3637 { 0x20, HDA_INPUT, 1 }, /* Mic */
3638 { 0x20, HDA_INPUT, 2 }, /* CD */
3639 { 0x20, HDA_INPUT, 4 }, /* Docking */
3647 * Port A: Headphone jack
3649 * Port C: Internal MIC
3650 * Port D: Dock Line Out (if enabled)
3651 * Port E: Dock Line In (if enabled)
3652 * Port F: Internal speakers
3655 static struct hda_input_mux ad1884a_laptop_capture_source = {
3658 { "Mic", 0x0 }, /* port-B */
3659 { "Internal Mic", 0x1 }, /* port-C */
3660 { "Dock Mic", 0x4 }, /* port-E */
3665 static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3666 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3667 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3668 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3669 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3670 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3671 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3672 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3673 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3674 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3675 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3676 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3677 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3678 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3679 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3680 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3681 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3682 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3683 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3684 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3685 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3687 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3688 /* The multiple "Capture Source" controls confuse alsamixer
3689 * So call somewhat different..
3691 /* .name = "Capture Source", */
3692 .name = "Input Source",
3694 .info = ad198x_mux_enum_info,
3695 .get = ad198x_mux_enum_get,
3696 .put = ad198x_mux_enum_put,
3701 static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3702 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3703 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3704 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3705 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3706 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3707 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3708 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
3709 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
3710 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3711 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3715 /* mute internal speaker if HP is plugged */
3716 static void ad1884a_hp_automute(struct hda_codec *codec)
3718 unsigned int present;
3720 present = snd_hda_codec_read(codec, 0x11, 0,
3721 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3722 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3723 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3724 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3725 present ? 0x00 : 0x02);
3728 /* switch to external mic if plugged */
3729 static void ad1884a_hp_automic(struct hda_codec *codec)
3731 unsigned int present;
3733 present = snd_hda_codec_read(codec, 0x14, 0,
3734 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3735 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3739 #define AD1884A_HP_EVENT 0x37
3740 #define AD1884A_MIC_EVENT 0x36
3742 /* unsolicited event for HP jack sensing */
3743 static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3745 switch (res >> 26) {
3746 case AD1884A_HP_EVENT:
3747 ad1884a_hp_automute(codec);
3749 case AD1884A_MIC_EVENT:
3750 ad1884a_hp_automic(codec);
3755 /* initialize jack-sensing, too */
3756 static int ad1884a_hp_init(struct hda_codec *codec)
3759 ad1884a_hp_automute(codec);
3760 ad1884a_hp_automic(codec);
3764 /* additional verbs for laptop model */
3765 static struct hda_verb ad1884a_laptop_verbs[] = {
3766 /* Port-A (HP) pin - always unmuted */
3767 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3768 /* Port-F (int speaker) mixer - route only from analog mixer */
3769 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3770 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3772 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3773 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3774 /* Port-C pin - internal mic-in */
3775 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3776 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3777 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3779 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3780 /* unsolicited event for pin-sense */
3781 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3782 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3791 * 0x17 - built-in mic
3794 static struct hda_verb ad1984a_thinkpad_verbs[] = {
3796 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3798 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3800 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3801 /* unsolicited event for pin-sense */
3802 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3803 /* internal mic - dmic */
3804 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3805 /* set magic COEFs for dmic */
3806 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3807 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
3811 static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3812 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3813 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3814 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3815 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3816 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3817 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3818 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3819 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3820 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3821 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3822 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3823 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3825 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3826 .name = "Capture Source",
3827 .info = ad198x_mux_enum_info,
3828 .get = ad198x_mux_enum_get,
3829 .put = ad198x_mux_enum_put,
3834 static struct hda_input_mux ad1984a_thinkpad_capture_source = {
3838 { "Internal Mic", 0x5 },
3843 /* mute internal speaker if HP is plugged */
3844 static void ad1984a_thinkpad_automute(struct hda_codec *codec)
3846 unsigned int present;
3848 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0)
3849 & AC_PINSENSE_PRESENCE;
3850 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
3851 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3854 /* unsolicited event for HP jack sensing */
3855 static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
3858 if ((res >> 26) != AD1884A_HP_EVENT)
3860 ad1984a_thinkpad_automute(codec);
3863 /* initialize jack-sensing, too */
3864 static int ad1984a_thinkpad_init(struct hda_codec *codec)
3867 ad1984a_thinkpad_automute(codec);
3882 static const char *ad1884a_models[AD1884A_MODELS] = {
3883 [AD1884A_DESKTOP] = "desktop",
3884 [AD1884A_LAPTOP] = "laptop",
3885 [AD1884A_MOBILE] = "mobile",
3886 [AD1884A_THINKPAD] = "thinkpad",
3889 static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3890 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
3891 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
3892 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
3893 SND_PCI_QUIRK(0x103c, 0x3072, "HP", AD1884A_LAPTOP),
3894 SND_PCI_QUIRK(0x103c, 0x3077, "HP", AD1884A_LAPTOP),
3895 SND_PCI_QUIRK(0x103c, 0x30e6, "HP 6730b", AD1884A_LAPTOP),
3896 SND_PCI_QUIRK(0x103c, 0x30e7, "HP EliteBook 8530p", AD1884A_LAPTOP),
3897 SND_PCI_QUIRK(0x103c, 0x3614, "HP 6730s", AD1884A_LAPTOP),
3898 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
3902 static int patch_ad1884a(struct hda_codec *codec)
3904 struct ad198x_spec *spec;
3907 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3913 spec->multiout.max_channels = 2;
3914 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
3915 spec->multiout.dac_nids = ad1884a_dac_nids;
3916 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
3917 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
3918 spec->adc_nids = ad1884a_adc_nids;
3919 spec->capsrc_nids = ad1884a_capsrc_nids;
3920 spec->input_mux = &ad1884a_capture_source;
3921 spec->num_mixers = 1;
3922 spec->mixers[0] = ad1884a_base_mixers;
3923 spec->num_init_verbs = 1;
3924 spec->init_verbs[0] = ad1884a_init_verbs;
3925 spec->spdif_route = 0;
3926 #ifdef CONFIG_SND_HDA_POWER_SAVE
3927 spec->loopback.amplist = ad1884a_loopbacks;
3929 codec->patch_ops = ad198x_patch_ops;
3931 /* override some parameters */
3932 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
3935 switch (board_config) {
3936 case AD1884A_LAPTOP:
3937 spec->mixers[0] = ad1884a_laptop_mixers;
3938 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3939 spec->multiout.dig_out_nid = 0;
3940 spec->input_mux = &ad1884a_laptop_capture_source;
3941 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3942 codec->patch_ops.init = ad1884a_hp_init;
3944 case AD1884A_MOBILE:
3945 spec->mixers[0] = ad1884a_mobile_mixers;
3946 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3947 spec->multiout.dig_out_nid = 0;
3948 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3949 codec->patch_ops.init = ad1884a_hp_init;
3951 case AD1884A_THINKPAD:
3952 spec->mixers[0] = ad1984a_thinkpad_mixers;
3953 spec->init_verbs[spec->num_init_verbs++] =
3954 ad1984a_thinkpad_verbs;
3955 spec->multiout.dig_out_nid = 0;
3956 spec->input_mux = &ad1984a_thinkpad_capture_source;
3957 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
3958 codec->patch_ops.init = ad1984a_thinkpad_init;
3969 * port-A - front hp-out
3970 * port-B - front mic-in
3971 * port-C - rear line-in, shared surr-out (3stack)
3972 * port-D - rear line-out
3973 * port-E - rear mic-in, shared clfe-out (3stack)
3974 * port-F - rear surr-out (6stack)
3975 * port-G - rear clfe-out (6stack)
3978 static hda_nid_t ad1882_dac_nids[3] = {
3982 static hda_nid_t ad1882_adc_nids[2] = {
3986 static hda_nid_t ad1882_capsrc_nids[2] = {
3990 #define AD1882_SPDIF_OUT 0x02
3992 /* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
3993 static struct hda_input_mux ad1882_capture_source = {
3996 { "Front Mic", 0x1 },
4004 /* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
4005 static struct hda_input_mux ad1882a_capture_source = {
4008 { "Front Mic", 0x1 },
4011 { "Digital Mic", 0x06 },
4016 static struct snd_kcontrol_new ad1882_base_mixers[] = {
4017 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
4018 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
4019 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
4020 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
4021 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
4022 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4023 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4024 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
4026 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
4027 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
4028 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
4029 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4030 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4031 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
4032 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
4034 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4035 /* The multiple "Capture Source" controls confuse alsamixer
4036 * So call somewhat different..
4038 /* .name = "Capture Source", */
4039 .name = "Input Source",
4041 .info = ad198x_mux_enum_info,
4042 .get = ad198x_mux_enum_get,
4043 .put = ad198x_mux_enum_put,
4045 /* SPDIF controls */
4046 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
4048 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4049 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4050 /* identical with ad1983 */
4051 .info = ad1983_spdif_route_info,
4052 .get = ad1983_spdif_route_get,
4053 .put = ad1983_spdif_route_put,
4058 static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4059 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4060 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4061 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4062 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4063 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4064 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4065 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4066 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4067 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
4068 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
4072 static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4073 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4074 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4075 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4076 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4077 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4078 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4079 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4080 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4081 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
4082 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
4083 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT),
4087 static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
4088 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4089 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
4090 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
4092 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4093 .name = "Channel Mode",
4094 .info = ad198x_ch_mode_info,
4095 .get = ad198x_ch_mode_get,
4096 .put = ad198x_ch_mode_put,
4101 static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
4102 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4103 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4104 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4108 static struct hda_verb ad1882_ch2_init[] = {
4109 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4110 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4111 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4112 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4113 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4114 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4118 static struct hda_verb ad1882_ch4_init[] = {
4119 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4120 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4121 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4122 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4123 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4124 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4128 static struct hda_verb ad1882_ch6_init[] = {
4129 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4130 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4131 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4132 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4133 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4134 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4138 static struct hda_channel_mode ad1882_modes[3] = {
4139 { 2, ad1882_ch2_init },
4140 { 4, ad1882_ch4_init },
4141 { 6, ad1882_ch6_init },
4145 * initialization verbs
4147 static struct hda_verb ad1882_init_verbs[] = {
4148 /* DACs; mute as default */
4149 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4150 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4151 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4152 /* Port-A (HP) mixer */
4153 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4154 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4156 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4157 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4158 /* HP selector - select DAC2 */
4159 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4160 /* Port-D (Line-out) mixer */
4161 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4162 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4164 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4165 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4166 /* Mono-out mixer */
4167 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4168 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4170 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4171 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4172 /* Port-B (front mic) pin */
4173 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4174 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4175 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4176 /* Port-C (line-in) pin */
4177 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4178 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4179 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4180 /* Port-C mixer - mute as input */
4181 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4182 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4183 /* Port-E (mic-in) pin */
4184 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4185 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4186 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4187 /* Port-E mixer - mute as input */
4188 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4189 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4190 /* Port-F (surround) */
4191 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4192 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4194 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4195 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4196 /* Analog mixer; mute as default */
4197 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4198 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4199 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4200 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4201 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4202 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4203 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4204 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4205 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4206 /* Analog Mix output amp */
4207 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4208 /* SPDIF output selector */
4209 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4210 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4211 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4215 #ifdef CONFIG_SND_HDA_POWER_SAVE
4216 static struct hda_amp_list ad1882_loopbacks[] = {
4217 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4218 { 0x20, HDA_INPUT, 1 }, /* Mic */
4219 { 0x20, HDA_INPUT, 4 }, /* Line */
4220 { 0x20, HDA_INPUT, 6 }, /* CD */
4232 static const char *ad1882_models[AD1986A_MODELS] = {
4233 [AD1882_3STACK] = "3stack",
4234 [AD1882_6STACK] = "6stack",
4238 static int patch_ad1882(struct hda_codec *codec)
4240 struct ad198x_spec *spec;
4243 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4249 spec->multiout.max_channels = 6;
4250 spec->multiout.num_dacs = 3;
4251 spec->multiout.dac_nids = ad1882_dac_nids;
4252 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4253 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4254 spec->adc_nids = ad1882_adc_nids;
4255 spec->capsrc_nids = ad1882_capsrc_nids;
4256 if (codec->vendor_id == 0x11d41882)
4257 spec->input_mux = &ad1882_capture_source;
4259 spec->input_mux = &ad1882a_capture_source;
4260 spec->num_mixers = 2;
4261 spec->mixers[0] = ad1882_base_mixers;
4262 if (codec->vendor_id == 0x11d41882)
4263 spec->mixers[1] = ad1882_loopback_mixers;
4265 spec->mixers[1] = ad1882a_loopback_mixers;
4266 spec->num_init_verbs = 1;
4267 spec->init_verbs[0] = ad1882_init_verbs;
4268 spec->spdif_route = 0;
4269 #ifdef CONFIG_SND_HDA_POWER_SAVE
4270 spec->loopback.amplist = ad1882_loopbacks;
4272 spec->vmaster_nid = 0x04;
4274 codec->patch_ops = ad198x_patch_ops;
4276 /* override some parameters */
4277 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4278 ad1882_models, NULL);
4279 switch (board_config) {
4282 spec->num_mixers = 3;
4283 spec->mixers[2] = ad1882_3stack_mixers;
4284 spec->channel_mode = ad1882_modes;
4285 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4286 spec->need_dac_fix = 1;
4287 spec->multiout.max_channels = 2;
4288 spec->multiout.num_dacs = 1;
4291 spec->num_mixers = 3;
4292 spec->mixers[2] = ad1882_6stack_mixers;
4302 static struct hda_codec_preset snd_hda_preset_analog[] = {
4303 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
4304 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
4305 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
4306 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
4307 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4308 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
4309 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4310 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
4311 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
4312 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
4313 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
4314 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
4315 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
4316 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4317 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
4321 MODULE_ALIAS("snd-hda-codec-id:11d4*");
4323 MODULE_LICENSE("GPL");
4324 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
4326 static struct hda_codec_preset_list analog_list = {
4327 .preset = snd_hda_preset_analog,
4328 .owner = THIS_MODULE,
4331 static int __init patch_analog_init(void)
4333 return snd_hda_add_codec_preset(&analog_list);
4336 static void __exit patch_analog_exit(void)
4338 snd_hda_delete_codec_preset(&analog_list);
4341 module_init(patch_analog_init)
4342 module_exit(patch_analog_exit)