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>
26 #include <linux/mutex.h>
28 #include <sound/core.h>
29 #include "hda_codec.h"
30 #include "hda_local.h"
31 #include "hda_patch.h"
34 struct snd_kcontrol_new *mixers[5];
37 const struct hda_verb *init_verbs[5]; /* initialization verbs
38 * don't forget NULL termination!
40 unsigned int num_init_verbs;
43 struct hda_multi_out multiout; /* playback set-up
44 * max_channels, dacs must be set
45 * dig_out_nid and hp_nid are optional
47 unsigned int cur_eapd;
48 unsigned int need_dac_fix;
51 unsigned int num_adc_nids;
53 hda_nid_t dig_in_nid; /* digital-in NID; optional */
56 const struct hda_input_mux *input_mux;
57 hda_nid_t *capsrc_nids;
58 unsigned int cur_mux[3];
61 const struct hda_channel_mode *channel_mode;
65 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
67 struct mutex amp_mutex; /* PCM volume/mute control mutex */
68 unsigned int spdif_route;
70 /* dynamic controls, init_verbs and input_mux */
71 struct auto_pin_cfg autocfg;
72 unsigned int num_kctl_alloc, num_kctl_used;
73 struct snd_kcontrol_new *kctl_alloc;
74 struct hda_input_mux private_imux;
75 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
77 unsigned int jack_present :1;
79 #ifdef CONFIG_SND_HDA_POWER_SAVE
80 struct hda_loopback_check loopback;
82 /* for virtual master */
83 hda_nid_t vmaster_nid;
84 const char **slave_vols;
85 const char **slave_sws;
89 * input MUX handling (common part)
91 static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
93 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
94 struct ad198x_spec *spec = codec->spec;
96 return snd_hda_input_mux_info(spec->input_mux, uinfo);
99 static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
101 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
102 struct ad198x_spec *spec = codec->spec;
103 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
105 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
109 static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
111 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
112 struct ad198x_spec *spec = codec->spec;
113 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
115 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
116 spec->capsrc_nids[adc_idx],
117 &spec->cur_mux[adc_idx]);
121 * initialization (common callbacks)
123 static int ad198x_init(struct hda_codec *codec)
125 struct ad198x_spec *spec = codec->spec;
128 for (i = 0; i < spec->num_init_verbs; i++)
129 snd_hda_sequence_write(codec, spec->init_verbs[i]);
133 static const char *ad_slave_vols[] = {
134 "Front Playback Volume",
135 "Surround Playback Volume",
136 "Center Playback Volume",
137 "LFE Playback Volume",
138 "Side Playback Volume",
139 "Headphone Playback Volume",
140 "Mono Playback Volume",
141 "Speaker Playback Volume",
142 "IEC958 Playback Volume",
146 static const char *ad_slave_sws[] = {
147 "Front Playback Switch",
148 "Surround Playback Switch",
149 "Center Playback Switch",
150 "LFE Playback Switch",
151 "Side Playback Switch",
152 "Headphone Playback Switch",
153 "Mono Playback Switch",
154 "Speaker Playback Switch",
155 "IEC958 Playback Switch",
159 static int ad198x_build_controls(struct hda_codec *codec)
161 struct ad198x_spec *spec = codec->spec;
165 for (i = 0; i < spec->num_mixers; i++) {
166 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
170 if (spec->multiout.dig_out_nid) {
171 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
174 err = snd_hda_create_spdif_share_sw(codec,
178 spec->multiout.share_spdif = 1;
180 if (spec->dig_in_nid) {
181 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
186 /* if we have no master control, let's create it */
187 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
188 unsigned int vmaster_tlv[4];
189 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
190 HDA_OUTPUT, vmaster_tlv);
191 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
194 spec->slave_vols : ad_slave_vols));
198 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
199 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
202 spec->slave_sws : ad_slave_sws));
210 #ifdef CONFIG_SND_HDA_POWER_SAVE
211 static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
213 struct ad198x_spec *spec = codec->spec;
214 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
219 * Analog playback callbacks
221 static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
222 struct hda_codec *codec,
223 struct snd_pcm_substream *substream)
225 struct ad198x_spec *spec = codec->spec;
226 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
230 static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
231 struct hda_codec *codec,
232 unsigned int stream_tag,
234 struct snd_pcm_substream *substream)
236 struct ad198x_spec *spec = codec->spec;
237 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
241 static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
242 struct hda_codec *codec,
243 struct snd_pcm_substream *substream)
245 struct ad198x_spec *spec = codec->spec;
246 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
252 static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
253 struct hda_codec *codec,
254 struct snd_pcm_substream *substream)
256 struct ad198x_spec *spec = codec->spec;
257 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
260 static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
261 struct hda_codec *codec,
262 struct snd_pcm_substream *substream)
264 struct ad198x_spec *spec = codec->spec;
265 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
268 static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
269 struct hda_codec *codec,
270 unsigned int stream_tag,
272 struct snd_pcm_substream *substream)
274 struct ad198x_spec *spec = codec->spec;
275 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
282 static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
283 struct hda_codec *codec,
284 unsigned int stream_tag,
286 struct snd_pcm_substream *substream)
288 struct ad198x_spec *spec = codec->spec;
289 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
290 stream_tag, 0, format);
294 static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
295 struct hda_codec *codec,
296 struct snd_pcm_substream *substream)
298 struct ad198x_spec *spec = codec->spec;
299 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
306 static struct hda_pcm_stream ad198x_pcm_analog_playback = {
309 .channels_max = 6, /* changed later */
310 .nid = 0, /* fill later */
312 .open = ad198x_playback_pcm_open,
313 .prepare = ad198x_playback_pcm_prepare,
314 .cleanup = ad198x_playback_pcm_cleanup
318 static struct hda_pcm_stream ad198x_pcm_analog_capture = {
322 .nid = 0, /* fill later */
324 .prepare = ad198x_capture_pcm_prepare,
325 .cleanup = ad198x_capture_pcm_cleanup
329 static struct hda_pcm_stream ad198x_pcm_digital_playback = {
333 .nid = 0, /* fill later */
335 .open = ad198x_dig_playback_pcm_open,
336 .close = ad198x_dig_playback_pcm_close,
337 .prepare = ad198x_dig_playback_pcm_prepare
341 static struct hda_pcm_stream ad198x_pcm_digital_capture = {
345 /* NID is set in alc_build_pcms */
348 static int ad198x_build_pcms(struct hda_codec *codec)
350 struct ad198x_spec *spec = codec->spec;
351 struct hda_pcm *info = spec->pcm_rec;
354 codec->pcm_info = info;
356 info->name = "AD198x Analog";
357 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
358 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
359 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
360 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
361 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
362 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
364 if (spec->multiout.dig_out_nid) {
367 info->name = "AD198x Digital";
368 info->pcm_type = HDA_PCM_TYPE_SPDIF;
369 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
370 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
371 if (spec->dig_in_nid) {
372 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
373 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
380 static void ad198x_free(struct hda_codec *codec)
382 struct ad198x_spec *spec = codec->spec;
385 if (spec->kctl_alloc) {
386 for (i = 0; i < spec->num_kctl_used; i++)
387 kfree(spec->kctl_alloc[i].name);
388 kfree(spec->kctl_alloc);
393 static struct hda_codec_ops ad198x_patch_ops = {
394 .build_controls = ad198x_build_controls,
395 .build_pcms = ad198x_build_pcms,
398 #ifdef CONFIG_SND_HDA_POWER_SAVE
399 .check_power_status = ad198x_check_power_status,
406 * the private value = nid | (invert << 8)
408 #define ad198x_eapd_info snd_ctl_boolean_mono_info
410 static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
411 struct snd_ctl_elem_value *ucontrol)
413 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
414 struct ad198x_spec *spec = codec->spec;
415 int invert = (kcontrol->private_value >> 8) & 1;
417 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
419 ucontrol->value.integer.value[0] = spec->cur_eapd;
423 static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
424 struct snd_ctl_elem_value *ucontrol)
426 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
427 struct ad198x_spec *spec = codec->spec;
428 int invert = (kcontrol->private_value >> 8) & 1;
429 hda_nid_t nid = kcontrol->private_value & 0xff;
431 eapd = !!ucontrol->value.integer.value[0];
434 if (eapd == spec->cur_eapd)
436 spec->cur_eapd = eapd;
437 snd_hda_codec_write_cache(codec, nid,
438 0, AC_VERB_SET_EAPD_BTLENABLE,
443 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
444 struct snd_ctl_elem_info *uinfo);
445 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
446 struct snd_ctl_elem_value *ucontrol);
447 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
448 struct snd_ctl_elem_value *ucontrol);
455 #define AD1986A_SPDIF_OUT 0x02
456 #define AD1986A_FRONT_DAC 0x03
457 #define AD1986A_SURR_DAC 0x04
458 #define AD1986A_CLFE_DAC 0x05
459 #define AD1986A_ADC 0x06
461 static hda_nid_t ad1986a_dac_nids[3] = {
462 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
464 static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
465 static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
467 static struct hda_input_mux ad1986a_capture_source = {
481 static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
482 .ops = &snd_hda_bind_vol,
484 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
485 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
486 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
491 static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
492 .ops = &snd_hda_bind_sw,
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),
504 static struct snd_kcontrol_new ad1986a_mixers[] = {
506 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
508 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
509 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
510 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
511 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
512 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
513 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
514 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
515 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
516 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
517 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
518 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
519 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
520 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
521 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
522 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
523 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
524 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
525 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
526 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
527 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
528 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
529 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
530 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
531 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
532 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
533 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
534 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
536 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
537 .name = "Capture Source",
538 .info = ad198x_mux_enum_info,
539 .get = ad198x_mux_enum_get,
540 .put = ad198x_mux_enum_put,
542 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
546 /* additional mixers for 3stack mode */
547 static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
549 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
550 .name = "Channel Mode",
551 .info = ad198x_ch_mode_info,
552 .get = ad198x_ch_mode_get,
553 .put = ad198x_ch_mode_put,
558 /* laptop model - 2ch only */
559 static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
561 /* master controls both pins 0x1a and 0x1b */
562 static struct hda_bind_ctls ad1986a_laptop_master_vol = {
563 .ops = &snd_hda_bind_vol,
565 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
566 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
571 static struct hda_bind_ctls ad1986a_laptop_master_sw = {
572 .ops = &snd_hda_bind_sw,
574 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
575 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
580 static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
581 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
582 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
583 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
584 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
585 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
586 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
587 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
588 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
589 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
590 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
591 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
592 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
593 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
594 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
595 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
596 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
597 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
598 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
599 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
601 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
602 .name = "Capture Source",
603 .info = ad198x_mux_enum_info,
604 .get = ad198x_mux_enum_get,
605 .put = ad198x_mux_enum_put,
610 /* laptop-eapd model - 2ch only */
612 static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
616 { "Internal Mic", 0x4 },
621 static struct hda_input_mux ad1986a_automic_capture_source = {
629 static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
630 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
631 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
632 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
633 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
634 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
635 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
636 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
637 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
638 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
640 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
641 .name = "Capture Source",
642 .info = ad198x_mux_enum_info,
643 .get = ad198x_mux_enum_get,
644 .put = ad198x_mux_enum_put,
647 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
648 .name = "External Amplifier",
649 .info = ad198x_eapd_info,
650 .get = ad198x_eapd_get,
651 .put = ad198x_eapd_put,
652 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
657 /* re-connect the mic boost input according to the jack sensing */
658 static void ad1986a_automic(struct hda_codec *codec)
660 unsigned int present;
661 present = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_PIN_SENSE, 0);
662 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
663 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
664 (present & AC_PINSENSE_PRESENCE) ? 0 : 2);
667 #define AD1986A_MIC_EVENT 0x36
669 static void ad1986a_automic_unsol_event(struct hda_codec *codec,
672 if ((res >> 26) != AD1986A_MIC_EVENT)
674 ad1986a_automic(codec);
677 static int ad1986a_automic_init(struct hda_codec *codec)
680 ad1986a_automic(codec);
684 /* laptop-automute - 2ch only */
686 static void ad1986a_update_hp(struct hda_codec *codec)
688 struct ad198x_spec *spec = codec->spec;
691 if (spec->jack_present)
692 mute = HDA_AMP_MUTE; /* mute internal speaker */
694 /* unmute internal speaker if necessary */
695 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
696 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
700 static void ad1986a_hp_automute(struct hda_codec *codec)
702 struct ad198x_spec *spec = codec->spec;
703 unsigned int present;
705 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0);
706 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
707 spec->jack_present = !(present & 0x80000000);
708 ad1986a_update_hp(codec);
711 #define AD1986A_HP_EVENT 0x37
713 static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
715 if ((res >> 26) != AD1986A_HP_EVENT)
717 ad1986a_hp_automute(codec);
720 static int ad1986a_hp_init(struct hda_codec *codec)
723 ad1986a_hp_automute(codec);
727 /* bind hp and internal speaker mute (with plug check) */
728 static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
729 struct snd_ctl_elem_value *ucontrol)
731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
732 long *valp = ucontrol->value.integer.value;
735 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
737 valp[0] ? 0 : HDA_AMP_MUTE);
738 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
740 valp[1] ? 0 : HDA_AMP_MUTE);
742 ad1986a_update_hp(codec);
746 static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = {
747 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
749 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
750 .name = "Master Playback Switch",
751 .info = snd_hda_mixer_amp_switch_info,
752 .get = snd_hda_mixer_amp_switch_get,
753 .put = ad1986a_hp_master_sw_put,
754 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
756 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
757 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
758 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
759 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
760 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
761 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
762 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
763 HDA_CODEC_VOLUME("Beep Playback Volume", 0x18, 0x0, HDA_OUTPUT),
764 HDA_CODEC_MUTE("Beep Playback Switch", 0x18, 0x0, HDA_OUTPUT),
765 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
766 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
768 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
769 .name = "Capture Source",
770 .info = ad198x_mux_enum_info,
771 .get = ad198x_mux_enum_get,
772 .put = ad198x_mux_enum_put,
775 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
776 .name = "External Amplifier",
777 .info = ad198x_eapd_info,
778 .get = ad198x_eapd_get,
779 .put = ad198x_eapd_put,
780 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
786 * initialization verbs
788 static struct hda_verb ad1986a_init_verbs[] = {
789 /* Front, Surround, CLFE DAC; mute as default */
790 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
791 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
792 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
794 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
795 /* HP, Line-Out, Surround, CLFE selectors */
796 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
797 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
798 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
799 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
801 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
802 /* Mic selector: Mic 1/2 pin */
803 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
804 /* Line-in selector: Line-in */
805 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
807 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
808 /* Record selector: mic */
809 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
810 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
811 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
812 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
813 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
814 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
815 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
817 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
818 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
819 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
820 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
821 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
822 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
823 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
825 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
826 /* Front, Surround, CLFE Pins */
827 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
828 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
829 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
831 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
833 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
834 /* Line, Aux, CD, Beep-In Pin */
835 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
836 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
837 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
838 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
839 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
843 static struct hda_verb ad1986a_ch2_init[] = {
844 /* Surround out -> Line In */
845 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
846 /* Line-in selectors */
847 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
849 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
850 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
851 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
855 static struct hda_verb ad1986a_ch4_init[] = {
856 /* Surround out -> Surround */
857 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
858 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
860 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
861 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
865 static struct hda_verb ad1986a_ch6_init[] = {
866 /* Surround out -> Surround out */
867 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
868 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
870 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
871 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
875 static struct hda_channel_mode ad1986a_modes[3] = {
876 { 2, ad1986a_ch2_init },
877 { 4, ad1986a_ch4_init },
878 { 6, ad1986a_ch6_init },
881 /* eapd initialization */
882 static struct hda_verb ad1986a_eapd_init_verbs[] = {
883 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
887 static struct hda_verb ad1986a_automic_verbs[] = {
888 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
889 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
890 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
891 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
892 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
896 /* Ultra initialization */
897 static struct hda_verb ad1986a_ultra_init[] = {
898 /* eapd initialization */
899 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
901 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
902 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
903 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
907 /* pin sensing on HP jack */
908 static struct hda_verb ad1986a_hp_init_verbs[] = {
909 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
920 AD1986A_LAPTOP_AUTOMUTE,
925 static const char *ad1986a_models[AD1986A_MODELS] = {
926 [AD1986A_6STACK] = "6stack",
927 [AD1986A_3STACK] = "3stack",
928 [AD1986A_LAPTOP] = "laptop",
929 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
930 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
931 [AD1986A_ULTRA] = "ultra",
934 static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
935 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
936 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
937 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
938 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
939 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
940 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
941 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
942 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
943 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
944 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
945 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
946 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
947 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
948 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
949 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
950 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
951 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
952 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
953 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
954 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
955 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
956 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
957 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
958 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
959 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
960 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
961 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
962 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
966 #ifdef CONFIG_SND_HDA_POWER_SAVE
967 static struct hda_amp_list ad1986a_loopbacks[] = {
968 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
969 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
970 { 0x15, HDA_OUTPUT, 0 }, /* CD */
971 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
972 { 0x17, HDA_OUTPUT, 0 }, /* Line */
977 static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
979 unsigned int conf = snd_hda_codec_read(codec, nid, 0,
980 AC_VERB_GET_CONFIG_DEFAULT, 0);
981 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
984 static int patch_ad1986a(struct hda_codec *codec)
986 struct ad198x_spec *spec;
989 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
995 spec->multiout.max_channels = 6;
996 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
997 spec->multiout.dac_nids = ad1986a_dac_nids;
998 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
999 spec->num_adc_nids = 1;
1000 spec->adc_nids = ad1986a_adc_nids;
1001 spec->capsrc_nids = ad1986a_capsrc_nids;
1002 spec->input_mux = &ad1986a_capture_source;
1003 spec->num_mixers = 1;
1004 spec->mixers[0] = ad1986a_mixers;
1005 spec->num_init_verbs = 1;
1006 spec->init_verbs[0] = ad1986a_init_verbs;
1007 #ifdef CONFIG_SND_HDA_POWER_SAVE
1008 spec->loopback.amplist = ad1986a_loopbacks;
1010 spec->vmaster_nid = 0x1b;
1012 codec->patch_ops = ad198x_patch_ops;
1014 /* override some parameters */
1015 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1018 switch (board_config) {
1019 case AD1986A_3STACK:
1020 spec->num_mixers = 2;
1021 spec->mixers[1] = ad1986a_3st_mixers;
1022 spec->num_init_verbs = 2;
1023 spec->init_verbs[1] = ad1986a_ch2_init;
1024 spec->channel_mode = ad1986a_modes;
1025 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
1026 spec->need_dac_fix = 1;
1027 spec->multiout.max_channels = 2;
1028 spec->multiout.num_dacs = 1;
1030 case AD1986A_LAPTOP:
1031 spec->mixers[0] = ad1986a_laptop_mixers;
1032 spec->multiout.max_channels = 2;
1033 spec->multiout.num_dacs = 1;
1034 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1036 case AD1986A_LAPTOP_EAPD:
1037 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1038 spec->num_init_verbs = 3;
1039 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1040 spec->init_verbs[2] = ad1986a_automic_verbs;
1041 spec->multiout.max_channels = 2;
1042 spec->multiout.num_dacs = 1;
1043 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1044 if (!is_jack_available(codec, 0x25))
1045 spec->multiout.dig_out_nid = 0;
1046 spec->input_mux = &ad1986a_automic_capture_source;
1047 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1048 codec->patch_ops.init = ad1986a_automic_init;
1050 case AD1986A_LAPTOP_AUTOMUTE:
1051 spec->mixers[0] = ad1986a_laptop_automute_mixers;
1052 spec->num_init_verbs = 3;
1053 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1054 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1055 spec->multiout.max_channels = 2;
1056 spec->multiout.num_dacs = 1;
1057 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1058 if (!is_jack_available(codec, 0x25))
1059 spec->multiout.dig_out_nid = 0;
1060 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1061 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1062 codec->patch_ops.init = ad1986a_hp_init;
1065 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1066 spec->num_init_verbs = 2;
1067 spec->init_verbs[1] = ad1986a_ultra_init;
1068 spec->multiout.max_channels = 2;
1069 spec->multiout.num_dacs = 1;
1070 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1071 spec->multiout.dig_out_nid = 0;
1075 /* AD1986A has a hardware problem that it can't share a stream
1076 * with multiple output pins. The copy of front to surrounds
1077 * causes noisy or silent outputs at a certain timing, e.g.
1078 * changing the volume.
1079 * So, let's disable the shared stream.
1081 spec->multiout.no_share_stream = 1;
1090 #define AD1983_SPDIF_OUT 0x02
1091 #define AD1983_DAC 0x03
1092 #define AD1983_ADC 0x04
1094 static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
1095 static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
1096 static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
1098 static struct hda_input_mux ad1983_capture_source = {
1104 { "Mix Mono", 0x3 },
1109 * SPDIF playback route
1111 static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1113 static char *texts[] = { "PCM", "ADC" };
1115 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1117 uinfo->value.enumerated.items = 2;
1118 if (uinfo->value.enumerated.item > 1)
1119 uinfo->value.enumerated.item = 1;
1120 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1124 static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1126 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1127 struct ad198x_spec *spec = codec->spec;
1129 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1133 static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1135 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1136 struct ad198x_spec *spec = codec->spec;
1138 if (ucontrol->value.enumerated.item[0] > 1)
1140 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1141 spec->spdif_route = ucontrol->value.enumerated.item[0];
1142 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1143 AC_VERB_SET_CONNECT_SEL,
1150 static struct snd_kcontrol_new ad1983_mixers[] = {
1151 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1152 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1153 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1154 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1155 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1156 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1157 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1158 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1159 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1160 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1161 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1162 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1163 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
1164 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
1165 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1166 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1167 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1169 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1170 .name = "Capture Source",
1171 .info = ad198x_mux_enum_info,
1172 .get = ad198x_mux_enum_get,
1173 .put = ad198x_mux_enum_put,
1176 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1177 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1178 .info = ad1983_spdif_route_info,
1179 .get = ad1983_spdif_route_get,
1180 .put = ad1983_spdif_route_put,
1185 static struct hda_verb ad1983_init_verbs[] = {
1186 /* Front, HP, Mono; mute as default */
1187 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1188 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1189 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1190 /* Beep, PCM, Mic, Line-In: mute */
1191 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1192 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1193 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1194 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1195 /* Front, HP selectors; from Mix */
1196 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1197 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1198 /* Mono selector; from Mix */
1199 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1200 /* Mic selector; Mic */
1201 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1202 /* Line-in selector: Line-in */
1203 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1204 /* Mic boost: 0dB */
1205 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1206 /* Record selector: mic */
1207 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1208 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1209 /* SPDIF route: PCM */
1210 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1212 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1214 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1216 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1218 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1220 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1224 #ifdef CONFIG_SND_HDA_POWER_SAVE
1225 static struct hda_amp_list ad1983_loopbacks[] = {
1226 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1227 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1232 static int patch_ad1983(struct hda_codec *codec)
1234 struct ad198x_spec *spec;
1236 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1242 spec->multiout.max_channels = 2;
1243 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1244 spec->multiout.dac_nids = ad1983_dac_nids;
1245 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
1246 spec->num_adc_nids = 1;
1247 spec->adc_nids = ad1983_adc_nids;
1248 spec->capsrc_nids = ad1983_capsrc_nids;
1249 spec->input_mux = &ad1983_capture_source;
1250 spec->num_mixers = 1;
1251 spec->mixers[0] = ad1983_mixers;
1252 spec->num_init_verbs = 1;
1253 spec->init_verbs[0] = ad1983_init_verbs;
1254 spec->spdif_route = 0;
1255 #ifdef CONFIG_SND_HDA_POWER_SAVE
1256 spec->loopback.amplist = ad1983_loopbacks;
1258 spec->vmaster_nid = 0x05;
1260 codec->patch_ops = ad198x_patch_ops;
1267 * AD1981 HD specific
1270 #define AD1981_SPDIF_OUT 0x02
1271 #define AD1981_DAC 0x03
1272 #define AD1981_ADC 0x04
1274 static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
1275 static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
1276 static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
1278 /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1279 static struct hda_input_mux ad1981_capture_source = {
1282 { "Front Mic", 0x0 },
1285 { "Mix Mono", 0x3 },
1292 static struct snd_kcontrol_new ad1981_mixers[] = {
1293 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1294 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1295 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1296 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1297 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1298 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1299 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1300 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1301 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1302 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1303 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1304 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1305 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1306 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1307 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1308 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1309 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1310 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1311 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1312 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1313 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1314 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1315 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1316 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1318 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1319 .name = "Capture Source",
1320 .info = ad198x_mux_enum_info,
1321 .get = ad198x_mux_enum_get,
1322 .put = ad198x_mux_enum_put,
1324 /* identical with AD1983 */
1326 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1327 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1328 .info = ad1983_spdif_route_info,
1329 .get = ad1983_spdif_route_get,
1330 .put = ad1983_spdif_route_put,
1335 static struct hda_verb ad1981_init_verbs[] = {
1336 /* Front, HP, Mono; mute as default */
1337 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1338 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1339 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1340 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1341 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1342 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1343 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1344 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1345 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1346 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1347 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1348 /* Front, HP selectors; from Mix */
1349 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1350 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1351 /* Mono selector; from Mix */
1352 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1353 /* Mic Mixer; select Front Mic */
1354 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1355 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1356 /* Mic boost: 0dB */
1357 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1358 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1359 /* Record selector: Front mic */
1360 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1361 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1362 /* SPDIF route: PCM */
1363 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1365 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1367 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1369 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1370 /* Front & Rear Mic Pins */
1371 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1372 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1374 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1376 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1377 /* Line-Out as Input: disabled */
1378 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1382 #ifdef CONFIG_SND_HDA_POWER_SAVE
1383 static struct hda_amp_list ad1981_loopbacks[] = {
1384 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1385 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1386 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1387 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1388 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1394 * Patch for HP nx6320
1396 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
1397 * speaker output enabled _and_ mute-LED off.
1400 #define AD1981_HP_EVENT 0x37
1401 #define AD1981_MIC_EVENT 0x38
1403 static struct hda_verb ad1981_hp_init_verbs[] = {
1404 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1405 /* pin sensing on HP and Mic jacks */
1406 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1407 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1411 /* turn on/off EAPD (+ mute HP) as a master switch */
1412 static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1413 struct snd_ctl_elem_value *ucontrol)
1415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1416 struct ad198x_spec *spec = codec->spec;
1418 if (! ad198x_eapd_put(kcontrol, ucontrol))
1420 /* change speaker pin appropriately */
1421 snd_hda_codec_write(codec, 0x05, 0,
1422 AC_VERB_SET_PIN_WIDGET_CONTROL,
1423 spec->cur_eapd ? PIN_OUT : 0);
1424 /* toggle HP mute appropriately */
1425 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1427 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
1431 /* bind volumes of both NID 0x05 and 0x06 */
1432 static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1433 .ops = &snd_hda_bind_vol,
1435 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1436 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1441 /* mute internal speaker if HP is plugged */
1442 static void ad1981_hp_automute(struct hda_codec *codec)
1444 unsigned int present;
1446 present = snd_hda_codec_read(codec, 0x06, 0,
1447 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1448 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1449 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1452 /* toggle input of built-in and mic jack appropriately */
1453 static void ad1981_hp_automic(struct hda_codec *codec)
1455 static struct hda_verb mic_jack_on[] = {
1456 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1457 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1460 static struct hda_verb mic_jack_off[] = {
1461 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1462 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1465 unsigned int present;
1467 present = snd_hda_codec_read(codec, 0x08, 0,
1468 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1470 snd_hda_sequence_write(codec, mic_jack_on);
1472 snd_hda_sequence_write(codec, mic_jack_off);
1475 /* unsolicited event for HP jack sensing */
1476 static void ad1981_hp_unsol_event(struct hda_codec *codec,
1481 case AD1981_HP_EVENT:
1482 ad1981_hp_automute(codec);
1484 case AD1981_MIC_EVENT:
1485 ad1981_hp_automic(codec);
1490 static struct hda_input_mux ad1981_hp_capture_source = {
1494 { "Docking-Station", 0x1 },
1499 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1500 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
1502 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1503 .name = "Master Playback Switch",
1504 .info = ad198x_eapd_info,
1505 .get = ad198x_eapd_get,
1506 .put = ad1981_hp_master_sw_put,
1507 .private_value = 0x05,
1509 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1510 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1512 /* FIXME: analog mic/line loopback doesn't work with my tests...
1513 * (although recording is OK)
1515 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1516 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1517 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1518 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1519 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1520 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1521 /* FIXME: does this laptop have analog CD connection? */
1522 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1523 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1525 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1526 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1527 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1528 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1530 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1531 .name = "Capture Source",
1532 .info = ad198x_mux_enum_info,
1533 .get = ad198x_mux_enum_get,
1534 .put = ad198x_mux_enum_put,
1539 /* initialize jack-sensing, too */
1540 static int ad1981_hp_init(struct hda_codec *codec)
1543 ad1981_hp_automute(codec);
1544 ad1981_hp_automic(codec);
1548 /* configuration for Toshiba Laptops */
1549 static struct hda_verb ad1981_toshiba_init_verbs[] = {
1550 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1551 /* pin sensing on HP and Mic jacks */
1552 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1553 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1557 static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1558 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1559 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1563 /* configuration for Lenovo Thinkpad T60 */
1564 static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1565 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1566 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1567 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1568 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1569 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1570 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1571 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1572 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1573 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1574 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1575 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1577 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1578 .name = "Capture Source",
1579 .info = ad198x_mux_enum_info,
1580 .get = ad198x_mux_enum_get,
1581 .put = ad198x_mux_enum_put,
1583 /* identical with AD1983 */
1585 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1586 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1587 .info = ad1983_spdif_route_info,
1588 .get = ad1983_spdif_route_get,
1589 .put = ad1983_spdif_route_put,
1594 static struct hda_input_mux ad1981_thinkpad_capture_source = {
1612 static const char *ad1981_models[AD1981_MODELS] = {
1614 [AD1981_THINKPAD] = "thinkpad",
1615 [AD1981_BASIC] = "basic",
1616 [AD1981_TOSHIBA] = "toshiba"
1619 static struct snd_pci_quirk ad1981_cfg_tbl[] = {
1620 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
1622 SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
1623 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
1624 /* Lenovo Thinkpad T60/X60/Z6xx */
1625 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
1626 /* HP nx6320 (reversed SSID, H/W bug) */
1627 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
1631 static int patch_ad1981(struct hda_codec *codec)
1633 struct ad198x_spec *spec;
1636 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1642 spec->multiout.max_channels = 2;
1643 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1644 spec->multiout.dac_nids = ad1981_dac_nids;
1645 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
1646 spec->num_adc_nids = 1;
1647 spec->adc_nids = ad1981_adc_nids;
1648 spec->capsrc_nids = ad1981_capsrc_nids;
1649 spec->input_mux = &ad1981_capture_source;
1650 spec->num_mixers = 1;
1651 spec->mixers[0] = ad1981_mixers;
1652 spec->num_init_verbs = 1;
1653 spec->init_verbs[0] = ad1981_init_verbs;
1654 spec->spdif_route = 0;
1655 #ifdef CONFIG_SND_HDA_POWER_SAVE
1656 spec->loopback.amplist = ad1981_loopbacks;
1658 spec->vmaster_nid = 0x05;
1660 codec->patch_ops = ad198x_patch_ops;
1662 /* override some parameters */
1663 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1666 switch (board_config) {
1668 spec->mixers[0] = ad1981_hp_mixers;
1669 spec->num_init_verbs = 2;
1670 spec->init_verbs[1] = ad1981_hp_init_verbs;
1671 spec->multiout.dig_out_nid = 0;
1672 spec->input_mux = &ad1981_hp_capture_source;
1674 codec->patch_ops.init = ad1981_hp_init;
1675 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1677 case AD1981_THINKPAD:
1678 spec->mixers[0] = ad1981_thinkpad_mixers;
1679 spec->input_mux = &ad1981_thinkpad_capture_source;
1681 case AD1981_TOSHIBA:
1682 spec->mixers[0] = ad1981_hp_mixers;
1683 spec->mixers[1] = ad1981_toshiba_mixers;
1684 spec->num_init_verbs = 2;
1685 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1686 spec->multiout.dig_out_nid = 0;
1687 spec->input_mux = &ad1981_hp_capture_source;
1688 codec->patch_ops.init = ad1981_hp_init;
1689 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1699 * Output pins and routes
1701 * Pin Mix Sel DAC (*)
1702 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1703 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1704 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1705 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1706 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1707 * port-F 0x16 (mute) <- 0x2a <- 06
1708 * port-G 0x24 (mute) <- 0x27 <- 05
1709 * port-H 0x25 (mute) <- 0x28 <- 0a
1710 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1712 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1713 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
1715 * Input pins and routes
1717 * pin boost mix input # / adc input #
1718 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1719 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1720 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1721 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1722 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1723 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1724 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1725 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1729 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
1730 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
1732 * Inputs of Analog Mix (0x20)
1733 * 0:Port-B (front mic)
1734 * 1:Port-C/G/H (line-in)
1736 * 3:Port-D (line-in/2)
1737 * 4:Port-E/G/H (mic-in)
1738 * 5:Port-F (mic2-in)
1744 * 1:Port-B (front mic-in)
1745 * 2:Port-C (line-in)
1746 * 3:Port-F (mic2-in)
1751 * 8:Port-D (line-in/2)
1754 * Proposed pin assignments by the datasheet
1757 * Port-A front headphone
1767 * Port-A front headphone
1769 * C rear line-in/surround
1771 * E rear mic-in/CLFE
1777 * D internal speaker (with EAPD)
1778 * E/F quad mic array
1794 /* reivision id to check workarounds */
1795 #define AD1988A_REV2 0x100200
1797 #define is_rev2(codec) \
1798 ((codec)->vendor_id == 0x11d41988 && \
1799 (codec)->revision_id == AD1988A_REV2)
1805 static hda_nid_t ad1988_6stack_dac_nids[4] = {
1806 0x04, 0x06, 0x05, 0x0a
1809 static hda_nid_t ad1988_3stack_dac_nids[3] = {
1813 /* for AD1988A revision-2, DAC2-4 are swapped */
1814 static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1815 0x04, 0x05, 0x0a, 0x06
1818 static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
1822 static hda_nid_t ad1988_adc_nids[3] = {
1826 static hda_nid_t ad1988_capsrc_nids[3] = {
1830 #define AD1988_SPDIF_OUT 0x02
1831 #define AD1988_SPDIF_IN 0x07
1833 static struct hda_input_mux ad1988_6stack_capture_source = {
1836 { "Front Mic", 0x1 }, /* port-B */
1837 { "Line", 0x2 }, /* port-C */
1838 { "Mic", 0x4 }, /* port-E */
1844 static struct hda_input_mux ad1988_laptop_capture_source = {
1847 { "Mic/Line", 0x1 }, /* port-B */
1855 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1856 struct snd_ctl_elem_info *uinfo)
1858 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1859 struct ad198x_spec *spec = codec->spec;
1860 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1861 spec->num_channel_mode);
1864 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1865 struct snd_ctl_elem_value *ucontrol)
1867 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1868 struct ad198x_spec *spec = codec->spec;
1869 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1870 spec->num_channel_mode, spec->multiout.max_channels);
1873 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1874 struct snd_ctl_elem_value *ucontrol)
1876 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1877 struct ad198x_spec *spec = codec->spec;
1878 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1879 spec->num_channel_mode,
1880 &spec->multiout.max_channels);
1881 if (err >= 0 && spec->need_dac_fix)
1882 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
1887 static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
1888 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1889 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1890 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1891 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1892 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1896 static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1897 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1898 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1899 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1900 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1901 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1905 static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
1906 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1907 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1908 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1909 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1910 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1911 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1912 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1914 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1915 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1916 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1917 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1918 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1919 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1920 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1921 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1923 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1924 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1926 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1927 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1929 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1930 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1936 static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
1937 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1938 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1939 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1940 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1944 static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1945 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1946 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1947 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1948 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
1952 static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
1953 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1954 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1955 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1956 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
1957 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1958 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1960 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1961 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1962 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1963 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1964 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1965 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1966 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1967 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1969 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1970 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1972 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1973 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1975 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1976 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1978 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1979 .name = "Channel Mode",
1980 .info = ad198x_ch_mode_info,
1981 .get = ad198x_ch_mode_get,
1982 .put = ad198x_ch_mode_put,
1989 static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1990 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1991 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1992 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1994 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1995 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1996 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1997 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1998 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1999 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2001 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2002 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2004 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2005 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2007 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2010 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2011 .name = "External Amplifier",
2012 .info = ad198x_eapd_info,
2013 .get = ad198x_eapd_get,
2014 .put = ad198x_eapd_put,
2015 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
2022 static struct snd_kcontrol_new ad1988_capture_mixers[] = {
2023 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2024 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2025 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2026 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2027 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2028 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2030 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2031 /* The multiple "Capture Source" controls confuse alsamixer
2032 * So call somewhat different..
2034 /* .name = "Capture Source", */
2035 .name = "Input Source",
2037 .info = ad198x_mux_enum_info,
2038 .get = ad198x_mux_enum_get,
2039 .put = ad198x_mux_enum_put,
2044 static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2045 struct snd_ctl_elem_info *uinfo)
2047 static char *texts[] = {
2048 "PCM", "ADC1", "ADC2", "ADC3"
2050 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2052 uinfo->value.enumerated.items = 4;
2053 if (uinfo->value.enumerated.item >= 4)
2054 uinfo->value.enumerated.item = 3;
2055 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2059 static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2060 struct snd_ctl_elem_value *ucontrol)
2062 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2065 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2068 ucontrol->value.enumerated.item[0] = 0;
2070 sel = snd_hda_codec_read(codec, 0x0b, 0,
2071 AC_VERB_GET_CONNECT_SEL, 0);
2076 ucontrol->value.enumerated.item[0] = sel;
2081 static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2082 struct snd_ctl_elem_value *ucontrol)
2084 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2085 unsigned int val, sel;
2088 val = ucontrol->value.enumerated.item[0];
2092 sel = snd_hda_codec_read(codec, 0x1d, 0,
2093 AC_VERB_GET_AMP_GAIN_MUTE,
2095 change = sel & 0x80;
2097 snd_hda_codec_write_cache(codec, 0x1d, 0,
2098 AC_VERB_SET_AMP_GAIN_MUTE,
2100 snd_hda_codec_write_cache(codec, 0x1d, 0,
2101 AC_VERB_SET_AMP_GAIN_MUTE,
2105 sel = snd_hda_codec_read(codec, 0x1d, 0,
2106 AC_VERB_GET_AMP_GAIN_MUTE,
2107 AC_AMP_GET_INPUT | 0x01);
2108 change = sel & 0x80;
2110 snd_hda_codec_write_cache(codec, 0x1d, 0,
2111 AC_VERB_SET_AMP_GAIN_MUTE,
2113 snd_hda_codec_write_cache(codec, 0x1d, 0,
2114 AC_VERB_SET_AMP_GAIN_MUTE,
2117 sel = snd_hda_codec_read(codec, 0x0b, 0,
2118 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2119 change |= sel != val;
2121 snd_hda_codec_write_cache(codec, 0x0b, 0,
2122 AC_VERB_SET_CONNECT_SEL,
2128 static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2129 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2131 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2132 .name = "IEC958 Playback Source",
2133 .info = ad1988_spdif_playback_source_info,
2134 .get = ad1988_spdif_playback_source_get,
2135 .put = ad1988_spdif_playback_source_put,
2140 static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2141 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2145 static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2146 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2151 * initialization verbs
2155 * for 6-stack (+dig)
2157 static struct hda_verb ad1988_6stack_init_verbs[] = {
2158 /* Front, Surround, CLFE, side DAC; unmute as default */
2159 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2160 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2161 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2162 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2163 /* Port-A front headphon path */
2164 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2165 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2166 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2167 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2168 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2169 /* Port-D line-out path */
2170 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2171 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2172 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2173 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2174 /* Port-F surround path */
2175 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2176 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2177 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2178 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2179 /* Port-G CLFE path */
2180 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2181 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2182 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2183 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2184 /* Port-H side path */
2185 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2186 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2187 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2188 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2190 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2191 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2192 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2193 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2194 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2195 /* Port-B front mic-in path */
2196 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2197 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2198 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2199 /* Port-C line-in path */
2200 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2201 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2202 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2203 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2204 /* Port-E mic-in path */
2205 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2206 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2207 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2208 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2209 /* Analog CD Input */
2210 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2215 static struct hda_verb ad1988_capture_init_verbs[] = {
2216 /* mute analog mix */
2217 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2218 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2219 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2220 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2221 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2222 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2223 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2224 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2225 /* select ADCs - front-mic */
2226 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2227 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2228 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2230 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2231 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2232 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2237 static struct hda_verb ad1988_spdif_init_verbs[] = {
2239 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2240 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2241 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2242 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2244 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2249 /* AD1989 has no ADC -> SPDIF route */
2250 static struct hda_verb ad1989_spdif_init_verbs[] = {
2252 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2257 * verbs for 3stack (+dig)
2259 static struct hda_verb ad1988_3stack_ch2_init[] = {
2260 /* set port-C to line-in */
2261 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2262 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2263 /* set port-E to mic-in */
2264 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2265 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2269 static struct hda_verb ad1988_3stack_ch6_init[] = {
2270 /* set port-C to surround out */
2271 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2272 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2273 /* set port-E to CLFE out */
2274 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2275 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2279 static struct hda_channel_mode ad1988_3stack_modes[2] = {
2280 { 2, ad1988_3stack_ch2_init },
2281 { 6, ad1988_3stack_ch6_init },
2284 static struct hda_verb ad1988_3stack_init_verbs[] = {
2285 /* Front, Surround, CLFE, side DAC; unmute as default */
2286 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2287 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2288 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2289 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2290 /* Port-A front headphon path */
2291 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2292 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2293 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2294 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2295 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2296 /* Port-D line-out path */
2297 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2298 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2299 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2300 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2302 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2303 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2304 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2305 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2306 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2307 /* Port-B front mic-in path */
2308 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2309 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2310 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2311 /* Port-C line-in/surround path - 6ch mode as default */
2312 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2313 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2314 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2315 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
2316 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2317 /* Port-E mic-in/CLFE path - 6ch mode as default */
2318 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2319 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2320 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2321 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
2322 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2323 /* mute analog mix */
2324 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2325 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2326 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2327 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2328 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2329 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2330 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2331 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2332 /* select ADCs - front-mic */
2333 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2334 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2335 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2337 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2338 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2339 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2344 * verbs for laptop mode (+dig)
2346 static struct hda_verb ad1988_laptop_hp_on[] = {
2347 /* unmute port-A and mute port-D */
2348 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2349 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2352 static struct hda_verb ad1988_laptop_hp_off[] = {
2353 /* mute port-A and unmute port-D */
2354 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2355 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2359 #define AD1988_HP_EVENT 0x01
2361 static struct hda_verb ad1988_laptop_init_verbs[] = {
2362 /* Front, Surround, CLFE, side DAC; unmute as default */
2363 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2364 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2365 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2366 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2367 /* Port-A front headphon path */
2368 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2369 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2370 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2371 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2372 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2373 /* unsolicited event for pin-sense */
2374 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2375 /* Port-D line-out path + EAPD */
2376 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2377 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2378 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2379 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2380 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2382 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2383 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2384 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2385 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2386 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2387 /* Port-B mic-in path */
2388 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2389 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2390 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2391 /* Port-C docking station - try to output */
2392 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2393 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2394 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2395 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2396 /* mute analog mix */
2397 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2398 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2399 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2400 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2401 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2402 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2403 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2404 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2405 /* select ADCs - mic */
2406 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2407 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2408 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2410 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2411 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2412 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2416 static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2418 if ((res >> 26) != AD1988_HP_EVENT)
2420 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2421 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2423 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2426 #ifdef CONFIG_SND_HDA_POWER_SAVE
2427 static struct hda_amp_list ad1988_loopbacks[] = {
2428 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2429 { 0x20, HDA_INPUT, 1 }, /* Line */
2430 { 0x20, HDA_INPUT, 4 }, /* Mic */
2431 { 0x20, HDA_INPUT, 6 }, /* CD */
2437 * Automatic parse of I/O pins from the BIOS configuration
2440 #define NUM_CONTROL_ALLOC 32
2441 #define NUM_VERB_ALLOC 32
2448 static struct snd_kcontrol_new ad1988_control_templates[] = {
2449 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2450 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2451 HDA_BIND_MUTE(NULL, 0, 0, 0),
2454 /* add dynamic controls */
2455 static int add_control(struct ad198x_spec *spec, int type, const char *name,
2458 struct snd_kcontrol_new *knew;
2460 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2461 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2463 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2466 if (spec->kctl_alloc) {
2467 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2468 kfree(spec->kctl_alloc);
2470 spec->kctl_alloc = knew;
2471 spec->num_kctl_alloc = num;
2474 knew = &spec->kctl_alloc[spec->num_kctl_used];
2475 *knew = ad1988_control_templates[type];
2476 knew->name = kstrdup(name, GFP_KERNEL);
2479 knew->private_value = val;
2480 spec->num_kctl_used++;
2484 #define AD1988_PIN_CD_NID 0x18
2485 #define AD1988_PIN_BEEP_NID 0x10
2487 static hda_nid_t ad1988_mixer_nids[8] = {
2488 /* A B C D E F G H */
2489 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2492 static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2494 static hda_nid_t idx_to_dac[8] = {
2495 /* A B C D E F G H */
2496 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
2498 static hda_nid_t idx_to_dac_rev2[8] = {
2499 /* A B C D E F G H */
2500 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
2503 return idx_to_dac_rev2[idx];
2505 return idx_to_dac[idx];
2508 static hda_nid_t ad1988_boost_nids[8] = {
2509 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2512 static int ad1988_pin_idx(hda_nid_t nid)
2514 static hda_nid_t ad1988_io_pins[8] = {
2515 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2518 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2519 if (ad1988_io_pins[i] == nid)
2521 return 0; /* should be -1 */
2524 static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2526 static int loopback_idx[8] = {
2527 2, 0, 1, 3, 4, 5, 1, 4
2530 case AD1988_PIN_CD_NID:
2533 return loopback_idx[ad1988_pin_idx(nid)];
2537 static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2539 static int adc_idx[8] = {
2540 0, 1, 2, 8, 4, 3, 6, 7
2543 case AD1988_PIN_CD_NID:
2546 return adc_idx[ad1988_pin_idx(nid)];
2550 /* fill in the dac_nids table from the parsed pin configuration */
2551 static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2552 const struct auto_pin_cfg *cfg)
2554 struct ad198x_spec *spec = codec->spec;
2557 spec->multiout.dac_nids = spec->private_dac_nids;
2559 /* check the pins hardwired to audio widget */
2560 for (i = 0; i < cfg->line_outs; i++) {
2561 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2562 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2564 spec->multiout.num_dacs = cfg->line_outs;
2568 /* add playback controls from the parsed DAC table */
2569 static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2570 const struct auto_pin_cfg *cfg)
2573 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2577 for (i = 0; i < cfg->line_outs; i++) {
2578 hda_nid_t dac = spec->multiout.dac_nids[i];
2581 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2584 err = add_control(spec, AD_CTL_WIDGET_VOL,
2585 "Center Playback Volume",
2586 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2589 err = add_control(spec, AD_CTL_WIDGET_VOL,
2590 "LFE Playback Volume",
2591 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2594 err = add_control(spec, AD_CTL_BIND_MUTE,
2595 "Center Playback Switch",
2596 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2599 err = add_control(spec, AD_CTL_BIND_MUTE,
2600 "LFE Playback Switch",
2601 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2605 sprintf(name, "%s Playback Volume", chname[i]);
2606 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2607 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2610 sprintf(name, "%s Playback Switch", chname[i]);
2611 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2612 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2620 /* add playback controls for speaker and HP outputs */
2621 static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2624 struct ad198x_spec *spec = codec->spec;
2632 idx = ad1988_pin_idx(pin);
2633 nid = ad1988_idx_to_dac(codec, idx);
2634 /* specify the DAC as the extra output */
2635 if (! spec->multiout.hp_nid)
2636 spec->multiout.hp_nid = nid;
2638 spec->multiout.extra_out_nid[0] = nid;
2639 /* control HP volume/switch on the output mixer amp */
2640 sprintf(name, "%s Playback Volume", pfx);
2641 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2642 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2644 nid = ad1988_mixer_nids[idx];
2645 sprintf(name, "%s Playback Switch", pfx);
2646 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2647 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2652 /* create input playback/capture controls for the given pin */
2653 static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2654 const char *ctlname, int boost)
2659 sprintf(name, "%s Playback Volume", ctlname);
2660 idx = ad1988_pin_to_loopback_idx(pin);
2661 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2662 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2664 sprintf(name, "%s Playback Switch", ctlname);
2665 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2666 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2670 idx = ad1988_pin_idx(pin);
2671 bnid = ad1988_boost_nids[idx];
2673 sprintf(name, "%s Boost", ctlname);
2674 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2675 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2682 /* create playback/capture controls for input pins */
2683 static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2684 const struct auto_pin_cfg *cfg)
2686 struct hda_input_mux *imux = &spec->private_imux;
2689 for (i = 0; i < AUTO_PIN_LAST; i++) {
2690 err = new_analog_input(spec, cfg->input_pins[i],
2691 auto_pin_cfg_labels[i],
2692 i <= AUTO_PIN_FRONT_MIC);
2695 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2696 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2699 imux->items[imux->num_items].label = "Mix";
2700 imux->items[imux->num_items].index = 9;
2703 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2704 "Analog Mix Playback Volume",
2705 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2707 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2708 "Analog Mix Playback Switch",
2709 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2715 static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2716 hda_nid_t nid, int pin_type,
2720 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2721 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2723 case 0x11: /* port-A - DAC 04 */
2724 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2726 case 0x14: /* port-B - DAC 06 */
2727 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2729 case 0x15: /* port-C - DAC 05 */
2730 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2732 case 0x17: /* port-E - DAC 0a */
2733 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2735 case 0x13: /* mono - DAC 04 */
2736 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2741 static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2743 struct ad198x_spec *spec = codec->spec;
2746 for (i = 0; i < spec->autocfg.line_outs; i++) {
2747 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2748 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2752 static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2754 struct ad198x_spec *spec = codec->spec;
2757 pin = spec->autocfg.speaker_pins[0];
2758 if (pin) /* connect to front */
2759 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2760 pin = spec->autocfg.hp_pins[0];
2761 if (pin) /* connect to front */
2762 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2765 static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2767 struct ad198x_spec *spec = codec->spec;
2770 for (i = 0; i < AUTO_PIN_LAST; i++) {
2771 hda_nid_t nid = spec->autocfg.input_pins[i];
2775 case 0x15: /* port-C */
2776 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2778 case 0x17: /* port-E */
2779 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2782 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2783 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2784 if (nid != AD1988_PIN_CD_NID)
2785 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2787 idx = ad1988_pin_idx(nid);
2788 if (ad1988_boost_nids[idx])
2789 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2790 AC_VERB_SET_AMP_GAIN_MUTE,
2795 /* parse the BIOS configuration and set up the alc_spec */
2796 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2797 static int ad1988_parse_auto_config(struct hda_codec *codec)
2799 struct ad198x_spec *spec = codec->spec;
2802 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2804 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2806 if (! spec->autocfg.line_outs)
2807 return 0; /* can't find valid BIOS pin config */
2808 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2809 (err = ad1988_auto_create_extra_out(codec,
2810 spec->autocfg.speaker_pins[0],
2812 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
2813 "Headphone")) < 0 ||
2814 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2817 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2819 if (spec->autocfg.dig_out_pin)
2820 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2821 if (spec->autocfg.dig_in_pin)
2822 spec->dig_in_nid = AD1988_SPDIF_IN;
2824 if (spec->kctl_alloc)
2825 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2827 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2829 spec->input_mux = &spec->private_imux;
2834 /* init callback for auto-configuration model -- overriding the default init */
2835 static int ad1988_auto_init(struct hda_codec *codec)
2838 ad1988_auto_init_multi_out(codec);
2839 ad1988_auto_init_extra_out(codec);
2840 ad1988_auto_init_analog_input(codec);
2848 static const char *ad1988_models[AD1988_MODEL_LAST] = {
2849 [AD1988_6STACK] = "6stack",
2850 [AD1988_6STACK_DIG] = "6stack-dig",
2851 [AD1988_3STACK] = "3stack",
2852 [AD1988_3STACK_DIG] = "3stack-dig",
2853 [AD1988_LAPTOP] = "laptop",
2854 [AD1988_LAPTOP_DIG] = "laptop-dig",
2855 [AD1988_AUTO] = "auto",
2858 static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2859 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
2860 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
2861 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
2865 static int patch_ad1988(struct hda_codec *codec)
2867 struct ad198x_spec *spec;
2870 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2877 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2879 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
2880 ad1988_models, ad1988_cfg_tbl);
2881 if (board_config < 0) {
2882 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2883 board_config = AD1988_AUTO;
2886 if (board_config == AD1988_AUTO) {
2887 /* automatic parse from the BIOS config */
2888 int err = ad1988_parse_auto_config(codec);
2893 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2894 board_config = AD1988_6STACK;
2898 switch (board_config) {
2900 case AD1988_6STACK_DIG:
2901 spec->multiout.max_channels = 8;
2902 spec->multiout.num_dacs = 4;
2904 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2906 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
2907 spec->input_mux = &ad1988_6stack_capture_source;
2908 spec->num_mixers = 2;
2910 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2912 spec->mixers[0] = ad1988_6stack_mixers1;
2913 spec->mixers[1] = ad1988_6stack_mixers2;
2914 spec->num_init_verbs = 1;
2915 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2916 if (board_config == AD1988_6STACK_DIG) {
2917 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2918 spec->dig_in_nid = AD1988_SPDIF_IN;
2922 case AD1988_3STACK_DIG:
2923 spec->multiout.max_channels = 6;
2924 spec->multiout.num_dacs = 3;
2926 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2928 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2929 spec->input_mux = &ad1988_6stack_capture_source;
2930 spec->channel_mode = ad1988_3stack_modes;
2931 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
2932 spec->num_mixers = 2;
2934 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2936 spec->mixers[0] = ad1988_3stack_mixers1;
2937 spec->mixers[1] = ad1988_3stack_mixers2;
2938 spec->num_init_verbs = 1;
2939 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2940 if (board_config == AD1988_3STACK_DIG)
2941 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2944 case AD1988_LAPTOP_DIG:
2945 spec->multiout.max_channels = 2;
2946 spec->multiout.num_dacs = 1;
2947 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2948 spec->input_mux = &ad1988_laptop_capture_source;
2949 spec->num_mixers = 1;
2950 spec->mixers[0] = ad1988_laptop_mixers;
2951 spec->num_init_verbs = 1;
2952 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2953 if (board_config == AD1988_LAPTOP_DIG)
2954 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2958 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2959 spec->adc_nids = ad1988_adc_nids;
2960 spec->capsrc_nids = ad1988_capsrc_nids;
2961 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2962 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2963 if (spec->multiout.dig_out_nid) {
2964 if (codec->vendor_id >= 0x11d4989a) {
2965 spec->mixers[spec->num_mixers++] =
2966 ad1989_spdif_out_mixers;
2967 spec->init_verbs[spec->num_init_verbs++] =
2968 ad1989_spdif_init_verbs;
2970 spec->mixers[spec->num_mixers++] =
2971 ad1988_spdif_out_mixers;
2972 spec->init_verbs[spec->num_init_verbs++] =
2973 ad1988_spdif_init_verbs;
2976 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
2977 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2979 codec->patch_ops = ad198x_patch_ops;
2980 switch (board_config) {
2982 codec->patch_ops.init = ad1988_auto_init;
2985 case AD1988_LAPTOP_DIG:
2986 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2989 #ifdef CONFIG_SND_HDA_POWER_SAVE
2990 spec->loopback.amplist = ad1988_loopbacks;
2992 spec->vmaster_nid = 0x04;
3001 * port-B - front line/mic-in
3002 * port-E - aux in/out
3003 * port-F - aux in/out
3004 * port-C - rear line/mic-in
3005 * port-D - rear line/hp-out
3006 * port-A - front line/hp-out
3008 * AD1984 = AD1884 + two digital mic-ins
3011 * For simplicity, we share the single DAC for both HP and line-outs
3012 * right now. The inidividual playbacks could be easily implemented,
3013 * but no build-up framework is given, so far.
3016 static hda_nid_t ad1884_dac_nids[1] = {
3020 static hda_nid_t ad1884_adc_nids[2] = {
3024 static hda_nid_t ad1884_capsrc_nids[2] = {
3028 #define AD1884_SPDIF_OUT 0x02
3030 static struct hda_input_mux ad1884_capture_source = {
3033 { "Front Mic", 0x0 },
3040 static struct snd_kcontrol_new ad1884_base_mixers[] = {
3041 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3042 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3043 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3044 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3045 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3046 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3047 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3048 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3049 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3050 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3051 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3052 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3054 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
3055 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
3056 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
3057 HDA_CODEC_MUTE("Digital Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3059 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3060 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3061 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3062 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3063 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3064 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3066 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3067 /* The multiple "Capture Source" controls confuse alsamixer
3068 * So call somewhat different..
3070 /* .name = "Capture Source", */
3071 .name = "Input Source",
3073 .info = ad198x_mux_enum_info,
3074 .get = ad198x_mux_enum_get,
3075 .put = ad198x_mux_enum_put,
3077 /* SPDIF controls */
3078 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3080 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3081 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3082 /* identical with ad1983 */
3083 .info = ad1983_spdif_route_info,
3084 .get = ad1983_spdif_route_get,
3085 .put = ad1983_spdif_route_put,
3090 static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3091 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3092 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3093 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
3095 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
3101 * initialization verbs
3103 static struct hda_verb ad1884_init_verbs[] = {
3104 /* DACs; mute as default */
3105 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3106 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3107 /* Port-A (HP) mixer */
3108 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3109 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3111 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3112 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3113 /* HP selector - select DAC2 */
3114 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3115 /* Port-D (Line-out) mixer */
3116 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3117 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3119 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3120 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3121 /* Mono-out mixer */
3122 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3123 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3125 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3126 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3128 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3129 /* Port-B (front mic) pin */
3130 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3131 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3132 /* Port-C (rear mic) pin */
3133 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3134 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3135 /* Analog mixer; mute as default */
3136 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3137 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3138 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3139 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3140 /* Analog Mix output amp */
3141 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3142 /* SPDIF output selector */
3143 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3144 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3148 #ifdef CONFIG_SND_HDA_POWER_SAVE
3149 static struct hda_amp_list ad1884_loopbacks[] = {
3150 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3151 { 0x20, HDA_INPUT, 1 }, /* Mic */
3152 { 0x20, HDA_INPUT, 2 }, /* CD */
3153 { 0x20, HDA_INPUT, 4 }, /* Docking */
3158 static const char *ad1884_slave_vols[] = {
3159 "PCM Playback Volume",
3160 "Mic Playback Volume",
3161 "Mono Playback Volume",
3162 "Front Mic Playback Volume",
3163 "Mic Playback Volume",
3164 "CD Playback Volume",
3165 "Internal Mic Playback Volume",
3166 "Docking Mic Playback Volume"
3167 "Beep Playback Volume",
3168 "IEC958 Playback Volume",
3172 static int patch_ad1884(struct hda_codec *codec)
3174 struct ad198x_spec *spec;
3176 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3180 mutex_init(&spec->amp_mutex);
3183 spec->multiout.max_channels = 2;
3184 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3185 spec->multiout.dac_nids = ad1884_dac_nids;
3186 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3187 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3188 spec->adc_nids = ad1884_adc_nids;
3189 spec->capsrc_nids = ad1884_capsrc_nids;
3190 spec->input_mux = &ad1884_capture_source;
3191 spec->num_mixers = 1;
3192 spec->mixers[0] = ad1884_base_mixers;
3193 spec->num_init_verbs = 1;
3194 spec->init_verbs[0] = ad1884_init_verbs;
3195 spec->spdif_route = 0;
3196 #ifdef CONFIG_SND_HDA_POWER_SAVE
3197 spec->loopback.amplist = ad1884_loopbacks;
3199 spec->vmaster_nid = 0x04;
3200 /* we need to cover all playback volumes */
3201 spec->slave_vols = ad1884_slave_vols;
3203 codec->patch_ops = ad198x_patch_ops;
3209 * Lenovo Thinkpad T61/X61
3211 static struct hda_input_mux ad1984_thinkpad_capture_source = {
3215 { "Internal Mic", 0x1 },
3217 { "Docking-Station", 0x4 },
3223 * Dell Precision T3400
3225 static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3228 { "Front Mic", 0x0 },
3235 static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3236 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3237 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3238 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3239 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3240 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3241 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3242 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3243 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3244 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3245 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3246 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3247 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3248 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3249 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3250 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3251 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3252 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3253 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3254 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3256 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3257 /* The multiple "Capture Source" controls confuse alsamixer
3258 * So call somewhat different..
3260 /* .name = "Capture Source", */
3261 .name = "Input Source",
3263 .info = ad198x_mux_enum_info,
3264 .get = ad198x_mux_enum_get,
3265 .put = ad198x_mux_enum_put,
3267 /* SPDIF controls */
3268 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3270 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3271 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3272 /* identical with ad1983 */
3273 .info = ad1983_spdif_route_info,
3274 .get = ad1983_spdif_route_get,
3275 .put = ad1983_spdif_route_put,
3280 /* additional verbs */
3281 static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3282 /* Port-E (docking station mic) pin */
3283 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3284 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3285 /* docking mic boost */
3286 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3287 /* Analog mixer - docking mic; mute as default */
3288 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3289 /* enable EAPD bit */
3290 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3295 * Dell Precision T3400
3297 static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3298 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3299 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3300 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3301 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3302 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3303 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3304 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3305 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3306 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
3308 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
3309 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
3311 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3312 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3313 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3314 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3315 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3316 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3318 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3319 /* The multiple "Capture Source" controls confuse alsamixer
3320 * So call somewhat different..
3322 /* .name = "Capture Source", */
3323 .name = "Input Source",
3325 .info = ad198x_mux_enum_info,
3326 .get = ad198x_mux_enum_get,
3327 .put = ad198x_mux_enum_put,
3332 /* Digial MIC ADC NID 0x05 + 0x06 */
3333 static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3334 struct hda_codec *codec,
3335 unsigned int stream_tag,
3336 unsigned int format,
3337 struct snd_pcm_substream *substream)
3339 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3340 stream_tag, 0, format);
3344 static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3345 struct hda_codec *codec,
3346 struct snd_pcm_substream *substream)
3348 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
3352 static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3358 .prepare = ad1984_pcm_dmic_prepare,
3359 .cleanup = ad1984_pcm_dmic_cleanup
3363 static int ad1984_build_pcms(struct hda_codec *codec)
3365 struct ad198x_spec *spec = codec->spec;
3366 struct hda_pcm *info;
3369 err = ad198x_build_pcms(codec);
3373 info = spec->pcm_rec + codec->num_pcms;
3375 info->name = "AD1984 Digital Mic";
3376 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3384 AD1984_DELL_DESKTOP,
3388 static const char *ad1984_models[AD1984_MODELS] = {
3389 [AD1984_BASIC] = "basic",
3390 [AD1984_THINKPAD] = "thinkpad",
3391 [AD1984_DELL_DESKTOP] = "dell_desktop",
3394 static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3395 /* Lenovo Thinkpad T61/X61 */
3396 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1984_THINKPAD),
3397 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
3401 static int patch_ad1984(struct hda_codec *codec)
3403 struct ad198x_spec *spec;
3404 int board_config, err;
3406 err = patch_ad1884(codec);
3410 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3411 ad1984_models, ad1984_cfg_tbl);
3412 switch (board_config) {
3414 /* additional digital mics */
3415 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3416 codec->patch_ops.build_pcms = ad1984_build_pcms;
3418 case AD1984_THINKPAD:
3419 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3420 spec->input_mux = &ad1984_thinkpad_capture_source;
3421 spec->mixers[0] = ad1984_thinkpad_mixers;
3422 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3424 case AD1984_DELL_DESKTOP:
3425 spec->multiout.dig_out_nid = 0;
3426 spec->input_mux = &ad1984_dell_desktop_capture_source;
3427 spec->mixers[0] = ad1984_dell_desktop_mixers;
3435 * AD1883 / AD1884A / AD1984A / AD1984B
3437 * port-B (0x14) - front mic-in
3438 * port-E (0x1c) - rear mic-in
3439 * port-F (0x16) - CD / ext out
3440 * port-C (0x15) - rear line-in
3441 * port-D (0x12) - rear line-out
3442 * port-A (0x11) - front hp-out
3444 * AD1984A = AD1884A + digital-mic
3445 * AD1883 = equivalent with AD1984A
3446 * AD1984B = AD1984A + extra SPDIF-out
3449 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3452 static hda_nid_t ad1884a_dac_nids[1] = {
3456 #define ad1884a_adc_nids ad1884_adc_nids
3457 #define ad1884a_capsrc_nids ad1884_capsrc_nids
3459 #define AD1884A_SPDIF_OUT 0x02
3461 static struct hda_input_mux ad1884a_capture_source = {
3464 { "Front Mic", 0x0 },
3472 static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3473 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3474 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3475 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3476 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3477 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3478 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3479 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3480 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3481 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3482 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3483 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3484 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3485 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3486 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3487 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3488 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3489 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3490 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3491 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3492 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3493 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3494 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3495 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3496 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3497 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3499 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3500 /* The multiple "Capture Source" controls confuse alsamixer
3501 * So call somewhat different..
3503 /* .name = "Capture Source", */
3504 .name = "Input Source",
3506 .info = ad198x_mux_enum_info,
3507 .get = ad198x_mux_enum_get,
3508 .put = ad198x_mux_enum_put,
3510 /* SPDIF controls */
3511 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3513 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3514 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3515 /* identical with ad1983 */
3516 .info = ad1983_spdif_route_info,
3517 .get = ad1983_spdif_route_get,
3518 .put = ad1983_spdif_route_put,
3524 * initialization verbs
3526 static struct hda_verb ad1884a_init_verbs[] = {
3527 /* DACs; unmute as default */
3528 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3529 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3530 /* Port-A (HP) mixer - route only from analog mixer */
3531 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3532 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3534 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3535 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3536 /* Port-D (Line-out) mixer - route only from analog mixer */
3537 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3538 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3540 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3541 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3542 /* Mono-out mixer - route only from analog mixer */
3543 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3544 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3546 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3547 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3548 /* Port-B (front mic) pin */
3549 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3550 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3551 /* Port-C (rear line-in) pin */
3552 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3553 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3554 /* Port-E (rear mic) pin */
3555 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3556 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3557 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3558 /* Port-F (CD) pin */
3559 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3560 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3561 /* Analog mixer; mute as default */
3562 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3563 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3564 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3565 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3566 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3567 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3568 /* Analog Mix output amp */
3569 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3570 /* capture sources */
3571 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3572 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3573 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3574 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3575 /* SPDIF output amp */
3576 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3580 #ifdef CONFIG_SND_HDA_POWER_SAVE
3581 static struct hda_amp_list ad1884a_loopbacks[] = {
3582 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3583 { 0x20, HDA_INPUT, 1 }, /* Mic */
3584 { 0x20, HDA_INPUT, 2 }, /* CD */
3585 { 0x20, HDA_INPUT, 4 }, /* Docking */
3593 * Port A: Headphone jack
3595 * Port C: Internal MIC
3596 * Port D: Dock Line Out (if enabled)
3597 * Port E: Dock Line In (if enabled)
3598 * Port F: Internal speakers
3601 static struct hda_input_mux ad1884a_laptop_capture_source = {
3604 { "Mic", 0x0 }, /* port-B */
3605 { "Internal Mic", 0x1 }, /* port-C */
3606 { "Dock Mic", 0x4 }, /* port-E */
3611 static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3612 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3613 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3614 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3615 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3616 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3617 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3618 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3619 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3620 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3621 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3622 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3623 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3624 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3625 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3626 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3627 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3628 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3629 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3630 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3631 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3633 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3634 /* The multiple "Capture Source" controls confuse alsamixer
3635 * So call somewhat different..
3637 /* .name = "Capture Source", */
3638 .name = "Input Source",
3640 .info = ad198x_mux_enum_info,
3641 .get = ad198x_mux_enum_get,
3642 .put = ad198x_mux_enum_put,
3647 static struct hda_input_mux ad1884a_mobile_capture_source = {
3650 { "Mic", 0x1 }, /* port-C */
3655 static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3656 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3657 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3658 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3659 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3660 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3661 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3662 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3663 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3664 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3665 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3666 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3668 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3669 .name = "Capture Source",
3670 .info = ad198x_mux_enum_info,
3671 .get = ad198x_mux_enum_get,
3672 .put = ad198x_mux_enum_put,
3677 /* mute internal speaker if HP is plugged */
3678 static void ad1884a_hp_automute(struct hda_codec *codec)
3680 unsigned int present;
3682 present = snd_hda_codec_read(codec, 0x11, 0,
3683 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3684 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3685 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3686 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3687 present ? 0x00 : 0x02);
3690 #define AD1884A_HP_EVENT 0x37
3692 /* unsolicited event for HP jack sensing */
3693 static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3695 if ((res >> 26) != AD1884A_HP_EVENT)
3697 ad1884a_hp_automute(codec);
3700 /* initialize jack-sensing, too */
3701 static int ad1884a_hp_init(struct hda_codec *codec)
3704 ad1884a_hp_automute(codec);
3708 /* additional verbs for laptop model */
3709 static struct hda_verb ad1884a_laptop_verbs[] = {
3710 /* Port-A (HP) pin - always unmuted */
3711 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3712 /* Port-F (int speaker) mixer - route only from analog mixer */
3713 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3714 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3716 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3717 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3719 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3720 /* unsolicited event for pin-sense */
3721 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3730 * 0x17 - built-in mic
3733 static struct hda_verb ad1984a_thinkpad_verbs[] = {
3735 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3737 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3739 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3740 /* unsolicited event for pin-sense */
3741 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3742 /* internal mic - dmic */
3743 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3744 /* set magic COEFs for dmic */
3745 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3746 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
3750 static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3751 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3752 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3753 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3754 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3755 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3756 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3757 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3758 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3759 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3760 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3761 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3762 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3764 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3765 .name = "Capture Source",
3766 .info = ad198x_mux_enum_info,
3767 .get = ad198x_mux_enum_get,
3768 .put = ad198x_mux_enum_put,
3773 static struct hda_input_mux ad1984a_thinkpad_capture_source = {
3777 { "Internal Mic", 0x5 },
3782 /* mute internal speaker if HP is plugged */
3783 static void ad1984a_thinkpad_automute(struct hda_codec *codec)
3785 unsigned int present;
3787 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0)
3788 & AC_PINSENSE_PRESENCE;
3789 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
3790 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3793 /* unsolicited event for HP jack sensing */
3794 static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
3797 if ((res >> 26) != AD1884A_HP_EVENT)
3799 ad1984a_thinkpad_automute(codec);
3802 /* initialize jack-sensing, too */
3803 static int ad1984a_thinkpad_init(struct hda_codec *codec)
3806 ad1984a_thinkpad_automute(codec);
3821 static const char *ad1884a_models[AD1884A_MODELS] = {
3822 [AD1884A_DESKTOP] = "desktop",
3823 [AD1884A_LAPTOP] = "laptop",
3824 [AD1884A_MOBILE] = "mobile",
3825 [AD1884A_THINKPAD] = "thinkpad",
3828 static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3829 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
3830 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
3834 static int patch_ad1884a(struct hda_codec *codec)
3836 struct ad198x_spec *spec;
3839 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3843 mutex_init(&spec->amp_mutex);
3846 spec->multiout.max_channels = 2;
3847 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
3848 spec->multiout.dac_nids = ad1884a_dac_nids;
3849 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
3850 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
3851 spec->adc_nids = ad1884a_adc_nids;
3852 spec->capsrc_nids = ad1884a_capsrc_nids;
3853 spec->input_mux = &ad1884a_capture_source;
3854 spec->num_mixers = 1;
3855 spec->mixers[0] = ad1884a_base_mixers;
3856 spec->num_init_verbs = 1;
3857 spec->init_verbs[0] = ad1884a_init_verbs;
3858 spec->spdif_route = 0;
3859 #ifdef CONFIG_SND_HDA_POWER_SAVE
3860 spec->loopback.amplist = ad1884a_loopbacks;
3862 codec->patch_ops = ad198x_patch_ops;
3864 /* override some parameters */
3865 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
3868 switch (board_config) {
3869 case AD1884A_LAPTOP:
3870 spec->mixers[0] = ad1884a_laptop_mixers;
3871 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3872 spec->multiout.dig_out_nid = 0;
3873 spec->input_mux = &ad1884a_laptop_capture_source;
3874 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3875 codec->patch_ops.init = ad1884a_hp_init;
3877 case AD1884A_MOBILE:
3878 spec->mixers[0] = ad1884a_mobile_mixers;
3879 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3880 spec->multiout.dig_out_nid = 0;
3881 spec->input_mux = &ad1884a_mobile_capture_source;
3882 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3883 codec->patch_ops.init = ad1884a_hp_init;
3885 case AD1884A_THINKPAD:
3886 spec->mixers[0] = ad1984a_thinkpad_mixers;
3887 spec->init_verbs[spec->num_init_verbs++] =
3888 ad1984a_thinkpad_verbs;
3889 spec->multiout.dig_out_nid = 0;
3890 spec->input_mux = &ad1984a_thinkpad_capture_source;
3891 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
3892 codec->patch_ops.init = ad1984a_thinkpad_init;
3903 * port-A - front hp-out
3904 * port-B - front mic-in
3905 * port-C - rear line-in, shared surr-out (3stack)
3906 * port-D - rear line-out
3907 * port-E - rear mic-in, shared clfe-out (3stack)
3908 * port-F - rear surr-out (6stack)
3909 * port-G - rear clfe-out (6stack)
3912 static hda_nid_t ad1882_dac_nids[3] = {
3916 static hda_nid_t ad1882_adc_nids[2] = {
3920 static hda_nid_t ad1882_capsrc_nids[2] = {
3924 #define AD1882_SPDIF_OUT 0x02
3926 /* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
3927 static struct hda_input_mux ad1882_capture_source = {
3930 { "Front Mic", 0x1 },
3938 static struct snd_kcontrol_new ad1882_base_mixers[] = {
3939 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3940 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
3941 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
3942 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
3943 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3944 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3945 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3946 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3947 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3948 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3949 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3950 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3951 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
3952 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
3953 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
3954 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
3955 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
3956 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
3957 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
3958 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
3959 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
3960 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3961 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3962 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3963 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3965 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3966 /* The multiple "Capture Source" controls confuse alsamixer
3967 * So call somewhat different..
3969 /* .name = "Capture Source", */
3970 .name = "Input Source",
3972 .info = ad198x_mux_enum_info,
3973 .get = ad198x_mux_enum_get,
3974 .put = ad198x_mux_enum_put,
3976 /* SPDIF controls */
3977 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3979 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3980 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3981 /* identical with ad1983 */
3982 .info = ad1983_spdif_route_info,
3983 .get = ad1983_spdif_route_get,
3984 .put = ad1983_spdif_route_put,
3989 static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
3990 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3991 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
3992 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
3994 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3995 .name = "Channel Mode",
3996 .info = ad198x_ch_mode_info,
3997 .get = ad198x_ch_mode_get,
3998 .put = ad198x_ch_mode_put,
4003 static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
4004 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4005 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4006 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4010 static struct hda_verb ad1882_ch2_init[] = {
4011 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4012 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4013 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4014 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4015 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4016 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4020 static struct hda_verb ad1882_ch4_init[] = {
4021 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4022 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4023 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4024 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4025 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4026 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4030 static struct hda_verb ad1882_ch6_init[] = {
4031 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4032 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4033 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4034 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4035 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4036 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4040 static struct hda_channel_mode ad1882_modes[3] = {
4041 { 2, ad1882_ch2_init },
4042 { 4, ad1882_ch4_init },
4043 { 6, ad1882_ch6_init },
4047 * initialization verbs
4049 static struct hda_verb ad1882_init_verbs[] = {
4050 /* DACs; mute as default */
4051 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4052 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4053 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4054 /* Port-A (HP) mixer */
4055 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4056 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4058 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4059 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4060 /* HP selector - select DAC2 */
4061 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4062 /* Port-D (Line-out) mixer */
4063 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4064 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4066 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4067 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4068 /* Mono-out mixer */
4069 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4070 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4072 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4073 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4074 /* Port-B (front mic) pin */
4075 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4076 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4077 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4078 /* Port-C (line-in) pin */
4079 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4080 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4081 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4082 /* Port-C mixer - mute as input */
4083 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4084 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4085 /* Port-E (mic-in) pin */
4086 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4087 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4088 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4089 /* Port-E mixer - mute as input */
4090 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4091 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4092 /* Port-F (surround) */
4093 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4094 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4096 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4097 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4098 /* Analog mixer; mute as default */
4099 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4100 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4101 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4102 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4103 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4104 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4105 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4106 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4107 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4108 /* Analog Mix output amp */
4109 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4110 /* SPDIF output selector */
4111 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4112 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4113 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4117 #ifdef CONFIG_SND_HDA_POWER_SAVE
4118 static struct hda_amp_list ad1882_loopbacks[] = {
4119 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4120 { 0x20, HDA_INPUT, 1 }, /* Mic */
4121 { 0x20, HDA_INPUT, 4 }, /* Line */
4122 { 0x20, HDA_INPUT, 6 }, /* CD */
4134 static const char *ad1882_models[AD1986A_MODELS] = {
4135 [AD1882_3STACK] = "3stack",
4136 [AD1882_6STACK] = "6stack",
4140 static int patch_ad1882(struct hda_codec *codec)
4142 struct ad198x_spec *spec;
4145 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4149 mutex_init(&spec->amp_mutex);
4152 spec->multiout.max_channels = 6;
4153 spec->multiout.num_dacs = 3;
4154 spec->multiout.dac_nids = ad1882_dac_nids;
4155 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4156 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4157 spec->adc_nids = ad1882_adc_nids;
4158 spec->capsrc_nids = ad1882_capsrc_nids;
4159 spec->input_mux = &ad1882_capture_source;
4160 spec->num_mixers = 1;
4161 spec->mixers[0] = ad1882_base_mixers;
4162 spec->num_init_verbs = 1;
4163 spec->init_verbs[0] = ad1882_init_verbs;
4164 spec->spdif_route = 0;
4165 #ifdef CONFIG_SND_HDA_POWER_SAVE
4166 spec->loopback.amplist = ad1882_loopbacks;
4168 spec->vmaster_nid = 0x04;
4170 codec->patch_ops = ad198x_patch_ops;
4172 /* override some parameters */
4173 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4174 ad1882_models, NULL);
4175 switch (board_config) {
4178 spec->num_mixers = 2;
4179 spec->mixers[1] = ad1882_3stack_mixers;
4180 spec->channel_mode = ad1882_modes;
4181 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4182 spec->need_dac_fix = 1;
4183 spec->multiout.max_channels = 2;
4184 spec->multiout.num_dacs = 1;
4187 spec->num_mixers = 2;
4188 spec->mixers[1] = ad1882_6stack_mixers;
4198 struct hda_codec_preset snd_hda_preset_analog[] = {
4199 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
4200 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
4201 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
4202 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
4203 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4204 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
4205 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4206 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
4207 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
4208 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
4209 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
4210 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
4211 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4212 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },