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"
33 struct snd_kcontrol_new *mixers[5];
36 const struct hda_verb *init_verbs[5]; /* initialization verbs
37 * don't forget NULL termination!
39 unsigned int num_init_verbs;
42 struct hda_multi_out multiout; /* playback set-up
43 * max_channels, dacs must be set
44 * dig_out_nid and hp_nid are optional
46 unsigned int cur_eapd;
47 unsigned int need_dac_fix;
50 unsigned int num_adc_nids;
52 hda_nid_t dig_in_nid; /* digital-in NID; optional */
55 const struct hda_input_mux *input_mux;
56 hda_nid_t *capsrc_nids;
57 unsigned int cur_mux[3];
60 const struct hda_channel_mode *channel_mode;
64 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
66 struct mutex amp_mutex; /* PCM volume/mute control mutex */
67 unsigned int spdif_route;
69 /* dynamic controls, init_verbs and input_mux */
70 struct auto_pin_cfg autocfg;
71 unsigned int num_kctl_alloc, num_kctl_used;
72 struct snd_kcontrol_new *kctl_alloc;
73 struct hda_input_mux private_imux;
74 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
76 unsigned int jack_present :1;
78 #ifdef CONFIG_SND_HDA_POWER_SAVE
79 struct hda_loopback_check loopback;
81 /* for virtual master */
82 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",
144 static const char *ad_slave_sws[] = {
145 "Front Playback Switch",
146 "Surround Playback Switch",
147 "Center Playback Switch",
148 "LFE Playback Switch",
149 "Side Playback Switch",
150 "Headphone Playback Switch",
151 "Mono Playback Switch",
155 static int ad198x_build_controls(struct hda_codec *codec)
157 struct ad198x_spec *spec = codec->spec;
161 for (i = 0; i < spec->num_mixers; i++) {
162 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
166 if (spec->multiout.dig_out_nid) {
167 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
171 if (spec->dig_in_nid) {
172 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
177 /* if we have no master control, let's create it */
178 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
179 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
180 HDA_OUTPUT, spec->vmaster_tlv);
181 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
184 spec->slave_vols : ad_slave_vols));
188 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
189 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
192 spec->slave_sws : ad_slave_sws));
200 #ifdef CONFIG_SND_HDA_POWER_SAVE
201 static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
203 struct ad198x_spec *spec = codec->spec;
204 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
209 * Analog playback callbacks
211 static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
212 struct hda_codec *codec,
213 struct snd_pcm_substream *substream)
215 struct ad198x_spec *spec = codec->spec;
216 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
219 static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
220 struct hda_codec *codec,
221 unsigned int stream_tag,
223 struct snd_pcm_substream *substream)
225 struct ad198x_spec *spec = codec->spec;
226 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
230 static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
231 struct hda_codec *codec,
232 struct snd_pcm_substream *substream)
234 struct ad198x_spec *spec = codec->spec;
235 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
241 static int ad198x_dig_playback_pcm_open(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_dig_open(codec, &spec->multiout);
249 static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
250 struct hda_codec *codec,
251 struct snd_pcm_substream *substream)
253 struct ad198x_spec *spec = codec->spec;
254 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
257 static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
258 struct hda_codec *codec,
259 unsigned int stream_tag,
261 struct snd_pcm_substream *substream)
263 struct ad198x_spec *spec = codec->spec;
264 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
271 static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
272 struct hda_codec *codec,
273 unsigned int stream_tag,
275 struct snd_pcm_substream *substream)
277 struct ad198x_spec *spec = codec->spec;
278 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
279 stream_tag, 0, format);
283 static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
284 struct hda_codec *codec,
285 struct snd_pcm_substream *substream)
287 struct ad198x_spec *spec = codec->spec;
288 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
296 static struct hda_pcm_stream ad198x_pcm_analog_playback = {
299 .channels_max = 6, /* changed later */
300 .nid = 0, /* fill later */
302 .open = ad198x_playback_pcm_open,
303 .prepare = ad198x_playback_pcm_prepare,
304 .cleanup = ad198x_playback_pcm_cleanup
308 static struct hda_pcm_stream ad198x_pcm_analog_capture = {
312 .nid = 0, /* fill later */
314 .prepare = ad198x_capture_pcm_prepare,
315 .cleanup = ad198x_capture_pcm_cleanup
319 static struct hda_pcm_stream ad198x_pcm_digital_playback = {
323 .nid = 0, /* fill later */
325 .open = ad198x_dig_playback_pcm_open,
326 .close = ad198x_dig_playback_pcm_close,
327 .prepare = ad198x_dig_playback_pcm_prepare
331 static struct hda_pcm_stream ad198x_pcm_digital_capture = {
335 /* NID is set in alc_build_pcms */
338 static int ad198x_build_pcms(struct hda_codec *codec)
340 struct ad198x_spec *spec = codec->spec;
341 struct hda_pcm *info = spec->pcm_rec;
344 codec->pcm_info = info;
346 info->name = "AD198x Analog";
347 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
348 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
349 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
350 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
351 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
352 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
354 if (spec->multiout.dig_out_nid) {
357 info->name = "AD198x Digital";
358 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
359 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
360 if (spec->dig_in_nid) {
361 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
362 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
369 static void ad198x_free(struct hda_codec *codec)
371 struct ad198x_spec *spec = codec->spec;
374 if (spec->kctl_alloc) {
375 for (i = 0; i < spec->num_kctl_used; i++)
376 kfree(spec->kctl_alloc[i].name);
377 kfree(spec->kctl_alloc);
382 static struct hda_codec_ops ad198x_patch_ops = {
383 .build_controls = ad198x_build_controls,
384 .build_pcms = ad198x_build_pcms,
387 #ifdef CONFIG_SND_HDA_POWER_SAVE
388 .check_power_status = ad198x_check_power_status,
395 * the private value = nid | (invert << 8)
397 #define ad198x_eapd_info snd_ctl_boolean_mono_info
399 static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
400 struct snd_ctl_elem_value *ucontrol)
402 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
403 struct ad198x_spec *spec = codec->spec;
404 int invert = (kcontrol->private_value >> 8) & 1;
406 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
408 ucontrol->value.integer.value[0] = spec->cur_eapd;
412 static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
413 struct snd_ctl_elem_value *ucontrol)
415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
416 struct ad198x_spec *spec = codec->spec;
417 int invert = (kcontrol->private_value >> 8) & 1;
418 hda_nid_t nid = kcontrol->private_value & 0xff;
420 eapd = !!ucontrol->value.integer.value[0];
423 if (eapd == spec->cur_eapd)
425 spec->cur_eapd = eapd;
426 snd_hda_codec_write_cache(codec, nid,
427 0, AC_VERB_SET_EAPD_BTLENABLE,
432 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
433 struct snd_ctl_elem_info *uinfo);
434 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
435 struct snd_ctl_elem_value *ucontrol);
436 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
437 struct snd_ctl_elem_value *ucontrol);
444 #define AD1986A_SPDIF_OUT 0x02
445 #define AD1986A_FRONT_DAC 0x03
446 #define AD1986A_SURR_DAC 0x04
447 #define AD1986A_CLFE_DAC 0x05
448 #define AD1986A_ADC 0x06
450 static hda_nid_t ad1986a_dac_nids[3] = {
451 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
453 static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
454 static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
456 static struct hda_input_mux ad1986a_capture_source = {
470 static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
471 .ops = &snd_hda_bind_vol,
473 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
474 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
475 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
480 static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
481 .ops = &snd_hda_bind_sw,
483 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
484 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
485 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
493 static struct snd_kcontrol_new ad1986a_mixers[] = {
495 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
497 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
498 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
499 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
500 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
501 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
502 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
503 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
504 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
505 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
506 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
507 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
508 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
509 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
510 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
511 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
512 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
513 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
514 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
515 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
516 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
517 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
518 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
519 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
520 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
521 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
522 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
523 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
525 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
526 .name = "Capture Source",
527 .info = ad198x_mux_enum_info,
528 .get = ad198x_mux_enum_get,
529 .put = ad198x_mux_enum_put,
531 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
535 /* additional mixers for 3stack mode */
536 static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
538 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
539 .name = "Channel Mode",
540 .info = ad198x_ch_mode_info,
541 .get = ad198x_ch_mode_get,
542 .put = ad198x_ch_mode_put,
547 /* laptop model - 2ch only */
548 static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
550 /* master controls both pins 0x1a and 0x1b */
551 static struct hda_bind_ctls ad1986a_laptop_master_vol = {
552 .ops = &snd_hda_bind_vol,
554 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
555 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
560 static struct hda_bind_ctls ad1986a_laptop_master_sw = {
561 .ops = &snd_hda_bind_sw,
563 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
564 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
569 static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
570 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
571 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
572 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
573 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
574 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
575 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
576 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
577 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
578 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
579 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
580 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
581 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
582 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
583 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
584 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
585 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
586 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
587 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
588 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
590 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
591 .name = "Capture Source",
592 .info = ad198x_mux_enum_info,
593 .get = ad198x_mux_enum_get,
594 .put = ad198x_mux_enum_put,
599 /* laptop-eapd model - 2ch only */
601 static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
605 { "Internal Mic", 0x4 },
610 static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
611 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
612 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
613 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
614 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
615 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
616 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
617 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
618 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
619 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
620 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
621 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
623 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
624 .name = "Capture Source",
625 .info = ad198x_mux_enum_info,
626 .get = ad198x_mux_enum_get,
627 .put = ad198x_mux_enum_put,
630 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
631 .name = "External Amplifier",
632 .info = ad198x_eapd_info,
633 .get = ad198x_eapd_get,
634 .put = ad198x_eapd_put,
635 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
640 /* laptop-automute - 2ch only */
642 static void ad1986a_update_hp(struct hda_codec *codec)
644 struct ad198x_spec *spec = codec->spec;
647 if (spec->jack_present)
648 mute = HDA_AMP_MUTE; /* mute internal speaker */
650 /* unmute internal speaker if necessary */
651 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
652 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
656 static void ad1986a_hp_automute(struct hda_codec *codec)
658 struct ad198x_spec *spec = codec->spec;
659 unsigned int present;
661 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0);
662 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
663 spec->jack_present = !(present & 0x80000000);
664 ad1986a_update_hp(codec);
667 #define AD1986A_HP_EVENT 0x37
669 static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
671 if ((res >> 26) != AD1986A_HP_EVENT)
673 ad1986a_hp_automute(codec);
676 static int ad1986a_hp_init(struct hda_codec *codec)
679 ad1986a_hp_automute(codec);
683 /* bind hp and internal speaker mute (with plug check) */
684 static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
685 struct snd_ctl_elem_value *ucontrol)
687 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
688 long *valp = ucontrol->value.integer.value;
691 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
693 valp[0] ? 0 : HDA_AMP_MUTE);
694 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
696 valp[1] ? 0 : HDA_AMP_MUTE);
698 ad1986a_update_hp(codec);
702 static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = {
703 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
705 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
706 .name = "Master Playback Switch",
707 .info = snd_hda_mixer_amp_switch_info,
708 .get = snd_hda_mixer_amp_switch_get,
709 .put = ad1986a_hp_master_sw_put,
710 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
712 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
713 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
714 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
715 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
716 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
717 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
718 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
719 HDA_CODEC_VOLUME("Beep Playback Volume", 0x18, 0x0, HDA_OUTPUT),
720 HDA_CODEC_MUTE("Beep Playback Switch", 0x18, 0x0, HDA_OUTPUT),
721 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
722 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
724 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
725 .name = "Capture Source",
726 .info = ad198x_mux_enum_info,
727 .get = ad198x_mux_enum_get,
728 .put = ad198x_mux_enum_put,
731 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
732 .name = "External Amplifier",
733 .info = ad198x_eapd_info,
734 .get = ad198x_eapd_get,
735 .put = ad198x_eapd_put,
736 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
742 * initialization verbs
744 static struct hda_verb ad1986a_init_verbs[] = {
745 /* Front, Surround, CLFE DAC; mute as default */
746 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
747 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
748 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
750 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
751 /* HP, Line-Out, Surround, CLFE selectors */
752 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
753 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
754 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
755 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
757 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
758 /* Mic selector: Mic 1/2 pin */
759 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
760 /* Line-in selector: Line-in */
761 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
763 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
764 /* Record selector: mic */
765 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
766 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
767 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
768 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
769 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
770 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
771 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
773 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
774 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
775 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
776 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
777 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
778 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
779 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
781 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
782 /* Front, Surround, CLFE Pins */
783 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
784 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
785 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
787 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
789 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
790 /* Line, Aux, CD, Beep-In Pin */
791 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
792 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
793 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
794 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
795 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
799 static struct hda_verb ad1986a_ch2_init[] = {
800 /* Surround out -> Line In */
801 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
802 /* Line-in selectors */
803 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
805 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
806 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
807 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
811 static struct hda_verb ad1986a_ch4_init[] = {
812 /* Surround out -> Surround */
813 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
814 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
816 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
817 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
821 static struct hda_verb ad1986a_ch6_init[] = {
822 /* Surround out -> Surround out */
823 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
824 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
826 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
827 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
831 static struct hda_channel_mode ad1986a_modes[3] = {
832 { 2, ad1986a_ch2_init },
833 { 4, ad1986a_ch4_init },
834 { 6, ad1986a_ch6_init },
837 /* eapd initialization */
838 static struct hda_verb ad1986a_eapd_init_verbs[] = {
839 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
843 /* Ultra initialization */
844 static struct hda_verb ad1986a_ultra_init[] = {
845 /* eapd initialization */
846 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
848 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
849 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
850 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
854 /* pin sensing on HP jack */
855 static struct hda_verb ad1986a_hp_init_verbs[] = {
856 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
867 AD1986A_LAPTOP_AUTOMUTE,
872 static const char *ad1986a_models[AD1986A_MODELS] = {
873 [AD1986A_6STACK] = "6stack",
874 [AD1986A_3STACK] = "3stack",
875 [AD1986A_LAPTOP] = "laptop",
876 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
877 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
878 [AD1986A_ULTRA] = "ultra",
881 static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
882 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
883 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
884 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
885 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
886 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
887 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
888 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
889 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
890 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
891 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
892 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
893 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
894 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
895 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
896 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
897 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
898 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
899 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
900 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
901 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
902 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
903 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
904 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
905 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
906 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
907 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
908 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
909 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
913 #ifdef CONFIG_SND_HDA_POWER_SAVE
914 static struct hda_amp_list ad1986a_loopbacks[] = {
915 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
916 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
917 { 0x15, HDA_OUTPUT, 0 }, /* CD */
918 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
919 { 0x17, HDA_OUTPUT, 0 }, /* Line */
924 static int patch_ad1986a(struct hda_codec *codec)
926 struct ad198x_spec *spec;
929 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
935 spec->multiout.max_channels = 6;
936 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
937 spec->multiout.dac_nids = ad1986a_dac_nids;
938 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
939 spec->num_adc_nids = 1;
940 spec->adc_nids = ad1986a_adc_nids;
941 spec->capsrc_nids = ad1986a_capsrc_nids;
942 spec->input_mux = &ad1986a_capture_source;
943 spec->num_mixers = 1;
944 spec->mixers[0] = ad1986a_mixers;
945 spec->num_init_verbs = 1;
946 spec->init_verbs[0] = ad1986a_init_verbs;
947 #ifdef CONFIG_SND_HDA_POWER_SAVE
948 spec->loopback.amplist = ad1986a_loopbacks;
950 spec->vmaster_nid = 0x1b;
952 codec->patch_ops = ad198x_patch_ops;
954 /* override some parameters */
955 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
958 switch (board_config) {
960 spec->num_mixers = 2;
961 spec->mixers[1] = ad1986a_3st_mixers;
962 spec->num_init_verbs = 2;
963 spec->init_verbs[1] = ad1986a_ch2_init;
964 spec->channel_mode = ad1986a_modes;
965 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
966 spec->need_dac_fix = 1;
967 spec->multiout.max_channels = 2;
968 spec->multiout.num_dacs = 1;
971 spec->mixers[0] = ad1986a_laptop_mixers;
972 spec->multiout.max_channels = 2;
973 spec->multiout.num_dacs = 1;
974 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
976 case AD1986A_LAPTOP_EAPD:
977 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
978 spec->num_init_verbs = 2;
979 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
980 spec->multiout.max_channels = 2;
981 spec->multiout.num_dacs = 1;
982 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
983 spec->multiout.dig_out_nid = 0;
984 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
986 case AD1986A_LAPTOP_AUTOMUTE:
987 spec->mixers[0] = ad1986a_laptop_automute_mixers;
988 spec->num_init_verbs = 3;
989 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
990 spec->init_verbs[2] = ad1986a_hp_init_verbs;
991 spec->multiout.max_channels = 2;
992 spec->multiout.num_dacs = 1;
993 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
994 spec->multiout.dig_out_nid = 0;
995 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
996 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
997 codec->patch_ops.init = ad1986a_hp_init;
1000 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1001 spec->num_init_verbs = 2;
1002 spec->init_verbs[1] = ad1986a_ultra_init;
1003 spec->multiout.max_channels = 2;
1004 spec->multiout.num_dacs = 1;
1005 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1006 spec->multiout.dig_out_nid = 0;
1010 /* AD1986A has a hardware problem that it can't share a stream
1011 * with multiple output pins. The copy of front to surrounds
1012 * causes noisy or silent outputs at a certain timing, e.g.
1013 * changing the volume.
1014 * So, let's disable the shared stream.
1016 spec->multiout.no_share_stream = 1;
1025 #define AD1983_SPDIF_OUT 0x02
1026 #define AD1983_DAC 0x03
1027 #define AD1983_ADC 0x04
1029 static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
1030 static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
1031 static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
1033 static struct hda_input_mux ad1983_capture_source = {
1039 { "Mix Mono", 0x3 },
1044 * SPDIF playback route
1046 static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1048 static char *texts[] = { "PCM", "ADC" };
1050 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1052 uinfo->value.enumerated.items = 2;
1053 if (uinfo->value.enumerated.item > 1)
1054 uinfo->value.enumerated.item = 1;
1055 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1059 static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1061 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1062 struct ad198x_spec *spec = codec->spec;
1064 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1068 static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1070 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1071 struct ad198x_spec *spec = codec->spec;
1073 if (ucontrol->value.enumerated.item[0] > 1)
1075 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1076 spec->spdif_route = ucontrol->value.enumerated.item[0];
1077 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1078 AC_VERB_SET_CONNECT_SEL,
1085 static struct snd_kcontrol_new ad1983_mixers[] = {
1086 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1087 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1088 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1089 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1090 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1091 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1092 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1093 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1094 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1095 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1096 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1097 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1098 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
1099 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
1100 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1101 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1102 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1104 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1105 .name = "Capture Source",
1106 .info = ad198x_mux_enum_info,
1107 .get = ad198x_mux_enum_get,
1108 .put = ad198x_mux_enum_put,
1111 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1112 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1113 .info = ad1983_spdif_route_info,
1114 .get = ad1983_spdif_route_get,
1115 .put = ad1983_spdif_route_put,
1120 static struct hda_verb ad1983_init_verbs[] = {
1121 /* Front, HP, Mono; mute as default */
1122 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1123 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1124 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1125 /* Beep, PCM, Mic, Line-In: mute */
1126 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1127 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1128 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1129 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1130 /* Front, HP selectors; from Mix */
1131 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1132 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1133 /* Mono selector; from Mix */
1134 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1135 /* Mic selector; Mic */
1136 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1137 /* Line-in selector: Line-in */
1138 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1139 /* Mic boost: 0dB */
1140 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1141 /* Record selector: mic */
1142 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1143 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1144 /* SPDIF route: PCM */
1145 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1147 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1149 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1151 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1153 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1155 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1159 #ifdef CONFIG_SND_HDA_POWER_SAVE
1160 static struct hda_amp_list ad1983_loopbacks[] = {
1161 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1162 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1167 static int patch_ad1983(struct hda_codec *codec)
1169 struct ad198x_spec *spec;
1171 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1177 spec->multiout.max_channels = 2;
1178 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1179 spec->multiout.dac_nids = ad1983_dac_nids;
1180 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
1181 spec->num_adc_nids = 1;
1182 spec->adc_nids = ad1983_adc_nids;
1183 spec->capsrc_nids = ad1983_capsrc_nids;
1184 spec->input_mux = &ad1983_capture_source;
1185 spec->num_mixers = 1;
1186 spec->mixers[0] = ad1983_mixers;
1187 spec->num_init_verbs = 1;
1188 spec->init_verbs[0] = ad1983_init_verbs;
1189 spec->spdif_route = 0;
1190 #ifdef CONFIG_SND_HDA_POWER_SAVE
1191 spec->loopback.amplist = ad1983_loopbacks;
1193 spec->vmaster_nid = 0x05;
1195 codec->patch_ops = ad198x_patch_ops;
1202 * AD1981 HD specific
1205 #define AD1981_SPDIF_OUT 0x02
1206 #define AD1981_DAC 0x03
1207 #define AD1981_ADC 0x04
1209 static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
1210 static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
1211 static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
1213 /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1214 static struct hda_input_mux ad1981_capture_source = {
1217 { "Front Mic", 0x0 },
1220 { "Mix Mono", 0x3 },
1227 static struct snd_kcontrol_new ad1981_mixers[] = {
1228 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1229 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1230 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1231 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1232 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1233 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1234 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1235 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1236 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1237 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1238 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1239 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1240 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1241 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1242 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1243 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1244 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1245 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1246 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1247 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1248 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1249 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1250 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1251 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1253 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1254 .name = "Capture Source",
1255 .info = ad198x_mux_enum_info,
1256 .get = ad198x_mux_enum_get,
1257 .put = ad198x_mux_enum_put,
1259 /* identical with AD1983 */
1261 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1262 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1263 .info = ad1983_spdif_route_info,
1264 .get = ad1983_spdif_route_get,
1265 .put = ad1983_spdif_route_put,
1270 static struct hda_verb ad1981_init_verbs[] = {
1271 /* Front, HP, Mono; mute as default */
1272 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1273 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1274 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1275 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1276 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1277 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1278 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1279 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1280 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1281 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1282 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1283 /* Front, HP selectors; from Mix */
1284 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1285 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1286 /* Mono selector; from Mix */
1287 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1288 /* Mic Mixer; select Front Mic */
1289 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1290 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1291 /* Mic boost: 0dB */
1292 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1293 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1294 /* Record selector: Front mic */
1295 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1296 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1297 /* SPDIF route: PCM */
1298 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1300 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1302 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1304 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1305 /* Front & Rear Mic Pins */
1306 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1307 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1309 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1311 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1312 /* Line-Out as Input: disabled */
1313 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1317 #ifdef CONFIG_SND_HDA_POWER_SAVE
1318 static struct hda_amp_list ad1981_loopbacks[] = {
1319 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1320 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1321 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1322 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1323 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1329 * Patch for HP nx6320
1331 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
1332 * speaker output enabled _and_ mute-LED off.
1335 #define AD1981_HP_EVENT 0x37
1336 #define AD1981_MIC_EVENT 0x38
1338 static struct hda_verb ad1981_hp_init_verbs[] = {
1339 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1340 /* pin sensing on HP and Mic jacks */
1341 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1342 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1346 /* turn on/off EAPD (+ mute HP) as a master switch */
1347 static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1348 struct snd_ctl_elem_value *ucontrol)
1350 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1351 struct ad198x_spec *spec = codec->spec;
1353 if (! ad198x_eapd_put(kcontrol, ucontrol))
1356 /* toggle HP mute appropriately */
1357 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1359 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
1363 /* bind volumes of both NID 0x05 and 0x06 */
1364 static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1365 .ops = &snd_hda_bind_vol,
1367 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1368 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1373 /* mute internal speaker if HP is plugged */
1374 static void ad1981_hp_automute(struct hda_codec *codec)
1376 unsigned int present;
1378 present = snd_hda_codec_read(codec, 0x06, 0,
1379 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1380 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1381 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1384 /* toggle input of built-in and mic jack appropriately */
1385 static void ad1981_hp_automic(struct hda_codec *codec)
1387 static struct hda_verb mic_jack_on[] = {
1388 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1389 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1392 static struct hda_verb mic_jack_off[] = {
1393 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1394 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1397 unsigned int present;
1399 present = snd_hda_codec_read(codec, 0x08, 0,
1400 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1402 snd_hda_sequence_write(codec, mic_jack_on);
1404 snd_hda_sequence_write(codec, mic_jack_off);
1407 /* unsolicited event for HP jack sensing */
1408 static void ad1981_hp_unsol_event(struct hda_codec *codec,
1413 case AD1981_HP_EVENT:
1414 ad1981_hp_automute(codec);
1416 case AD1981_MIC_EVENT:
1417 ad1981_hp_automic(codec);
1422 static struct hda_input_mux ad1981_hp_capture_source = {
1426 { "Docking-Station", 0x1 },
1431 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1432 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
1434 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1435 .name = "Master Playback Switch",
1436 .info = ad198x_eapd_info,
1437 .get = ad198x_eapd_get,
1438 .put = ad1981_hp_master_sw_put,
1439 .private_value = 0x05,
1441 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1442 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1444 /* FIXME: analog mic/line loopback doesn't work with my tests...
1445 * (although recording is OK)
1447 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1448 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1449 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1450 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1451 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1452 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1453 /* FIXME: does this laptop have analog CD connection? */
1454 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1455 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1457 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1458 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1459 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1460 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1462 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1463 .name = "Capture Source",
1464 .info = ad198x_mux_enum_info,
1465 .get = ad198x_mux_enum_get,
1466 .put = ad198x_mux_enum_put,
1471 /* initialize jack-sensing, too */
1472 static int ad1981_hp_init(struct hda_codec *codec)
1475 ad1981_hp_automute(codec);
1476 ad1981_hp_automic(codec);
1480 /* configuration for Toshiba Laptops */
1481 static struct hda_verb ad1981_toshiba_init_verbs[] = {
1482 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1483 /* pin sensing on HP and Mic jacks */
1484 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1485 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1489 static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1490 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1491 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1495 /* configuration for Lenovo Thinkpad T60 */
1496 static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1497 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1498 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1499 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1500 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1501 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1502 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1503 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1504 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1505 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1506 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1507 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1509 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1510 .name = "Capture Source",
1511 .info = ad198x_mux_enum_info,
1512 .get = ad198x_mux_enum_get,
1513 .put = ad198x_mux_enum_put,
1515 /* identical with AD1983 */
1517 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1518 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1519 .info = ad1983_spdif_route_info,
1520 .get = ad1983_spdif_route_get,
1521 .put = ad1983_spdif_route_put,
1526 static struct hda_input_mux ad1981_thinkpad_capture_source = {
1544 static const char *ad1981_models[AD1981_MODELS] = {
1546 [AD1981_THINKPAD] = "thinkpad",
1547 [AD1981_BASIC] = "basic",
1548 [AD1981_TOSHIBA] = "toshiba"
1551 static struct snd_pci_quirk ad1981_cfg_tbl[] = {
1552 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
1554 SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
1555 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
1556 /* Lenovo Thinkpad T60/X60/Z6xx */
1557 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
1558 /* HP nx6320 (reversed SSID, H/W bug) */
1559 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
1563 static int patch_ad1981(struct hda_codec *codec)
1565 struct ad198x_spec *spec;
1568 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1574 spec->multiout.max_channels = 2;
1575 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1576 spec->multiout.dac_nids = ad1981_dac_nids;
1577 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
1578 spec->num_adc_nids = 1;
1579 spec->adc_nids = ad1981_adc_nids;
1580 spec->capsrc_nids = ad1981_capsrc_nids;
1581 spec->input_mux = &ad1981_capture_source;
1582 spec->num_mixers = 1;
1583 spec->mixers[0] = ad1981_mixers;
1584 spec->num_init_verbs = 1;
1585 spec->init_verbs[0] = ad1981_init_verbs;
1586 spec->spdif_route = 0;
1587 #ifdef CONFIG_SND_HDA_POWER_SAVE
1588 spec->loopback.amplist = ad1981_loopbacks;
1590 spec->vmaster_nid = 0x05;
1592 codec->patch_ops = ad198x_patch_ops;
1594 /* override some parameters */
1595 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1598 switch (board_config) {
1600 spec->mixers[0] = ad1981_hp_mixers;
1601 spec->num_init_verbs = 2;
1602 spec->init_verbs[1] = ad1981_hp_init_verbs;
1603 spec->multiout.dig_out_nid = 0;
1604 spec->input_mux = &ad1981_hp_capture_source;
1606 codec->patch_ops.init = ad1981_hp_init;
1607 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1609 case AD1981_THINKPAD:
1610 spec->mixers[0] = ad1981_thinkpad_mixers;
1611 spec->input_mux = &ad1981_thinkpad_capture_source;
1613 case AD1981_TOSHIBA:
1614 spec->mixers[0] = ad1981_hp_mixers;
1615 spec->mixers[1] = ad1981_toshiba_mixers;
1616 spec->num_init_verbs = 2;
1617 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1618 spec->multiout.dig_out_nid = 0;
1619 spec->input_mux = &ad1981_hp_capture_source;
1620 codec->patch_ops.init = ad1981_hp_init;
1621 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1631 * Output pins and routes
1633 * Pin Mix Sel DAC (*)
1634 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1635 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1636 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1637 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1638 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1639 * port-F 0x16 (mute) <- 0x2a <- 06
1640 * port-G 0x24 (mute) <- 0x27 <- 05
1641 * port-H 0x25 (mute) <- 0x28 <- 0a
1642 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1644 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1645 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
1647 * Input pins and routes
1649 * pin boost mix input # / adc input #
1650 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1651 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1652 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1653 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1654 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1655 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1656 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1657 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1661 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
1662 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
1664 * Inputs of Analog Mix (0x20)
1665 * 0:Port-B (front mic)
1666 * 1:Port-C/G/H (line-in)
1668 * 3:Port-D (line-in/2)
1669 * 4:Port-E/G/H (mic-in)
1670 * 5:Port-F (mic2-in)
1676 * 1:Port-B (front mic-in)
1677 * 2:Port-C (line-in)
1678 * 3:Port-F (mic2-in)
1683 * 8:Port-D (line-in/2)
1686 * Proposed pin assignments by the datasheet
1689 * Port-A front headphone
1699 * Port-A front headphone
1701 * C rear line-in/surround
1703 * E rear mic-in/CLFE
1709 * D internal speaker (with EAPD)
1710 * E/F quad mic array
1726 /* reivision id to check workarounds */
1727 #define AD1988A_REV2 0x100200
1729 #define is_rev2(codec) \
1730 ((codec)->vendor_id == 0x11d41988 && \
1731 (codec)->revision_id == AD1988A_REV2)
1737 static hda_nid_t ad1988_6stack_dac_nids[4] = {
1738 0x04, 0x06, 0x05, 0x0a
1741 static hda_nid_t ad1988_3stack_dac_nids[3] = {
1745 /* for AD1988A revision-2, DAC2-4 are swapped */
1746 static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1747 0x04, 0x05, 0x0a, 0x06
1750 static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
1754 static hda_nid_t ad1988_adc_nids[3] = {
1758 static hda_nid_t ad1988_capsrc_nids[3] = {
1762 #define AD1988_SPDIF_OUT 0x02
1763 #define AD1988_SPDIF_IN 0x07
1765 static struct hda_input_mux ad1988_6stack_capture_source = {
1768 { "Front Mic", 0x0 },
1776 static struct hda_input_mux ad1988_laptop_capture_source = {
1779 { "Mic/Line", 0x0 },
1787 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1788 struct snd_ctl_elem_info *uinfo)
1790 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1791 struct ad198x_spec *spec = codec->spec;
1792 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1793 spec->num_channel_mode);
1796 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1797 struct snd_ctl_elem_value *ucontrol)
1799 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1800 struct ad198x_spec *spec = codec->spec;
1801 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1802 spec->num_channel_mode, spec->multiout.max_channels);
1805 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1806 struct snd_ctl_elem_value *ucontrol)
1808 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1809 struct ad198x_spec *spec = codec->spec;
1810 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1811 spec->num_channel_mode,
1812 &spec->multiout.max_channels);
1813 if (err >= 0 && spec->need_dac_fix)
1814 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
1819 static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
1820 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1821 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1822 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1823 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1824 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1828 static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1829 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1830 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1831 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1832 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1833 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1837 static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
1838 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1839 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1840 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1841 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1842 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1843 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1844 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1846 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1847 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1848 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1849 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1850 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1851 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1852 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1853 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1855 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1856 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1858 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1859 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1861 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1862 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1868 static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
1869 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1870 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1871 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1872 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1876 static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1877 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1878 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1879 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1880 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
1884 static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
1885 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1886 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1887 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1888 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
1889 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1890 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1892 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1893 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1894 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1895 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1896 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1897 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1898 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1899 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1901 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1902 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1904 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1905 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1907 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1908 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1910 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1911 .name = "Channel Mode",
1912 .info = ad198x_ch_mode_info,
1913 .get = ad198x_ch_mode_get,
1914 .put = ad198x_ch_mode_put,
1921 static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1922 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1923 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1924 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1926 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1927 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1928 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1929 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1930 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1931 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1933 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1934 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1936 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1937 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1939 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1942 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1943 .name = "External Amplifier",
1944 .info = ad198x_eapd_info,
1945 .get = ad198x_eapd_get,
1946 .put = ad198x_eapd_put,
1947 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
1954 static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1955 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1956 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1957 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1958 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1959 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1960 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1962 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1963 /* The multiple "Capture Source" controls confuse alsamixer
1964 * So call somewhat different..
1966 /* .name = "Capture Source", */
1967 .name = "Input Source",
1969 .info = ad198x_mux_enum_info,
1970 .get = ad198x_mux_enum_get,
1971 .put = ad198x_mux_enum_put,
1976 static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1977 struct snd_ctl_elem_info *uinfo)
1979 static char *texts[] = {
1980 "PCM", "ADC1", "ADC2", "ADC3"
1982 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1984 uinfo->value.enumerated.items = 4;
1985 if (uinfo->value.enumerated.item >= 4)
1986 uinfo->value.enumerated.item = 3;
1987 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1991 static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1992 struct snd_ctl_elem_value *ucontrol)
1994 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1997 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2000 ucontrol->value.enumerated.item[0] = 0;
2002 sel = snd_hda_codec_read(codec, 0x0b, 0,
2003 AC_VERB_GET_CONNECT_SEL, 0);
2008 ucontrol->value.enumerated.item[0] = sel;
2013 static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2014 struct snd_ctl_elem_value *ucontrol)
2016 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2017 unsigned int val, sel;
2020 val = ucontrol->value.enumerated.item[0];
2024 sel = snd_hda_codec_read(codec, 0x1d, 0,
2025 AC_VERB_GET_AMP_GAIN_MUTE,
2027 change = sel & 0x80;
2029 snd_hda_codec_write_cache(codec, 0x1d, 0,
2030 AC_VERB_SET_AMP_GAIN_MUTE,
2032 snd_hda_codec_write_cache(codec, 0x1d, 0,
2033 AC_VERB_SET_AMP_GAIN_MUTE,
2037 sel = snd_hda_codec_read(codec, 0x1d, 0,
2038 AC_VERB_GET_AMP_GAIN_MUTE,
2039 AC_AMP_GET_INPUT | 0x01);
2040 change = sel & 0x80;
2042 snd_hda_codec_write_cache(codec, 0x1d, 0,
2043 AC_VERB_SET_AMP_GAIN_MUTE,
2045 snd_hda_codec_write_cache(codec, 0x1d, 0,
2046 AC_VERB_SET_AMP_GAIN_MUTE,
2049 sel = snd_hda_codec_read(codec, 0x0b, 0,
2050 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2051 change |= sel != val;
2053 snd_hda_codec_write_cache(codec, 0x0b, 0,
2054 AC_VERB_SET_CONNECT_SEL,
2060 static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2061 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2063 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2064 .name = "IEC958 Playback Source",
2065 .info = ad1988_spdif_playback_source_info,
2066 .get = ad1988_spdif_playback_source_get,
2067 .put = ad1988_spdif_playback_source_put,
2072 static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2073 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2079 * initialization verbs
2083 * for 6-stack (+dig)
2085 static struct hda_verb ad1988_6stack_init_verbs[] = {
2086 /* Front, Surround, CLFE, side DAC; unmute as default */
2087 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2088 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2089 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2090 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2091 /* Port-A front headphon path */
2092 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2093 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2094 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2095 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2096 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2097 /* Port-D line-out path */
2098 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2099 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2100 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2101 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2102 /* Port-F surround path */
2103 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2104 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2105 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2106 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2107 /* Port-G CLFE path */
2108 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2109 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2110 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2111 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2112 /* Port-H side path */
2113 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2114 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2115 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2116 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2118 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2119 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2120 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2121 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2122 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2123 /* Port-B front mic-in path */
2124 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2125 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2126 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2127 /* Port-C line-in path */
2128 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2129 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2130 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2131 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2132 /* Port-E mic-in path */
2133 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2134 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2135 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2136 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2137 /* Analog CD Input */
2138 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2143 static struct hda_verb ad1988_capture_init_verbs[] = {
2144 /* mute analog mix */
2145 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2146 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2147 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2148 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2149 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2150 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2151 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2152 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2153 /* select ADCs - front-mic */
2154 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2155 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2156 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2158 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2159 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2160 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2165 static struct hda_verb ad1988_spdif_init_verbs[] = {
2167 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2168 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2169 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2170 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2172 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2178 * verbs for 3stack (+dig)
2180 static struct hda_verb ad1988_3stack_ch2_init[] = {
2181 /* set port-C to line-in */
2182 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2183 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2184 /* set port-E to mic-in */
2185 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2186 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2190 static struct hda_verb ad1988_3stack_ch6_init[] = {
2191 /* set port-C to surround out */
2192 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2193 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2194 /* set port-E to CLFE out */
2195 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2196 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2200 static struct hda_channel_mode ad1988_3stack_modes[2] = {
2201 { 2, ad1988_3stack_ch2_init },
2202 { 6, ad1988_3stack_ch6_init },
2205 static struct hda_verb ad1988_3stack_init_verbs[] = {
2206 /* Front, Surround, CLFE, side DAC; unmute as default */
2207 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2208 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2209 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2210 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2211 /* Port-A front headphon path */
2212 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2213 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2214 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2215 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2216 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2217 /* Port-D line-out path */
2218 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2219 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2220 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2221 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2223 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2224 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2225 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2226 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2227 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2228 /* Port-B front mic-in path */
2229 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2230 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2231 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2232 /* Port-C line-in/surround path - 6ch mode as default */
2233 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2234 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2235 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2236 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
2237 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2238 /* Port-E mic-in/CLFE path - 6ch mode as default */
2239 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2240 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2241 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2242 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
2243 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2244 /* mute analog mix */
2245 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2246 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2247 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2248 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2249 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2250 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2251 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2252 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2253 /* select ADCs - front-mic */
2254 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2255 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2256 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2258 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2259 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2260 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2265 * verbs for laptop mode (+dig)
2267 static struct hda_verb ad1988_laptop_hp_on[] = {
2268 /* unmute port-A and mute port-D */
2269 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2270 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2273 static struct hda_verb ad1988_laptop_hp_off[] = {
2274 /* mute port-A and unmute port-D */
2275 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2276 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2280 #define AD1988_HP_EVENT 0x01
2282 static struct hda_verb ad1988_laptop_init_verbs[] = {
2283 /* Front, Surround, CLFE, side DAC; unmute as default */
2284 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2285 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2286 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2287 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2288 /* Port-A front headphon path */
2289 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2290 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2291 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2292 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2293 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2294 /* unsolicited event for pin-sense */
2295 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2296 /* Port-D line-out path + EAPD */
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},
2301 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2303 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2304 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2305 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2306 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2307 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2308 /* Port-B mic-in path */
2309 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2310 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2311 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2312 /* Port-C docking station - try to output */
2313 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2314 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2315 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2316 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2317 /* mute analog mix */
2318 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2319 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2320 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2321 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2322 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2323 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2324 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2325 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2326 /* select ADCs - mic */
2327 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2328 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2329 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2331 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2332 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2333 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2337 static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2339 if ((res >> 26) != AD1988_HP_EVENT)
2341 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2342 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2344 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2347 #ifdef CONFIG_SND_HDA_POWER_SAVE
2348 static struct hda_amp_list ad1988_loopbacks[] = {
2349 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2350 { 0x20, HDA_INPUT, 1 }, /* Line */
2351 { 0x20, HDA_INPUT, 4 }, /* Mic */
2352 { 0x20, HDA_INPUT, 6 }, /* CD */
2358 * Automatic parse of I/O pins from the BIOS configuration
2361 #define NUM_CONTROL_ALLOC 32
2362 #define NUM_VERB_ALLOC 32
2369 static struct snd_kcontrol_new ad1988_control_templates[] = {
2370 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2371 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2372 HDA_BIND_MUTE(NULL, 0, 0, 0),
2375 /* add dynamic controls */
2376 static int add_control(struct ad198x_spec *spec, int type, const char *name,
2379 struct snd_kcontrol_new *knew;
2381 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2382 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2384 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2387 if (spec->kctl_alloc) {
2388 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2389 kfree(spec->kctl_alloc);
2391 spec->kctl_alloc = knew;
2392 spec->num_kctl_alloc = num;
2395 knew = &spec->kctl_alloc[spec->num_kctl_used];
2396 *knew = ad1988_control_templates[type];
2397 knew->name = kstrdup(name, GFP_KERNEL);
2400 knew->private_value = val;
2401 spec->num_kctl_used++;
2405 #define AD1988_PIN_CD_NID 0x18
2406 #define AD1988_PIN_BEEP_NID 0x10
2408 static hda_nid_t ad1988_mixer_nids[8] = {
2409 /* A B C D E F G H */
2410 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2413 static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2415 static hda_nid_t idx_to_dac[8] = {
2416 /* A B C D E F G H */
2417 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
2419 static hda_nid_t idx_to_dac_rev2[8] = {
2420 /* A B C D E F G H */
2421 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
2424 return idx_to_dac_rev2[idx];
2426 return idx_to_dac[idx];
2429 static hda_nid_t ad1988_boost_nids[8] = {
2430 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2433 static int ad1988_pin_idx(hda_nid_t nid)
2435 static hda_nid_t ad1988_io_pins[8] = {
2436 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2439 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2440 if (ad1988_io_pins[i] == nid)
2442 return 0; /* should be -1 */
2445 static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2447 static int loopback_idx[8] = {
2448 2, 0, 1, 3, 4, 5, 1, 4
2451 case AD1988_PIN_CD_NID:
2454 return loopback_idx[ad1988_pin_idx(nid)];
2458 static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2460 static int adc_idx[8] = {
2461 0, 1, 2, 8, 4, 3, 6, 7
2464 case AD1988_PIN_CD_NID:
2467 return adc_idx[ad1988_pin_idx(nid)];
2471 /* fill in the dac_nids table from the parsed pin configuration */
2472 static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2473 const struct auto_pin_cfg *cfg)
2475 struct ad198x_spec *spec = codec->spec;
2478 spec->multiout.dac_nids = spec->private_dac_nids;
2480 /* check the pins hardwired to audio widget */
2481 for (i = 0; i < cfg->line_outs; i++) {
2482 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2483 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2485 spec->multiout.num_dacs = cfg->line_outs;
2489 /* add playback controls from the parsed DAC table */
2490 static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2491 const struct auto_pin_cfg *cfg)
2494 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2498 for (i = 0; i < cfg->line_outs; i++) {
2499 hda_nid_t dac = spec->multiout.dac_nids[i];
2502 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2505 err = add_control(spec, AD_CTL_WIDGET_VOL,
2506 "Center Playback Volume",
2507 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2510 err = add_control(spec, AD_CTL_WIDGET_VOL,
2511 "LFE Playback Volume",
2512 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2515 err = add_control(spec, AD_CTL_BIND_MUTE,
2516 "Center Playback Switch",
2517 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2520 err = add_control(spec, AD_CTL_BIND_MUTE,
2521 "LFE Playback Switch",
2522 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2526 sprintf(name, "%s Playback Volume", chname[i]);
2527 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2528 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2531 sprintf(name, "%s Playback Switch", chname[i]);
2532 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2533 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2541 /* add playback controls for speaker and HP outputs */
2542 static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2545 struct ad198x_spec *spec = codec->spec;
2553 idx = ad1988_pin_idx(pin);
2554 nid = ad1988_idx_to_dac(codec, idx);
2555 /* specify the DAC as the extra output */
2556 if (! spec->multiout.hp_nid)
2557 spec->multiout.hp_nid = nid;
2559 spec->multiout.extra_out_nid[0] = nid;
2560 /* control HP volume/switch on the output mixer amp */
2561 sprintf(name, "%s Playback Volume", pfx);
2562 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2563 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2565 nid = ad1988_mixer_nids[idx];
2566 sprintf(name, "%s Playback Switch", pfx);
2567 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2568 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2573 /* create input playback/capture controls for the given pin */
2574 static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2575 const char *ctlname, int boost)
2580 sprintf(name, "%s Playback Volume", ctlname);
2581 idx = ad1988_pin_to_loopback_idx(pin);
2582 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2583 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2585 sprintf(name, "%s Playback Switch", ctlname);
2586 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2587 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2591 idx = ad1988_pin_idx(pin);
2592 bnid = ad1988_boost_nids[idx];
2594 sprintf(name, "%s Boost", ctlname);
2595 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2596 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2603 /* create playback/capture controls for input pins */
2604 static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2605 const struct auto_pin_cfg *cfg)
2607 struct hda_input_mux *imux = &spec->private_imux;
2610 for (i = 0; i < AUTO_PIN_LAST; i++) {
2611 err = new_analog_input(spec, cfg->input_pins[i],
2612 auto_pin_cfg_labels[i],
2613 i <= AUTO_PIN_FRONT_MIC);
2616 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2617 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2620 imux->items[imux->num_items].label = "Mix";
2621 imux->items[imux->num_items].index = 9;
2624 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2625 "Analog Mix Playback Volume",
2626 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2628 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2629 "Analog Mix Playback Switch",
2630 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2636 static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2637 hda_nid_t nid, int pin_type,
2641 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2642 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2644 case 0x11: /* port-A - DAC 04 */
2645 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2647 case 0x14: /* port-B - DAC 06 */
2648 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2650 case 0x15: /* port-C - DAC 05 */
2651 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2653 case 0x17: /* port-E - DAC 0a */
2654 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2656 case 0x13: /* mono - DAC 04 */
2657 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2662 static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2664 struct ad198x_spec *spec = codec->spec;
2667 for (i = 0; i < spec->autocfg.line_outs; i++) {
2668 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2669 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2673 static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2675 struct ad198x_spec *spec = codec->spec;
2678 pin = spec->autocfg.speaker_pins[0];
2679 if (pin) /* connect to front */
2680 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2681 pin = spec->autocfg.hp_pins[0];
2682 if (pin) /* connect to front */
2683 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2686 static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2688 struct ad198x_spec *spec = codec->spec;
2691 for (i = 0; i < AUTO_PIN_LAST; i++) {
2692 hda_nid_t nid = spec->autocfg.input_pins[i];
2696 case 0x15: /* port-C */
2697 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2699 case 0x17: /* port-E */
2700 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2703 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2704 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2705 if (nid != AD1988_PIN_CD_NID)
2706 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2708 idx = ad1988_pin_idx(nid);
2709 if (ad1988_boost_nids[idx])
2710 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2711 AC_VERB_SET_AMP_GAIN_MUTE,
2716 /* parse the BIOS configuration and set up the alc_spec */
2717 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2718 static int ad1988_parse_auto_config(struct hda_codec *codec)
2720 struct ad198x_spec *spec = codec->spec;
2723 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2725 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2727 if (! spec->autocfg.line_outs)
2728 return 0; /* can't find valid BIOS pin config */
2729 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2730 (err = ad1988_auto_create_extra_out(codec,
2731 spec->autocfg.speaker_pins[0],
2733 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
2734 "Headphone")) < 0 ||
2735 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2738 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2740 if (spec->autocfg.dig_out_pin)
2741 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2742 if (spec->autocfg.dig_in_pin)
2743 spec->dig_in_nid = AD1988_SPDIF_IN;
2745 if (spec->kctl_alloc)
2746 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2748 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2750 spec->input_mux = &spec->private_imux;
2755 /* init callback for auto-configuration model -- overriding the default init */
2756 static int ad1988_auto_init(struct hda_codec *codec)
2759 ad1988_auto_init_multi_out(codec);
2760 ad1988_auto_init_extra_out(codec);
2761 ad1988_auto_init_analog_input(codec);
2769 static const char *ad1988_models[AD1988_MODEL_LAST] = {
2770 [AD1988_6STACK] = "6stack",
2771 [AD1988_6STACK_DIG] = "6stack-dig",
2772 [AD1988_3STACK] = "3stack",
2773 [AD1988_3STACK_DIG] = "3stack-dig",
2774 [AD1988_LAPTOP] = "laptop",
2775 [AD1988_LAPTOP_DIG] = "laptop-dig",
2776 [AD1988_AUTO] = "auto",
2779 static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2780 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
2781 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
2785 static int patch_ad1988(struct hda_codec *codec)
2787 struct ad198x_spec *spec;
2790 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2797 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2799 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
2800 ad1988_models, ad1988_cfg_tbl);
2801 if (board_config < 0) {
2802 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2803 board_config = AD1988_AUTO;
2806 if (board_config == AD1988_AUTO) {
2807 /* automatic parse from the BIOS config */
2808 int err = ad1988_parse_auto_config(codec);
2813 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2814 board_config = AD1988_6STACK;
2818 switch (board_config) {
2820 case AD1988_6STACK_DIG:
2821 spec->multiout.max_channels = 8;
2822 spec->multiout.num_dacs = 4;
2824 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2826 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
2827 spec->input_mux = &ad1988_6stack_capture_source;
2828 spec->num_mixers = 2;
2830 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2832 spec->mixers[0] = ad1988_6stack_mixers1;
2833 spec->mixers[1] = ad1988_6stack_mixers2;
2834 spec->num_init_verbs = 1;
2835 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2836 if (board_config == AD1988_6STACK_DIG) {
2837 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2838 spec->dig_in_nid = AD1988_SPDIF_IN;
2842 case AD1988_3STACK_DIG:
2843 spec->multiout.max_channels = 6;
2844 spec->multiout.num_dacs = 3;
2846 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2848 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2849 spec->input_mux = &ad1988_6stack_capture_source;
2850 spec->channel_mode = ad1988_3stack_modes;
2851 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
2852 spec->num_mixers = 2;
2854 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2856 spec->mixers[0] = ad1988_3stack_mixers1;
2857 spec->mixers[1] = ad1988_3stack_mixers2;
2858 spec->num_init_verbs = 1;
2859 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2860 if (board_config == AD1988_3STACK_DIG)
2861 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2864 case AD1988_LAPTOP_DIG:
2865 spec->multiout.max_channels = 2;
2866 spec->multiout.num_dacs = 1;
2867 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2868 spec->input_mux = &ad1988_laptop_capture_source;
2869 spec->num_mixers = 1;
2870 spec->mixers[0] = ad1988_laptop_mixers;
2871 spec->num_init_verbs = 1;
2872 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2873 if (board_config == AD1988_LAPTOP_DIG)
2874 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2878 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2879 spec->adc_nids = ad1988_adc_nids;
2880 spec->capsrc_nids = ad1988_capsrc_nids;
2881 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2882 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2883 if (spec->multiout.dig_out_nid) {
2884 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2885 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2887 if (spec->dig_in_nid)
2888 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2890 codec->patch_ops = ad198x_patch_ops;
2891 switch (board_config) {
2893 codec->patch_ops.init = ad1988_auto_init;
2896 case AD1988_LAPTOP_DIG:
2897 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2900 #ifdef CONFIG_SND_HDA_POWER_SAVE
2901 spec->loopback.amplist = ad1988_loopbacks;
2903 spec->vmaster_nid = 0x04;
2912 * port-B - front line/mic-in
2913 * port-E - aux in/out
2914 * port-F - aux in/out
2915 * port-C - rear line/mic-in
2916 * port-D - rear line/hp-out
2917 * port-A - front line/hp-out
2919 * AD1984 = AD1884 + two digital mic-ins
2922 * For simplicity, we share the single DAC for both HP and line-outs
2923 * right now. The inidividual playbacks could be easily implemented,
2924 * but no build-up framework is given, so far.
2927 static hda_nid_t ad1884_dac_nids[1] = {
2931 static hda_nid_t ad1884_adc_nids[2] = {
2935 static hda_nid_t ad1884_capsrc_nids[2] = {
2939 #define AD1884_SPDIF_OUT 0x02
2941 static struct hda_input_mux ad1884_capture_source = {
2944 { "Front Mic", 0x0 },
2951 static struct snd_kcontrol_new ad1884_base_mixers[] = {
2952 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2953 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
2954 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
2955 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
2956 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
2957 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
2958 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
2959 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
2960 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
2961 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
2962 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
2963 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
2965 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
2966 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
2967 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2968 HDA_CODEC_MUTE("Digital Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2970 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
2971 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
2972 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2973 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2974 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2975 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2977 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2978 /* The multiple "Capture Source" controls confuse alsamixer
2979 * So call somewhat different..
2981 /* .name = "Capture Source", */
2982 .name = "Input Source",
2984 .info = ad198x_mux_enum_info,
2985 .get = ad198x_mux_enum_get,
2986 .put = ad198x_mux_enum_put,
2988 /* SPDIF controls */
2989 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2991 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2992 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2993 /* identical with ad1983 */
2994 .info = ad1983_spdif_route_info,
2995 .get = ad1983_spdif_route_get,
2996 .put = ad1983_spdif_route_put,
3001 static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3002 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3003 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3004 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
3006 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
3012 * initialization verbs
3014 static struct hda_verb ad1884_init_verbs[] = {
3015 /* DACs; mute as default */
3016 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3017 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3018 /* Port-A (HP) mixer */
3019 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3020 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3022 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3023 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3024 /* HP selector - select DAC2 */
3025 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3026 /* Port-D (Line-out) mixer */
3027 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3028 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3030 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3031 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3032 /* Mono-out mixer */
3033 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3034 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3036 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3037 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3039 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3040 /* Port-B (front mic) pin */
3041 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3042 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3043 /* Port-C (rear mic) pin */
3044 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3045 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3046 /* Analog mixer; mute as default */
3047 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3048 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3049 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3050 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3051 /* Analog Mix output amp */
3052 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3053 /* SPDIF output selector */
3054 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3055 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3059 #ifdef CONFIG_SND_HDA_POWER_SAVE
3060 static struct hda_amp_list ad1884_loopbacks[] = {
3061 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3062 { 0x20, HDA_INPUT, 1 }, /* Mic */
3063 { 0x20, HDA_INPUT, 2 }, /* CD */
3064 { 0x20, HDA_INPUT, 4 }, /* Docking */
3069 static const char *ad1884_slave_vols[] = {
3070 "PCM Playback Volume",
3071 "Mic Playback Volume",
3072 "Mono Playback Volume",
3073 "Front Mic Playback Volume",
3074 "Mic Playback Volume",
3075 "CD Playback Volume",
3076 "Internal Mic Playback Volume",
3077 "Docking Mic Playback Volume"
3078 "Beep Playback Volume",
3082 static int patch_ad1884(struct hda_codec *codec)
3084 struct ad198x_spec *spec;
3086 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3090 mutex_init(&spec->amp_mutex);
3093 spec->multiout.max_channels = 2;
3094 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3095 spec->multiout.dac_nids = ad1884_dac_nids;
3096 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3097 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3098 spec->adc_nids = ad1884_adc_nids;
3099 spec->capsrc_nids = ad1884_capsrc_nids;
3100 spec->input_mux = &ad1884_capture_source;
3101 spec->num_mixers = 1;
3102 spec->mixers[0] = ad1884_base_mixers;
3103 spec->num_init_verbs = 1;
3104 spec->init_verbs[0] = ad1884_init_verbs;
3105 spec->spdif_route = 0;
3106 #ifdef CONFIG_SND_HDA_POWER_SAVE
3107 spec->loopback.amplist = ad1884_loopbacks;
3109 spec->vmaster_nid = 0x04;
3110 /* we need to cover all playback volumes */
3111 spec->slave_vols = ad1884_slave_vols;
3113 codec->patch_ops = ad198x_patch_ops;
3119 * Lenovo Thinkpad T61/X61
3121 static struct hda_input_mux ad1984_thinkpad_capture_source = {
3125 { "Internal Mic", 0x1 },
3130 static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3131 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3132 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3133 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3134 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3135 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3136 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3137 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3138 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3139 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3140 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3141 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3142 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3143 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3144 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3145 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3146 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3147 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3148 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3149 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3151 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3152 /* The multiple "Capture Source" controls confuse alsamixer
3153 * So call somewhat different..
3155 /* .name = "Capture Source", */
3156 .name = "Input Source",
3158 .info = ad198x_mux_enum_info,
3159 .get = ad198x_mux_enum_get,
3160 .put = ad198x_mux_enum_put,
3162 /* SPDIF controls */
3163 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3165 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3166 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3167 /* identical with ad1983 */
3168 .info = ad1983_spdif_route_info,
3169 .get = ad1983_spdif_route_get,
3170 .put = ad1983_spdif_route_put,
3175 /* additional verbs */
3176 static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3177 /* Port-E (docking station mic) pin */
3178 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3179 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3180 /* docking mic boost */
3181 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3182 /* Analog mixer - docking mic; mute as default */
3183 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3184 /* enable EAPD bit */
3185 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3189 /* Digial MIC ADC NID 0x05 + 0x06 */
3190 static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3191 struct hda_codec *codec,
3192 unsigned int stream_tag,
3193 unsigned int format,
3194 struct snd_pcm_substream *substream)
3196 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3197 stream_tag, 0, format);
3201 static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3202 struct hda_codec *codec,
3203 struct snd_pcm_substream *substream)
3205 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3210 static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3216 .prepare = ad1984_pcm_dmic_prepare,
3217 .cleanup = ad1984_pcm_dmic_cleanup
3221 static int ad1984_build_pcms(struct hda_codec *codec)
3223 struct ad198x_spec *spec = codec->spec;
3224 struct hda_pcm *info;
3227 err = ad198x_build_pcms(codec);
3231 info = spec->pcm_rec + codec->num_pcms;
3233 info->name = "AD1984 Digital Mic";
3234 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3245 static const char *ad1984_models[AD1984_MODELS] = {
3246 [AD1984_BASIC] = "basic",
3247 [AD1984_THINKPAD] = "thinkpad",
3250 static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3251 /* Lenovo Thinkpad T61/X61 */
3252 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1984_THINKPAD),
3256 static int patch_ad1984(struct hda_codec *codec)
3258 struct ad198x_spec *spec;
3259 int board_config, err;
3261 err = patch_ad1884(codec);
3265 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3266 ad1984_models, ad1984_cfg_tbl);
3267 switch (board_config) {
3269 /* additional digital mics */
3270 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3271 codec->patch_ops.build_pcms = ad1984_build_pcms;
3273 case AD1984_THINKPAD:
3274 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3275 spec->input_mux = &ad1984_thinkpad_capture_source;
3276 spec->mixers[0] = ad1984_thinkpad_mixers;
3277 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3287 * port-A - front hp-out
3288 * port-B - front mic-in
3289 * port-C - rear line-in, shared surr-out (3stack)
3290 * port-D - rear line-out
3291 * port-E - rear mic-in, shared clfe-out (3stack)
3292 * port-F - rear surr-out (6stack)
3293 * port-G - rear clfe-out (6stack)
3296 static hda_nid_t ad1882_dac_nids[3] = {
3300 static hda_nid_t ad1882_adc_nids[2] = {
3304 static hda_nid_t ad1882_capsrc_nids[2] = {
3308 #define AD1882_SPDIF_OUT 0x02
3310 /* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
3311 static struct hda_input_mux ad1882_capture_source = {
3314 { "Front Mic", 0x1 },
3322 static struct snd_kcontrol_new ad1882_base_mixers[] = {
3323 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3324 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
3325 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
3326 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
3327 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3328 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3329 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3330 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3331 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3332 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3333 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3334 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3335 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
3336 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
3337 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
3338 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
3339 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
3340 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
3341 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
3342 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
3343 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
3344 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3345 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3346 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3347 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3349 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3350 /* The multiple "Capture Source" controls confuse alsamixer
3351 * So call somewhat different..
3353 /* .name = "Capture Source", */
3354 .name = "Input Source",
3356 .info = ad198x_mux_enum_info,
3357 .get = ad198x_mux_enum_get,
3358 .put = ad198x_mux_enum_put,
3360 /* SPDIF controls */
3361 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3363 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3364 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3365 /* identical with ad1983 */
3366 .info = ad1983_spdif_route_info,
3367 .get = ad1983_spdif_route_get,
3368 .put = ad1983_spdif_route_put,
3373 static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
3374 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3375 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
3376 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
3378 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3379 .name = "Channel Mode",
3380 .info = ad198x_ch_mode_info,
3381 .get = ad198x_ch_mode_get,
3382 .put = ad198x_ch_mode_put,
3387 static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
3388 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
3389 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
3390 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
3394 static struct hda_verb ad1882_ch2_init[] = {
3395 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3396 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3397 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3398 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3399 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3400 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3404 static struct hda_verb ad1882_ch4_init[] = {
3405 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3406 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3407 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3408 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3409 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3410 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3414 static struct hda_verb ad1882_ch6_init[] = {
3415 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3416 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3417 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3418 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3419 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3420 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3424 static struct hda_channel_mode ad1882_modes[3] = {
3425 { 2, ad1882_ch2_init },
3426 { 4, ad1882_ch4_init },
3427 { 6, ad1882_ch6_init },
3431 * initialization verbs
3433 static struct hda_verb ad1882_init_verbs[] = {
3434 /* DACs; mute as default */
3435 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3436 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3437 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3438 /* Port-A (HP) mixer */
3439 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3440 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3442 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3443 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3444 /* HP selector - select DAC2 */
3445 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
3446 /* Port-D (Line-out) mixer */
3447 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3448 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3450 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3451 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3452 /* Mono-out mixer */
3453 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3454 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3456 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3457 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3458 /* Port-B (front mic) pin */
3459 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3460 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3461 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3462 /* Port-C (line-in) pin */
3463 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3464 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3465 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3466 /* Port-C mixer - mute as input */
3467 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3468 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3469 /* Port-E (mic-in) pin */
3470 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3471 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3472 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3473 /* Port-E mixer - mute as input */
3474 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3475 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3476 /* Port-F (surround) */
3477 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3478 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3480 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3481 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3482 /* Analog mixer; mute as default */
3483 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
3484 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3485 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3486 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3487 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3488 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3489 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3490 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3491 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3492 /* Analog Mix output amp */
3493 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3494 /* SPDIF output selector */
3495 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3496 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3497 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3501 #ifdef CONFIG_SND_HDA_POWER_SAVE
3502 static struct hda_amp_list ad1882_loopbacks[] = {
3503 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3504 { 0x20, HDA_INPUT, 1 }, /* Mic */
3505 { 0x20, HDA_INPUT, 4 }, /* Line */
3506 { 0x20, HDA_INPUT, 6 }, /* CD */
3518 static const char *ad1882_models[AD1986A_MODELS] = {
3519 [AD1882_3STACK] = "3stack",
3520 [AD1882_6STACK] = "6stack",
3524 static int patch_ad1882(struct hda_codec *codec)
3526 struct ad198x_spec *spec;
3529 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3533 mutex_init(&spec->amp_mutex);
3536 spec->multiout.max_channels = 6;
3537 spec->multiout.num_dacs = 3;
3538 spec->multiout.dac_nids = ad1882_dac_nids;
3539 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
3540 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
3541 spec->adc_nids = ad1882_adc_nids;
3542 spec->capsrc_nids = ad1882_capsrc_nids;
3543 spec->input_mux = &ad1882_capture_source;
3544 spec->num_mixers = 1;
3545 spec->mixers[0] = ad1882_base_mixers;
3546 spec->num_init_verbs = 1;
3547 spec->init_verbs[0] = ad1882_init_verbs;
3548 spec->spdif_route = 0;
3549 #ifdef CONFIG_SND_HDA_POWER_SAVE
3550 spec->loopback.amplist = ad1882_loopbacks;
3552 spec->vmaster_nid = 0x04;
3554 codec->patch_ops = ad198x_patch_ops;
3556 /* override some parameters */
3557 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
3558 ad1882_models, NULL);
3559 switch (board_config) {
3562 spec->num_mixers = 2;
3563 spec->mixers[1] = ad1882_3stack_mixers;
3564 spec->channel_mode = ad1882_modes;
3565 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
3566 spec->need_dac_fix = 1;
3567 spec->multiout.max_channels = 2;
3568 spec->multiout.num_dacs = 1;
3571 spec->num_mixers = 2;
3572 spec->mixers[1] = ad1882_6stack_mixers;
3582 struct hda_codec_preset snd_hda_preset_analog[] = {
3583 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
3584 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
3585 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
3586 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
3587 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
3588 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
3589 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
3590 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },