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 <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
27 #include <linux/mutex.h>
29 #include <sound/core.h>
30 #include "hda_codec.h"
31 #include "hda_local.h"
34 struct snd_kcontrol_new *mixers[5];
37 const struct hda_verb *init_verbs[5]; /* initialization verbs
38 * don't forget NULL termination!
40 unsigned int num_init_verbs;
43 struct hda_multi_out multiout; /* playback set-up
44 * max_channels, dacs must be set
45 * dig_out_nid and hp_nid are optional
47 unsigned int cur_eapd;
48 unsigned int need_dac_fix;
51 unsigned int num_adc_nids;
53 hda_nid_t dig_in_nid; /* digital-in NID; optional */
56 const struct hda_input_mux *input_mux;
57 hda_nid_t *capsrc_nids;
58 unsigned int cur_mux[3];
61 const struct hda_channel_mode *channel_mode;
65 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
67 struct mutex amp_mutex; /* PCM volume/mute control mutex */
68 unsigned int spdif_route;
70 /* dynamic controls, init_verbs and input_mux */
71 struct auto_pin_cfg autocfg;
72 unsigned int num_kctl_alloc, num_kctl_used;
73 struct snd_kcontrol_new *kctl_alloc;
74 struct hda_input_mux private_imux;
75 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
77 unsigned int jack_present :1;
79 #ifdef CONFIG_SND_HDA_POWER_SAVE
80 struct hda_loopback_check loopback;
85 * input MUX handling (common part)
87 static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
89 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
90 struct ad198x_spec *spec = codec->spec;
92 return snd_hda_input_mux_info(spec->input_mux, uinfo);
95 static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
97 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
98 struct ad198x_spec *spec = codec->spec;
99 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
101 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
105 static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
107 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
108 struct ad198x_spec *spec = codec->spec;
109 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
111 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
112 spec->capsrc_nids[adc_idx],
113 &spec->cur_mux[adc_idx]);
117 * initialization (common callbacks)
119 static int ad198x_init(struct hda_codec *codec)
121 struct ad198x_spec *spec = codec->spec;
124 for (i = 0; i < spec->num_init_verbs; i++)
125 snd_hda_sequence_write(codec, spec->init_verbs[i]);
129 static int ad198x_build_controls(struct hda_codec *codec)
131 struct ad198x_spec *spec = codec->spec;
135 for (i = 0; i < spec->num_mixers; i++) {
136 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
140 if (spec->multiout.dig_out_nid) {
141 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
145 if (spec->dig_in_nid) {
146 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
153 #ifdef CONFIG_SND_HDA_POWER_SAVE
154 static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
156 struct ad198x_spec *spec = codec->spec;
157 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
162 * Analog playback callbacks
164 static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
165 struct hda_codec *codec,
166 struct snd_pcm_substream *substream)
168 struct ad198x_spec *spec = codec->spec;
169 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
172 static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
173 struct hda_codec *codec,
174 unsigned int stream_tag,
176 struct snd_pcm_substream *substream)
178 struct ad198x_spec *spec = codec->spec;
179 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
183 static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
184 struct hda_codec *codec,
185 struct snd_pcm_substream *substream)
187 struct ad198x_spec *spec = codec->spec;
188 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
194 static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
195 struct hda_codec *codec,
196 struct snd_pcm_substream *substream)
198 struct ad198x_spec *spec = codec->spec;
199 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
202 static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
203 struct hda_codec *codec,
204 struct snd_pcm_substream *substream)
206 struct ad198x_spec *spec = codec->spec;
207 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
210 static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
211 struct hda_codec *codec,
212 unsigned int stream_tag,
214 struct snd_pcm_substream *substream)
216 struct ad198x_spec *spec = codec->spec;
217 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
224 static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
225 struct hda_codec *codec,
226 unsigned int stream_tag,
228 struct snd_pcm_substream *substream)
230 struct ad198x_spec *spec = codec->spec;
231 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
232 stream_tag, 0, format);
236 static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
237 struct hda_codec *codec,
238 struct snd_pcm_substream *substream)
240 struct ad198x_spec *spec = codec->spec;
241 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
249 static struct hda_pcm_stream ad198x_pcm_analog_playback = {
252 .channels_max = 6, /* changed later */
253 .nid = 0, /* fill later */
255 .open = ad198x_playback_pcm_open,
256 .prepare = ad198x_playback_pcm_prepare,
257 .cleanup = ad198x_playback_pcm_cleanup
261 static struct hda_pcm_stream ad198x_pcm_analog_capture = {
265 .nid = 0, /* fill later */
267 .prepare = ad198x_capture_pcm_prepare,
268 .cleanup = ad198x_capture_pcm_cleanup
272 static struct hda_pcm_stream ad198x_pcm_digital_playback = {
276 .nid = 0, /* fill later */
278 .open = ad198x_dig_playback_pcm_open,
279 .close = ad198x_dig_playback_pcm_close,
280 .prepare = ad198x_dig_playback_pcm_prepare
284 static struct hda_pcm_stream ad198x_pcm_digital_capture = {
288 /* NID is set in alc_build_pcms */
291 static int ad198x_build_pcms(struct hda_codec *codec)
293 struct ad198x_spec *spec = codec->spec;
294 struct hda_pcm *info = spec->pcm_rec;
297 codec->pcm_info = info;
299 info->name = "AD198x Analog";
300 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
301 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
302 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
303 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
304 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
305 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
307 if (spec->multiout.dig_out_nid) {
310 info->name = "AD198x Digital";
311 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
312 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
313 if (spec->dig_in_nid) {
314 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
315 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
322 static void ad198x_free(struct hda_codec *codec)
324 struct ad198x_spec *spec = codec->spec;
327 if (spec->kctl_alloc) {
328 for (i = 0; i < spec->num_kctl_used; i++)
329 kfree(spec->kctl_alloc[i].name);
330 kfree(spec->kctl_alloc);
335 static struct hda_codec_ops ad198x_patch_ops = {
336 .build_controls = ad198x_build_controls,
337 .build_pcms = ad198x_build_pcms,
340 #ifdef CONFIG_SND_HDA_POWER_SAVE
341 .check_power_status = ad198x_check_power_status,
348 * the private value = nid | (invert << 8)
350 #define ad198x_eapd_info snd_ctl_boolean_mono_info
352 static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
353 struct snd_ctl_elem_value *ucontrol)
355 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
356 struct ad198x_spec *spec = codec->spec;
357 int invert = (kcontrol->private_value >> 8) & 1;
359 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
361 ucontrol->value.integer.value[0] = spec->cur_eapd;
365 static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
366 struct snd_ctl_elem_value *ucontrol)
368 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
369 struct ad198x_spec *spec = codec->spec;
370 int invert = (kcontrol->private_value >> 8) & 1;
371 hda_nid_t nid = kcontrol->private_value & 0xff;
373 eapd = !!ucontrol->value.integer.value[0];
376 if (eapd == spec->cur_eapd)
378 spec->cur_eapd = eapd;
379 snd_hda_codec_write_cache(codec, nid,
380 0, AC_VERB_SET_EAPD_BTLENABLE,
385 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
386 struct snd_ctl_elem_info *uinfo);
387 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
388 struct snd_ctl_elem_value *ucontrol);
389 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
390 struct snd_ctl_elem_value *ucontrol);
397 #define AD1986A_SPDIF_OUT 0x02
398 #define AD1986A_FRONT_DAC 0x03
399 #define AD1986A_SURR_DAC 0x04
400 #define AD1986A_CLFE_DAC 0x05
401 #define AD1986A_ADC 0x06
403 static hda_nid_t ad1986a_dac_nids[3] = {
404 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
406 static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
407 static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
409 static struct hda_input_mux ad1986a_capture_source = {
423 static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
424 .ops = &snd_hda_bind_vol,
426 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
427 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
428 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
433 static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
434 .ops = &snd_hda_bind_sw,
436 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
437 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
438 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
446 static struct snd_kcontrol_new ad1986a_mixers[] = {
448 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
450 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
451 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
452 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
453 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
454 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
455 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
456 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
457 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
458 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
459 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
460 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
461 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
462 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
463 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
464 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
465 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
466 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
467 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
468 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
469 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
470 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
471 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
472 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
473 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
474 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
475 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
476 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
478 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
479 .name = "Capture Source",
480 .info = ad198x_mux_enum_info,
481 .get = ad198x_mux_enum_get,
482 .put = ad198x_mux_enum_put,
484 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
488 /* additional mixers for 3stack mode */
489 static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
491 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
492 .name = "Channel Mode",
493 .info = ad198x_ch_mode_info,
494 .get = ad198x_ch_mode_get,
495 .put = ad198x_ch_mode_put,
500 /* laptop model - 2ch only */
501 static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
503 /* master controls both pins 0x1a and 0x1b */
504 static struct hda_bind_ctls ad1986a_laptop_master_vol = {
505 .ops = &snd_hda_bind_vol,
507 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
508 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
513 static struct hda_bind_ctls ad1986a_laptop_master_sw = {
514 .ops = &snd_hda_bind_sw,
516 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
517 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
522 static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
523 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
524 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
525 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
526 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
527 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
528 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
529 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
530 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
531 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
532 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
533 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
534 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
535 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
536 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
537 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
538 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
539 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
540 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
541 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
543 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
544 .name = "Capture Source",
545 .info = ad198x_mux_enum_info,
546 .get = ad198x_mux_enum_get,
547 .put = ad198x_mux_enum_put,
552 /* laptop-eapd model - 2ch only */
554 static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
558 { "Internal Mic", 0x4 },
563 static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
564 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
565 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
566 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
567 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
568 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
569 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
570 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
571 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
572 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
573 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
574 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
576 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
577 .name = "Capture Source",
578 .info = ad198x_mux_enum_info,
579 .get = ad198x_mux_enum_get,
580 .put = ad198x_mux_enum_put,
583 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
584 .name = "External Amplifier",
585 .info = ad198x_eapd_info,
586 .get = ad198x_eapd_get,
587 .put = ad198x_eapd_put,
588 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
593 /* laptop-automute - 2ch only */
595 static void ad1986a_update_hp(struct hda_codec *codec)
597 struct ad198x_spec *spec = codec->spec;
600 if (spec->jack_present)
601 mute = HDA_AMP_MUTE; /* mute internal speaker */
603 /* unmute internal speaker if necessary */
604 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
605 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
609 static void ad1986a_hp_automute(struct hda_codec *codec)
611 struct ad198x_spec *spec = codec->spec;
612 unsigned int present;
614 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0);
615 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
616 spec->jack_present = !(present & 0x80000000);
617 ad1986a_update_hp(codec);
620 #define AD1986A_HP_EVENT 0x37
622 static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
624 if ((res >> 26) != AD1986A_HP_EVENT)
626 ad1986a_hp_automute(codec);
629 static int ad1986a_hp_init(struct hda_codec *codec)
632 ad1986a_hp_automute(codec);
636 /* bind hp and internal speaker mute (with plug check) */
637 static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
638 struct snd_ctl_elem_value *ucontrol)
640 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
641 long *valp = ucontrol->value.integer.value;
644 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
646 valp[0] ? 0 : HDA_AMP_MUTE);
647 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
649 valp[1] ? 0 : HDA_AMP_MUTE);
651 ad1986a_update_hp(codec);
655 static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = {
656 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
658 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
659 .name = "Master Playback Switch",
660 .info = snd_hda_mixer_amp_switch_info,
661 .get = snd_hda_mixer_amp_switch_get,
662 .put = ad1986a_hp_master_sw_put,
663 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
665 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
666 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
667 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
668 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
669 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
670 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
671 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
672 HDA_CODEC_VOLUME("Beep Playback Volume", 0x18, 0x0, HDA_OUTPUT),
673 HDA_CODEC_MUTE("Beep Playback Switch", 0x18, 0x0, HDA_OUTPUT),
674 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
675 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
677 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
678 .name = "Capture Source",
679 .info = ad198x_mux_enum_info,
680 .get = ad198x_mux_enum_get,
681 .put = ad198x_mux_enum_put,
684 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
685 .name = "External Amplifier",
686 .info = ad198x_eapd_info,
687 .get = ad198x_eapd_get,
688 .put = ad198x_eapd_put,
689 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
695 * initialization verbs
697 static struct hda_verb ad1986a_init_verbs[] = {
698 /* Front, Surround, CLFE DAC; mute as default */
699 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
700 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
701 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
703 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
704 /* HP, Line-Out, Surround, CLFE selectors */
705 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
706 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
707 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
708 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
710 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
711 /* Mic selector: Mic 1/2 pin */
712 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
713 /* Line-in selector: Line-in */
714 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
716 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
717 /* Record selector: mic */
718 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
719 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
720 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
721 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
722 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
723 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
724 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
726 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
727 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
728 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
729 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
730 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
731 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
732 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
734 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
735 /* Front, Surround, CLFE Pins */
736 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
737 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
738 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
740 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
742 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
743 /* Line, Aux, CD, Beep-In Pin */
744 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
745 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
746 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
747 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
748 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
752 static struct hda_verb ad1986a_ch2_init[] = {
753 /* Surround out -> Line In */
754 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
755 /* Line-in selectors */
756 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
758 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
759 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
760 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
764 static struct hda_verb ad1986a_ch4_init[] = {
765 /* Surround out -> Surround */
766 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
767 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
769 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
770 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
774 static struct hda_verb ad1986a_ch6_init[] = {
775 /* Surround out -> Surround out */
776 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
777 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
779 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
780 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
784 static struct hda_channel_mode ad1986a_modes[3] = {
785 { 2, ad1986a_ch2_init },
786 { 4, ad1986a_ch4_init },
787 { 6, ad1986a_ch6_init },
790 /* eapd initialization */
791 static struct hda_verb ad1986a_eapd_init_verbs[] = {
792 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
796 /* Ultra initialization */
797 static struct hda_verb ad1986a_ultra_init[] = {
798 /* eapd initialization */
799 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
801 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
802 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
803 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
807 /* pin sensing on HP jack */
808 static struct hda_verb ad1986a_hp_init_verbs[] = {
809 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
820 AD1986A_LAPTOP_AUTOMUTE,
825 static const char *ad1986a_models[AD1986A_MODELS] = {
826 [AD1986A_6STACK] = "6stack",
827 [AD1986A_3STACK] = "3stack",
828 [AD1986A_LAPTOP] = "laptop",
829 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
830 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
831 [AD1986A_ULTRA] = "ultra",
834 static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
835 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
836 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
837 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
838 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
839 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
840 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
841 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
842 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
843 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
844 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
845 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
846 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
847 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
848 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
849 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
850 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
851 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
852 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
853 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
854 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
855 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
856 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
857 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
858 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
859 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
860 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
861 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
865 #ifdef CONFIG_SND_HDA_POWER_SAVE
866 static struct hda_amp_list ad1986a_loopbacks[] = {
867 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
868 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
869 { 0x15, HDA_OUTPUT, 0 }, /* CD */
870 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
871 { 0x17, HDA_OUTPUT, 0 }, /* Line */
876 static int patch_ad1986a(struct hda_codec *codec)
878 struct ad198x_spec *spec;
881 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
887 spec->multiout.max_channels = 6;
888 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
889 spec->multiout.dac_nids = ad1986a_dac_nids;
890 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
891 spec->num_adc_nids = 1;
892 spec->adc_nids = ad1986a_adc_nids;
893 spec->capsrc_nids = ad1986a_capsrc_nids;
894 spec->input_mux = &ad1986a_capture_source;
895 spec->num_mixers = 1;
896 spec->mixers[0] = ad1986a_mixers;
897 spec->num_init_verbs = 1;
898 spec->init_verbs[0] = ad1986a_init_verbs;
899 #ifdef CONFIG_SND_HDA_POWER_SAVE
900 spec->loopback.amplist = ad1986a_loopbacks;
903 codec->patch_ops = ad198x_patch_ops;
905 /* override some parameters */
906 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
909 switch (board_config) {
911 spec->num_mixers = 2;
912 spec->mixers[1] = ad1986a_3st_mixers;
913 spec->num_init_verbs = 2;
914 spec->init_verbs[1] = ad1986a_ch2_init;
915 spec->channel_mode = ad1986a_modes;
916 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
917 spec->need_dac_fix = 1;
918 spec->multiout.max_channels = 2;
919 spec->multiout.num_dacs = 1;
922 spec->mixers[0] = ad1986a_laptop_mixers;
923 spec->multiout.max_channels = 2;
924 spec->multiout.num_dacs = 1;
925 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
927 case AD1986A_LAPTOP_EAPD:
928 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
929 spec->num_init_verbs = 2;
930 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
931 spec->multiout.max_channels = 2;
932 spec->multiout.num_dacs = 1;
933 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
934 spec->multiout.dig_out_nid = 0;
935 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
937 case AD1986A_LAPTOP_AUTOMUTE:
938 spec->mixers[0] = ad1986a_laptop_automute_mixers;
939 spec->num_init_verbs = 3;
940 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
941 spec->init_verbs[2] = ad1986a_hp_init_verbs;
942 spec->multiout.max_channels = 2;
943 spec->multiout.num_dacs = 1;
944 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
945 spec->multiout.dig_out_nid = 0;
946 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
947 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
948 codec->patch_ops.init = ad1986a_hp_init;
951 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
952 spec->num_init_verbs = 2;
953 spec->init_verbs[1] = ad1986a_ultra_init;
954 spec->multiout.max_channels = 2;
955 spec->multiout.num_dacs = 1;
956 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
957 spec->multiout.dig_out_nid = 0;
961 /* AD1986A has a hardware problem that it can't share a stream
962 * with multiple output pins. The copy of front to surrounds
963 * causes noisy or silent outputs at a certain timing, e.g.
964 * changing the volume.
965 * So, let's disable the shared stream.
967 spec->multiout.no_share_stream = 1;
976 #define AD1983_SPDIF_OUT 0x02
977 #define AD1983_DAC 0x03
978 #define AD1983_ADC 0x04
980 static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
981 static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
982 static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
984 static struct hda_input_mux ad1983_capture_source = {
995 * SPDIF playback route
997 static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
999 static char *texts[] = { "PCM", "ADC" };
1001 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1003 uinfo->value.enumerated.items = 2;
1004 if (uinfo->value.enumerated.item > 1)
1005 uinfo->value.enumerated.item = 1;
1006 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1010 static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1012 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1013 struct ad198x_spec *spec = codec->spec;
1015 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1019 static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1021 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1022 struct ad198x_spec *spec = codec->spec;
1024 if (ucontrol->value.enumerated.item[0] > 1)
1026 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1027 spec->spdif_route = ucontrol->value.enumerated.item[0];
1028 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1029 AC_VERB_SET_CONNECT_SEL,
1036 static struct snd_kcontrol_new ad1983_mixers[] = {
1037 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1038 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1039 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1040 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1041 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1042 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1043 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1044 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1045 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1046 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1047 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1048 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1049 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
1050 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
1051 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1052 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1053 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1055 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1056 .name = "Capture Source",
1057 .info = ad198x_mux_enum_info,
1058 .get = ad198x_mux_enum_get,
1059 .put = ad198x_mux_enum_put,
1062 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1063 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1064 .info = ad1983_spdif_route_info,
1065 .get = ad1983_spdif_route_get,
1066 .put = ad1983_spdif_route_put,
1071 static struct hda_verb ad1983_init_verbs[] = {
1072 /* Front, HP, Mono; mute as default */
1073 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1074 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1075 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1076 /* Beep, PCM, Mic, Line-In: mute */
1077 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1078 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1079 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1080 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1081 /* Front, HP selectors; from Mix */
1082 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1083 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1084 /* Mono selector; from Mix */
1085 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1086 /* Mic selector; Mic */
1087 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1088 /* Line-in selector: Line-in */
1089 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1090 /* Mic boost: 0dB */
1091 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1092 /* Record selector: mic */
1093 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1094 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1095 /* SPDIF route: PCM */
1096 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1098 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1100 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1102 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1104 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1106 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1110 #ifdef CONFIG_SND_HDA_POWER_SAVE
1111 static struct hda_amp_list ad1983_loopbacks[] = {
1112 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1113 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1118 static int patch_ad1983(struct hda_codec *codec)
1120 struct ad198x_spec *spec;
1122 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1128 spec->multiout.max_channels = 2;
1129 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1130 spec->multiout.dac_nids = ad1983_dac_nids;
1131 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
1132 spec->num_adc_nids = 1;
1133 spec->adc_nids = ad1983_adc_nids;
1134 spec->capsrc_nids = ad1983_capsrc_nids;
1135 spec->input_mux = &ad1983_capture_source;
1136 spec->num_mixers = 1;
1137 spec->mixers[0] = ad1983_mixers;
1138 spec->num_init_verbs = 1;
1139 spec->init_verbs[0] = ad1983_init_verbs;
1140 spec->spdif_route = 0;
1141 #ifdef CONFIG_SND_HDA_POWER_SAVE
1142 spec->loopback.amplist = ad1983_loopbacks;
1145 codec->patch_ops = ad198x_patch_ops;
1152 * AD1981 HD specific
1155 #define AD1981_SPDIF_OUT 0x02
1156 #define AD1981_DAC 0x03
1157 #define AD1981_ADC 0x04
1159 static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
1160 static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
1161 static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
1163 /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1164 static struct hda_input_mux ad1981_capture_source = {
1167 { "Front Mic", 0x0 },
1170 { "Mix Mono", 0x3 },
1177 static struct snd_kcontrol_new ad1981_mixers[] = {
1178 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1179 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1180 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1181 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1182 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1183 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1184 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1185 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1186 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1187 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1188 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1189 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1190 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1191 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1192 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1193 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1194 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1195 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1196 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1197 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1198 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1199 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1200 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1201 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1203 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1204 .name = "Capture Source",
1205 .info = ad198x_mux_enum_info,
1206 .get = ad198x_mux_enum_get,
1207 .put = ad198x_mux_enum_put,
1209 /* identical with AD1983 */
1211 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1212 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1213 .info = ad1983_spdif_route_info,
1214 .get = ad1983_spdif_route_get,
1215 .put = ad1983_spdif_route_put,
1220 static struct hda_verb ad1981_init_verbs[] = {
1221 /* Front, HP, Mono; mute as default */
1222 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1223 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1224 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1225 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1226 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1227 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1228 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1229 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1230 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1231 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1232 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1233 /* Front, HP selectors; from Mix */
1234 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1235 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1236 /* Mono selector; from Mix */
1237 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1238 /* Mic Mixer; select Front Mic */
1239 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1240 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1241 /* Mic boost: 0dB */
1242 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1243 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1244 /* Record selector: Front mic */
1245 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1246 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1247 /* SPDIF route: PCM */
1248 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1250 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1252 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1254 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1255 /* Front & Rear Mic Pins */
1256 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1257 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1259 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1261 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1262 /* Line-Out as Input: disabled */
1263 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1267 #ifdef CONFIG_SND_HDA_POWER_SAVE
1268 static struct hda_amp_list ad1981_loopbacks[] = {
1269 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1270 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1271 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1272 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1273 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1279 * Patch for HP nx6320
1281 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
1282 * speaker output enabled _and_ mute-LED off.
1285 #define AD1981_HP_EVENT 0x37
1286 #define AD1981_MIC_EVENT 0x38
1288 static struct hda_verb ad1981_hp_init_verbs[] = {
1289 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1290 /* pin sensing on HP and Mic jacks */
1291 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1292 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1296 /* turn on/off EAPD (+ mute HP) as a master switch */
1297 static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1298 struct snd_ctl_elem_value *ucontrol)
1300 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1301 struct ad198x_spec *spec = codec->spec;
1303 if (! ad198x_eapd_put(kcontrol, ucontrol))
1306 /* toggle HP mute appropriately */
1307 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1309 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
1313 /* bind volumes of both NID 0x05 and 0x06 */
1314 static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1315 .ops = &snd_hda_bind_vol,
1317 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1318 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1323 /* mute internal speaker if HP is plugged */
1324 static void ad1981_hp_automute(struct hda_codec *codec)
1326 unsigned int present;
1328 present = snd_hda_codec_read(codec, 0x06, 0,
1329 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1330 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1331 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1334 /* toggle input of built-in and mic jack appropriately */
1335 static void ad1981_hp_automic(struct hda_codec *codec)
1337 static struct hda_verb mic_jack_on[] = {
1338 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1339 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1342 static struct hda_verb mic_jack_off[] = {
1343 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1344 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1347 unsigned int present;
1349 present = snd_hda_codec_read(codec, 0x08, 0,
1350 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1352 snd_hda_sequence_write(codec, mic_jack_on);
1354 snd_hda_sequence_write(codec, mic_jack_off);
1357 /* unsolicited event for HP jack sensing */
1358 static void ad1981_hp_unsol_event(struct hda_codec *codec,
1363 case AD1981_HP_EVENT:
1364 ad1981_hp_automute(codec);
1366 case AD1981_MIC_EVENT:
1367 ad1981_hp_automic(codec);
1372 static struct hda_input_mux ad1981_hp_capture_source = {
1376 { "Docking-Station", 0x1 },
1381 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1382 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
1384 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1385 .name = "Master Playback Switch",
1386 .info = ad198x_eapd_info,
1387 .get = ad198x_eapd_get,
1388 .put = ad1981_hp_master_sw_put,
1389 .private_value = 0x05,
1391 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1392 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1394 /* FIXME: analog mic/line loopback doesn't work with my tests...
1395 * (although recording is OK)
1397 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1398 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1400 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1401 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1402 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1403 /* FIXME: does this laptop have analog CD connection? */
1404 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1405 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1407 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1408 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1409 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1410 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1412 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1413 .name = "Capture Source",
1414 .info = ad198x_mux_enum_info,
1415 .get = ad198x_mux_enum_get,
1416 .put = ad198x_mux_enum_put,
1421 /* initialize jack-sensing, too */
1422 static int ad1981_hp_init(struct hda_codec *codec)
1425 ad1981_hp_automute(codec);
1426 ad1981_hp_automic(codec);
1430 /* configuration for Toshiba Laptops */
1431 static struct hda_verb ad1981_toshiba_init_verbs[] = {
1432 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1433 /* pin sensing on HP and Mic jacks */
1434 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1435 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1439 static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1440 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1441 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1445 /* configuration for Lenovo Thinkpad T60 */
1446 static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1447 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1448 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1449 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1450 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1451 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1452 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1453 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1454 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1455 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1456 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1457 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1459 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1460 .name = "Capture Source",
1461 .info = ad198x_mux_enum_info,
1462 .get = ad198x_mux_enum_get,
1463 .put = ad198x_mux_enum_put,
1465 /* identical with AD1983 */
1467 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1468 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1469 .info = ad1983_spdif_route_info,
1470 .get = ad1983_spdif_route_get,
1471 .put = ad1983_spdif_route_put,
1476 static struct hda_input_mux ad1981_thinkpad_capture_source = {
1494 static const char *ad1981_models[AD1981_MODELS] = {
1496 [AD1981_THINKPAD] = "thinkpad",
1497 [AD1981_BASIC] = "basic",
1498 [AD1981_TOSHIBA] = "toshiba"
1501 static struct snd_pci_quirk ad1981_cfg_tbl[] = {
1502 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
1504 SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
1505 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
1506 /* Lenovo Thinkpad T60/X60/Z6xx */
1507 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
1508 /* HP nx6320 (reversed SSID, H/W bug) */
1509 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
1513 static int patch_ad1981(struct hda_codec *codec)
1515 struct ad198x_spec *spec;
1518 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1524 spec->multiout.max_channels = 2;
1525 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1526 spec->multiout.dac_nids = ad1981_dac_nids;
1527 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
1528 spec->num_adc_nids = 1;
1529 spec->adc_nids = ad1981_adc_nids;
1530 spec->capsrc_nids = ad1981_capsrc_nids;
1531 spec->input_mux = &ad1981_capture_source;
1532 spec->num_mixers = 1;
1533 spec->mixers[0] = ad1981_mixers;
1534 spec->num_init_verbs = 1;
1535 spec->init_verbs[0] = ad1981_init_verbs;
1536 spec->spdif_route = 0;
1537 #ifdef CONFIG_SND_HDA_POWER_SAVE
1538 spec->loopback.amplist = ad1981_loopbacks;
1541 codec->patch_ops = ad198x_patch_ops;
1543 /* override some parameters */
1544 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1547 switch (board_config) {
1549 spec->mixers[0] = ad1981_hp_mixers;
1550 spec->num_init_verbs = 2;
1551 spec->init_verbs[1] = ad1981_hp_init_verbs;
1552 spec->multiout.dig_out_nid = 0;
1553 spec->input_mux = &ad1981_hp_capture_source;
1555 codec->patch_ops.init = ad1981_hp_init;
1556 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1558 case AD1981_THINKPAD:
1559 spec->mixers[0] = ad1981_thinkpad_mixers;
1560 spec->input_mux = &ad1981_thinkpad_capture_source;
1562 case AD1981_TOSHIBA:
1563 spec->mixers[0] = ad1981_hp_mixers;
1564 spec->mixers[1] = ad1981_toshiba_mixers;
1565 spec->num_init_verbs = 2;
1566 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1567 spec->multiout.dig_out_nid = 0;
1568 spec->input_mux = &ad1981_hp_capture_source;
1569 codec->patch_ops.init = ad1981_hp_init;
1570 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1580 * Output pins and routes
1582 * Pin Mix Sel DAC (*)
1583 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1584 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1585 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1586 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1587 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1588 * port-F 0x16 (mute) <- 0x2a <- 06
1589 * port-G 0x24 (mute) <- 0x27 <- 05
1590 * port-H 0x25 (mute) <- 0x28 <- 0a
1591 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1593 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1594 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
1596 * Input pins and routes
1598 * pin boost mix input # / adc input #
1599 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1600 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1601 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1602 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1603 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1604 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1605 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1606 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1610 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
1611 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
1613 * Inputs of Analog Mix (0x20)
1614 * 0:Port-B (front mic)
1615 * 1:Port-C/G/H (line-in)
1617 * 3:Port-D (line-in/2)
1618 * 4:Port-E/G/H (mic-in)
1619 * 5:Port-F (mic2-in)
1625 * 1:Port-B (front mic-in)
1626 * 2:Port-C (line-in)
1627 * 3:Port-F (mic2-in)
1632 * 8:Port-D (line-in/2)
1635 * Proposed pin assignments by the datasheet
1638 * Port-A front headphone
1648 * Port-A front headphone
1650 * C rear line-in/surround
1652 * E rear mic-in/CLFE
1658 * D internal speaker (with EAPD)
1659 * E/F quad mic array
1675 /* reivision id to check workarounds */
1676 #define AD1988A_REV2 0x100200
1678 #define is_rev2(codec) \
1679 ((codec)->vendor_id == 0x11d41988 && \
1680 (codec)->revision_id == AD1988A_REV2)
1686 static hda_nid_t ad1988_6stack_dac_nids[4] = {
1687 0x04, 0x06, 0x05, 0x0a
1690 static hda_nid_t ad1988_3stack_dac_nids[3] = {
1694 /* for AD1988A revision-2, DAC2-4 are swapped */
1695 static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1696 0x04, 0x05, 0x0a, 0x06
1699 static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
1703 static hda_nid_t ad1988_adc_nids[3] = {
1707 static hda_nid_t ad1988_capsrc_nids[3] = {
1711 #define AD1988_SPDIF_OUT 0x02
1712 #define AD1988_SPDIF_IN 0x07
1714 static struct hda_input_mux ad1988_6stack_capture_source = {
1717 { "Front Mic", 0x0 },
1725 static struct hda_input_mux ad1988_laptop_capture_source = {
1728 { "Mic/Line", 0x0 },
1736 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1737 struct snd_ctl_elem_info *uinfo)
1739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1740 struct ad198x_spec *spec = codec->spec;
1741 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1742 spec->num_channel_mode);
1745 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1746 struct snd_ctl_elem_value *ucontrol)
1748 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1749 struct ad198x_spec *spec = codec->spec;
1750 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1751 spec->num_channel_mode, spec->multiout.max_channels);
1754 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1755 struct snd_ctl_elem_value *ucontrol)
1757 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1758 struct ad198x_spec *spec = codec->spec;
1759 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1760 spec->num_channel_mode,
1761 &spec->multiout.max_channels);
1762 if (err >= 0 && spec->need_dac_fix)
1763 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
1768 static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
1769 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1770 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1771 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1772 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1773 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1777 static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1778 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1779 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1780 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1781 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1782 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1786 static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
1787 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1788 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1789 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1790 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1791 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1792 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1793 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1795 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1796 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1797 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1798 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1799 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1800 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1801 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1802 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1804 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1805 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1807 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1808 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1810 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1811 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1817 static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
1818 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1819 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1820 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1821 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1825 static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1826 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1827 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1828 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1829 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
1833 static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
1834 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1835 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1836 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1837 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
1838 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1839 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1841 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1842 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1843 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1844 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1845 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1846 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1847 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1848 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1850 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1851 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1853 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1854 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1856 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1857 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1859 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1860 .name = "Channel Mode",
1861 .info = ad198x_ch_mode_info,
1862 .get = ad198x_ch_mode_get,
1863 .put = ad198x_ch_mode_put,
1870 static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1871 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1872 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1873 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1875 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1876 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1877 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1878 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1879 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1880 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1882 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1883 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1885 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1886 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1888 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1891 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1892 .name = "External Amplifier",
1893 .info = ad198x_eapd_info,
1894 .get = ad198x_eapd_get,
1895 .put = ad198x_eapd_put,
1896 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
1903 static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1904 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1905 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1906 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1907 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1908 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1909 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1911 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1912 /* The multiple "Capture Source" controls confuse alsamixer
1913 * So call somewhat different..
1914 * FIXME: the controls appear in the "playback" view!
1916 /* .name = "Capture Source", */
1917 .name = "Input Source",
1919 .info = ad198x_mux_enum_info,
1920 .get = ad198x_mux_enum_get,
1921 .put = ad198x_mux_enum_put,
1926 static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1927 struct snd_ctl_elem_info *uinfo)
1929 static char *texts[] = {
1930 "PCM", "ADC1", "ADC2", "ADC3"
1932 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1934 uinfo->value.enumerated.items = 4;
1935 if (uinfo->value.enumerated.item >= 4)
1936 uinfo->value.enumerated.item = 3;
1937 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1941 static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1942 struct snd_ctl_elem_value *ucontrol)
1944 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1947 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
1950 ucontrol->value.enumerated.item[0] = 0;
1952 sel = snd_hda_codec_read(codec, 0x0b, 0,
1953 AC_VERB_GET_CONNECT_SEL, 0);
1958 ucontrol->value.enumerated.item[0] = sel;
1963 static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
1964 struct snd_ctl_elem_value *ucontrol)
1966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1967 unsigned int val, sel;
1970 val = ucontrol->value.enumerated.item[0];
1974 sel = snd_hda_codec_read(codec, 0x1d, 0,
1975 AC_VERB_GET_AMP_GAIN_MUTE,
1977 change = sel & 0x80;
1979 snd_hda_codec_write_cache(codec, 0x1d, 0,
1980 AC_VERB_SET_AMP_GAIN_MUTE,
1982 snd_hda_codec_write_cache(codec, 0x1d, 0,
1983 AC_VERB_SET_AMP_GAIN_MUTE,
1987 sel = snd_hda_codec_read(codec, 0x1d, 0,
1988 AC_VERB_GET_AMP_GAIN_MUTE,
1989 AC_AMP_GET_INPUT | 0x01);
1990 change = sel & 0x80;
1992 snd_hda_codec_write_cache(codec, 0x1d, 0,
1993 AC_VERB_SET_AMP_GAIN_MUTE,
1995 snd_hda_codec_write_cache(codec, 0x1d, 0,
1996 AC_VERB_SET_AMP_GAIN_MUTE,
1999 sel = snd_hda_codec_read(codec, 0x0b, 0,
2000 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2001 change |= sel != val;
2003 snd_hda_codec_write_cache(codec, 0x0b, 0,
2004 AC_VERB_SET_CONNECT_SEL,
2010 static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2011 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2013 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2014 .name = "IEC958 Playback Source",
2015 .info = ad1988_spdif_playback_source_info,
2016 .get = ad1988_spdif_playback_source_get,
2017 .put = ad1988_spdif_playback_source_put,
2022 static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2023 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2029 * initialization verbs
2033 * for 6-stack (+dig)
2035 static struct hda_verb ad1988_6stack_init_verbs[] = {
2036 /* Front, Surround, CLFE, side DAC; unmute as default */
2037 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2038 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2039 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2040 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2041 /* Port-A front headphon path */
2042 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2043 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2044 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2045 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2046 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2047 /* Port-D line-out path */
2048 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2049 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2050 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2051 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2052 /* Port-F surround path */
2053 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2054 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2055 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2056 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2057 /* Port-G CLFE path */
2058 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2059 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2060 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2061 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2062 /* Port-H side path */
2063 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2064 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2065 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2066 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2068 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2069 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2070 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2071 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2072 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2073 /* Port-B front mic-in path */
2074 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2075 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2076 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2077 /* Port-C line-in path */
2078 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2079 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2080 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2081 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2082 /* Port-E mic-in path */
2083 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2084 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2085 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2086 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2087 /* Analog CD Input */
2088 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2093 static struct hda_verb ad1988_capture_init_verbs[] = {
2094 /* mute analog mix */
2095 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2096 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2097 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2098 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2099 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2100 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2101 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2102 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2103 /* select ADCs - front-mic */
2104 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2105 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2106 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2108 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2109 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2110 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2115 static struct hda_verb ad1988_spdif_init_verbs[] = {
2117 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2118 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2119 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2120 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2122 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2128 * verbs for 3stack (+dig)
2130 static struct hda_verb ad1988_3stack_ch2_init[] = {
2131 /* set port-C to line-in */
2132 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2133 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2134 /* set port-E to mic-in */
2135 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2136 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2140 static struct hda_verb ad1988_3stack_ch6_init[] = {
2141 /* set port-C to surround out */
2142 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2143 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2144 /* set port-E to CLFE out */
2145 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2146 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2150 static struct hda_channel_mode ad1988_3stack_modes[2] = {
2151 { 2, ad1988_3stack_ch2_init },
2152 { 6, ad1988_3stack_ch6_init },
2155 static struct hda_verb ad1988_3stack_init_verbs[] = {
2156 /* Front, Surround, CLFE, side DAC; unmute as default */
2157 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2158 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2159 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2160 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2161 /* Port-A front headphon path */
2162 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2163 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2164 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2165 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2166 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2167 /* Port-D line-out path */
2168 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2169 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2170 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2171 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2173 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2174 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2175 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2176 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2177 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2178 /* Port-B front mic-in path */
2179 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2180 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2181 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2182 /* Port-C line-in/surround path - 6ch mode as default */
2183 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2184 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2185 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2186 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
2187 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2188 /* Port-E mic-in/CLFE path - 6ch mode as default */
2189 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2190 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2191 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2192 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
2193 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2194 /* mute analog mix */
2195 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2196 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2197 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2198 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2199 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2200 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2201 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2202 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2203 /* select ADCs - front-mic */
2204 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2205 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2206 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2208 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2209 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2210 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2215 * verbs for laptop mode (+dig)
2217 static struct hda_verb ad1988_laptop_hp_on[] = {
2218 /* unmute port-A and mute port-D */
2219 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2220 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2223 static struct hda_verb ad1988_laptop_hp_off[] = {
2224 /* mute port-A and unmute port-D */
2225 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2226 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2230 #define AD1988_HP_EVENT 0x01
2232 static struct hda_verb ad1988_laptop_init_verbs[] = {
2233 /* Front, Surround, CLFE, side DAC; unmute as default */
2234 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2235 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2236 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2237 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2238 /* Port-A front headphon path */
2239 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2240 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2241 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2242 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2243 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2244 /* unsolicited event for pin-sense */
2245 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2246 /* Port-D line-out path + EAPD */
2247 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2248 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2249 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2250 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2251 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2253 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2254 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2255 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2256 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2257 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2258 /* Port-B mic-in path */
2259 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2260 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2261 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2262 /* Port-C docking station - try to output */
2263 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2264 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2265 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2266 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2267 /* mute analog mix */
2268 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2269 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2270 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2271 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2272 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2273 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2274 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2275 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2276 /* select ADCs - mic */
2277 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2278 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2279 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2281 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2282 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2283 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2287 static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2289 if ((res >> 26) != AD1988_HP_EVENT)
2291 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2292 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2294 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2297 #ifdef CONFIG_SND_HDA_POWER_SAVE
2298 static struct hda_amp_list ad1988_loopbacks[] = {
2299 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2300 { 0x20, HDA_INPUT, 1 }, /* Line */
2301 { 0x20, HDA_INPUT, 4 }, /* Mic */
2302 { 0x20, HDA_INPUT, 6 }, /* CD */
2308 * Automatic parse of I/O pins from the BIOS configuration
2311 #define NUM_CONTROL_ALLOC 32
2312 #define NUM_VERB_ALLOC 32
2319 static struct snd_kcontrol_new ad1988_control_templates[] = {
2320 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2321 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2322 HDA_BIND_MUTE(NULL, 0, 0, 0),
2325 /* add dynamic controls */
2326 static int add_control(struct ad198x_spec *spec, int type, const char *name,
2329 struct snd_kcontrol_new *knew;
2331 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2332 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2334 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2337 if (spec->kctl_alloc) {
2338 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2339 kfree(spec->kctl_alloc);
2341 spec->kctl_alloc = knew;
2342 spec->num_kctl_alloc = num;
2345 knew = &spec->kctl_alloc[spec->num_kctl_used];
2346 *knew = ad1988_control_templates[type];
2347 knew->name = kstrdup(name, GFP_KERNEL);
2350 knew->private_value = val;
2351 spec->num_kctl_used++;
2355 #define AD1988_PIN_CD_NID 0x18
2356 #define AD1988_PIN_BEEP_NID 0x10
2358 static hda_nid_t ad1988_mixer_nids[8] = {
2359 /* A B C D E F G H */
2360 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2363 static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2365 static hda_nid_t idx_to_dac[8] = {
2366 /* A B C D E F G H */
2367 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
2369 static hda_nid_t idx_to_dac_rev2[8] = {
2370 /* A B C D E F G H */
2371 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
2374 return idx_to_dac_rev2[idx];
2376 return idx_to_dac[idx];
2379 static hda_nid_t ad1988_boost_nids[8] = {
2380 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2383 static int ad1988_pin_idx(hda_nid_t nid)
2385 static hda_nid_t ad1988_io_pins[8] = {
2386 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2389 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2390 if (ad1988_io_pins[i] == nid)
2392 return 0; /* should be -1 */
2395 static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2397 static int loopback_idx[8] = {
2398 2, 0, 1, 3, 4, 5, 1, 4
2401 case AD1988_PIN_CD_NID:
2404 return loopback_idx[ad1988_pin_idx(nid)];
2408 static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2410 static int adc_idx[8] = {
2411 0, 1, 2, 8, 4, 3, 6, 7
2414 case AD1988_PIN_CD_NID:
2417 return adc_idx[ad1988_pin_idx(nid)];
2421 /* fill in the dac_nids table from the parsed pin configuration */
2422 static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2423 const struct auto_pin_cfg *cfg)
2425 struct ad198x_spec *spec = codec->spec;
2428 spec->multiout.dac_nids = spec->private_dac_nids;
2430 /* check the pins hardwired to audio widget */
2431 for (i = 0; i < cfg->line_outs; i++) {
2432 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2433 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2435 spec->multiout.num_dacs = cfg->line_outs;
2439 /* add playback controls from the parsed DAC table */
2440 static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2441 const struct auto_pin_cfg *cfg)
2444 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2448 for (i = 0; i < cfg->line_outs; i++) {
2449 hda_nid_t dac = spec->multiout.dac_nids[i];
2452 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2455 err = add_control(spec, AD_CTL_WIDGET_VOL,
2456 "Center Playback Volume",
2457 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2460 err = add_control(spec, AD_CTL_WIDGET_VOL,
2461 "LFE Playback Volume",
2462 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2465 err = add_control(spec, AD_CTL_BIND_MUTE,
2466 "Center Playback Switch",
2467 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2470 err = add_control(spec, AD_CTL_BIND_MUTE,
2471 "LFE Playback Switch",
2472 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2476 sprintf(name, "%s Playback Volume", chname[i]);
2477 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2478 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2481 sprintf(name, "%s Playback Switch", chname[i]);
2482 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2483 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2491 /* add playback controls for speaker and HP outputs */
2492 static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2495 struct ad198x_spec *spec = codec->spec;
2503 idx = ad1988_pin_idx(pin);
2504 nid = ad1988_idx_to_dac(codec, idx);
2505 /* specify the DAC as the extra output */
2506 if (! spec->multiout.hp_nid)
2507 spec->multiout.hp_nid = nid;
2509 spec->multiout.extra_out_nid[0] = nid;
2510 /* control HP volume/switch on the output mixer amp */
2511 sprintf(name, "%s Playback Volume", pfx);
2512 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2513 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2515 nid = ad1988_mixer_nids[idx];
2516 sprintf(name, "%s Playback Switch", pfx);
2517 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2518 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2523 /* create input playback/capture controls for the given pin */
2524 static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2525 const char *ctlname, int boost)
2530 sprintf(name, "%s Playback Volume", ctlname);
2531 idx = ad1988_pin_to_loopback_idx(pin);
2532 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2533 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2535 sprintf(name, "%s Playback Switch", ctlname);
2536 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2537 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2541 idx = ad1988_pin_idx(pin);
2542 bnid = ad1988_boost_nids[idx];
2544 sprintf(name, "%s Boost", ctlname);
2545 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2546 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2553 /* create playback/capture controls for input pins */
2554 static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2555 const struct auto_pin_cfg *cfg)
2557 struct hda_input_mux *imux = &spec->private_imux;
2560 for (i = 0; i < AUTO_PIN_LAST; i++) {
2561 err = new_analog_input(spec, cfg->input_pins[i],
2562 auto_pin_cfg_labels[i],
2563 i <= AUTO_PIN_FRONT_MIC);
2566 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2567 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2570 imux->items[imux->num_items].label = "Mix";
2571 imux->items[imux->num_items].index = 9;
2574 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2575 "Analog Mix Playback Volume",
2576 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2578 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2579 "Analog Mix Playback Switch",
2580 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2586 static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2587 hda_nid_t nid, int pin_type,
2591 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2592 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2594 case 0x11: /* port-A - DAC 04 */
2595 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2597 case 0x14: /* port-B - DAC 06 */
2598 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2600 case 0x15: /* port-C - DAC 05 */
2601 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2603 case 0x17: /* port-E - DAC 0a */
2604 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2606 case 0x13: /* mono - DAC 04 */
2607 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2612 static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2614 struct ad198x_spec *spec = codec->spec;
2617 for (i = 0; i < spec->autocfg.line_outs; i++) {
2618 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2619 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2623 static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2625 struct ad198x_spec *spec = codec->spec;
2628 pin = spec->autocfg.speaker_pins[0];
2629 if (pin) /* connect to front */
2630 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2631 pin = spec->autocfg.hp_pins[0];
2632 if (pin) /* connect to front */
2633 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2636 static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2638 struct ad198x_spec *spec = codec->spec;
2641 for (i = 0; i < AUTO_PIN_LAST; i++) {
2642 hda_nid_t nid = spec->autocfg.input_pins[i];
2646 case 0x15: /* port-C */
2647 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2649 case 0x17: /* port-E */
2650 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2653 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2654 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2655 if (nid != AD1988_PIN_CD_NID)
2656 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2658 idx = ad1988_pin_idx(nid);
2659 if (ad1988_boost_nids[idx])
2660 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2661 AC_VERB_SET_AMP_GAIN_MUTE,
2666 /* parse the BIOS configuration and set up the alc_spec */
2667 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2668 static int ad1988_parse_auto_config(struct hda_codec *codec)
2670 struct ad198x_spec *spec = codec->spec;
2673 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2675 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2677 if (! spec->autocfg.line_outs)
2678 return 0; /* can't find valid BIOS pin config */
2679 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2680 (err = ad1988_auto_create_extra_out(codec,
2681 spec->autocfg.speaker_pins[0],
2683 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
2684 "Headphone")) < 0 ||
2685 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2688 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2690 if (spec->autocfg.dig_out_pin)
2691 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2692 if (spec->autocfg.dig_in_pin)
2693 spec->dig_in_nid = AD1988_SPDIF_IN;
2695 if (spec->kctl_alloc)
2696 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2698 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2700 spec->input_mux = &spec->private_imux;
2705 /* init callback for auto-configuration model -- overriding the default init */
2706 static int ad1988_auto_init(struct hda_codec *codec)
2709 ad1988_auto_init_multi_out(codec);
2710 ad1988_auto_init_extra_out(codec);
2711 ad1988_auto_init_analog_input(codec);
2719 static const char *ad1988_models[AD1988_MODEL_LAST] = {
2720 [AD1988_6STACK] = "6stack",
2721 [AD1988_6STACK_DIG] = "6stack-dig",
2722 [AD1988_3STACK] = "3stack",
2723 [AD1988_3STACK_DIG] = "3stack-dig",
2724 [AD1988_LAPTOP] = "laptop",
2725 [AD1988_LAPTOP_DIG] = "laptop-dig",
2726 [AD1988_AUTO] = "auto",
2729 static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2730 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
2731 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
2735 static int patch_ad1988(struct hda_codec *codec)
2737 struct ad198x_spec *spec;
2740 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2747 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2749 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
2750 ad1988_models, ad1988_cfg_tbl);
2751 if (board_config < 0) {
2752 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2753 board_config = AD1988_AUTO;
2756 if (board_config == AD1988_AUTO) {
2757 /* automatic parse from the BIOS config */
2758 int err = ad1988_parse_auto_config(codec);
2763 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2764 board_config = AD1988_6STACK;
2768 switch (board_config) {
2770 case AD1988_6STACK_DIG:
2771 spec->multiout.max_channels = 8;
2772 spec->multiout.num_dacs = 4;
2774 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2776 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
2777 spec->input_mux = &ad1988_6stack_capture_source;
2778 spec->num_mixers = 2;
2780 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2782 spec->mixers[0] = ad1988_6stack_mixers1;
2783 spec->mixers[1] = ad1988_6stack_mixers2;
2784 spec->num_init_verbs = 1;
2785 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2786 if (board_config == AD1988_6STACK_DIG) {
2787 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2788 spec->dig_in_nid = AD1988_SPDIF_IN;
2792 case AD1988_3STACK_DIG:
2793 spec->multiout.max_channels = 6;
2794 spec->multiout.num_dacs = 3;
2796 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2798 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2799 spec->input_mux = &ad1988_6stack_capture_source;
2800 spec->channel_mode = ad1988_3stack_modes;
2801 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
2802 spec->num_mixers = 2;
2804 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2806 spec->mixers[0] = ad1988_3stack_mixers1;
2807 spec->mixers[1] = ad1988_3stack_mixers2;
2808 spec->num_init_verbs = 1;
2809 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2810 if (board_config == AD1988_3STACK_DIG)
2811 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2814 case AD1988_LAPTOP_DIG:
2815 spec->multiout.max_channels = 2;
2816 spec->multiout.num_dacs = 1;
2817 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2818 spec->input_mux = &ad1988_laptop_capture_source;
2819 spec->num_mixers = 1;
2820 spec->mixers[0] = ad1988_laptop_mixers;
2821 spec->num_init_verbs = 1;
2822 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2823 if (board_config == AD1988_LAPTOP_DIG)
2824 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2828 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2829 spec->adc_nids = ad1988_adc_nids;
2830 spec->capsrc_nids = ad1988_capsrc_nids;
2831 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2832 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2833 if (spec->multiout.dig_out_nid) {
2834 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2835 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2837 if (spec->dig_in_nid)
2838 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2840 codec->patch_ops = ad198x_patch_ops;
2841 switch (board_config) {
2843 codec->patch_ops.init = ad1988_auto_init;
2846 case AD1988_LAPTOP_DIG:
2847 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2850 #ifdef CONFIG_SND_HDA_POWER_SAVE
2851 spec->loopback.amplist = ad1988_loopbacks;
2861 * port-B - front line/mic-in
2862 * port-E - aux in/out
2863 * port-F - aux in/out
2864 * port-C - rear line/mic-in
2865 * port-D - rear line/hp-out
2866 * port-A - front line/hp-out
2868 * AD1984 = AD1884 + two digital mic-ins
2871 * For simplicity, we share the single DAC for both HP and line-outs
2872 * right now. The inidividual playbacks could be easily implemented,
2873 * but no build-up framework is given, so far.
2876 static hda_nid_t ad1884_dac_nids[1] = {
2880 static hda_nid_t ad1884_adc_nids[2] = {
2884 static hda_nid_t ad1884_capsrc_nids[2] = {
2888 #define AD1884_SPDIF_OUT 0x02
2890 static struct hda_input_mux ad1884_capture_source = {
2893 { "Front Mic", 0x0 },
2900 static struct snd_kcontrol_new ad1884_base_mixers[] = {
2901 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2902 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
2903 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
2904 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
2905 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
2906 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
2907 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
2908 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
2909 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
2910 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
2911 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
2912 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
2914 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
2915 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
2916 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2917 HDA_CODEC_MUTE("Digital Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2919 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
2920 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
2921 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2922 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2923 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2924 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2926 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2927 /* The multiple "Capture Source" controls confuse alsamixer
2928 * So call somewhat different..
2929 * FIXME: the controls appear in the "playback" view!
2931 /* .name = "Capture Source", */
2932 .name = "Input Source",
2934 .info = ad198x_mux_enum_info,
2935 .get = ad198x_mux_enum_get,
2936 .put = ad198x_mux_enum_put,
2938 /* SPDIF controls */
2939 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2941 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2942 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2943 /* identical with ad1983 */
2944 .info = ad1983_spdif_route_info,
2945 .get = ad1983_spdif_route_get,
2946 .put = ad1983_spdif_route_put,
2951 static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
2952 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
2953 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
2954 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
2956 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
2962 * initialization verbs
2964 static struct hda_verb ad1884_init_verbs[] = {
2965 /* DACs; mute as default */
2966 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2967 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2968 /* Port-A (HP) mixer */
2969 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2970 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2972 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2973 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2974 /* HP selector - select DAC2 */
2975 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
2976 /* Port-D (Line-out) mixer */
2977 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2978 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2980 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2981 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2982 /* Mono-out mixer */
2983 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2984 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2986 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2987 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2989 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2990 /* Port-B (front mic) pin */
2991 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2992 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2993 /* Port-C (rear mic) pin */
2994 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2995 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2996 /* Analog mixer; mute as default */
2997 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2998 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2999 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3000 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3001 /* Analog Mix output amp */
3002 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3003 /* SPDIF output selector */
3004 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3005 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3009 #ifdef CONFIG_SND_HDA_POWER_SAVE
3010 static struct hda_amp_list ad1884_loopbacks[] = {
3011 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3012 { 0x20, HDA_INPUT, 1 }, /* Mic */
3013 { 0x20, HDA_INPUT, 2 }, /* CD */
3014 { 0x20, HDA_INPUT, 4 }, /* Docking */
3019 static int patch_ad1884(struct hda_codec *codec)
3021 struct ad198x_spec *spec;
3023 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3027 mutex_init(&spec->amp_mutex);
3030 spec->multiout.max_channels = 2;
3031 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3032 spec->multiout.dac_nids = ad1884_dac_nids;
3033 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3034 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3035 spec->adc_nids = ad1884_adc_nids;
3036 spec->capsrc_nids = ad1884_capsrc_nids;
3037 spec->input_mux = &ad1884_capture_source;
3038 spec->num_mixers = 1;
3039 spec->mixers[0] = ad1884_base_mixers;
3040 spec->num_init_verbs = 1;
3041 spec->init_verbs[0] = ad1884_init_verbs;
3042 spec->spdif_route = 0;
3043 #ifdef CONFIG_SND_HDA_POWER_SAVE
3044 spec->loopback.amplist = ad1884_loopbacks;
3047 codec->patch_ops = ad198x_patch_ops;
3053 * Lenovo Thinkpad T61/X61
3055 static struct hda_input_mux ad1984_thinkpad_capture_source = {
3059 { "Internal Mic", 0x1 },
3064 static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3065 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3066 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3067 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3068 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3069 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3070 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3071 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3072 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3073 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3074 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3075 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3076 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3077 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3078 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3079 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3080 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3081 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3082 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3083 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3085 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3086 /* The multiple "Capture Source" controls confuse alsamixer
3087 * So call somewhat different..
3088 * FIXME: the controls appear in the "playback" view!
3090 /* .name = "Capture Source", */
3091 .name = "Input Source",
3093 .info = ad198x_mux_enum_info,
3094 .get = ad198x_mux_enum_get,
3095 .put = ad198x_mux_enum_put,
3100 /* additional verbs */
3101 static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3102 /* Port-E (docking station mic) pin */
3103 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3104 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3105 /* docking mic boost */
3106 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3107 /* Analog mixer - docking mic; mute as default */
3108 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3109 /* enable EAPD bit */
3110 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3114 /* Digial MIC ADC NID 0x05 + 0x06 */
3115 static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3116 struct hda_codec *codec,
3117 unsigned int stream_tag,
3118 unsigned int format,
3119 struct snd_pcm_substream *substream)
3121 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3122 stream_tag, 0, format);
3126 static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3127 struct hda_codec *codec,
3128 struct snd_pcm_substream *substream)
3130 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3135 static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3141 .prepare = ad1984_pcm_dmic_prepare,
3142 .cleanup = ad1984_pcm_dmic_cleanup
3146 static int ad1984_build_pcms(struct hda_codec *codec)
3148 struct ad198x_spec *spec = codec->spec;
3149 struct hda_pcm *info;
3152 err = ad198x_build_pcms(codec);
3156 info = spec->pcm_rec + codec->num_pcms;
3158 info->name = "AD1984 Digital Mic";
3159 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3170 static const char *ad1984_models[AD1984_MODELS] = {
3171 [AD1984_BASIC] = "basic",
3172 [AD1984_THINKPAD] = "thinkpad",
3175 static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3176 /* Lenovo Thinkpad T61/X61 */
3177 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1984_THINKPAD),
3181 static int patch_ad1984(struct hda_codec *codec)
3183 struct ad198x_spec *spec;
3184 int board_config, err;
3186 err = patch_ad1884(codec);
3190 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3191 ad1984_models, ad1984_cfg_tbl);
3192 switch (board_config) {
3194 /* additional digital mics */
3195 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3196 codec->patch_ops.build_pcms = ad1984_build_pcms;
3198 case AD1984_THINKPAD:
3199 spec->multiout.dig_out_nid = 0;
3200 spec->input_mux = &ad1984_thinkpad_capture_source;
3201 spec->mixers[0] = ad1984_thinkpad_mixers;
3202 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3212 * port-A - front hp-out
3213 * port-B - front mic-in
3214 * port-C - rear line-in, shared surr-out (3stack)
3215 * port-D - rear line-out
3216 * port-E - rear mic-in, shared clfe-out (3stack)
3217 * port-F - rear surr-out (6stack)
3218 * port-G - rear clfe-out (6stack)
3221 static hda_nid_t ad1882_dac_nids[3] = {
3225 static hda_nid_t ad1882_adc_nids[2] = {
3229 static hda_nid_t ad1882_capsrc_nids[2] = {
3233 #define AD1882_SPDIF_OUT 0x02
3235 /* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
3236 static struct hda_input_mux ad1882_capture_source = {
3239 { "Front Mic", 0x1 },
3247 static struct snd_kcontrol_new ad1882_base_mixers[] = {
3248 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3249 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
3250 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
3251 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
3252 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3253 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3254 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3255 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3256 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3257 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3258 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3259 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3260 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
3261 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
3262 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
3263 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
3264 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
3265 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
3266 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
3267 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
3268 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
3269 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3270 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3271 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3272 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3274 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3275 /* The multiple "Capture Source" controls confuse alsamixer
3276 * So call somewhat different..
3277 * FIXME: the controls appear in the "playback" view!
3279 /* .name = "Capture Source", */
3280 .name = "Input Source",
3282 .info = ad198x_mux_enum_info,
3283 .get = ad198x_mux_enum_get,
3284 .put = ad198x_mux_enum_put,
3286 /* SPDIF controls */
3287 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3289 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3290 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3291 /* identical with ad1983 */
3292 .info = ad1983_spdif_route_info,
3293 .get = ad1983_spdif_route_get,
3294 .put = ad1983_spdif_route_put,
3299 static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
3300 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3301 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
3302 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
3304 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3305 .name = "Channel Mode",
3306 .info = ad198x_ch_mode_info,
3307 .get = ad198x_ch_mode_get,
3308 .put = ad198x_ch_mode_put,
3313 static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
3314 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
3315 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
3316 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
3320 static struct hda_verb ad1882_ch2_init[] = {
3321 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3322 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3323 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3324 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3325 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3326 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3330 static struct hda_verb ad1882_ch4_init[] = {
3331 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3332 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3333 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3334 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3335 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3336 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3340 static struct hda_verb ad1882_ch6_init[] = {
3341 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3342 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3343 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3344 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3345 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3346 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3350 static struct hda_channel_mode ad1882_modes[3] = {
3351 { 2, ad1882_ch2_init },
3352 { 4, ad1882_ch4_init },
3353 { 6, ad1882_ch6_init },
3357 * initialization verbs
3359 static struct hda_verb ad1882_init_verbs[] = {
3360 /* DACs; mute as default */
3361 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3362 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3363 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3364 /* Port-A (HP) mixer */
3365 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3366 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3368 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3369 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3370 /* HP selector - select DAC2 */
3371 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
3372 /* Port-D (Line-out) mixer */
3373 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3374 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3376 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3377 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3378 /* Mono-out mixer */
3379 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3380 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3382 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3383 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3384 /* Port-B (front mic) pin */
3385 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3386 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3387 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3388 /* Port-C (line-in) pin */
3389 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3390 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3391 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3392 /* Port-C mixer - mute as input */
3393 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3394 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3395 /* Port-E (mic-in) pin */
3396 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3397 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3398 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3399 /* Port-E mixer - mute as input */
3400 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3401 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3402 /* Port-F (surround) */
3403 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3404 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3406 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3407 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3408 /* Analog mixer; mute as default */
3409 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
3410 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3411 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3412 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3413 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3414 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3415 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3416 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3417 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3418 /* Analog Mix output amp */
3419 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3420 /* SPDIF output selector */
3421 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3422 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3423 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3427 #ifdef CONFIG_SND_HDA_POWER_SAVE
3428 static struct hda_amp_list ad1882_loopbacks[] = {
3429 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3430 { 0x20, HDA_INPUT, 1 }, /* Mic */
3431 { 0x20, HDA_INPUT, 4 }, /* Line */
3432 { 0x20, HDA_INPUT, 6 }, /* CD */
3444 static const char *ad1882_models[AD1986A_MODELS] = {
3445 [AD1882_3STACK] = "3stack",
3446 [AD1882_6STACK] = "6stack",
3450 static int patch_ad1882(struct hda_codec *codec)
3452 struct ad198x_spec *spec;
3455 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3459 mutex_init(&spec->amp_mutex);
3462 spec->multiout.max_channels = 6;
3463 spec->multiout.num_dacs = 3;
3464 spec->multiout.dac_nids = ad1882_dac_nids;
3465 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
3466 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
3467 spec->adc_nids = ad1882_adc_nids;
3468 spec->capsrc_nids = ad1882_capsrc_nids;
3469 spec->input_mux = &ad1882_capture_source;
3470 spec->num_mixers = 1;
3471 spec->mixers[0] = ad1882_base_mixers;
3472 spec->num_init_verbs = 1;
3473 spec->init_verbs[0] = ad1882_init_verbs;
3474 spec->spdif_route = 0;
3475 #ifdef CONFIG_SND_HDA_POWER_SAVE
3476 spec->loopback.amplist = ad1882_loopbacks;
3479 codec->patch_ops = ad198x_patch_ops;
3481 /* override some parameters */
3482 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
3483 ad1882_models, NULL);
3484 switch (board_config) {
3487 spec->num_mixers = 2;
3488 spec->mixers[1] = ad1882_3stack_mixers;
3489 spec->channel_mode = ad1882_modes;
3490 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
3491 spec->need_dac_fix = 1;
3492 spec->multiout.max_channels = 2;
3493 spec->multiout.num_dacs = 1;
3496 spec->num_mixers = 2;
3497 spec->mixers[1] = ad1882_6stack_mixers;
3507 struct hda_codec_preset snd_hda_preset_analog[] = {
3508 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
3509 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
3510 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
3511 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
3512 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
3513 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
3514 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
3515 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },