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, 0xb000},
1411 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
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},
2292 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2293 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2294 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2299 static struct hda_verb ad1988_spdif_init_verbs[] = {
2301 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2302 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2303 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2304 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2306 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2311 /* AD1989 has no ADC -> SPDIF route */
2312 static struct hda_verb ad1989_spdif_init_verbs[] = {
2313 /* SPDIF-1 out pin */
2314 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2315 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2316 /* SPDIF-2/HDMI out pin */
2317 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2318 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2323 * verbs for 3stack (+dig)
2325 static struct hda_verb ad1988_3stack_ch2_init[] = {
2326 /* set port-C to line-in */
2327 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2328 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2329 /* set port-E to mic-in */
2330 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2331 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2335 static struct hda_verb ad1988_3stack_ch6_init[] = {
2336 /* set port-C to surround out */
2337 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2338 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2339 /* set port-E to CLFE out */
2340 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2341 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2345 static struct hda_channel_mode ad1988_3stack_modes[2] = {
2346 { 2, ad1988_3stack_ch2_init },
2347 { 6, ad1988_3stack_ch6_init },
2350 static struct hda_verb ad1988_3stack_init_verbs[] = {
2351 /* Front, Surround, CLFE, side DAC; unmute as default */
2352 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2353 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2354 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2355 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2356 /* Port-A front headphon path */
2357 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2358 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2359 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2360 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2361 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2362 /* Port-D line-out path */
2363 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2364 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2365 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2366 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2368 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2369 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2370 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2371 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2372 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2373 /* Port-B front mic-in path */
2374 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2375 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2376 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2377 /* Port-C line-in/surround path - 6ch mode as default */
2378 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2379 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2380 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2381 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
2382 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2383 /* Port-E mic-in/CLFE path - 6ch mode as default */
2384 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2385 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2386 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2387 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
2388 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2389 /* mute analog mix */
2390 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2391 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2392 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2393 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2394 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2395 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2396 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2397 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2398 /* select ADCs - front-mic */
2399 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2400 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2401 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2403 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2404 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2405 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2406 /* Analog Mix output amp */
2407 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2412 * verbs for laptop mode (+dig)
2414 static struct hda_verb ad1988_laptop_hp_on[] = {
2415 /* unmute port-A and mute port-D */
2416 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2417 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2420 static struct hda_verb ad1988_laptop_hp_off[] = {
2421 /* mute port-A and unmute port-D */
2422 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2423 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2427 #define AD1988_HP_EVENT 0x01
2429 static struct hda_verb ad1988_laptop_init_verbs[] = {
2430 /* Front, Surround, CLFE, side DAC; unmute as default */
2431 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2432 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2433 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2434 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2435 /* Port-A front headphon path */
2436 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2437 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2438 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2439 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2440 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2441 /* unsolicited event for pin-sense */
2442 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2443 /* Port-D line-out path + EAPD */
2444 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2445 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2446 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2447 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2448 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2450 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2451 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2452 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2453 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2454 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2455 /* Port-B mic-in path */
2456 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2457 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2458 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2459 /* Port-C docking station - try to output */
2460 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2461 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2462 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2463 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2464 /* mute analog mix */
2465 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2466 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2467 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2468 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2469 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2470 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2471 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2472 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2473 /* select ADCs - mic */
2474 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2475 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2476 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2478 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2479 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2480 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2481 /* Analog Mix output amp */
2482 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2486 static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2488 if ((res >> 26) != AD1988_HP_EVENT)
2490 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2491 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2493 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2496 #ifdef CONFIG_SND_HDA_POWER_SAVE
2497 static struct hda_amp_list ad1988_loopbacks[] = {
2498 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2499 { 0x20, HDA_INPUT, 1 }, /* Line */
2500 { 0x20, HDA_INPUT, 4 }, /* Mic */
2501 { 0x20, HDA_INPUT, 6 }, /* CD */
2507 * Automatic parse of I/O pins from the BIOS configuration
2515 static struct snd_kcontrol_new ad1988_control_templates[] = {
2516 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2517 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2518 HDA_BIND_MUTE(NULL, 0, 0, 0),
2521 /* add dynamic controls */
2522 static int add_control(struct ad198x_spec *spec, int type, const char *name,
2525 struct snd_kcontrol_new *knew;
2527 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2528 knew = snd_array_new(&spec->kctls);
2531 *knew = ad1988_control_templates[type];
2532 knew->name = kstrdup(name, GFP_KERNEL);
2535 knew->private_value = val;
2539 #define AD1988_PIN_CD_NID 0x18
2540 #define AD1988_PIN_BEEP_NID 0x10
2542 static hda_nid_t ad1988_mixer_nids[8] = {
2543 /* A B C D E F G H */
2544 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2547 static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2549 static hda_nid_t idx_to_dac[8] = {
2550 /* A B C D E F G H */
2551 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
2553 static hda_nid_t idx_to_dac_rev2[8] = {
2554 /* A B C D E F G H */
2555 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
2558 return idx_to_dac_rev2[idx];
2560 return idx_to_dac[idx];
2563 static hda_nid_t ad1988_boost_nids[8] = {
2564 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2567 static int ad1988_pin_idx(hda_nid_t nid)
2569 static hda_nid_t ad1988_io_pins[8] = {
2570 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2573 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2574 if (ad1988_io_pins[i] == nid)
2576 return 0; /* should be -1 */
2579 static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2581 static int loopback_idx[8] = {
2582 2, 0, 1, 3, 4, 5, 1, 4
2585 case AD1988_PIN_CD_NID:
2588 return loopback_idx[ad1988_pin_idx(nid)];
2592 static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2594 static int adc_idx[8] = {
2595 0, 1, 2, 8, 4, 3, 6, 7
2598 case AD1988_PIN_CD_NID:
2601 return adc_idx[ad1988_pin_idx(nid)];
2605 /* fill in the dac_nids table from the parsed pin configuration */
2606 static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2607 const struct auto_pin_cfg *cfg)
2609 struct ad198x_spec *spec = codec->spec;
2612 spec->multiout.dac_nids = spec->private_dac_nids;
2614 /* check the pins hardwired to audio widget */
2615 for (i = 0; i < cfg->line_outs; i++) {
2616 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2617 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2619 spec->multiout.num_dacs = cfg->line_outs;
2623 /* add playback controls from the parsed DAC table */
2624 static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2625 const struct auto_pin_cfg *cfg)
2628 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2632 for (i = 0; i < cfg->line_outs; i++) {
2633 hda_nid_t dac = spec->multiout.dac_nids[i];
2636 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2639 err = add_control(spec, AD_CTL_WIDGET_VOL,
2640 "Center Playback Volume",
2641 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2644 err = add_control(spec, AD_CTL_WIDGET_VOL,
2645 "LFE Playback Volume",
2646 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2649 err = add_control(spec, AD_CTL_BIND_MUTE,
2650 "Center Playback Switch",
2651 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2654 err = add_control(spec, AD_CTL_BIND_MUTE,
2655 "LFE Playback Switch",
2656 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2660 sprintf(name, "%s Playback Volume", chname[i]);
2661 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2662 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2665 sprintf(name, "%s Playback Switch", chname[i]);
2666 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2667 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2675 /* add playback controls for speaker and HP outputs */
2676 static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2679 struct ad198x_spec *spec = codec->spec;
2687 idx = ad1988_pin_idx(pin);
2688 nid = ad1988_idx_to_dac(codec, idx);
2689 /* check whether the corresponding DAC was already taken */
2690 for (i = 0; i < spec->autocfg.line_outs; i++) {
2691 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2692 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
2696 if (i >= spec->autocfg.line_outs) {
2697 /* specify the DAC as the extra output */
2698 if (!spec->multiout.hp_nid)
2699 spec->multiout.hp_nid = nid;
2701 spec->multiout.extra_out_nid[0] = nid;
2702 /* control HP volume/switch on the output mixer amp */
2703 sprintf(name, "%s Playback Volume", pfx);
2704 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2705 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2709 nid = ad1988_mixer_nids[idx];
2710 sprintf(name, "%s Playback Switch", pfx);
2711 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2712 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2717 /* create input playback/capture controls for the given pin */
2718 static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2719 const char *ctlname, int boost)
2724 sprintf(name, "%s Playback Volume", ctlname);
2725 idx = ad1988_pin_to_loopback_idx(pin);
2726 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2727 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2729 sprintf(name, "%s Playback Switch", ctlname);
2730 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2731 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2735 idx = ad1988_pin_idx(pin);
2736 bnid = ad1988_boost_nids[idx];
2738 sprintf(name, "%s Boost", ctlname);
2739 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2740 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2747 /* create playback/capture controls for input pins */
2748 static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2749 const struct auto_pin_cfg *cfg)
2751 struct hda_input_mux *imux = &spec->private_imux;
2754 for (i = 0; i < AUTO_PIN_LAST; i++) {
2755 err = new_analog_input(spec, cfg->input_pins[i],
2756 auto_pin_cfg_labels[i],
2757 i <= AUTO_PIN_FRONT_MIC);
2760 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2761 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2764 imux->items[imux->num_items].label = "Mix";
2765 imux->items[imux->num_items].index = 9;
2768 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2769 "Analog Mix Playback Volume",
2770 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2772 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2773 "Analog Mix Playback Switch",
2774 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2780 static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2781 hda_nid_t nid, int pin_type,
2785 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2786 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2788 case 0x11: /* port-A - DAC 04 */
2789 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2791 case 0x14: /* port-B - DAC 06 */
2792 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2794 case 0x15: /* port-C - DAC 05 */
2795 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2797 case 0x17: /* port-E - DAC 0a */
2798 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2800 case 0x13: /* mono - DAC 04 */
2801 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2806 static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2808 struct ad198x_spec *spec = codec->spec;
2811 for (i = 0; i < spec->autocfg.line_outs; i++) {
2812 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2813 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2817 static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2819 struct ad198x_spec *spec = codec->spec;
2822 pin = spec->autocfg.speaker_pins[0];
2823 if (pin) /* connect to front */
2824 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2825 pin = spec->autocfg.hp_pins[0];
2826 if (pin) /* connect to front */
2827 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2830 static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2832 struct ad198x_spec *spec = codec->spec;
2835 for (i = 0; i < AUTO_PIN_LAST; i++) {
2836 hda_nid_t nid = spec->autocfg.input_pins[i];
2840 case 0x15: /* port-C */
2841 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2843 case 0x17: /* port-E */
2844 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2847 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2848 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2849 if (nid != AD1988_PIN_CD_NID)
2850 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2852 idx = ad1988_pin_idx(nid);
2853 if (ad1988_boost_nids[idx])
2854 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2855 AC_VERB_SET_AMP_GAIN_MUTE,
2860 /* parse the BIOS configuration and set up the alc_spec */
2861 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2862 static int ad1988_parse_auto_config(struct hda_codec *codec)
2864 struct ad198x_spec *spec = codec->spec;
2867 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2869 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2871 if (! spec->autocfg.line_outs)
2872 return 0; /* can't find valid BIOS pin config */
2873 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2874 (err = ad1988_auto_create_extra_out(codec,
2875 spec->autocfg.speaker_pins[0],
2877 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
2878 "Headphone")) < 0 ||
2879 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2882 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2884 if (spec->autocfg.dig_out_pin)
2885 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2886 if (spec->autocfg.dig_in_pin)
2887 spec->dig_in_nid = AD1988_SPDIF_IN;
2889 if (spec->kctls.list)
2890 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2892 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2894 spec->input_mux = &spec->private_imux;
2899 /* init callback for auto-configuration model -- overriding the default init */
2900 static int ad1988_auto_init(struct hda_codec *codec)
2903 ad1988_auto_init_multi_out(codec);
2904 ad1988_auto_init_extra_out(codec);
2905 ad1988_auto_init_analog_input(codec);
2913 static const char *ad1988_models[AD1988_MODEL_LAST] = {
2914 [AD1988_6STACK] = "6stack",
2915 [AD1988_6STACK_DIG] = "6stack-dig",
2916 [AD1988_3STACK] = "3stack",
2917 [AD1988_3STACK_DIG] = "3stack-dig",
2918 [AD1988_LAPTOP] = "laptop",
2919 [AD1988_LAPTOP_DIG] = "laptop-dig",
2920 [AD1988_AUTO] = "auto",
2923 static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2924 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
2925 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
2926 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
2927 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
2931 static int patch_ad1988(struct hda_codec *codec)
2933 struct ad198x_spec *spec;
2936 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2943 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2945 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
2946 ad1988_models, ad1988_cfg_tbl);
2947 if (board_config < 0) {
2948 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2949 board_config = AD1988_AUTO;
2952 if (board_config == AD1988_AUTO) {
2953 /* automatic parse from the BIOS config */
2954 int err = ad1988_parse_auto_config(codec);
2959 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2960 board_config = AD1988_6STACK;
2964 switch (board_config) {
2966 case AD1988_6STACK_DIG:
2967 spec->multiout.max_channels = 8;
2968 spec->multiout.num_dacs = 4;
2970 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2972 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
2973 spec->input_mux = &ad1988_6stack_capture_source;
2974 spec->num_mixers = 2;
2976 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2978 spec->mixers[0] = ad1988_6stack_mixers1;
2979 spec->mixers[1] = ad1988_6stack_mixers2;
2980 spec->num_init_verbs = 1;
2981 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2982 if (board_config == AD1988_6STACK_DIG) {
2983 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2984 spec->dig_in_nid = AD1988_SPDIF_IN;
2988 case AD1988_3STACK_DIG:
2989 spec->multiout.max_channels = 6;
2990 spec->multiout.num_dacs = 3;
2992 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2994 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2995 spec->input_mux = &ad1988_6stack_capture_source;
2996 spec->channel_mode = ad1988_3stack_modes;
2997 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
2998 spec->num_mixers = 2;
3000 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
3002 spec->mixers[0] = ad1988_3stack_mixers1;
3003 spec->mixers[1] = ad1988_3stack_mixers2;
3004 spec->num_init_verbs = 1;
3005 spec->init_verbs[0] = ad1988_3stack_init_verbs;
3006 if (board_config == AD1988_3STACK_DIG)
3007 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3010 case AD1988_LAPTOP_DIG:
3011 spec->multiout.max_channels = 2;
3012 spec->multiout.num_dacs = 1;
3013 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
3014 spec->input_mux = &ad1988_laptop_capture_source;
3015 spec->num_mixers = 1;
3016 spec->mixers[0] = ad1988_laptop_mixers;
3017 spec->num_init_verbs = 1;
3018 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3019 if (board_config == AD1988_LAPTOP_DIG)
3020 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3024 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3025 spec->adc_nids = ad1988_adc_nids;
3026 spec->capsrc_nids = ad1988_capsrc_nids;
3027 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
3028 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
3029 if (spec->multiout.dig_out_nid) {
3030 if (codec->vendor_id >= 0x11d4989a) {
3031 spec->mixers[spec->num_mixers++] =
3032 ad1989_spdif_out_mixers;
3033 spec->init_verbs[spec->num_init_verbs++] =
3034 ad1989_spdif_init_verbs;
3035 codec->slave_dig_outs = ad1989b_slave_dig_outs;
3037 spec->mixers[spec->num_mixers++] =
3038 ad1988_spdif_out_mixers;
3039 spec->init_verbs[spec->num_init_verbs++] =
3040 ad1988_spdif_init_verbs;
3043 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
3044 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
3046 codec->patch_ops = ad198x_patch_ops;
3047 switch (board_config) {
3049 codec->patch_ops.init = ad1988_auto_init;
3052 case AD1988_LAPTOP_DIG:
3053 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
3056 #ifdef CONFIG_SND_HDA_POWER_SAVE
3057 spec->loopback.amplist = ad1988_loopbacks;
3059 spec->vmaster_nid = 0x04;
3068 * port-B - front line/mic-in
3069 * port-E - aux in/out
3070 * port-F - aux in/out
3071 * port-C - rear line/mic-in
3072 * port-D - rear line/hp-out
3073 * port-A - front line/hp-out
3075 * AD1984 = AD1884 + two digital mic-ins
3078 * For simplicity, we share the single DAC for both HP and line-outs
3079 * right now. The inidividual playbacks could be easily implemented,
3080 * but no build-up framework is given, so far.
3083 static hda_nid_t ad1884_dac_nids[1] = {
3087 static hda_nid_t ad1884_adc_nids[2] = {
3091 static hda_nid_t ad1884_capsrc_nids[2] = {
3095 #define AD1884_SPDIF_OUT 0x02
3097 static struct hda_input_mux ad1884_capture_source = {
3100 { "Front Mic", 0x0 },
3107 static struct snd_kcontrol_new ad1884_base_mixers[] = {
3108 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3109 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3110 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3111 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3112 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3113 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3114 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3115 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3116 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3117 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3118 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3119 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3121 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
3122 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
3123 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
3124 HDA_CODEC_MUTE("Digital Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3126 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3127 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3128 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3129 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3130 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3131 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3133 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3134 /* The multiple "Capture Source" controls confuse alsamixer
3135 * So call somewhat different..
3137 /* .name = "Capture Source", */
3138 .name = "Input Source",
3140 .info = ad198x_mux_enum_info,
3141 .get = ad198x_mux_enum_get,
3142 .put = ad198x_mux_enum_put,
3144 /* SPDIF controls */
3145 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3147 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3148 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3149 /* identical with ad1983 */
3150 .info = ad1983_spdif_route_info,
3151 .get = ad1983_spdif_route_get,
3152 .put = ad1983_spdif_route_put,
3157 static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3158 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3159 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3160 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
3162 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
3168 * initialization verbs
3170 static struct hda_verb ad1884_init_verbs[] = {
3171 /* DACs; mute as default */
3172 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3173 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3174 /* Port-A (HP) mixer */
3175 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3176 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3178 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3179 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3180 /* HP selector - select DAC2 */
3181 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3182 /* Port-D (Line-out) mixer */
3183 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3184 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3186 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3187 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3188 /* Mono-out mixer */
3189 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3190 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3192 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3193 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3195 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3196 /* Port-B (front mic) pin */
3197 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3198 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3199 /* Port-C (rear mic) pin */
3200 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3201 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3202 /* Analog mixer; mute as default */
3203 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3204 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3205 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3206 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3207 /* Analog Mix output amp */
3208 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3209 /* SPDIF output selector */
3210 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3211 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3215 #ifdef CONFIG_SND_HDA_POWER_SAVE
3216 static struct hda_amp_list ad1884_loopbacks[] = {
3217 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3218 { 0x20, HDA_INPUT, 1 }, /* Mic */
3219 { 0x20, HDA_INPUT, 2 }, /* CD */
3220 { 0x20, HDA_INPUT, 4 }, /* Docking */
3225 static const char *ad1884_slave_vols[] = {
3226 "PCM Playback Volume",
3227 "Mic Playback Volume",
3228 "Mono Playback Volume",
3229 "Front Mic Playback Volume",
3230 "Mic Playback Volume",
3231 "CD Playback Volume",
3232 "Internal Mic Playback Volume",
3233 "Docking Mic Playback Volume"
3234 "Beep Playback Volume",
3235 "IEC958 Playback Volume",
3239 static int patch_ad1884(struct hda_codec *codec)
3241 struct ad198x_spec *spec;
3243 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3249 spec->multiout.max_channels = 2;
3250 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3251 spec->multiout.dac_nids = ad1884_dac_nids;
3252 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3253 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3254 spec->adc_nids = ad1884_adc_nids;
3255 spec->capsrc_nids = ad1884_capsrc_nids;
3256 spec->input_mux = &ad1884_capture_source;
3257 spec->num_mixers = 1;
3258 spec->mixers[0] = ad1884_base_mixers;
3259 spec->num_init_verbs = 1;
3260 spec->init_verbs[0] = ad1884_init_verbs;
3261 spec->spdif_route = 0;
3262 #ifdef CONFIG_SND_HDA_POWER_SAVE
3263 spec->loopback.amplist = ad1884_loopbacks;
3265 spec->vmaster_nid = 0x04;
3266 /* we need to cover all playback volumes */
3267 spec->slave_vols = ad1884_slave_vols;
3269 codec->patch_ops = ad198x_patch_ops;
3275 * Lenovo Thinkpad T61/X61
3277 static struct hda_input_mux ad1984_thinkpad_capture_source = {
3281 { "Internal Mic", 0x1 },
3283 { "Docking-Station", 0x4 },
3289 * Dell Precision T3400
3291 static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3294 { "Front Mic", 0x0 },
3301 static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3302 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3303 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3304 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3305 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3306 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3307 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3308 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3309 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3310 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3311 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3312 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3313 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3314 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3315 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3316 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3317 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3318 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3319 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3320 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3322 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3323 /* The multiple "Capture Source" controls confuse alsamixer
3324 * So call somewhat different..
3326 /* .name = "Capture Source", */
3327 .name = "Input Source",
3329 .info = ad198x_mux_enum_info,
3330 .get = ad198x_mux_enum_get,
3331 .put = ad198x_mux_enum_put,
3333 /* SPDIF controls */
3334 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3336 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3337 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3338 /* identical with ad1983 */
3339 .info = ad1983_spdif_route_info,
3340 .get = ad1983_spdif_route_get,
3341 .put = ad1983_spdif_route_put,
3346 /* additional verbs */
3347 static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3348 /* Port-E (docking station mic) pin */
3349 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3350 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3351 /* docking mic boost */
3352 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3353 /* Analog mixer - docking mic; mute as default */
3354 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3355 /* enable EAPD bit */
3356 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3361 * Dell Precision T3400
3363 static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3364 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3365 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3366 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3367 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3368 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3369 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3370 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3371 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3372 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
3374 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
3375 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
3377 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3378 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3379 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3380 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3381 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3382 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3384 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3385 /* The multiple "Capture Source" controls confuse alsamixer
3386 * So call somewhat different..
3388 /* .name = "Capture Source", */
3389 .name = "Input Source",
3391 .info = ad198x_mux_enum_info,
3392 .get = ad198x_mux_enum_get,
3393 .put = ad198x_mux_enum_put,
3398 /* Digial MIC ADC NID 0x05 + 0x06 */
3399 static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3400 struct hda_codec *codec,
3401 unsigned int stream_tag,
3402 unsigned int format,
3403 struct snd_pcm_substream *substream)
3405 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3406 stream_tag, 0, format);
3410 static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3411 struct hda_codec *codec,
3412 struct snd_pcm_substream *substream)
3414 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
3418 static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3424 .prepare = ad1984_pcm_dmic_prepare,
3425 .cleanup = ad1984_pcm_dmic_cleanup
3429 static int ad1984_build_pcms(struct hda_codec *codec)
3431 struct ad198x_spec *spec = codec->spec;
3432 struct hda_pcm *info;
3435 err = ad198x_build_pcms(codec);
3439 info = spec->pcm_rec + codec->num_pcms;
3441 info->name = "AD1984 Digital Mic";
3442 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3450 AD1984_DELL_DESKTOP,
3454 static const char *ad1984_models[AD1984_MODELS] = {
3455 [AD1984_BASIC] = "basic",
3456 [AD1984_THINKPAD] = "thinkpad",
3457 [AD1984_DELL_DESKTOP] = "dell_desktop",
3460 static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3461 /* Lenovo Thinkpad T61/X61 */
3462 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1984_THINKPAD),
3463 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
3467 static int patch_ad1984(struct hda_codec *codec)
3469 struct ad198x_spec *spec;
3470 int board_config, err;
3472 err = patch_ad1884(codec);
3476 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3477 ad1984_models, ad1984_cfg_tbl);
3478 switch (board_config) {
3480 /* additional digital mics */
3481 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3482 codec->patch_ops.build_pcms = ad1984_build_pcms;
3484 case AD1984_THINKPAD:
3485 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3486 spec->input_mux = &ad1984_thinkpad_capture_source;
3487 spec->mixers[0] = ad1984_thinkpad_mixers;
3488 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3490 case AD1984_DELL_DESKTOP:
3491 spec->multiout.dig_out_nid = 0;
3492 spec->input_mux = &ad1984_dell_desktop_capture_source;
3493 spec->mixers[0] = ad1984_dell_desktop_mixers;
3501 * AD1883 / AD1884A / AD1984A / AD1984B
3503 * port-B (0x14) - front mic-in
3504 * port-E (0x1c) - rear mic-in
3505 * port-F (0x16) - CD / ext out
3506 * port-C (0x15) - rear line-in
3507 * port-D (0x12) - rear line-out
3508 * port-A (0x11) - front hp-out
3510 * AD1984A = AD1884A + digital-mic
3511 * AD1883 = equivalent with AD1984A
3512 * AD1984B = AD1984A + extra SPDIF-out
3515 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3518 static hda_nid_t ad1884a_dac_nids[1] = {
3522 #define ad1884a_adc_nids ad1884_adc_nids
3523 #define ad1884a_capsrc_nids ad1884_capsrc_nids
3525 #define AD1884A_SPDIF_OUT 0x02
3527 static struct hda_input_mux ad1884a_capture_source = {
3530 { "Front Mic", 0x0 },
3538 static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3539 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3540 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3541 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3542 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3543 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3544 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3545 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3546 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3547 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3548 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3549 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3550 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3551 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3552 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3553 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3554 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3555 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3556 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3557 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3558 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3559 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3560 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3561 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3562 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3563 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3565 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3566 /* The multiple "Capture Source" controls confuse alsamixer
3567 * So call somewhat different..
3569 /* .name = "Capture Source", */
3570 .name = "Input Source",
3572 .info = ad198x_mux_enum_info,
3573 .get = ad198x_mux_enum_get,
3574 .put = ad198x_mux_enum_put,
3576 /* SPDIF controls */
3577 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3579 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3580 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3581 /* identical with ad1983 */
3582 .info = ad1983_spdif_route_info,
3583 .get = ad1983_spdif_route_get,
3584 .put = ad1983_spdif_route_put,
3590 * initialization verbs
3592 static struct hda_verb ad1884a_init_verbs[] = {
3593 /* DACs; unmute as default */
3594 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3595 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3596 /* Port-A (HP) mixer - route only from analog mixer */
3597 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3598 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3600 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3601 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3602 /* Port-D (Line-out) mixer - route only from analog mixer */
3603 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3604 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3606 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3607 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3608 /* Mono-out mixer - route only from analog mixer */
3609 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3610 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3612 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3613 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3614 /* Port-B (front mic) pin */
3615 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3616 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3617 /* Port-C (rear line-in) pin */
3618 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3619 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3620 /* Port-E (rear mic) pin */
3621 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3622 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3623 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3624 /* Port-F (CD) pin */
3625 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3626 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3627 /* Analog mixer; mute as default */
3628 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3629 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3630 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3631 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3632 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3633 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3634 /* Analog Mix output amp */
3635 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3636 /* capture sources */
3637 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3638 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3639 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3640 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3641 /* SPDIF output amp */
3642 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3646 #ifdef CONFIG_SND_HDA_POWER_SAVE
3647 static struct hda_amp_list ad1884a_loopbacks[] = {
3648 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3649 { 0x20, HDA_INPUT, 1 }, /* Mic */
3650 { 0x20, HDA_INPUT, 2 }, /* CD */
3651 { 0x20, HDA_INPUT, 4 }, /* Docking */
3659 * Port A: Headphone jack
3661 * Port C: Internal MIC
3662 * Port D: Dock Line Out (if enabled)
3663 * Port E: Dock Line In (if enabled)
3664 * Port F: Internal speakers
3667 static struct hda_input_mux ad1884a_laptop_capture_source = {
3670 { "Mic", 0x0 }, /* port-B */
3671 { "Internal Mic", 0x1 }, /* port-C */
3672 { "Dock Mic", 0x4 }, /* port-E */
3677 static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3678 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3679 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3680 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3681 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3682 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3683 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3684 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3685 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3686 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3687 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3688 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3689 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3690 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3691 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3692 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3693 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3694 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3695 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3696 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3697 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3699 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3700 /* The multiple "Capture Source" controls confuse alsamixer
3701 * So call somewhat different..
3703 /* .name = "Capture Source", */
3704 .name = "Input Source",
3706 .info = ad198x_mux_enum_info,
3707 .get = ad198x_mux_enum_get,
3708 .put = ad198x_mux_enum_put,
3713 static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3714 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3715 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3716 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3717 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3718 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3719 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3720 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
3721 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
3722 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3723 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3727 /* mute internal speaker if HP is plugged */
3728 static void ad1884a_hp_automute(struct hda_codec *codec)
3730 unsigned int present;
3732 present = snd_hda_codec_read(codec, 0x11, 0,
3733 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3734 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3735 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3736 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3737 present ? 0x00 : 0x02);
3740 /* switch to external mic if plugged */
3741 static void ad1884a_hp_automic(struct hda_codec *codec)
3743 unsigned int present;
3745 present = snd_hda_codec_read(codec, 0x14, 0,
3746 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3747 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3751 #define AD1884A_HP_EVENT 0x37
3752 #define AD1884A_MIC_EVENT 0x36
3754 /* unsolicited event for HP jack sensing */
3755 static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3757 switch (res >> 26) {
3758 case AD1884A_HP_EVENT:
3759 ad1884a_hp_automute(codec);
3761 case AD1884A_MIC_EVENT:
3762 ad1884a_hp_automic(codec);
3767 /* initialize jack-sensing, too */
3768 static int ad1884a_hp_init(struct hda_codec *codec)
3771 ad1884a_hp_automute(codec);
3772 ad1884a_hp_automic(codec);
3776 /* additional verbs for laptop model */
3777 static struct hda_verb ad1884a_laptop_verbs[] = {
3778 /* Port-A (HP) pin - always unmuted */
3779 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3780 /* Port-F (int speaker) mixer - route only from analog mixer */
3781 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3782 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3784 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3785 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3786 /* Port-C pin - internal mic-in */
3787 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3788 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3789 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3791 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3792 /* unsolicited event for pin-sense */
3793 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3794 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3803 * 0x17 - built-in mic
3806 static struct hda_verb ad1984a_thinkpad_verbs[] = {
3808 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3810 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3812 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3813 /* unsolicited event for pin-sense */
3814 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3815 /* internal mic - dmic */
3816 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3817 /* set magic COEFs for dmic */
3818 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3819 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
3823 static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3824 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3825 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3826 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3827 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3828 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3829 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3830 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3831 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3832 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3833 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3834 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3835 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3837 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3838 .name = "Capture Source",
3839 .info = ad198x_mux_enum_info,
3840 .get = ad198x_mux_enum_get,
3841 .put = ad198x_mux_enum_put,
3846 static struct hda_input_mux ad1984a_thinkpad_capture_source = {
3850 { "Internal Mic", 0x5 },
3855 /* mute internal speaker if HP is plugged */
3856 static void ad1984a_thinkpad_automute(struct hda_codec *codec)
3858 unsigned int present;
3860 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0)
3861 & AC_PINSENSE_PRESENCE;
3862 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
3863 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3866 /* unsolicited event for HP jack sensing */
3867 static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
3870 if ((res >> 26) != AD1884A_HP_EVENT)
3872 ad1984a_thinkpad_automute(codec);
3875 /* initialize jack-sensing, too */
3876 static int ad1984a_thinkpad_init(struct hda_codec *codec)
3879 ad1984a_thinkpad_automute(codec);
3894 static const char *ad1884a_models[AD1884A_MODELS] = {
3895 [AD1884A_DESKTOP] = "desktop",
3896 [AD1884A_LAPTOP] = "laptop",
3897 [AD1884A_MOBILE] = "mobile",
3898 [AD1884A_THINKPAD] = "thinkpad",
3901 static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3902 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
3903 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
3904 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
3905 SND_PCI_QUIRK(0x103c, 0x30e6, "HP 6730b", AD1884A_LAPTOP),
3906 SND_PCI_QUIRK(0x103c, 0x30e7, "HP EliteBook 8530p", AD1884A_LAPTOP),
3907 SND_PCI_QUIRK(0x103c, 0x3614, "HP 6730s", AD1884A_LAPTOP),
3908 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
3912 static int patch_ad1884a(struct hda_codec *codec)
3914 struct ad198x_spec *spec;
3917 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3923 spec->multiout.max_channels = 2;
3924 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
3925 spec->multiout.dac_nids = ad1884a_dac_nids;
3926 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
3927 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
3928 spec->adc_nids = ad1884a_adc_nids;
3929 spec->capsrc_nids = ad1884a_capsrc_nids;
3930 spec->input_mux = &ad1884a_capture_source;
3931 spec->num_mixers = 1;
3932 spec->mixers[0] = ad1884a_base_mixers;
3933 spec->num_init_verbs = 1;
3934 spec->init_verbs[0] = ad1884a_init_verbs;
3935 spec->spdif_route = 0;
3936 #ifdef CONFIG_SND_HDA_POWER_SAVE
3937 spec->loopback.amplist = ad1884a_loopbacks;
3939 codec->patch_ops = ad198x_patch_ops;
3941 /* override some parameters */
3942 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
3945 switch (board_config) {
3946 case AD1884A_LAPTOP:
3947 spec->mixers[0] = ad1884a_laptop_mixers;
3948 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3949 spec->multiout.dig_out_nid = 0;
3950 spec->input_mux = &ad1884a_laptop_capture_source;
3951 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3952 codec->patch_ops.init = ad1884a_hp_init;
3954 case AD1884A_MOBILE:
3955 spec->mixers[0] = ad1884a_mobile_mixers;
3956 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3957 spec->multiout.dig_out_nid = 0;
3958 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3959 codec->patch_ops.init = ad1884a_hp_init;
3961 case AD1884A_THINKPAD:
3962 spec->mixers[0] = ad1984a_thinkpad_mixers;
3963 spec->init_verbs[spec->num_init_verbs++] =
3964 ad1984a_thinkpad_verbs;
3965 spec->multiout.dig_out_nid = 0;
3966 spec->input_mux = &ad1984a_thinkpad_capture_source;
3967 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
3968 codec->patch_ops.init = ad1984a_thinkpad_init;
3979 * port-A - front hp-out
3980 * port-B - front mic-in
3981 * port-C - rear line-in, shared surr-out (3stack)
3982 * port-D - rear line-out
3983 * port-E - rear mic-in, shared clfe-out (3stack)
3984 * port-F - rear surr-out (6stack)
3985 * port-G - rear clfe-out (6stack)
3988 static hda_nid_t ad1882_dac_nids[3] = {
3992 static hda_nid_t ad1882_adc_nids[2] = {
3996 static hda_nid_t ad1882_capsrc_nids[2] = {
4000 #define AD1882_SPDIF_OUT 0x02
4002 /* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
4003 static struct hda_input_mux ad1882_capture_source = {
4006 { "Front Mic", 0x1 },
4014 /* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
4015 static struct hda_input_mux ad1882a_capture_source = {
4018 { "Front Mic", 0x1 },
4021 { "Digital Mic", 0x06 },
4026 static struct snd_kcontrol_new ad1882_base_mixers[] = {
4027 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
4028 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
4029 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
4030 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
4031 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
4032 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4033 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4034 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
4036 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
4037 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
4038 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
4039 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4040 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4041 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
4042 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
4044 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4045 /* The multiple "Capture Source" controls confuse alsamixer
4046 * So call somewhat different..
4048 /* .name = "Capture Source", */
4049 .name = "Input Source",
4051 .info = ad198x_mux_enum_info,
4052 .get = ad198x_mux_enum_get,
4053 .put = ad198x_mux_enum_put,
4055 /* SPDIF controls */
4056 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
4058 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4059 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4060 /* identical with ad1983 */
4061 .info = ad1983_spdif_route_info,
4062 .get = ad1983_spdif_route_get,
4063 .put = ad1983_spdif_route_put,
4068 static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4069 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4070 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4071 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4072 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4073 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4074 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4075 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4076 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4077 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
4078 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
4082 static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4083 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4084 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4085 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4086 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4087 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4088 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4089 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4090 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4091 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
4092 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
4093 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT),
4097 static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
4098 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4099 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
4100 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
4102 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4103 .name = "Channel Mode",
4104 .info = ad198x_ch_mode_info,
4105 .get = ad198x_ch_mode_get,
4106 .put = ad198x_ch_mode_put,
4111 static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
4112 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4113 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4114 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4118 static struct hda_verb ad1882_ch2_init[] = {
4119 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4120 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4121 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(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_ch4_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_VREF80},
4133 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4134 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4138 static struct hda_verb ad1882_ch6_init[] = {
4139 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4140 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4141 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4142 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4143 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4144 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4148 static struct hda_channel_mode ad1882_modes[3] = {
4149 { 2, ad1882_ch2_init },
4150 { 4, ad1882_ch4_init },
4151 { 6, ad1882_ch6_init },
4155 * initialization verbs
4157 static struct hda_verb ad1882_init_verbs[] = {
4158 /* DACs; mute as default */
4159 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4160 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4161 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4162 /* Port-A (HP) mixer */
4163 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4164 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4166 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4167 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4168 /* HP selector - select DAC2 */
4169 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4170 /* Port-D (Line-out) mixer */
4171 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4172 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4174 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4175 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4176 /* Mono-out mixer */
4177 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4178 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4180 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4181 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4182 /* Port-B (front mic) pin */
4183 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4184 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4185 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4186 /* Port-C (line-in) pin */
4187 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4188 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4189 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4190 /* Port-C mixer - mute as input */
4191 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4192 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4193 /* Port-E (mic-in) pin */
4194 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4195 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4196 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4197 /* Port-E mixer - mute as input */
4198 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4199 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4200 /* Port-F (surround) */
4201 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4202 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4204 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4205 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4206 /* Analog mixer; mute as default */
4207 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4208 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4209 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4210 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4211 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4212 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4213 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4214 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4215 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4216 /* Analog Mix output amp */
4217 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4218 /* SPDIF output selector */
4219 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4220 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4221 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4225 #ifdef CONFIG_SND_HDA_POWER_SAVE
4226 static struct hda_amp_list ad1882_loopbacks[] = {
4227 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4228 { 0x20, HDA_INPUT, 1 }, /* Mic */
4229 { 0x20, HDA_INPUT, 4 }, /* Line */
4230 { 0x20, HDA_INPUT, 6 }, /* CD */
4242 static const char *ad1882_models[AD1986A_MODELS] = {
4243 [AD1882_3STACK] = "3stack",
4244 [AD1882_6STACK] = "6stack",
4248 static int patch_ad1882(struct hda_codec *codec)
4250 struct ad198x_spec *spec;
4253 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4259 spec->multiout.max_channels = 6;
4260 spec->multiout.num_dacs = 3;
4261 spec->multiout.dac_nids = ad1882_dac_nids;
4262 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4263 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4264 spec->adc_nids = ad1882_adc_nids;
4265 spec->capsrc_nids = ad1882_capsrc_nids;
4266 if (codec->vendor_id == 0x11d41882)
4267 spec->input_mux = &ad1882_capture_source;
4269 spec->input_mux = &ad1882a_capture_source;
4270 spec->num_mixers = 2;
4271 spec->mixers[0] = ad1882_base_mixers;
4272 if (codec->vendor_id == 0x11d41882)
4273 spec->mixers[1] = ad1882_loopback_mixers;
4275 spec->mixers[1] = ad1882a_loopback_mixers;
4276 spec->num_init_verbs = 1;
4277 spec->init_verbs[0] = ad1882_init_verbs;
4278 spec->spdif_route = 0;
4279 #ifdef CONFIG_SND_HDA_POWER_SAVE
4280 spec->loopback.amplist = ad1882_loopbacks;
4282 spec->vmaster_nid = 0x04;
4284 codec->patch_ops = ad198x_patch_ops;
4286 /* override some parameters */
4287 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4288 ad1882_models, NULL);
4289 switch (board_config) {
4292 spec->num_mixers = 3;
4293 spec->mixers[2] = ad1882_3stack_mixers;
4294 spec->channel_mode = ad1882_modes;
4295 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4296 spec->need_dac_fix = 1;
4297 spec->multiout.max_channels = 2;
4298 spec->multiout.num_dacs = 1;
4301 spec->num_mixers = 3;
4302 spec->mixers[2] = ad1882_6stack_mixers;
4312 static struct hda_codec_preset snd_hda_preset_analog[] = {
4313 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
4314 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
4315 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
4316 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
4317 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4318 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
4319 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4320 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
4321 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
4322 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
4323 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
4324 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
4325 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
4326 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4327 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
4331 MODULE_ALIAS("snd-hda-codec-id:11d4*");
4333 MODULE_LICENSE("GPL");
4334 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
4336 static struct hda_codec_preset_list analog_list = {
4337 .preset = snd_hda_preset_analog,
4338 .owner = THIS_MODULE,
4341 static int __init patch_analog_init(void)
4343 return snd_hda_add_codec_preset(&analog_list);
4346 static void __exit patch_analog_exit(void)
4348 snd_hda_delete_codec_preset(&analog_list);
4351 module_init(patch_analog_init)
4352 module_exit(patch_analog_exit)