ALSA: hda - make laptop-eapd model back for AD1986A
[linux-2.6/kvm.git] / sound / pci / hda / patch_analog.c
blob0cc6be12b8b7f87cb9352c5ebe279b31453f22e6
1 /*
2 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
3 * AD1986A, AD1988
5 * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/init.h>
23 #include <linux/delay.h>
24 #include <linux/slab.h>
25 #include <linux/pci.h>
27 #include <sound/core.h>
28 #include "hda_codec.h"
29 #include "hda_local.h"
30 #include "hda_patch.h"
32 struct ad198x_spec {
33 struct snd_kcontrol_new *mixers[5];
34 int num_mixers;
36 const struct hda_verb *init_verbs[5]; /* initialization verbs
37 * don't forget NULL termination!
39 unsigned int num_init_verbs;
41 /* playback */
42 struct hda_multi_out multiout; /* playback set-up
43 * max_channels, dacs must be set
44 * dig_out_nid and hp_nid are optional
46 unsigned int cur_eapd;
47 unsigned int need_dac_fix;
49 /* capture */
50 unsigned int num_adc_nids;
51 hda_nid_t *adc_nids;
52 hda_nid_t dig_in_nid; /* digital-in NID; optional */
54 /* capture source */
55 const struct hda_input_mux *input_mux;
56 hda_nid_t *capsrc_nids;
57 unsigned int cur_mux[3];
59 /* channel model */
60 const struct hda_channel_mode *channel_mode;
61 int num_channel_mode;
63 /* PCM information */
64 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
66 unsigned int spdif_route;
68 /* dynamic controls, init_verbs and input_mux */
69 struct auto_pin_cfg autocfg;
70 struct snd_array kctls;
71 struct hda_input_mux private_imux;
72 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
74 unsigned int jack_present :1;
76 #ifdef CONFIG_SND_HDA_POWER_SAVE
77 struct hda_loopback_check loopback;
78 #endif
79 /* for virtual master */
80 hda_nid_t vmaster_nid;
81 const char **slave_vols;
82 const char **slave_sws;
86 * input MUX handling (common part)
88 static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
90 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
91 struct ad198x_spec *spec = codec->spec;
93 return snd_hda_input_mux_info(spec->input_mux, uinfo);
96 static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
98 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
99 struct ad198x_spec *spec = codec->spec;
100 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
102 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
103 return 0;
106 static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
108 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
109 struct ad198x_spec *spec = codec->spec;
110 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
112 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
113 spec->capsrc_nids[adc_idx],
114 &spec->cur_mux[adc_idx]);
118 * initialization (common callbacks)
120 static int ad198x_init(struct hda_codec *codec)
122 struct ad198x_spec *spec = codec->spec;
123 int i;
125 for (i = 0; i < spec->num_init_verbs; i++)
126 snd_hda_sequence_write(codec, spec->init_verbs[i]);
127 return 0;
130 static const char *ad_slave_vols[] = {
131 "Front Playback Volume",
132 "Surround Playback Volume",
133 "Center Playback Volume",
134 "LFE Playback Volume",
135 "Side Playback Volume",
136 "Headphone Playback Volume",
137 "Mono Playback Volume",
138 "Speaker Playback Volume",
139 "IEC958 Playback Volume",
140 NULL
143 static const char *ad_slave_sws[] = {
144 "Front Playback Switch",
145 "Surround Playback Switch",
146 "Center Playback Switch",
147 "LFE Playback Switch",
148 "Side Playback Switch",
149 "Headphone Playback Switch",
150 "Mono Playback Switch",
151 "Speaker Playback Switch",
152 "IEC958 Playback Switch",
153 NULL
156 static void ad198x_free_kctls(struct hda_codec *codec);
158 static int ad198x_build_controls(struct hda_codec *codec)
160 struct ad198x_spec *spec = codec->spec;
161 unsigned int i;
162 int err;
164 for (i = 0; i < spec->num_mixers; i++) {
165 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
166 if (err < 0)
167 return err;
169 if (spec->multiout.dig_out_nid) {
170 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
171 if (err < 0)
172 return err;
173 err = snd_hda_create_spdif_share_sw(codec,
174 &spec->multiout);
175 if (err < 0)
176 return err;
177 spec->multiout.share_spdif = 1;
179 if (spec->dig_in_nid) {
180 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
181 if (err < 0)
182 return err;
185 /* if we have no master control, let's create it */
186 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
187 unsigned int vmaster_tlv[4];
188 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
189 HDA_OUTPUT, vmaster_tlv);
190 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
191 vmaster_tlv,
192 (spec->slave_vols ?
193 spec->slave_vols : ad_slave_vols));
194 if (err < 0)
195 return err;
197 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
198 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
199 NULL,
200 (spec->slave_sws ?
201 spec->slave_sws : ad_slave_sws));
202 if (err < 0)
203 return err;
206 ad198x_free_kctls(codec); /* no longer needed */
207 return 0;
210 #ifdef CONFIG_SND_HDA_POWER_SAVE
211 static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
213 struct ad198x_spec *spec = codec->spec;
214 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
216 #endif
219 * Analog playback callbacks
221 static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
222 struct hda_codec *codec,
223 struct snd_pcm_substream *substream)
225 struct ad198x_spec *spec = codec->spec;
226 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
227 hinfo);
230 static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
231 struct hda_codec *codec,
232 unsigned int stream_tag,
233 unsigned int format,
234 struct snd_pcm_substream *substream)
236 struct ad198x_spec *spec = codec->spec;
237 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
238 format, substream);
241 static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
242 struct hda_codec *codec,
243 struct snd_pcm_substream *substream)
245 struct ad198x_spec *spec = codec->spec;
246 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
250 * Digital out
252 static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
253 struct hda_codec *codec,
254 struct snd_pcm_substream *substream)
256 struct ad198x_spec *spec = codec->spec;
257 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
260 static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
261 struct hda_codec *codec,
262 struct snd_pcm_substream *substream)
264 struct ad198x_spec *spec = codec->spec;
265 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
268 static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
269 struct hda_codec *codec,
270 unsigned int stream_tag,
271 unsigned int format,
272 struct snd_pcm_substream *substream)
274 struct ad198x_spec *spec = codec->spec;
275 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
276 format, substream);
280 * Analog capture
282 static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
283 struct hda_codec *codec,
284 unsigned int stream_tag,
285 unsigned int format,
286 struct snd_pcm_substream *substream)
288 struct ad198x_spec *spec = codec->spec;
289 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
290 stream_tag, 0, format);
291 return 0;
294 static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
295 struct hda_codec *codec,
296 struct snd_pcm_substream *substream)
298 struct ad198x_spec *spec = codec->spec;
299 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
300 return 0;
306 static struct hda_pcm_stream ad198x_pcm_analog_playback = {
307 .substreams = 1,
308 .channels_min = 2,
309 .channels_max = 6, /* changed later */
310 .nid = 0, /* fill later */
311 .ops = {
312 .open = ad198x_playback_pcm_open,
313 .prepare = ad198x_playback_pcm_prepare,
314 .cleanup = ad198x_playback_pcm_cleanup
318 static struct hda_pcm_stream ad198x_pcm_analog_capture = {
319 .substreams = 1,
320 .channels_min = 2,
321 .channels_max = 2,
322 .nid = 0, /* fill later */
323 .ops = {
324 .prepare = ad198x_capture_pcm_prepare,
325 .cleanup = ad198x_capture_pcm_cleanup
329 static struct hda_pcm_stream ad198x_pcm_digital_playback = {
330 .substreams = 1,
331 .channels_min = 2,
332 .channels_max = 2,
333 .nid = 0, /* fill later */
334 .ops = {
335 .open = ad198x_dig_playback_pcm_open,
336 .close = ad198x_dig_playback_pcm_close,
337 .prepare = ad198x_dig_playback_pcm_prepare
341 static struct hda_pcm_stream ad198x_pcm_digital_capture = {
342 .substreams = 1,
343 .channels_min = 2,
344 .channels_max = 2,
345 /* NID is set in alc_build_pcms */
348 static int ad198x_build_pcms(struct hda_codec *codec)
350 struct ad198x_spec *spec = codec->spec;
351 struct hda_pcm *info = spec->pcm_rec;
353 codec->num_pcms = 1;
354 codec->pcm_info = info;
356 info->name = "AD198x Analog";
357 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
358 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
359 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
360 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
361 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
362 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
364 if (spec->multiout.dig_out_nid) {
365 info++;
366 codec->num_pcms++;
367 info->name = "AD198x Digital";
368 info->pcm_type = HDA_PCM_TYPE_SPDIF;
369 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
370 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
371 if (spec->dig_in_nid) {
372 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
373 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
377 return 0;
380 static void ad198x_free_kctls(struct hda_codec *codec)
382 struct ad198x_spec *spec = codec->spec;
384 if (spec->kctls.list) {
385 struct snd_kcontrol_new *kctl = spec->kctls.list;
386 int i;
387 for (i = 0; i < spec->kctls.used; i++)
388 kfree(kctl[i].name);
390 snd_array_free(&spec->kctls);
393 static void ad198x_free(struct hda_codec *codec)
395 struct ad198x_spec *spec = codec->spec;
397 if (!spec)
398 return;
400 ad198x_free_kctls(codec);
401 kfree(codec->spec);
404 static struct hda_codec_ops ad198x_patch_ops = {
405 .build_controls = ad198x_build_controls,
406 .build_pcms = ad198x_build_pcms,
407 .init = ad198x_init,
408 .free = ad198x_free,
409 #ifdef CONFIG_SND_HDA_POWER_SAVE
410 .check_power_status = ad198x_check_power_status,
411 #endif
416 * EAPD control
417 * the private value = nid | (invert << 8)
419 #define ad198x_eapd_info snd_ctl_boolean_mono_info
421 static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
422 struct snd_ctl_elem_value *ucontrol)
424 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
425 struct ad198x_spec *spec = codec->spec;
426 int invert = (kcontrol->private_value >> 8) & 1;
427 if (invert)
428 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
429 else
430 ucontrol->value.integer.value[0] = spec->cur_eapd;
431 return 0;
434 static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
435 struct snd_ctl_elem_value *ucontrol)
437 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
438 struct ad198x_spec *spec = codec->spec;
439 int invert = (kcontrol->private_value >> 8) & 1;
440 hda_nid_t nid = kcontrol->private_value & 0xff;
441 unsigned int eapd;
442 eapd = !!ucontrol->value.integer.value[0];
443 if (invert)
444 eapd = !eapd;
445 if (eapd == spec->cur_eapd)
446 return 0;
447 spec->cur_eapd = eapd;
448 snd_hda_codec_write_cache(codec, nid,
449 0, AC_VERB_SET_EAPD_BTLENABLE,
450 eapd ? 0x02 : 0x00);
451 return 1;
454 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
455 struct snd_ctl_elem_info *uinfo);
456 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
457 struct snd_ctl_elem_value *ucontrol);
458 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
459 struct snd_ctl_elem_value *ucontrol);
463 * AD1986A specific
466 #define AD1986A_SPDIF_OUT 0x02
467 #define AD1986A_FRONT_DAC 0x03
468 #define AD1986A_SURR_DAC 0x04
469 #define AD1986A_CLFE_DAC 0x05
470 #define AD1986A_ADC 0x06
472 static hda_nid_t ad1986a_dac_nids[3] = {
473 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
475 static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
476 static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
478 static struct hda_input_mux ad1986a_capture_source = {
479 .num_items = 7,
480 .items = {
481 { "Mic", 0x0 },
482 { "CD", 0x1 },
483 { "Aux", 0x3 },
484 { "Line", 0x4 },
485 { "Mix", 0x5 },
486 { "Mono", 0x6 },
487 { "Phone", 0x7 },
492 static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
493 .ops = &snd_hda_bind_vol,
494 .values = {
495 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
496 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
497 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
502 static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
503 .ops = &snd_hda_bind_sw,
504 .values = {
505 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
506 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
507 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
513 * mixers
515 static struct snd_kcontrol_new ad1986a_mixers[] = {
517 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
519 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
520 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
521 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
522 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
523 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
524 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
525 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
526 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
527 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
528 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
529 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
530 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
531 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
532 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
533 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
534 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
535 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
536 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
537 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
538 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
539 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
540 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
541 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
542 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
543 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
544 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
545 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
547 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
548 .name = "Capture Source",
549 .info = ad198x_mux_enum_info,
550 .get = ad198x_mux_enum_get,
551 .put = ad198x_mux_enum_put,
553 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
554 { } /* end */
557 /* additional mixers for 3stack mode */
558 static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
560 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
561 .name = "Channel Mode",
562 .info = ad198x_ch_mode_info,
563 .get = ad198x_ch_mode_get,
564 .put = ad198x_ch_mode_put,
566 { } /* end */
569 /* laptop model - 2ch only */
570 static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
572 /* master controls both pins 0x1a and 0x1b */
573 static struct hda_bind_ctls ad1986a_laptop_master_vol = {
574 .ops = &snd_hda_bind_vol,
575 .values = {
576 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
577 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
582 static struct hda_bind_ctls ad1986a_laptop_master_sw = {
583 .ops = &snd_hda_bind_sw,
584 .values = {
585 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
586 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
591 static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
592 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
593 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
594 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
595 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
596 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
597 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
598 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
599 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
600 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
601 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
602 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
603 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
604 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
605 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
606 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
607 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
608 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
609 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
610 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
612 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
613 .name = "Capture Source",
614 .info = ad198x_mux_enum_info,
615 .get = ad198x_mux_enum_get,
616 .put = ad198x_mux_enum_put,
618 { } /* end */
621 /* laptop-eapd model - 2ch only */
623 static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
624 .num_items = 3,
625 .items = {
626 { "Mic", 0x0 },
627 { "Internal Mic", 0x4 },
628 { "Mix", 0x5 },
632 static struct hda_input_mux ad1986a_automic_capture_source = {
633 .num_items = 2,
634 .items = {
635 { "Mic", 0x0 },
636 { "Mix", 0x5 },
640 static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
641 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
642 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
643 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
644 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
645 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
646 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
647 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
648 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
649 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
650 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
651 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
653 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
654 .name = "Capture Source",
655 .info = ad198x_mux_enum_info,
656 .get = ad198x_mux_enum_get,
657 .put = ad198x_mux_enum_put,
660 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
661 .name = "External Amplifier",
662 .info = ad198x_eapd_info,
663 .get = ad198x_eapd_get,
664 .put = ad198x_eapd_put,
665 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
667 { } /* end */
670 static struct snd_kcontrol_new ad1986a_samsung_mixers[] = {
671 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
672 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
673 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
674 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
675 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
676 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
677 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
678 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
679 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
681 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
682 .name = "Capture Source",
683 .info = ad198x_mux_enum_info,
684 .get = ad198x_mux_enum_get,
685 .put = ad198x_mux_enum_put,
688 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
689 .name = "External Amplifier",
690 .info = ad198x_eapd_info,
691 .get = ad198x_eapd_get,
692 .put = ad198x_eapd_put,
693 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
695 { } /* end */
698 /* re-connect the mic boost input according to the jack sensing */
699 static void ad1986a_automic(struct hda_codec *codec)
701 unsigned int present;
702 present = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_PIN_SENSE, 0);
703 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
704 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
705 (present & AC_PINSENSE_PRESENCE) ? 0 : 2);
708 #define AD1986A_MIC_EVENT 0x36
710 static void ad1986a_automic_unsol_event(struct hda_codec *codec,
711 unsigned int res)
713 if ((res >> 26) != AD1986A_MIC_EVENT)
714 return;
715 ad1986a_automic(codec);
718 static int ad1986a_automic_init(struct hda_codec *codec)
720 ad198x_init(codec);
721 ad1986a_automic(codec);
722 return 0;
725 /* laptop-automute - 2ch only */
727 static void ad1986a_update_hp(struct hda_codec *codec)
729 struct ad198x_spec *spec = codec->spec;
730 unsigned int mute;
732 if (spec->jack_present)
733 mute = HDA_AMP_MUTE; /* mute internal speaker */
734 else
735 /* unmute internal speaker if necessary */
736 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
737 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
738 HDA_AMP_MUTE, mute);
741 static void ad1986a_hp_automute(struct hda_codec *codec)
743 struct ad198x_spec *spec = codec->spec;
744 unsigned int present;
746 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0);
747 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
748 spec->jack_present = !(present & 0x80000000);
749 ad1986a_update_hp(codec);
752 #define AD1986A_HP_EVENT 0x37
754 static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
756 if ((res >> 26) != AD1986A_HP_EVENT)
757 return;
758 ad1986a_hp_automute(codec);
761 static int ad1986a_hp_init(struct hda_codec *codec)
763 ad198x_init(codec);
764 ad1986a_hp_automute(codec);
765 return 0;
768 /* bind hp and internal speaker mute (with plug check) */
769 static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
770 struct snd_ctl_elem_value *ucontrol)
772 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
773 long *valp = ucontrol->value.integer.value;
774 int change;
776 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
777 HDA_AMP_MUTE,
778 valp[0] ? 0 : HDA_AMP_MUTE);
779 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
780 HDA_AMP_MUTE,
781 valp[1] ? 0 : HDA_AMP_MUTE);
782 if (change)
783 ad1986a_update_hp(codec);
784 return change;
787 static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = {
788 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
790 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
791 .name = "Master Playback Switch",
792 .info = snd_hda_mixer_amp_switch_info,
793 .get = snd_hda_mixer_amp_switch_get,
794 .put = ad1986a_hp_master_sw_put,
795 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
797 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
798 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
799 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
800 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
801 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
802 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
803 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
804 HDA_CODEC_VOLUME("Beep Playback Volume", 0x18, 0x0, HDA_OUTPUT),
805 HDA_CODEC_MUTE("Beep Playback Switch", 0x18, 0x0, HDA_OUTPUT),
806 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
807 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
810 .name = "Capture Source",
811 .info = ad198x_mux_enum_info,
812 .get = ad198x_mux_enum_get,
813 .put = ad198x_mux_enum_put,
816 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
817 .name = "External Amplifier",
818 .info = ad198x_eapd_info,
819 .get = ad198x_eapd_get,
820 .put = ad198x_eapd_put,
821 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
823 { } /* end */
827 * initialization verbs
829 static struct hda_verb ad1986a_init_verbs[] = {
830 /* Front, Surround, CLFE DAC; mute as default */
831 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
832 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
833 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
834 /* Downmix - off */
835 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
836 /* HP, Line-Out, Surround, CLFE selectors */
837 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
838 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
839 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
840 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
841 /* Mono selector */
842 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
843 /* Mic selector: Mic 1/2 pin */
844 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
845 /* Line-in selector: Line-in */
846 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
847 /* Mic 1/2 swap */
848 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
849 /* Record selector: mic */
850 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
851 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
852 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
853 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
854 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
855 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
856 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
857 /* PC beep */
858 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
859 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
860 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
861 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
862 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
863 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
864 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
865 /* HP Pin */
866 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
867 /* Front, Surround, CLFE Pins */
868 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
869 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
870 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
871 /* Mono Pin */
872 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
873 /* Mic Pin */
874 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
875 /* Line, Aux, CD, Beep-In Pin */
876 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
877 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
878 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
879 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
880 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
881 { } /* end */
884 static struct hda_verb ad1986a_ch2_init[] = {
885 /* Surround out -> Line In */
886 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
887 /* Line-in selectors */
888 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
889 /* CLFE -> Mic in */
890 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
891 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
892 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
893 { } /* end */
896 static struct hda_verb ad1986a_ch4_init[] = {
897 /* Surround out -> Surround */
898 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
899 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
900 /* CLFE -> Mic in */
901 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
902 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
903 { } /* end */
906 static struct hda_verb ad1986a_ch6_init[] = {
907 /* Surround out -> Surround out */
908 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
909 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
910 /* CLFE -> CLFE */
911 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
912 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
913 { } /* end */
916 static struct hda_channel_mode ad1986a_modes[3] = {
917 { 2, ad1986a_ch2_init },
918 { 4, ad1986a_ch4_init },
919 { 6, ad1986a_ch6_init },
922 /* eapd initialization */
923 static struct hda_verb ad1986a_eapd_init_verbs[] = {
924 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
928 static struct hda_verb ad1986a_automic_verbs[] = {
929 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
930 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
931 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
932 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
933 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
937 /* Ultra initialization */
938 static struct hda_verb ad1986a_ultra_init[] = {
939 /* eapd initialization */
940 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
941 /* CLFE -> Mic in */
942 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
943 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
944 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
945 { } /* end */
948 /* pin sensing on HP jack */
949 static struct hda_verb ad1986a_hp_init_verbs[] = {
950 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
955 /* models */
956 enum {
957 AD1986A_6STACK,
958 AD1986A_3STACK,
959 AD1986A_LAPTOP,
960 AD1986A_LAPTOP_EAPD,
961 AD1986A_LAPTOP_AUTOMUTE,
962 AD1986A_ULTRA,
963 AD1986A_SAMSUNG,
964 AD1986A_MODELS
967 static const char *ad1986a_models[AD1986A_MODELS] = {
968 [AD1986A_6STACK] = "6stack",
969 [AD1986A_3STACK] = "3stack",
970 [AD1986A_LAPTOP] = "laptop",
971 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
972 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
973 [AD1986A_ULTRA] = "ultra",
974 [AD1986A_SAMSUNG] = "samsung",
977 static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
978 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
979 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
980 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
981 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
982 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
983 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
984 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
985 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
986 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
987 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
988 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
989 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
990 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
991 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
992 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
993 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
994 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
995 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
996 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
997 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_SAMSUNG),
998 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_SAMSUNG),
999 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_SAMSUNG),
1000 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
1001 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
1002 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
1003 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
1004 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
1005 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
1009 #ifdef CONFIG_SND_HDA_POWER_SAVE
1010 static struct hda_amp_list ad1986a_loopbacks[] = {
1011 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
1012 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
1013 { 0x15, HDA_OUTPUT, 0 }, /* CD */
1014 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
1015 { 0x17, HDA_OUTPUT, 0 }, /* Line */
1016 { } /* end */
1018 #endif
1020 static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1022 unsigned int conf = snd_hda_codec_read(codec, nid, 0,
1023 AC_VERB_GET_CONFIG_DEFAULT, 0);
1024 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1027 static int patch_ad1986a(struct hda_codec *codec)
1029 struct ad198x_spec *spec;
1030 int board_config;
1032 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1033 if (spec == NULL)
1034 return -ENOMEM;
1036 codec->spec = spec;
1038 spec->multiout.max_channels = 6;
1039 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
1040 spec->multiout.dac_nids = ad1986a_dac_nids;
1041 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
1042 spec->num_adc_nids = 1;
1043 spec->adc_nids = ad1986a_adc_nids;
1044 spec->capsrc_nids = ad1986a_capsrc_nids;
1045 spec->input_mux = &ad1986a_capture_source;
1046 spec->num_mixers = 1;
1047 spec->mixers[0] = ad1986a_mixers;
1048 spec->num_init_verbs = 1;
1049 spec->init_verbs[0] = ad1986a_init_verbs;
1050 #ifdef CONFIG_SND_HDA_POWER_SAVE
1051 spec->loopback.amplist = ad1986a_loopbacks;
1052 #endif
1053 spec->vmaster_nid = 0x1b;
1055 codec->patch_ops = ad198x_patch_ops;
1057 /* override some parameters */
1058 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1059 ad1986a_models,
1060 ad1986a_cfg_tbl);
1061 switch (board_config) {
1062 case AD1986A_3STACK:
1063 spec->num_mixers = 2;
1064 spec->mixers[1] = ad1986a_3st_mixers;
1065 spec->num_init_verbs = 2;
1066 spec->init_verbs[1] = ad1986a_ch2_init;
1067 spec->channel_mode = ad1986a_modes;
1068 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
1069 spec->need_dac_fix = 1;
1070 spec->multiout.max_channels = 2;
1071 spec->multiout.num_dacs = 1;
1072 break;
1073 case AD1986A_LAPTOP:
1074 spec->mixers[0] = ad1986a_laptop_mixers;
1075 spec->multiout.max_channels = 2;
1076 spec->multiout.num_dacs = 1;
1077 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1078 break;
1079 case AD1986A_LAPTOP_EAPD:
1080 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1081 spec->num_init_verbs = 2;
1082 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1083 spec->multiout.max_channels = 2;
1084 spec->multiout.num_dacs = 1;
1085 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1086 if (!is_jack_available(codec, 0x25))
1087 spec->multiout.dig_out_nid = 0;
1088 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1089 break;
1090 case AD1986A_SAMSUNG:
1091 spec->mixers[0] = ad1986a_samsung_mixers;
1092 spec->num_init_verbs = 3;
1093 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1094 spec->init_verbs[2] = ad1986a_automic_verbs;
1095 spec->multiout.max_channels = 2;
1096 spec->multiout.num_dacs = 1;
1097 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1098 if (!is_jack_available(codec, 0x25))
1099 spec->multiout.dig_out_nid = 0;
1100 spec->input_mux = &ad1986a_automic_capture_source;
1101 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1102 codec->patch_ops.init = ad1986a_automic_init;
1103 break;
1104 case AD1986A_LAPTOP_AUTOMUTE:
1105 spec->mixers[0] = ad1986a_laptop_automute_mixers;
1106 spec->num_init_verbs = 3;
1107 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1108 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1109 spec->multiout.max_channels = 2;
1110 spec->multiout.num_dacs = 1;
1111 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1112 if (!is_jack_available(codec, 0x25))
1113 spec->multiout.dig_out_nid = 0;
1114 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1115 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1116 codec->patch_ops.init = ad1986a_hp_init;
1117 break;
1118 case AD1986A_ULTRA:
1119 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1120 spec->num_init_verbs = 2;
1121 spec->init_verbs[1] = ad1986a_ultra_init;
1122 spec->multiout.max_channels = 2;
1123 spec->multiout.num_dacs = 1;
1124 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1125 spec->multiout.dig_out_nid = 0;
1126 break;
1129 /* AD1986A has a hardware problem that it can't share a stream
1130 * with multiple output pins. The copy of front to surrounds
1131 * causes noisy or silent outputs at a certain timing, e.g.
1132 * changing the volume.
1133 * So, let's disable the shared stream.
1135 spec->multiout.no_share_stream = 1;
1137 return 0;
1141 * AD1983 specific
1144 #define AD1983_SPDIF_OUT 0x02
1145 #define AD1983_DAC 0x03
1146 #define AD1983_ADC 0x04
1148 static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
1149 static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
1150 static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
1152 static struct hda_input_mux ad1983_capture_source = {
1153 .num_items = 4,
1154 .items = {
1155 { "Mic", 0x0 },
1156 { "Line", 0x1 },
1157 { "Mix", 0x2 },
1158 { "Mix Mono", 0x3 },
1163 * SPDIF playback route
1165 static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1167 static char *texts[] = { "PCM", "ADC" };
1169 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1170 uinfo->count = 1;
1171 uinfo->value.enumerated.items = 2;
1172 if (uinfo->value.enumerated.item > 1)
1173 uinfo->value.enumerated.item = 1;
1174 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1175 return 0;
1178 static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1180 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1181 struct ad198x_spec *spec = codec->spec;
1183 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1184 return 0;
1187 static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1189 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1190 struct ad198x_spec *spec = codec->spec;
1192 if (ucontrol->value.enumerated.item[0] > 1)
1193 return -EINVAL;
1194 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1195 spec->spdif_route = ucontrol->value.enumerated.item[0];
1196 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1197 AC_VERB_SET_CONNECT_SEL,
1198 spec->spdif_route);
1199 return 1;
1201 return 0;
1204 static struct snd_kcontrol_new ad1983_mixers[] = {
1205 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1206 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1207 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1208 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1209 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1210 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1211 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1212 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1213 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1214 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1215 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1216 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1217 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
1218 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
1219 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1220 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1221 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1223 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1224 .name = "Capture Source",
1225 .info = ad198x_mux_enum_info,
1226 .get = ad198x_mux_enum_get,
1227 .put = ad198x_mux_enum_put,
1230 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1231 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1232 .info = ad1983_spdif_route_info,
1233 .get = ad1983_spdif_route_get,
1234 .put = ad1983_spdif_route_put,
1236 { } /* end */
1239 static struct hda_verb ad1983_init_verbs[] = {
1240 /* Front, HP, Mono; mute as default */
1241 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1242 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1243 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1244 /* Beep, PCM, Mic, Line-In: mute */
1245 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1246 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1247 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1248 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1249 /* Front, HP selectors; from Mix */
1250 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1251 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1252 /* Mono selector; from Mix */
1253 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1254 /* Mic selector; Mic */
1255 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1256 /* Line-in selector: Line-in */
1257 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1258 /* Mic boost: 0dB */
1259 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1260 /* Record selector: mic */
1261 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1262 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1263 /* SPDIF route: PCM */
1264 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1265 /* Front Pin */
1266 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1267 /* HP Pin */
1268 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1269 /* Mono Pin */
1270 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1271 /* Mic Pin */
1272 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1273 /* Line Pin */
1274 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1275 { } /* end */
1278 #ifdef CONFIG_SND_HDA_POWER_SAVE
1279 static struct hda_amp_list ad1983_loopbacks[] = {
1280 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1281 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1282 { } /* end */
1284 #endif
1286 static int patch_ad1983(struct hda_codec *codec)
1288 struct ad198x_spec *spec;
1290 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1291 if (spec == NULL)
1292 return -ENOMEM;
1294 codec->spec = spec;
1296 spec->multiout.max_channels = 2;
1297 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1298 spec->multiout.dac_nids = ad1983_dac_nids;
1299 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
1300 spec->num_adc_nids = 1;
1301 spec->adc_nids = ad1983_adc_nids;
1302 spec->capsrc_nids = ad1983_capsrc_nids;
1303 spec->input_mux = &ad1983_capture_source;
1304 spec->num_mixers = 1;
1305 spec->mixers[0] = ad1983_mixers;
1306 spec->num_init_verbs = 1;
1307 spec->init_verbs[0] = ad1983_init_verbs;
1308 spec->spdif_route = 0;
1309 #ifdef CONFIG_SND_HDA_POWER_SAVE
1310 spec->loopback.amplist = ad1983_loopbacks;
1311 #endif
1312 spec->vmaster_nid = 0x05;
1314 codec->patch_ops = ad198x_patch_ops;
1316 return 0;
1321 * AD1981 HD specific
1324 #define AD1981_SPDIF_OUT 0x02
1325 #define AD1981_DAC 0x03
1326 #define AD1981_ADC 0x04
1328 static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
1329 static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
1330 static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
1332 /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1333 static struct hda_input_mux ad1981_capture_source = {
1334 .num_items = 7,
1335 .items = {
1336 { "Front Mic", 0x0 },
1337 { "Line", 0x1 },
1338 { "Mix", 0x2 },
1339 { "Mix Mono", 0x3 },
1340 { "CD", 0x4 },
1341 { "Mic", 0x6 },
1342 { "Aux", 0x7 },
1346 static struct snd_kcontrol_new ad1981_mixers[] = {
1347 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1348 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1349 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1350 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1351 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1352 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1353 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1354 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1355 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1356 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1357 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1358 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1359 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1360 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1361 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1362 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1364 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1365 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1366 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1367 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1368 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1369 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1370 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1372 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1373 .name = "Capture Source",
1374 .info = ad198x_mux_enum_info,
1375 .get = ad198x_mux_enum_get,
1376 .put = ad198x_mux_enum_put,
1378 /* identical with AD1983 */
1380 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1381 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1382 .info = ad1983_spdif_route_info,
1383 .get = ad1983_spdif_route_get,
1384 .put = ad1983_spdif_route_put,
1386 { } /* end */
1389 static struct hda_verb ad1981_init_verbs[] = {
1390 /* Front, HP, Mono; mute as default */
1391 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1392 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1393 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1394 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1395 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1396 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1397 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1398 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1399 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1400 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1401 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1402 /* Front, HP selectors; from Mix */
1403 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1404 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1405 /* Mono selector; from Mix */
1406 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1407 /* Mic Mixer; select Front Mic */
1408 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1409 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1410 /* Mic boost: 0dB */
1411 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1412 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1413 /* Record selector: Front mic */
1414 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1415 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1416 /* SPDIF route: PCM */
1417 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1418 /* Front Pin */
1419 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1420 /* HP Pin */
1421 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1422 /* Mono Pin */
1423 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1424 /* Front & Rear Mic Pins */
1425 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1426 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1427 /* Line Pin */
1428 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1429 /* Digital Beep */
1430 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1431 /* Line-Out as Input: disabled */
1432 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1433 { } /* end */
1436 #ifdef CONFIG_SND_HDA_POWER_SAVE
1437 static struct hda_amp_list ad1981_loopbacks[] = {
1438 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1439 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1440 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1441 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1442 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1443 { } /* end */
1445 #endif
1448 * Patch for HP nx6320
1450 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
1451 * speaker output enabled _and_ mute-LED off.
1454 #define AD1981_HP_EVENT 0x37
1455 #define AD1981_MIC_EVENT 0x38
1457 static struct hda_verb ad1981_hp_init_verbs[] = {
1458 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1459 /* pin sensing on HP and Mic jacks */
1460 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1461 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1465 /* turn on/off EAPD (+ mute HP) as a master switch */
1466 static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1467 struct snd_ctl_elem_value *ucontrol)
1469 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1470 struct ad198x_spec *spec = codec->spec;
1472 if (! ad198x_eapd_put(kcontrol, ucontrol))
1473 return 0;
1474 /* change speaker pin appropriately */
1475 snd_hda_codec_write(codec, 0x05, 0,
1476 AC_VERB_SET_PIN_WIDGET_CONTROL,
1477 spec->cur_eapd ? PIN_OUT : 0);
1478 /* toggle HP mute appropriately */
1479 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1480 HDA_AMP_MUTE,
1481 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
1482 return 1;
1485 /* bind volumes of both NID 0x05 and 0x06 */
1486 static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1487 .ops = &snd_hda_bind_vol,
1488 .values = {
1489 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1490 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1495 /* mute internal speaker if HP is plugged */
1496 static void ad1981_hp_automute(struct hda_codec *codec)
1498 unsigned int present;
1500 present = snd_hda_codec_read(codec, 0x06, 0,
1501 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1502 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1503 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1506 /* toggle input of built-in and mic jack appropriately */
1507 static void ad1981_hp_automic(struct hda_codec *codec)
1509 static struct hda_verb mic_jack_on[] = {
1510 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1511 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1514 static struct hda_verb mic_jack_off[] = {
1515 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1516 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1519 unsigned int present;
1521 present = snd_hda_codec_read(codec, 0x08, 0,
1522 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1523 if (present)
1524 snd_hda_sequence_write(codec, mic_jack_on);
1525 else
1526 snd_hda_sequence_write(codec, mic_jack_off);
1529 /* unsolicited event for HP jack sensing */
1530 static void ad1981_hp_unsol_event(struct hda_codec *codec,
1531 unsigned int res)
1533 res >>= 26;
1534 switch (res) {
1535 case AD1981_HP_EVENT:
1536 ad1981_hp_automute(codec);
1537 break;
1538 case AD1981_MIC_EVENT:
1539 ad1981_hp_automic(codec);
1540 break;
1544 static struct hda_input_mux ad1981_hp_capture_source = {
1545 .num_items = 3,
1546 .items = {
1547 { "Mic", 0x0 },
1548 { "Docking-Station", 0x1 },
1549 { "Mix", 0x2 },
1553 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1554 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
1556 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1557 .name = "Master Playback Switch",
1558 .info = ad198x_eapd_info,
1559 .get = ad198x_eapd_get,
1560 .put = ad1981_hp_master_sw_put,
1561 .private_value = 0x05,
1563 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1564 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1565 #if 0
1566 /* FIXME: analog mic/line loopback doesn't work with my tests...
1567 * (although recording is OK)
1569 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1570 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1571 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1572 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1573 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1574 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1575 /* FIXME: does this laptop have analog CD connection? */
1576 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1577 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1578 #endif
1579 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1580 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1581 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1582 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1584 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1585 .name = "Capture Source",
1586 .info = ad198x_mux_enum_info,
1587 .get = ad198x_mux_enum_get,
1588 .put = ad198x_mux_enum_put,
1590 { } /* end */
1593 /* initialize jack-sensing, too */
1594 static int ad1981_hp_init(struct hda_codec *codec)
1596 ad198x_init(codec);
1597 ad1981_hp_automute(codec);
1598 ad1981_hp_automic(codec);
1599 return 0;
1602 /* configuration for Toshiba Laptops */
1603 static struct hda_verb ad1981_toshiba_init_verbs[] = {
1604 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1605 /* pin sensing on HP and Mic jacks */
1606 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1607 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1611 static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1612 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1613 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1617 /* configuration for Lenovo Thinkpad T60 */
1618 static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1619 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1620 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1621 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1622 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1623 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1624 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1625 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1626 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1627 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1628 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1629 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1631 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1632 .name = "Capture Source",
1633 .info = ad198x_mux_enum_info,
1634 .get = ad198x_mux_enum_get,
1635 .put = ad198x_mux_enum_put,
1637 /* identical with AD1983 */
1639 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1640 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1641 .info = ad1983_spdif_route_info,
1642 .get = ad1983_spdif_route_get,
1643 .put = ad1983_spdif_route_put,
1645 { } /* end */
1648 static struct hda_input_mux ad1981_thinkpad_capture_source = {
1649 .num_items = 3,
1650 .items = {
1651 { "Mic", 0x0 },
1652 { "Mix", 0x2 },
1653 { "CD", 0x4 },
1657 /* models */
1658 enum {
1659 AD1981_BASIC,
1660 AD1981_HP,
1661 AD1981_THINKPAD,
1662 AD1981_TOSHIBA,
1663 AD1981_MODELS
1666 static const char *ad1981_models[AD1981_MODELS] = {
1667 [AD1981_HP] = "hp",
1668 [AD1981_THINKPAD] = "thinkpad",
1669 [AD1981_BASIC] = "basic",
1670 [AD1981_TOSHIBA] = "toshiba"
1673 static struct snd_pci_quirk ad1981_cfg_tbl[] = {
1674 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
1675 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
1676 /* All HP models */
1677 SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
1678 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
1679 /* Lenovo Thinkpad T60/X60/Z6xx */
1680 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
1681 /* HP nx6320 (reversed SSID, H/W bug) */
1682 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
1686 static int patch_ad1981(struct hda_codec *codec)
1688 struct ad198x_spec *spec;
1689 int board_config;
1691 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1692 if (spec == NULL)
1693 return -ENOMEM;
1695 codec->spec = spec;
1697 spec->multiout.max_channels = 2;
1698 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1699 spec->multiout.dac_nids = ad1981_dac_nids;
1700 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
1701 spec->num_adc_nids = 1;
1702 spec->adc_nids = ad1981_adc_nids;
1703 spec->capsrc_nids = ad1981_capsrc_nids;
1704 spec->input_mux = &ad1981_capture_source;
1705 spec->num_mixers = 1;
1706 spec->mixers[0] = ad1981_mixers;
1707 spec->num_init_verbs = 1;
1708 spec->init_verbs[0] = ad1981_init_verbs;
1709 spec->spdif_route = 0;
1710 #ifdef CONFIG_SND_HDA_POWER_SAVE
1711 spec->loopback.amplist = ad1981_loopbacks;
1712 #endif
1713 spec->vmaster_nid = 0x05;
1715 codec->patch_ops = ad198x_patch_ops;
1717 /* override some parameters */
1718 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1719 ad1981_models,
1720 ad1981_cfg_tbl);
1721 switch (board_config) {
1722 case AD1981_HP:
1723 spec->mixers[0] = ad1981_hp_mixers;
1724 spec->num_init_verbs = 2;
1725 spec->init_verbs[1] = ad1981_hp_init_verbs;
1726 spec->multiout.dig_out_nid = 0;
1727 spec->input_mux = &ad1981_hp_capture_source;
1729 codec->patch_ops.init = ad1981_hp_init;
1730 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1731 break;
1732 case AD1981_THINKPAD:
1733 spec->mixers[0] = ad1981_thinkpad_mixers;
1734 spec->input_mux = &ad1981_thinkpad_capture_source;
1735 break;
1736 case AD1981_TOSHIBA:
1737 spec->mixers[0] = ad1981_hp_mixers;
1738 spec->mixers[1] = ad1981_toshiba_mixers;
1739 spec->num_init_verbs = 2;
1740 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1741 spec->multiout.dig_out_nid = 0;
1742 spec->input_mux = &ad1981_hp_capture_source;
1743 codec->patch_ops.init = ad1981_hp_init;
1744 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1745 break;
1747 return 0;
1752 * AD1988
1754 * Output pins and routes
1756 * Pin Mix Sel DAC (*)
1757 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1758 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1759 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1760 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1761 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1762 * port-F 0x16 (mute) <- 0x2a <- 06
1763 * port-G 0x24 (mute) <- 0x27 <- 05
1764 * port-H 0x25 (mute) <- 0x28 <- 0a
1765 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1767 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1768 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
1770 * Input pins and routes
1772 * pin boost mix input # / adc input #
1773 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1774 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1775 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1776 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1777 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1778 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1779 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1780 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1783 * DAC assignment
1784 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
1785 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
1787 * Inputs of Analog Mix (0x20)
1788 * 0:Port-B (front mic)
1789 * 1:Port-C/G/H (line-in)
1790 * 2:Port-A
1791 * 3:Port-D (line-in/2)
1792 * 4:Port-E/G/H (mic-in)
1793 * 5:Port-F (mic2-in)
1794 * 6:CD
1795 * 7:Beep
1797 * ADC selection
1798 * 0:Port-A
1799 * 1:Port-B (front mic-in)
1800 * 2:Port-C (line-in)
1801 * 3:Port-F (mic2-in)
1802 * 4:Port-E (mic-in)
1803 * 5:CD
1804 * 6:Port-G
1805 * 7:Port-H
1806 * 8:Port-D (line-in/2)
1807 * 9:Mix
1809 * Proposed pin assignments by the datasheet
1811 * 6-stack
1812 * Port-A front headphone
1813 * B front mic-in
1814 * C rear line-in
1815 * D rear front-out
1816 * E rear mic-in
1817 * F rear surround
1818 * G rear CLFE
1819 * H rear side
1821 * 3-stack
1822 * Port-A front headphone
1823 * B front mic
1824 * C rear line-in/surround
1825 * D rear front-out
1826 * E rear mic-in/CLFE
1828 * laptop
1829 * Port-A headphone
1830 * B mic-in
1831 * C docking station
1832 * D internal speaker (with EAPD)
1833 * E/F quad mic array
1837 /* models */
1838 enum {
1839 AD1988_6STACK,
1840 AD1988_6STACK_DIG,
1841 AD1988_3STACK,
1842 AD1988_3STACK_DIG,
1843 AD1988_LAPTOP,
1844 AD1988_LAPTOP_DIG,
1845 AD1988_AUTO,
1846 AD1988_MODEL_LAST,
1849 /* reivision id to check workarounds */
1850 #define AD1988A_REV2 0x100200
1852 #define is_rev2(codec) \
1853 ((codec)->vendor_id == 0x11d41988 && \
1854 (codec)->revision_id == AD1988A_REV2)
1857 * mixers
1860 static hda_nid_t ad1988_6stack_dac_nids[4] = {
1861 0x04, 0x06, 0x05, 0x0a
1864 static hda_nid_t ad1988_3stack_dac_nids[3] = {
1865 0x04, 0x05, 0x0a
1868 /* for AD1988A revision-2, DAC2-4 are swapped */
1869 static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1870 0x04, 0x05, 0x0a, 0x06
1873 static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
1874 0x04, 0x0a, 0x06
1877 static hda_nid_t ad1988_adc_nids[3] = {
1878 0x08, 0x09, 0x0f
1881 static hda_nid_t ad1988_capsrc_nids[3] = {
1882 0x0c, 0x0d, 0x0e
1885 #define AD1988_SPDIF_OUT 0x02
1886 #define AD1988_SPDIF_OUT_HDMI 0x0b
1887 #define AD1988_SPDIF_IN 0x07
1889 static hda_nid_t ad1989b_slave_dig_outs[2] = {
1890 AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI
1893 static struct hda_input_mux ad1988_6stack_capture_source = {
1894 .num_items = 5,
1895 .items = {
1896 { "Front Mic", 0x1 }, /* port-B */
1897 { "Line", 0x2 }, /* port-C */
1898 { "Mic", 0x4 }, /* port-E */
1899 { "CD", 0x5 },
1900 { "Mix", 0x9 },
1904 static struct hda_input_mux ad1988_laptop_capture_source = {
1905 .num_items = 3,
1906 .items = {
1907 { "Mic/Line", 0x1 }, /* port-B */
1908 { "CD", 0x5 },
1909 { "Mix", 0x9 },
1915 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1916 struct snd_ctl_elem_info *uinfo)
1918 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1919 struct ad198x_spec *spec = codec->spec;
1920 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1921 spec->num_channel_mode);
1924 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1925 struct snd_ctl_elem_value *ucontrol)
1927 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1928 struct ad198x_spec *spec = codec->spec;
1929 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1930 spec->num_channel_mode, spec->multiout.max_channels);
1933 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1934 struct snd_ctl_elem_value *ucontrol)
1936 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1937 struct ad198x_spec *spec = codec->spec;
1938 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1939 spec->num_channel_mode,
1940 &spec->multiout.max_channels);
1941 if (err >= 0 && spec->need_dac_fix)
1942 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
1943 return err;
1946 /* 6-stack mode */
1947 static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
1948 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1949 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1950 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1951 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1952 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1953 { } /* end */
1956 static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1957 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1958 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1959 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1960 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1961 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1962 { } /* end */
1965 static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
1966 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1967 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1968 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1969 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1970 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1971 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1972 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1974 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1975 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1976 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1977 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1978 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1979 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1980 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1981 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1983 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1984 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1986 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1987 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1989 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1990 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1992 { } /* end */
1995 /* 3-stack mode */
1996 static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
1997 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1998 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1999 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2000 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2001 { } /* end */
2004 static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
2005 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2006 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2007 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
2008 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
2009 { } /* end */
2012 static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
2013 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2014 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
2015 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
2016 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
2017 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2018 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2020 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2021 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2022 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2023 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2024 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2025 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2026 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2027 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2029 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2030 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2032 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2033 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2035 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2036 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2038 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2039 .name = "Channel Mode",
2040 .info = ad198x_ch_mode_info,
2041 .get = ad198x_ch_mode_get,
2042 .put = ad198x_ch_mode_put,
2045 { } /* end */
2048 /* laptop mode */
2049 static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2050 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2051 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
2052 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2054 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2055 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2056 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2057 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2058 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2059 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2061 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2062 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2064 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2065 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2067 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2070 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2071 .name = "External Amplifier",
2072 .info = ad198x_eapd_info,
2073 .get = ad198x_eapd_get,
2074 .put = ad198x_eapd_put,
2075 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
2078 { } /* end */
2081 /* capture */
2082 static struct snd_kcontrol_new ad1988_capture_mixers[] = {
2083 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2084 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2085 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2086 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2087 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2088 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2090 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2091 /* The multiple "Capture Source" controls confuse alsamixer
2092 * So call somewhat different..
2094 /* .name = "Capture Source", */
2095 .name = "Input Source",
2096 .count = 3,
2097 .info = ad198x_mux_enum_info,
2098 .get = ad198x_mux_enum_get,
2099 .put = ad198x_mux_enum_put,
2101 { } /* end */
2104 static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2105 struct snd_ctl_elem_info *uinfo)
2107 static char *texts[] = {
2108 "PCM", "ADC1", "ADC2", "ADC3"
2110 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2111 uinfo->count = 1;
2112 uinfo->value.enumerated.items = 4;
2113 if (uinfo->value.enumerated.item >= 4)
2114 uinfo->value.enumerated.item = 3;
2115 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2116 return 0;
2119 static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2120 struct snd_ctl_elem_value *ucontrol)
2122 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2123 unsigned int sel;
2125 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2126 AC_AMP_GET_INPUT);
2127 if (!(sel & 0x80))
2128 ucontrol->value.enumerated.item[0] = 0;
2129 else {
2130 sel = snd_hda_codec_read(codec, 0x0b, 0,
2131 AC_VERB_GET_CONNECT_SEL, 0);
2132 if (sel < 3)
2133 sel++;
2134 else
2135 sel = 0;
2136 ucontrol->value.enumerated.item[0] = sel;
2138 return 0;
2141 static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2142 struct snd_ctl_elem_value *ucontrol)
2144 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2145 unsigned int val, sel;
2146 int change;
2148 val = ucontrol->value.enumerated.item[0];
2149 if (val > 3)
2150 return -EINVAL;
2151 if (!val) {
2152 sel = snd_hda_codec_read(codec, 0x1d, 0,
2153 AC_VERB_GET_AMP_GAIN_MUTE,
2154 AC_AMP_GET_INPUT);
2155 change = sel & 0x80;
2156 if (change) {
2157 snd_hda_codec_write_cache(codec, 0x1d, 0,
2158 AC_VERB_SET_AMP_GAIN_MUTE,
2159 AMP_IN_UNMUTE(0));
2160 snd_hda_codec_write_cache(codec, 0x1d, 0,
2161 AC_VERB_SET_AMP_GAIN_MUTE,
2162 AMP_IN_MUTE(1));
2164 } else {
2165 sel = snd_hda_codec_read(codec, 0x1d, 0,
2166 AC_VERB_GET_AMP_GAIN_MUTE,
2167 AC_AMP_GET_INPUT | 0x01);
2168 change = sel & 0x80;
2169 if (change) {
2170 snd_hda_codec_write_cache(codec, 0x1d, 0,
2171 AC_VERB_SET_AMP_GAIN_MUTE,
2172 AMP_IN_MUTE(0));
2173 snd_hda_codec_write_cache(codec, 0x1d, 0,
2174 AC_VERB_SET_AMP_GAIN_MUTE,
2175 AMP_IN_UNMUTE(1));
2177 sel = snd_hda_codec_read(codec, 0x0b, 0,
2178 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2179 change |= sel != val;
2180 if (change)
2181 snd_hda_codec_write_cache(codec, 0x0b, 0,
2182 AC_VERB_SET_CONNECT_SEL,
2183 val - 1);
2185 return change;
2188 static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2189 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2191 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2192 .name = "IEC958 Playback Source",
2193 .info = ad1988_spdif_playback_source_info,
2194 .get = ad1988_spdif_playback_source_get,
2195 .put = ad1988_spdif_playback_source_put,
2197 { } /* end */
2200 static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2201 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2202 { } /* end */
2205 static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2206 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2207 HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
2208 { } /* end */
2212 * initialization verbs
2216 * for 6-stack (+dig)
2218 static struct hda_verb ad1988_6stack_init_verbs[] = {
2219 /* Front, Surround, CLFE, side DAC; unmute as default */
2220 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2221 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2222 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2223 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2224 /* Port-A front headphon path */
2225 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2226 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2227 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2228 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2229 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2230 /* Port-D line-out path */
2231 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2232 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2233 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2234 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2235 /* Port-F surround path */
2236 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2237 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2238 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2239 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2240 /* Port-G CLFE path */
2241 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2242 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2243 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2244 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2245 /* Port-H side path */
2246 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2247 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2248 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2249 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2250 /* Mono out path */
2251 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2252 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2253 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2254 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2255 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2256 /* Port-B front mic-in path */
2257 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2258 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2259 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2260 /* Port-C line-in path */
2261 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2262 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2263 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2264 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2265 /* Port-E mic-in path */
2266 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2267 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2268 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2269 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2270 /* Analog CD Input */
2271 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2272 /* Analog Mix output amp */
2273 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2278 static struct hda_verb ad1988_capture_init_verbs[] = {
2279 /* mute analog mix */
2280 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2281 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2282 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2283 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2284 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2285 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2286 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2287 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2288 /* select ADCs - front-mic */
2289 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2290 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2291 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2292 /* ADCs; muted */
2293 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2294 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2295 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2300 static struct hda_verb ad1988_spdif_init_verbs[] = {
2301 /* SPDIF out sel */
2302 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2303 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2304 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2305 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2306 /* SPDIF out pin */
2307 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2312 /* AD1989 has no ADC -> SPDIF route */
2313 static struct hda_verb ad1989_spdif_init_verbs[] = {
2314 /* SPDIF-1 out pin */
2315 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2316 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2317 /* SPDIF-2/HDMI out pin */
2318 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2319 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2324 * verbs for 3stack (+dig)
2326 static struct hda_verb ad1988_3stack_ch2_init[] = {
2327 /* set port-C to line-in */
2328 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2329 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2330 /* set port-E to mic-in */
2331 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2332 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2333 { } /* end */
2336 static struct hda_verb ad1988_3stack_ch6_init[] = {
2337 /* set port-C to surround out */
2338 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2339 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2340 /* set port-E to CLFE out */
2341 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2342 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2343 { } /* end */
2346 static struct hda_channel_mode ad1988_3stack_modes[2] = {
2347 { 2, ad1988_3stack_ch2_init },
2348 { 6, ad1988_3stack_ch6_init },
2351 static struct hda_verb ad1988_3stack_init_verbs[] = {
2352 /* Front, Surround, CLFE, side DAC; unmute as default */
2353 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2354 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2355 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2356 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2357 /* Port-A front headphon path */
2358 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2359 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2360 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2361 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2362 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2363 /* Port-D line-out path */
2364 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2365 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2366 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2367 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2368 /* Mono out path */
2369 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2370 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2371 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2372 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2373 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2374 /* Port-B front mic-in path */
2375 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2376 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2377 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2378 /* Port-C line-in/surround path - 6ch mode as default */
2379 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2380 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2381 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2382 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
2383 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2384 /* Port-E mic-in/CLFE path - 6ch mode as default */
2385 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2386 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2387 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2388 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
2389 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2390 /* mute analog mix */
2391 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2392 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2393 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2394 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2395 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2396 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2397 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2398 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2399 /* select ADCs - front-mic */
2400 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2401 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2402 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2403 /* ADCs; muted */
2404 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2405 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2406 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2407 /* Analog Mix output amp */
2408 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2413 * verbs for laptop mode (+dig)
2415 static struct hda_verb ad1988_laptop_hp_on[] = {
2416 /* unmute port-A and mute port-D */
2417 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2418 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2419 { } /* end */
2421 static struct hda_verb ad1988_laptop_hp_off[] = {
2422 /* mute port-A and unmute port-D */
2423 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2424 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2425 { } /* end */
2428 #define AD1988_HP_EVENT 0x01
2430 static struct hda_verb ad1988_laptop_init_verbs[] = {
2431 /* Front, Surround, CLFE, side DAC; unmute as default */
2432 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2433 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2434 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2435 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2436 /* Port-A front headphon path */
2437 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2438 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2439 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2440 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2441 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2442 /* unsolicited event for pin-sense */
2443 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2444 /* Port-D line-out path + EAPD */
2445 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2446 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2447 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2448 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2449 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2450 /* Mono out path */
2451 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2452 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2453 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2454 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2455 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2456 /* Port-B mic-in path */
2457 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2458 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2459 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2460 /* Port-C docking station - try to output */
2461 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2462 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2463 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2464 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2465 /* mute analog mix */
2466 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2467 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2468 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2469 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2470 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2471 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2472 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2473 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2474 /* select ADCs - mic */
2475 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2476 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2477 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2478 /* ADCs; muted */
2479 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2480 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2481 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2482 /* Analog Mix output amp */
2483 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2487 static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2489 if ((res >> 26) != AD1988_HP_EVENT)
2490 return;
2491 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2492 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2493 else
2494 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2497 #ifdef CONFIG_SND_HDA_POWER_SAVE
2498 static struct hda_amp_list ad1988_loopbacks[] = {
2499 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2500 { 0x20, HDA_INPUT, 1 }, /* Line */
2501 { 0x20, HDA_INPUT, 4 }, /* Mic */
2502 { 0x20, HDA_INPUT, 6 }, /* CD */
2503 { } /* end */
2505 #endif
2508 * Automatic parse of I/O pins from the BIOS configuration
2511 enum {
2512 AD_CTL_WIDGET_VOL,
2513 AD_CTL_WIDGET_MUTE,
2514 AD_CTL_BIND_MUTE,
2516 static struct snd_kcontrol_new ad1988_control_templates[] = {
2517 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2518 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2519 HDA_BIND_MUTE(NULL, 0, 0, 0),
2522 /* add dynamic controls */
2523 static int add_control(struct ad198x_spec *spec, int type, const char *name,
2524 unsigned long val)
2526 struct snd_kcontrol_new *knew;
2528 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2529 knew = snd_array_new(&spec->kctls);
2530 if (!knew)
2531 return -ENOMEM;
2532 *knew = ad1988_control_templates[type];
2533 knew->name = kstrdup(name, GFP_KERNEL);
2534 if (! knew->name)
2535 return -ENOMEM;
2536 knew->private_value = val;
2537 return 0;
2540 #define AD1988_PIN_CD_NID 0x18
2541 #define AD1988_PIN_BEEP_NID 0x10
2543 static hda_nid_t ad1988_mixer_nids[8] = {
2544 /* A B C D E F G H */
2545 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2548 static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2550 static hda_nid_t idx_to_dac[8] = {
2551 /* A B C D E F G H */
2552 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
2554 static hda_nid_t idx_to_dac_rev2[8] = {
2555 /* A B C D E F G H */
2556 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
2558 if (is_rev2(codec))
2559 return idx_to_dac_rev2[idx];
2560 else
2561 return idx_to_dac[idx];
2564 static hda_nid_t ad1988_boost_nids[8] = {
2565 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2568 static int ad1988_pin_idx(hda_nid_t nid)
2570 static hda_nid_t ad1988_io_pins[8] = {
2571 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2573 int i;
2574 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2575 if (ad1988_io_pins[i] == nid)
2576 return i;
2577 return 0; /* should be -1 */
2580 static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2582 static int loopback_idx[8] = {
2583 2, 0, 1, 3, 4, 5, 1, 4
2585 switch (nid) {
2586 case AD1988_PIN_CD_NID:
2587 return 6;
2588 default:
2589 return loopback_idx[ad1988_pin_idx(nid)];
2593 static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2595 static int adc_idx[8] = {
2596 0, 1, 2, 8, 4, 3, 6, 7
2598 switch (nid) {
2599 case AD1988_PIN_CD_NID:
2600 return 5;
2601 default:
2602 return adc_idx[ad1988_pin_idx(nid)];
2606 /* fill in the dac_nids table from the parsed pin configuration */
2607 static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2608 const struct auto_pin_cfg *cfg)
2610 struct ad198x_spec *spec = codec->spec;
2611 int i, idx;
2613 spec->multiout.dac_nids = spec->private_dac_nids;
2615 /* check the pins hardwired to audio widget */
2616 for (i = 0; i < cfg->line_outs; i++) {
2617 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2618 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2620 spec->multiout.num_dacs = cfg->line_outs;
2621 return 0;
2624 /* add playback controls from the parsed DAC table */
2625 static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2626 const struct auto_pin_cfg *cfg)
2628 char name[32];
2629 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2630 hda_nid_t nid;
2631 int i, err;
2633 for (i = 0; i < cfg->line_outs; i++) {
2634 hda_nid_t dac = spec->multiout.dac_nids[i];
2635 if (! dac)
2636 continue;
2637 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2638 if (i == 2) {
2639 /* Center/LFE */
2640 err = add_control(spec, AD_CTL_WIDGET_VOL,
2641 "Center Playback Volume",
2642 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2643 if (err < 0)
2644 return err;
2645 err = add_control(spec, AD_CTL_WIDGET_VOL,
2646 "LFE Playback Volume",
2647 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2648 if (err < 0)
2649 return err;
2650 err = add_control(spec, AD_CTL_BIND_MUTE,
2651 "Center Playback Switch",
2652 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2653 if (err < 0)
2654 return err;
2655 err = add_control(spec, AD_CTL_BIND_MUTE,
2656 "LFE Playback Switch",
2657 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2658 if (err < 0)
2659 return err;
2660 } else {
2661 sprintf(name, "%s Playback Volume", chname[i]);
2662 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2663 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2664 if (err < 0)
2665 return err;
2666 sprintf(name, "%s Playback Switch", chname[i]);
2667 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2668 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2669 if (err < 0)
2670 return err;
2673 return 0;
2676 /* add playback controls for speaker and HP outputs */
2677 static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2678 const char *pfx)
2680 struct ad198x_spec *spec = codec->spec;
2681 hda_nid_t nid;
2682 int i, idx, err;
2683 char name[32];
2685 if (! pin)
2686 return 0;
2688 idx = ad1988_pin_idx(pin);
2689 nid = ad1988_idx_to_dac(codec, idx);
2690 /* check whether the corresponding DAC was already taken */
2691 for (i = 0; i < spec->autocfg.line_outs; i++) {
2692 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2693 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
2694 if (dac == nid)
2695 break;
2697 if (i >= spec->autocfg.line_outs) {
2698 /* specify the DAC as the extra output */
2699 if (!spec->multiout.hp_nid)
2700 spec->multiout.hp_nid = nid;
2701 else
2702 spec->multiout.extra_out_nid[0] = nid;
2703 /* control HP volume/switch on the output mixer amp */
2704 sprintf(name, "%s Playback Volume", pfx);
2705 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2706 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2707 if (err < 0)
2708 return err;
2710 nid = ad1988_mixer_nids[idx];
2711 sprintf(name, "%s Playback Switch", pfx);
2712 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2713 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2714 return err;
2715 return 0;
2718 /* create input playback/capture controls for the given pin */
2719 static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2720 const char *ctlname, int boost)
2722 char name[32];
2723 int err, idx;
2725 sprintf(name, "%s Playback Volume", ctlname);
2726 idx = ad1988_pin_to_loopback_idx(pin);
2727 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2728 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2729 return err;
2730 sprintf(name, "%s Playback Switch", ctlname);
2731 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2732 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2733 return err;
2734 if (boost) {
2735 hda_nid_t bnid;
2736 idx = ad1988_pin_idx(pin);
2737 bnid = ad1988_boost_nids[idx];
2738 if (bnid) {
2739 sprintf(name, "%s Boost", ctlname);
2740 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2741 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2745 return 0;
2748 /* create playback/capture controls for input pins */
2749 static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2750 const struct auto_pin_cfg *cfg)
2752 struct hda_input_mux *imux = &spec->private_imux;
2753 int i, err;
2755 for (i = 0; i < AUTO_PIN_LAST; i++) {
2756 err = new_analog_input(spec, cfg->input_pins[i],
2757 auto_pin_cfg_labels[i],
2758 i <= AUTO_PIN_FRONT_MIC);
2759 if (err < 0)
2760 return err;
2761 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2762 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2763 imux->num_items++;
2765 imux->items[imux->num_items].label = "Mix";
2766 imux->items[imux->num_items].index = 9;
2767 imux->num_items++;
2769 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2770 "Analog Mix Playback Volume",
2771 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2772 return err;
2773 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2774 "Analog Mix Playback Switch",
2775 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2776 return err;
2778 return 0;
2781 static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2782 hda_nid_t nid, int pin_type,
2783 int dac_idx)
2785 /* set as output */
2786 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2787 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2788 switch (nid) {
2789 case 0x11: /* port-A - DAC 04 */
2790 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2791 break;
2792 case 0x14: /* port-B - DAC 06 */
2793 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2794 break;
2795 case 0x15: /* port-C - DAC 05 */
2796 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2797 break;
2798 case 0x17: /* port-E - DAC 0a */
2799 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2800 break;
2801 case 0x13: /* mono - DAC 04 */
2802 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2803 break;
2807 static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2809 struct ad198x_spec *spec = codec->spec;
2810 int i;
2812 for (i = 0; i < spec->autocfg.line_outs; i++) {
2813 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2814 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2818 static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2820 struct ad198x_spec *spec = codec->spec;
2821 hda_nid_t pin;
2823 pin = spec->autocfg.speaker_pins[0];
2824 if (pin) /* connect to front */
2825 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2826 pin = spec->autocfg.hp_pins[0];
2827 if (pin) /* connect to front */
2828 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2831 static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2833 struct ad198x_spec *spec = codec->spec;
2834 int i, idx;
2836 for (i = 0; i < AUTO_PIN_LAST; i++) {
2837 hda_nid_t nid = spec->autocfg.input_pins[i];
2838 if (! nid)
2839 continue;
2840 switch (nid) {
2841 case 0x15: /* port-C */
2842 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2843 break;
2844 case 0x17: /* port-E */
2845 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2846 break;
2848 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2849 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2850 if (nid != AD1988_PIN_CD_NID)
2851 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2852 AMP_OUT_MUTE);
2853 idx = ad1988_pin_idx(nid);
2854 if (ad1988_boost_nids[idx])
2855 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2856 AC_VERB_SET_AMP_GAIN_MUTE,
2857 AMP_OUT_ZERO);
2861 /* parse the BIOS configuration and set up the alc_spec */
2862 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2863 static int ad1988_parse_auto_config(struct hda_codec *codec)
2865 struct ad198x_spec *spec = codec->spec;
2866 int err;
2868 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2869 return err;
2870 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2871 return err;
2872 if (! spec->autocfg.line_outs)
2873 return 0; /* can't find valid BIOS pin config */
2874 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2875 (err = ad1988_auto_create_extra_out(codec,
2876 spec->autocfg.speaker_pins[0],
2877 "Speaker")) < 0 ||
2878 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
2879 "Headphone")) < 0 ||
2880 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2881 return err;
2883 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2885 if (spec->autocfg.dig_out_pin)
2886 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2887 if (spec->autocfg.dig_in_pin)
2888 spec->dig_in_nid = AD1988_SPDIF_IN;
2890 if (spec->kctls.list)
2891 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2893 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2895 spec->input_mux = &spec->private_imux;
2897 return 1;
2900 /* init callback for auto-configuration model -- overriding the default init */
2901 static int ad1988_auto_init(struct hda_codec *codec)
2903 ad198x_init(codec);
2904 ad1988_auto_init_multi_out(codec);
2905 ad1988_auto_init_extra_out(codec);
2906 ad1988_auto_init_analog_input(codec);
2907 return 0;
2914 static const char *ad1988_models[AD1988_MODEL_LAST] = {
2915 [AD1988_6STACK] = "6stack",
2916 [AD1988_6STACK_DIG] = "6stack-dig",
2917 [AD1988_3STACK] = "3stack",
2918 [AD1988_3STACK_DIG] = "3stack-dig",
2919 [AD1988_LAPTOP] = "laptop",
2920 [AD1988_LAPTOP_DIG] = "laptop-dig",
2921 [AD1988_AUTO] = "auto",
2924 static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2925 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
2926 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
2927 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
2928 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
2932 static int patch_ad1988(struct hda_codec *codec)
2934 struct ad198x_spec *spec;
2935 int board_config;
2937 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2938 if (spec == NULL)
2939 return -ENOMEM;
2941 codec->spec = spec;
2943 if (is_rev2(codec))
2944 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2946 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
2947 ad1988_models, ad1988_cfg_tbl);
2948 if (board_config < 0) {
2949 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2950 board_config = AD1988_AUTO;
2953 if (board_config == AD1988_AUTO) {
2954 /* automatic parse from the BIOS config */
2955 int err = ad1988_parse_auto_config(codec);
2956 if (err < 0) {
2957 ad198x_free(codec);
2958 return err;
2959 } else if (! err) {
2960 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2961 board_config = AD1988_6STACK;
2965 switch (board_config) {
2966 case AD1988_6STACK:
2967 case AD1988_6STACK_DIG:
2968 spec->multiout.max_channels = 8;
2969 spec->multiout.num_dacs = 4;
2970 if (is_rev2(codec))
2971 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2972 else
2973 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
2974 spec->input_mux = &ad1988_6stack_capture_source;
2975 spec->num_mixers = 2;
2976 if (is_rev2(codec))
2977 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2978 else
2979 spec->mixers[0] = ad1988_6stack_mixers1;
2980 spec->mixers[1] = ad1988_6stack_mixers2;
2981 spec->num_init_verbs = 1;
2982 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2983 if (board_config == AD1988_6STACK_DIG) {
2984 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2985 spec->dig_in_nid = AD1988_SPDIF_IN;
2987 break;
2988 case AD1988_3STACK:
2989 case AD1988_3STACK_DIG:
2990 spec->multiout.max_channels = 6;
2991 spec->multiout.num_dacs = 3;
2992 if (is_rev2(codec))
2993 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2994 else
2995 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2996 spec->input_mux = &ad1988_6stack_capture_source;
2997 spec->channel_mode = ad1988_3stack_modes;
2998 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
2999 spec->num_mixers = 2;
3000 if (is_rev2(codec))
3001 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
3002 else
3003 spec->mixers[0] = ad1988_3stack_mixers1;
3004 spec->mixers[1] = ad1988_3stack_mixers2;
3005 spec->num_init_verbs = 1;
3006 spec->init_verbs[0] = ad1988_3stack_init_verbs;
3007 if (board_config == AD1988_3STACK_DIG)
3008 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3009 break;
3010 case AD1988_LAPTOP:
3011 case AD1988_LAPTOP_DIG:
3012 spec->multiout.max_channels = 2;
3013 spec->multiout.num_dacs = 1;
3014 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
3015 spec->input_mux = &ad1988_laptop_capture_source;
3016 spec->num_mixers = 1;
3017 spec->mixers[0] = ad1988_laptop_mixers;
3018 spec->num_init_verbs = 1;
3019 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3020 if (board_config == AD1988_LAPTOP_DIG)
3021 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3022 break;
3025 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3026 spec->adc_nids = ad1988_adc_nids;
3027 spec->capsrc_nids = ad1988_capsrc_nids;
3028 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
3029 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
3030 if (spec->multiout.dig_out_nid) {
3031 if (codec->vendor_id >= 0x11d4989a) {
3032 spec->mixers[spec->num_mixers++] =
3033 ad1989_spdif_out_mixers;
3034 spec->init_verbs[spec->num_init_verbs++] =
3035 ad1989_spdif_init_verbs;
3036 codec->slave_dig_outs = ad1989b_slave_dig_outs;
3037 } else {
3038 spec->mixers[spec->num_mixers++] =
3039 ad1988_spdif_out_mixers;
3040 spec->init_verbs[spec->num_init_verbs++] =
3041 ad1988_spdif_init_verbs;
3044 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
3045 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
3047 codec->patch_ops = ad198x_patch_ops;
3048 switch (board_config) {
3049 case AD1988_AUTO:
3050 codec->patch_ops.init = ad1988_auto_init;
3051 break;
3052 case AD1988_LAPTOP:
3053 case AD1988_LAPTOP_DIG:
3054 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
3055 break;
3057 #ifdef CONFIG_SND_HDA_POWER_SAVE
3058 spec->loopback.amplist = ad1988_loopbacks;
3059 #endif
3060 spec->vmaster_nid = 0x04;
3062 return 0;
3067 * AD1884 / AD1984
3069 * port-B - front line/mic-in
3070 * port-E - aux in/out
3071 * port-F - aux in/out
3072 * port-C - rear line/mic-in
3073 * port-D - rear line/hp-out
3074 * port-A - front line/hp-out
3076 * AD1984 = AD1884 + two digital mic-ins
3078 * FIXME:
3079 * For simplicity, we share the single DAC for both HP and line-outs
3080 * right now. The inidividual playbacks could be easily implemented,
3081 * but no build-up framework is given, so far.
3084 static hda_nid_t ad1884_dac_nids[1] = {
3085 0x04,
3088 static hda_nid_t ad1884_adc_nids[2] = {
3089 0x08, 0x09,
3092 static hda_nid_t ad1884_capsrc_nids[2] = {
3093 0x0c, 0x0d,
3096 #define AD1884_SPDIF_OUT 0x02
3098 static struct hda_input_mux ad1884_capture_source = {
3099 .num_items = 4,
3100 .items = {
3101 { "Front Mic", 0x0 },
3102 { "Mic", 0x1 },
3103 { "CD", 0x2 },
3104 { "Mix", 0x3 },
3108 static struct snd_kcontrol_new ad1884_base_mixers[] = {
3109 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3110 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3111 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3112 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3113 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3114 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3115 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3116 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3117 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3118 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3119 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3120 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3122 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
3123 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
3124 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
3125 HDA_CODEC_MUTE("Digital Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3127 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3128 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3129 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3130 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3131 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3132 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3134 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3135 /* The multiple "Capture Source" controls confuse alsamixer
3136 * So call somewhat different..
3138 /* .name = "Capture Source", */
3139 .name = "Input Source",
3140 .count = 2,
3141 .info = ad198x_mux_enum_info,
3142 .get = ad198x_mux_enum_get,
3143 .put = ad198x_mux_enum_put,
3145 /* SPDIF controls */
3146 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3148 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3149 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3150 /* identical with ad1983 */
3151 .info = ad1983_spdif_route_info,
3152 .get = ad1983_spdif_route_get,
3153 .put = ad1983_spdif_route_put,
3155 { } /* end */
3158 static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3159 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3160 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3161 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
3162 HDA_INPUT),
3163 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
3164 HDA_INPUT),
3165 { } /* end */
3169 * initialization verbs
3171 static struct hda_verb ad1884_init_verbs[] = {
3172 /* DACs; mute as default */
3173 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3174 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3175 /* Port-A (HP) mixer */
3176 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3177 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3178 /* Port-A pin */
3179 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3180 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3181 /* HP selector - select DAC2 */
3182 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3183 /* Port-D (Line-out) mixer */
3184 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3185 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3186 /* Port-D pin */
3187 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3188 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3189 /* Mono-out mixer */
3190 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3191 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3192 /* Mono-out pin */
3193 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3194 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3195 /* Mono selector */
3196 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3197 /* Port-B (front mic) pin */
3198 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3199 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3200 /* Port-C (rear mic) pin */
3201 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3202 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3203 /* Analog mixer; mute as default */
3204 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3205 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3206 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3207 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3208 /* Analog Mix output amp */
3209 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3210 /* SPDIF output selector */
3211 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3212 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3213 { } /* end */
3216 #ifdef CONFIG_SND_HDA_POWER_SAVE
3217 static struct hda_amp_list ad1884_loopbacks[] = {
3218 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3219 { 0x20, HDA_INPUT, 1 }, /* Mic */
3220 { 0x20, HDA_INPUT, 2 }, /* CD */
3221 { 0x20, HDA_INPUT, 4 }, /* Docking */
3222 { } /* end */
3224 #endif
3226 static const char *ad1884_slave_vols[] = {
3227 "PCM Playback Volume",
3228 "Mic Playback Volume",
3229 "Mono Playback Volume",
3230 "Front Mic Playback Volume",
3231 "Mic Playback Volume",
3232 "CD Playback Volume",
3233 "Internal Mic Playback Volume",
3234 "Docking Mic Playback Volume"
3235 "Beep Playback Volume",
3236 "IEC958 Playback Volume",
3237 NULL
3240 static int patch_ad1884(struct hda_codec *codec)
3242 struct ad198x_spec *spec;
3244 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3245 if (spec == NULL)
3246 return -ENOMEM;
3248 codec->spec = spec;
3250 spec->multiout.max_channels = 2;
3251 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3252 spec->multiout.dac_nids = ad1884_dac_nids;
3253 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3254 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3255 spec->adc_nids = ad1884_adc_nids;
3256 spec->capsrc_nids = ad1884_capsrc_nids;
3257 spec->input_mux = &ad1884_capture_source;
3258 spec->num_mixers = 1;
3259 spec->mixers[0] = ad1884_base_mixers;
3260 spec->num_init_verbs = 1;
3261 spec->init_verbs[0] = ad1884_init_verbs;
3262 spec->spdif_route = 0;
3263 #ifdef CONFIG_SND_HDA_POWER_SAVE
3264 spec->loopback.amplist = ad1884_loopbacks;
3265 #endif
3266 spec->vmaster_nid = 0x04;
3267 /* we need to cover all playback volumes */
3268 spec->slave_vols = ad1884_slave_vols;
3270 codec->patch_ops = ad198x_patch_ops;
3272 return 0;
3276 * Lenovo Thinkpad T61/X61
3278 static struct hda_input_mux ad1984_thinkpad_capture_source = {
3279 .num_items = 4,
3280 .items = {
3281 { "Mic", 0x0 },
3282 { "Internal Mic", 0x1 },
3283 { "Mix", 0x3 },
3284 { "Docking-Station", 0x4 },
3290 * Dell Precision T3400
3292 static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3293 .num_items = 3,
3294 .items = {
3295 { "Front Mic", 0x0 },
3296 { "Line-In", 0x1 },
3297 { "Mix", 0x3 },
3302 static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3303 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3304 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3305 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3306 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3307 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3308 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3309 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3310 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3311 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3312 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3313 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3314 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3315 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3316 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3317 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3318 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3319 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3320 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3321 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3323 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3324 /* The multiple "Capture Source" controls confuse alsamixer
3325 * So call somewhat different..
3327 /* .name = "Capture Source", */
3328 .name = "Input Source",
3329 .count = 2,
3330 .info = ad198x_mux_enum_info,
3331 .get = ad198x_mux_enum_get,
3332 .put = ad198x_mux_enum_put,
3334 /* SPDIF controls */
3335 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3337 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3338 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3339 /* identical with ad1983 */
3340 .info = ad1983_spdif_route_info,
3341 .get = ad1983_spdif_route_get,
3342 .put = ad1983_spdif_route_put,
3344 { } /* end */
3347 /* additional verbs */
3348 static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3349 /* Port-E (docking station mic) pin */
3350 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3351 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3352 /* docking mic boost */
3353 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3354 /* Analog mixer - docking mic; mute as default */
3355 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3356 /* enable EAPD bit */
3357 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3358 { } /* end */
3362 * Dell Precision T3400
3364 static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3365 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3366 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3367 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3368 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3369 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3370 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3371 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3372 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3373 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
3375 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
3376 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
3378 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3379 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3380 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3381 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3382 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3383 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3385 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3386 /* The multiple "Capture Source" controls confuse alsamixer
3387 * So call somewhat different..
3389 /* .name = "Capture Source", */
3390 .name = "Input Source",
3391 .count = 2,
3392 .info = ad198x_mux_enum_info,
3393 .get = ad198x_mux_enum_get,
3394 .put = ad198x_mux_enum_put,
3396 { } /* end */
3399 /* Digial MIC ADC NID 0x05 + 0x06 */
3400 static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3401 struct hda_codec *codec,
3402 unsigned int stream_tag,
3403 unsigned int format,
3404 struct snd_pcm_substream *substream)
3406 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3407 stream_tag, 0, format);
3408 return 0;
3411 static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3412 struct hda_codec *codec,
3413 struct snd_pcm_substream *substream)
3415 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
3416 return 0;
3419 static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3420 .substreams = 2,
3421 .channels_min = 2,
3422 .channels_max = 2,
3423 .nid = 0x05,
3424 .ops = {
3425 .prepare = ad1984_pcm_dmic_prepare,
3426 .cleanup = ad1984_pcm_dmic_cleanup
3430 static int ad1984_build_pcms(struct hda_codec *codec)
3432 struct ad198x_spec *spec = codec->spec;
3433 struct hda_pcm *info;
3434 int err;
3436 err = ad198x_build_pcms(codec);
3437 if (err < 0)
3438 return err;
3440 info = spec->pcm_rec + codec->num_pcms;
3441 codec->num_pcms++;
3442 info->name = "AD1984 Digital Mic";
3443 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3444 return 0;
3447 /* models */
3448 enum {
3449 AD1984_BASIC,
3450 AD1984_THINKPAD,
3451 AD1984_DELL_DESKTOP,
3452 AD1984_MODELS
3455 static const char *ad1984_models[AD1984_MODELS] = {
3456 [AD1984_BASIC] = "basic",
3457 [AD1984_THINKPAD] = "thinkpad",
3458 [AD1984_DELL_DESKTOP] = "dell_desktop",
3461 static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3462 /* Lenovo Thinkpad T61/X61 */
3463 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1984_THINKPAD),
3464 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
3468 static int patch_ad1984(struct hda_codec *codec)
3470 struct ad198x_spec *spec;
3471 int board_config, err;
3473 err = patch_ad1884(codec);
3474 if (err < 0)
3475 return err;
3476 spec = codec->spec;
3477 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3478 ad1984_models, ad1984_cfg_tbl);
3479 switch (board_config) {
3480 case AD1984_BASIC:
3481 /* additional digital mics */
3482 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3483 codec->patch_ops.build_pcms = ad1984_build_pcms;
3484 break;
3485 case AD1984_THINKPAD:
3486 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3487 spec->input_mux = &ad1984_thinkpad_capture_source;
3488 spec->mixers[0] = ad1984_thinkpad_mixers;
3489 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3490 break;
3491 case AD1984_DELL_DESKTOP:
3492 spec->multiout.dig_out_nid = 0;
3493 spec->input_mux = &ad1984_dell_desktop_capture_source;
3494 spec->mixers[0] = ad1984_dell_desktop_mixers;
3495 break;
3497 return 0;
3502 * AD1883 / AD1884A / AD1984A / AD1984B
3504 * port-B (0x14) - front mic-in
3505 * port-E (0x1c) - rear mic-in
3506 * port-F (0x16) - CD / ext out
3507 * port-C (0x15) - rear line-in
3508 * port-D (0x12) - rear line-out
3509 * port-A (0x11) - front hp-out
3511 * AD1984A = AD1884A + digital-mic
3512 * AD1883 = equivalent with AD1984A
3513 * AD1984B = AD1984A + extra SPDIF-out
3515 * FIXME:
3516 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3519 static hda_nid_t ad1884a_dac_nids[1] = {
3520 0x03,
3523 #define ad1884a_adc_nids ad1884_adc_nids
3524 #define ad1884a_capsrc_nids ad1884_capsrc_nids
3526 #define AD1884A_SPDIF_OUT 0x02
3528 static struct hda_input_mux ad1884a_capture_source = {
3529 .num_items = 5,
3530 .items = {
3531 { "Front Mic", 0x0 },
3532 { "Mic", 0x4 },
3533 { "Line", 0x1 },
3534 { "CD", 0x2 },
3535 { "Mix", 0x3 },
3539 static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3540 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3541 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3542 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3543 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3544 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3545 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3546 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3547 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3548 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3549 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3550 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3551 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3552 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3553 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3554 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3555 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3556 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3557 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3558 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3559 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3560 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3561 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3562 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3563 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3564 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3566 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3567 /* The multiple "Capture Source" controls confuse alsamixer
3568 * So call somewhat different..
3570 /* .name = "Capture Source", */
3571 .name = "Input Source",
3572 .count = 2,
3573 .info = ad198x_mux_enum_info,
3574 .get = ad198x_mux_enum_get,
3575 .put = ad198x_mux_enum_put,
3577 /* SPDIF controls */
3578 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3580 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3581 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3582 /* identical with ad1983 */
3583 .info = ad1983_spdif_route_info,
3584 .get = ad1983_spdif_route_get,
3585 .put = ad1983_spdif_route_put,
3587 { } /* end */
3591 * initialization verbs
3593 static struct hda_verb ad1884a_init_verbs[] = {
3594 /* DACs; unmute as default */
3595 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3596 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3597 /* Port-A (HP) mixer - route only from analog mixer */
3598 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3599 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3600 /* Port-A pin */
3601 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3602 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3603 /* Port-D (Line-out) mixer - route only from analog mixer */
3604 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3605 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3606 /* Port-D pin */
3607 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3608 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3609 /* Mono-out mixer - route only from analog mixer */
3610 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3611 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3612 /* Mono-out pin */
3613 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3614 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3615 /* Port-B (front mic) pin */
3616 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3617 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3618 /* Port-C (rear line-in) pin */
3619 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3620 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3621 /* Port-E (rear mic) pin */
3622 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3623 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3624 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3625 /* Port-F (CD) pin */
3626 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3627 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3628 /* Analog mixer; mute as default */
3629 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3630 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3631 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3632 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3633 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3634 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3635 /* Analog Mix output amp */
3636 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3637 /* capture sources */
3638 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3639 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3640 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3641 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3642 /* SPDIF output amp */
3643 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3644 { } /* end */
3647 #ifdef CONFIG_SND_HDA_POWER_SAVE
3648 static struct hda_amp_list ad1884a_loopbacks[] = {
3649 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3650 { 0x20, HDA_INPUT, 1 }, /* Mic */
3651 { 0x20, HDA_INPUT, 2 }, /* CD */
3652 { 0x20, HDA_INPUT, 4 }, /* Docking */
3653 { } /* end */
3655 #endif
3658 * Laptop model
3660 * Port A: Headphone jack
3661 * Port B: MIC jack
3662 * Port C: Internal MIC
3663 * Port D: Dock Line Out (if enabled)
3664 * Port E: Dock Line In (if enabled)
3665 * Port F: Internal speakers
3668 static struct hda_input_mux ad1884a_laptop_capture_source = {
3669 .num_items = 4,
3670 .items = {
3671 { "Mic", 0x0 }, /* port-B */
3672 { "Internal Mic", 0x1 }, /* port-C */
3673 { "Dock Mic", 0x4 }, /* port-E */
3674 { "Mix", 0x3 },
3678 static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3679 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3680 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3681 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3682 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3683 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3684 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3685 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3686 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3687 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3688 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3689 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3690 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3691 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3692 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3693 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3694 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3695 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3696 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3697 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3698 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3700 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3701 /* The multiple "Capture Source" controls confuse alsamixer
3702 * So call somewhat different..
3704 /* .name = "Capture Source", */
3705 .name = "Input Source",
3706 .count = 2,
3707 .info = ad198x_mux_enum_info,
3708 .get = ad198x_mux_enum_get,
3709 .put = ad198x_mux_enum_put,
3711 { } /* end */
3714 static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3715 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3716 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3717 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3718 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3719 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3720 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3721 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
3722 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
3723 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3724 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3725 { } /* end */
3728 /* mute internal speaker if HP is plugged */
3729 static void ad1884a_hp_automute(struct hda_codec *codec)
3731 unsigned int present;
3733 present = snd_hda_codec_read(codec, 0x11, 0,
3734 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3735 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3736 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3737 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3738 present ? 0x00 : 0x02);
3741 /* switch to external mic if plugged */
3742 static void ad1884a_hp_automic(struct hda_codec *codec)
3744 unsigned int present;
3746 present = snd_hda_codec_read(codec, 0x14, 0,
3747 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3748 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3749 present ? 0 : 1);
3752 #define AD1884A_HP_EVENT 0x37
3753 #define AD1884A_MIC_EVENT 0x36
3755 /* unsolicited event for HP jack sensing */
3756 static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3758 switch (res >> 26) {
3759 case AD1884A_HP_EVENT:
3760 ad1884a_hp_automute(codec);
3761 break;
3762 case AD1884A_MIC_EVENT:
3763 ad1884a_hp_automic(codec);
3764 break;
3768 /* initialize jack-sensing, too */
3769 static int ad1884a_hp_init(struct hda_codec *codec)
3771 ad198x_init(codec);
3772 ad1884a_hp_automute(codec);
3773 ad1884a_hp_automic(codec);
3774 return 0;
3777 /* additional verbs for laptop model */
3778 static struct hda_verb ad1884a_laptop_verbs[] = {
3779 /* Port-A (HP) pin - always unmuted */
3780 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3781 /* Port-F (int speaker) mixer - route only from analog mixer */
3782 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3783 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3784 /* Port-F pin */
3785 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3786 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3787 /* Port-C pin - internal mic-in */
3788 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3789 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3790 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3791 /* analog mix */
3792 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3793 /* unsolicited event for pin-sense */
3794 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3795 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3796 { } /* end */
3800 * Thinkpad X300
3801 * 0x11 - HP
3802 * 0x12 - speaker
3803 * 0x14 - mic-in
3804 * 0x17 - built-in mic
3807 static struct hda_verb ad1984a_thinkpad_verbs[] = {
3808 /* HP unmute */
3809 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3810 /* analog mix */
3811 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3812 /* turn on EAPD */
3813 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3814 /* unsolicited event for pin-sense */
3815 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3816 /* internal mic - dmic */
3817 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3818 /* set magic COEFs for dmic */
3819 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3820 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
3821 { } /* end */
3824 static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3825 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3826 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3827 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3828 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3829 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3830 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3831 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3832 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3833 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3834 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3835 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3836 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3838 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3839 .name = "Capture Source",
3840 .info = ad198x_mux_enum_info,
3841 .get = ad198x_mux_enum_get,
3842 .put = ad198x_mux_enum_put,
3844 { } /* end */
3847 static struct hda_input_mux ad1984a_thinkpad_capture_source = {
3848 .num_items = 3,
3849 .items = {
3850 { "Mic", 0x0 },
3851 { "Internal Mic", 0x5 },
3852 { "Mix", 0x3 },
3856 /* mute internal speaker if HP is plugged */
3857 static void ad1984a_thinkpad_automute(struct hda_codec *codec)
3859 unsigned int present;
3861 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0)
3862 & AC_PINSENSE_PRESENCE;
3863 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
3864 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3867 /* unsolicited event for HP jack sensing */
3868 static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
3869 unsigned int res)
3871 if ((res >> 26) != AD1884A_HP_EVENT)
3872 return;
3873 ad1984a_thinkpad_automute(codec);
3876 /* initialize jack-sensing, too */
3877 static int ad1984a_thinkpad_init(struct hda_codec *codec)
3879 ad198x_init(codec);
3880 ad1984a_thinkpad_automute(codec);
3881 return 0;
3887 enum {
3888 AD1884A_DESKTOP,
3889 AD1884A_LAPTOP,
3890 AD1884A_MOBILE,
3891 AD1884A_THINKPAD,
3892 AD1884A_MODELS
3895 static const char *ad1884a_models[AD1884A_MODELS] = {
3896 [AD1884A_DESKTOP] = "desktop",
3897 [AD1884A_LAPTOP] = "laptop",
3898 [AD1884A_MOBILE] = "mobile",
3899 [AD1884A_THINKPAD] = "thinkpad",
3902 static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3903 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
3904 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
3905 SND_PCI_QUIRK(0x103c, 0x30e7, "HP EliteBook 8530p", AD1884A_LAPTOP),
3906 SND_PCI_QUIRK(0x103c, 0x3614, "HP 6730s", AD1884A_LAPTOP),
3907 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
3911 static int patch_ad1884a(struct hda_codec *codec)
3913 struct ad198x_spec *spec;
3914 int board_config;
3916 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3917 if (spec == NULL)
3918 return -ENOMEM;
3920 codec->spec = spec;
3922 spec->multiout.max_channels = 2;
3923 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
3924 spec->multiout.dac_nids = ad1884a_dac_nids;
3925 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
3926 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
3927 spec->adc_nids = ad1884a_adc_nids;
3928 spec->capsrc_nids = ad1884a_capsrc_nids;
3929 spec->input_mux = &ad1884a_capture_source;
3930 spec->num_mixers = 1;
3931 spec->mixers[0] = ad1884a_base_mixers;
3932 spec->num_init_verbs = 1;
3933 spec->init_verbs[0] = ad1884a_init_verbs;
3934 spec->spdif_route = 0;
3935 #ifdef CONFIG_SND_HDA_POWER_SAVE
3936 spec->loopback.amplist = ad1884a_loopbacks;
3937 #endif
3938 codec->patch_ops = ad198x_patch_ops;
3940 /* override some parameters */
3941 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
3942 ad1884a_models,
3943 ad1884a_cfg_tbl);
3944 switch (board_config) {
3945 case AD1884A_LAPTOP:
3946 spec->mixers[0] = ad1884a_laptop_mixers;
3947 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3948 spec->multiout.dig_out_nid = 0;
3949 spec->input_mux = &ad1884a_laptop_capture_source;
3950 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3951 codec->patch_ops.init = ad1884a_hp_init;
3952 break;
3953 case AD1884A_MOBILE:
3954 spec->mixers[0] = ad1884a_mobile_mixers;
3955 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3956 spec->multiout.dig_out_nid = 0;
3957 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3958 codec->patch_ops.init = ad1884a_hp_init;
3959 break;
3960 case AD1884A_THINKPAD:
3961 spec->mixers[0] = ad1984a_thinkpad_mixers;
3962 spec->init_verbs[spec->num_init_verbs++] =
3963 ad1984a_thinkpad_verbs;
3964 spec->multiout.dig_out_nid = 0;
3965 spec->input_mux = &ad1984a_thinkpad_capture_source;
3966 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
3967 codec->patch_ops.init = ad1984a_thinkpad_init;
3968 break;
3971 return 0;
3976 * AD1882 / AD1882A
3978 * port-A - front hp-out
3979 * port-B - front mic-in
3980 * port-C - rear line-in, shared surr-out (3stack)
3981 * port-D - rear line-out
3982 * port-E - rear mic-in, shared clfe-out (3stack)
3983 * port-F - rear surr-out (6stack)
3984 * port-G - rear clfe-out (6stack)
3987 static hda_nid_t ad1882_dac_nids[3] = {
3988 0x04, 0x03, 0x05
3991 static hda_nid_t ad1882_adc_nids[2] = {
3992 0x08, 0x09,
3995 static hda_nid_t ad1882_capsrc_nids[2] = {
3996 0x0c, 0x0d,
3999 #define AD1882_SPDIF_OUT 0x02
4001 /* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
4002 static struct hda_input_mux ad1882_capture_source = {
4003 .num_items = 5,
4004 .items = {
4005 { "Front Mic", 0x1 },
4006 { "Mic", 0x4 },
4007 { "Line", 0x2 },
4008 { "CD", 0x3 },
4009 { "Mix", 0x7 },
4013 /* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
4014 static struct hda_input_mux ad1882a_capture_source = {
4015 .num_items = 5,
4016 .items = {
4017 { "Front Mic", 0x1 },
4018 { "Mic", 0x4},
4019 { "Line", 0x2 },
4020 { "Digital Mic", 0x06 },
4021 { "Mix", 0x7 },
4025 static struct snd_kcontrol_new ad1882_base_mixers[] = {
4026 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
4027 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
4028 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
4029 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
4030 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
4031 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4032 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4033 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
4035 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
4036 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
4037 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
4038 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4039 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4040 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
4041 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
4043 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4044 /* The multiple "Capture Source" controls confuse alsamixer
4045 * So call somewhat different..
4047 /* .name = "Capture Source", */
4048 .name = "Input Source",
4049 .count = 2,
4050 .info = ad198x_mux_enum_info,
4051 .get = ad198x_mux_enum_get,
4052 .put = ad198x_mux_enum_put,
4054 /* SPDIF controls */
4055 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
4057 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4058 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4059 /* identical with ad1983 */
4060 .info = ad1983_spdif_route_info,
4061 .get = ad1983_spdif_route_get,
4062 .put = ad1983_spdif_route_put,
4064 { } /* end */
4067 static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4068 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4069 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4070 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4071 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4072 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4073 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4074 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4075 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4076 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
4077 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
4078 { } /* end */
4081 static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4082 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4083 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4084 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4085 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4086 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4087 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4088 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4089 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4090 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
4091 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
4092 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT),
4093 { } /* end */
4096 static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
4097 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4098 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
4099 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
4101 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4102 .name = "Channel Mode",
4103 .info = ad198x_ch_mode_info,
4104 .get = ad198x_ch_mode_get,
4105 .put = ad198x_ch_mode_put,
4107 { } /* end */
4110 static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
4111 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4112 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4113 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4114 { } /* end */
4117 static struct hda_verb ad1882_ch2_init[] = {
4118 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4119 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4120 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4121 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4122 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4123 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4124 { } /* end */
4127 static struct hda_verb ad1882_ch4_init[] = {
4128 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4129 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4130 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4131 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4132 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4133 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4134 { } /* end */
4137 static struct hda_verb ad1882_ch6_init[] = {
4138 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4139 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4140 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4141 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4142 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4143 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4144 { } /* end */
4147 static struct hda_channel_mode ad1882_modes[3] = {
4148 { 2, ad1882_ch2_init },
4149 { 4, ad1882_ch4_init },
4150 { 6, ad1882_ch6_init },
4154 * initialization verbs
4156 static struct hda_verb ad1882_init_verbs[] = {
4157 /* DACs; mute as default */
4158 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4159 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4160 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4161 /* Port-A (HP) mixer */
4162 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4163 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4164 /* Port-A pin */
4165 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4166 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4167 /* HP selector - select DAC2 */
4168 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4169 /* Port-D (Line-out) mixer */
4170 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4171 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4172 /* Port-D pin */
4173 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4174 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4175 /* Mono-out mixer */
4176 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4177 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4178 /* Mono-out pin */
4179 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4180 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4181 /* Port-B (front mic) pin */
4182 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4183 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4184 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4185 /* Port-C (line-in) pin */
4186 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4187 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4188 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4189 /* Port-C mixer - mute as input */
4190 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4191 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4192 /* Port-E (mic-in) pin */
4193 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4194 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4195 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4196 /* Port-E mixer - mute as input */
4197 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4198 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4199 /* Port-F (surround) */
4200 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4201 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4202 /* Port-G (CLFE) */
4203 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4204 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4205 /* Analog mixer; mute as default */
4206 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4207 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4208 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4209 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4210 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4211 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4212 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4213 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4214 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4215 /* Analog Mix output amp */
4216 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4217 /* SPDIF output selector */
4218 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4219 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4220 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4221 { } /* end */
4224 #ifdef CONFIG_SND_HDA_POWER_SAVE
4225 static struct hda_amp_list ad1882_loopbacks[] = {
4226 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4227 { 0x20, HDA_INPUT, 1 }, /* Mic */
4228 { 0x20, HDA_INPUT, 4 }, /* Line */
4229 { 0x20, HDA_INPUT, 6 }, /* CD */
4230 { } /* end */
4232 #endif
4234 /* models */
4235 enum {
4236 AD1882_3STACK,
4237 AD1882_6STACK,
4238 AD1882_MODELS
4241 static const char *ad1882_models[AD1986A_MODELS] = {
4242 [AD1882_3STACK] = "3stack",
4243 [AD1882_6STACK] = "6stack",
4247 static int patch_ad1882(struct hda_codec *codec)
4249 struct ad198x_spec *spec;
4250 int board_config;
4252 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4253 if (spec == NULL)
4254 return -ENOMEM;
4256 codec->spec = spec;
4258 spec->multiout.max_channels = 6;
4259 spec->multiout.num_dacs = 3;
4260 spec->multiout.dac_nids = ad1882_dac_nids;
4261 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4262 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4263 spec->adc_nids = ad1882_adc_nids;
4264 spec->capsrc_nids = ad1882_capsrc_nids;
4265 if (codec->vendor_id == 0x11d1882)
4266 spec->input_mux = &ad1882_capture_source;
4267 else
4268 spec->input_mux = &ad1882a_capture_source;
4269 spec->num_mixers = 2;
4270 spec->mixers[0] = ad1882_base_mixers;
4271 if (codec->vendor_id == 0x11d1882)
4272 spec->mixers[1] = ad1882_loopback_mixers;
4273 else
4274 spec->mixers[1] = ad1882a_loopback_mixers;
4275 spec->num_init_verbs = 1;
4276 spec->init_verbs[0] = ad1882_init_verbs;
4277 spec->spdif_route = 0;
4278 #ifdef CONFIG_SND_HDA_POWER_SAVE
4279 spec->loopback.amplist = ad1882_loopbacks;
4280 #endif
4281 spec->vmaster_nid = 0x04;
4283 codec->patch_ops = ad198x_patch_ops;
4285 /* override some parameters */
4286 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4287 ad1882_models, NULL);
4288 switch (board_config) {
4289 default:
4290 case AD1882_3STACK:
4291 spec->num_mixers = 3;
4292 spec->mixers[2] = ad1882_3stack_mixers;
4293 spec->channel_mode = ad1882_modes;
4294 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4295 spec->need_dac_fix = 1;
4296 spec->multiout.max_channels = 2;
4297 spec->multiout.num_dacs = 1;
4298 break;
4299 case AD1882_6STACK:
4300 spec->num_mixers = 3;
4301 spec->mixers[2] = ad1882_6stack_mixers;
4302 break;
4304 return 0;
4309 * patch entries
4311 struct hda_codec_preset snd_hda_preset_analog[] = {
4312 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
4313 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
4314 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
4315 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
4316 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4317 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
4318 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4319 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
4320 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
4321 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
4322 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
4323 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
4324 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
4325 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4326 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
4327 {} /* terminator */