xhci: Fix cycle bit calculation during stall handling.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / pci / hda / patch_analog.c
blob82c07c03e677e3ca12e8d67473e0ba54d7b3a938
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_beep.h"
32 struct ad198x_spec {
33 struct snd_kcontrol_new *mixers[5];
34 int num_mixers;
35 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
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;
75 unsigned int inv_jack_detect:1; /* inverted jack-detection */
76 unsigned int inv_eapd:1; /* inverted EAPD implementation */
78 #ifdef CONFIG_SND_HDA_POWER_SAVE
79 struct hda_loopback_check loopback;
80 #endif
81 /* for virtual master */
82 hda_nid_t vmaster_nid;
83 const char **slave_vols;
84 const char **slave_sws;
88 * input MUX handling (common part)
90 static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
92 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
93 struct ad198x_spec *spec = codec->spec;
95 return snd_hda_input_mux_info(spec->input_mux, uinfo);
98 static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
100 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
101 struct ad198x_spec *spec = codec->spec;
102 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
104 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
105 return 0;
108 static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
110 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
111 struct ad198x_spec *spec = codec->spec;
112 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
114 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
115 spec->capsrc_nids[adc_idx],
116 &spec->cur_mux[adc_idx]);
120 * initialization (common callbacks)
122 static int ad198x_init(struct hda_codec *codec)
124 struct ad198x_spec *spec = codec->spec;
125 int i;
127 for (i = 0; i < spec->num_init_verbs; i++)
128 snd_hda_sequence_write(codec, spec->init_verbs[i]);
129 return 0;
132 static const char *ad_slave_vols[] = {
133 "Front Playback Volume",
134 "Surround Playback Volume",
135 "Center Playback Volume",
136 "LFE Playback Volume",
137 "Side Playback Volume",
138 "Headphone Playback Volume",
139 "Mono Playback Volume",
140 "Speaker Playback Volume",
141 "IEC958 Playback Volume",
142 NULL
145 static const char *ad_slave_sws[] = {
146 "Front Playback Switch",
147 "Surround Playback Switch",
148 "Center Playback Switch",
149 "LFE Playback Switch",
150 "Side Playback Switch",
151 "Headphone Playback Switch",
152 "Mono Playback Switch",
153 "Speaker Playback Switch",
154 "IEC958 Playback Switch",
155 NULL
158 static void ad198x_free_kctls(struct hda_codec *codec);
160 #ifdef CONFIG_SND_HDA_INPUT_BEEP
161 /* additional beep mixers; the actual parameters are overwritten at build */
162 static struct snd_kcontrol_new ad_beep_mixer[] = {
163 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
164 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
165 { } /* end */
168 #define set_beep_amp(spec, nid, idx, dir) \
169 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
170 #else
171 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
172 #endif
174 static int ad198x_build_controls(struct hda_codec *codec)
176 struct ad198x_spec *spec = codec->spec;
177 unsigned int i;
178 int err;
180 for (i = 0; i < spec->num_mixers; i++) {
181 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
182 if (err < 0)
183 return err;
185 if (spec->multiout.dig_out_nid) {
186 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
187 if (err < 0)
188 return err;
189 err = snd_hda_create_spdif_share_sw(codec,
190 &spec->multiout);
191 if (err < 0)
192 return err;
193 spec->multiout.share_spdif = 1;
195 if (spec->dig_in_nid) {
196 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
197 if (err < 0)
198 return err;
201 /* create beep controls if needed */
202 #ifdef CONFIG_SND_HDA_INPUT_BEEP
203 if (spec->beep_amp) {
204 struct snd_kcontrol_new *knew;
205 for (knew = ad_beep_mixer; knew->name; knew++) {
206 struct snd_kcontrol *kctl;
207 kctl = snd_ctl_new1(knew, codec);
208 if (!kctl)
209 return -ENOMEM;
210 kctl->private_value = spec->beep_amp;
211 err = snd_hda_ctl_add(codec,
212 get_amp_nid_(spec->beep_amp),
213 kctl);
214 if (err < 0)
215 return err;
218 #endif
220 /* if we have no master control, let's create it */
221 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
222 unsigned int vmaster_tlv[4];
223 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
224 HDA_OUTPUT, vmaster_tlv);
225 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
226 vmaster_tlv,
227 (spec->slave_vols ?
228 spec->slave_vols : ad_slave_vols));
229 if (err < 0)
230 return err;
232 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
233 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
234 NULL,
235 (spec->slave_sws ?
236 spec->slave_sws : ad_slave_sws));
237 if (err < 0)
238 return err;
241 ad198x_free_kctls(codec); /* no longer needed */
242 return 0;
245 #ifdef CONFIG_SND_HDA_POWER_SAVE
246 static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
248 struct ad198x_spec *spec = codec->spec;
249 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
251 #endif
254 * Analog playback callbacks
256 static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
257 struct hda_codec *codec,
258 struct snd_pcm_substream *substream)
260 struct ad198x_spec *spec = codec->spec;
261 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
262 hinfo);
265 static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
266 struct hda_codec *codec,
267 unsigned int stream_tag,
268 unsigned int format,
269 struct snd_pcm_substream *substream)
271 struct ad198x_spec *spec = codec->spec;
272 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
273 format, substream);
276 static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
277 struct hda_codec *codec,
278 struct snd_pcm_substream *substream)
280 struct ad198x_spec *spec = codec->spec;
281 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
285 * Digital out
287 static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
288 struct hda_codec *codec,
289 struct snd_pcm_substream *substream)
291 struct ad198x_spec *spec = codec->spec;
292 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
295 static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
296 struct hda_codec *codec,
297 struct snd_pcm_substream *substream)
299 struct ad198x_spec *spec = codec->spec;
300 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
303 static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
304 struct hda_codec *codec,
305 unsigned int stream_tag,
306 unsigned int format,
307 struct snd_pcm_substream *substream)
309 struct ad198x_spec *spec = codec->spec;
310 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
311 format, substream);
314 static int ad198x_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
315 struct hda_codec *codec,
316 struct snd_pcm_substream *substream)
318 struct ad198x_spec *spec = codec->spec;
319 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
323 * Analog capture
325 static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
326 struct hda_codec *codec,
327 unsigned int stream_tag,
328 unsigned int format,
329 struct snd_pcm_substream *substream)
331 struct ad198x_spec *spec = codec->spec;
332 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
333 stream_tag, 0, format);
334 return 0;
337 static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
338 struct hda_codec *codec,
339 struct snd_pcm_substream *substream)
341 struct ad198x_spec *spec = codec->spec;
342 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
343 return 0;
349 static struct hda_pcm_stream ad198x_pcm_analog_playback = {
350 .substreams = 1,
351 .channels_min = 2,
352 .channels_max = 6, /* changed later */
353 .nid = 0, /* fill later */
354 .ops = {
355 .open = ad198x_playback_pcm_open,
356 .prepare = ad198x_playback_pcm_prepare,
357 .cleanup = ad198x_playback_pcm_cleanup
361 static struct hda_pcm_stream ad198x_pcm_analog_capture = {
362 .substreams = 1,
363 .channels_min = 2,
364 .channels_max = 2,
365 .nid = 0, /* fill later */
366 .ops = {
367 .prepare = ad198x_capture_pcm_prepare,
368 .cleanup = ad198x_capture_pcm_cleanup
372 static struct hda_pcm_stream ad198x_pcm_digital_playback = {
373 .substreams = 1,
374 .channels_min = 2,
375 .channels_max = 2,
376 .nid = 0, /* fill later */
377 .ops = {
378 .open = ad198x_dig_playback_pcm_open,
379 .close = ad198x_dig_playback_pcm_close,
380 .prepare = ad198x_dig_playback_pcm_prepare,
381 .cleanup = ad198x_dig_playback_pcm_cleanup
385 static struct hda_pcm_stream ad198x_pcm_digital_capture = {
386 .substreams = 1,
387 .channels_min = 2,
388 .channels_max = 2,
389 /* NID is set in alc_build_pcms */
392 static int ad198x_build_pcms(struct hda_codec *codec)
394 struct ad198x_spec *spec = codec->spec;
395 struct hda_pcm *info = spec->pcm_rec;
397 codec->num_pcms = 1;
398 codec->pcm_info = info;
400 info->name = "AD198x Analog";
401 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
402 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
403 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
404 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
405 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
406 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
408 if (spec->multiout.dig_out_nid) {
409 info++;
410 codec->num_pcms++;
411 info->name = "AD198x Digital";
412 info->pcm_type = HDA_PCM_TYPE_SPDIF;
413 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
414 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
415 if (spec->dig_in_nid) {
416 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
417 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
421 return 0;
424 static void ad198x_free_kctls(struct hda_codec *codec)
426 struct ad198x_spec *spec = codec->spec;
428 if (spec->kctls.list) {
429 struct snd_kcontrol_new *kctl = spec->kctls.list;
430 int i;
431 for (i = 0; i < spec->kctls.used; i++)
432 kfree(kctl[i].name);
434 snd_array_free(&spec->kctls);
437 static void ad198x_free(struct hda_codec *codec)
439 struct ad198x_spec *spec = codec->spec;
441 if (!spec)
442 return;
444 ad198x_free_kctls(codec);
445 kfree(spec);
446 snd_hda_detach_beep_device(codec);
449 static struct hda_codec_ops ad198x_patch_ops = {
450 .build_controls = ad198x_build_controls,
451 .build_pcms = ad198x_build_pcms,
452 .init = ad198x_init,
453 .free = ad198x_free,
454 #ifdef CONFIG_SND_HDA_POWER_SAVE
455 .check_power_status = ad198x_check_power_status,
456 #endif
461 * EAPD control
462 * the private value = nid
464 #define ad198x_eapd_info snd_ctl_boolean_mono_info
466 static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
467 struct snd_ctl_elem_value *ucontrol)
469 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
470 struct ad198x_spec *spec = codec->spec;
471 if (spec->inv_eapd)
472 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
473 else
474 ucontrol->value.integer.value[0] = spec->cur_eapd;
475 return 0;
478 static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
479 struct snd_ctl_elem_value *ucontrol)
481 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
482 struct ad198x_spec *spec = codec->spec;
483 hda_nid_t nid = kcontrol->private_value & 0xff;
484 unsigned int eapd;
485 eapd = !!ucontrol->value.integer.value[0];
486 if (spec->inv_eapd)
487 eapd = !eapd;
488 if (eapd == spec->cur_eapd)
489 return 0;
490 spec->cur_eapd = eapd;
491 snd_hda_codec_write_cache(codec, nid,
492 0, AC_VERB_SET_EAPD_BTLENABLE,
493 eapd ? 0x02 : 0x00);
494 return 1;
497 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
498 struct snd_ctl_elem_info *uinfo);
499 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
500 struct snd_ctl_elem_value *ucontrol);
501 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
502 struct snd_ctl_elem_value *ucontrol);
506 * AD1986A specific
509 #define AD1986A_SPDIF_OUT 0x02
510 #define AD1986A_FRONT_DAC 0x03
511 #define AD1986A_SURR_DAC 0x04
512 #define AD1986A_CLFE_DAC 0x05
513 #define AD1986A_ADC 0x06
515 static hda_nid_t ad1986a_dac_nids[3] = {
516 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
518 static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
519 static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
521 static struct hda_input_mux ad1986a_capture_source = {
522 .num_items = 7,
523 .items = {
524 { "Mic", 0x0 },
525 { "CD", 0x1 },
526 { "Aux", 0x3 },
527 { "Line", 0x4 },
528 { "Mix", 0x5 },
529 { "Mono", 0x6 },
530 { "Phone", 0x7 },
535 static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
536 .ops = &snd_hda_bind_vol,
537 .values = {
538 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
539 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
540 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
545 static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
546 .ops = &snd_hda_bind_sw,
547 .values = {
548 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
549 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
550 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
556 * mixers
558 static struct snd_kcontrol_new ad1986a_mixers[] = {
560 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
562 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
563 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
564 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
565 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
566 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
567 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
568 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
569 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
570 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
571 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
572 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
573 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
574 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
575 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
576 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
577 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
578 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
579 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
580 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
581 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
582 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
583 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
584 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
585 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
586 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
588 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
589 .name = "Capture Source",
590 .info = ad198x_mux_enum_info,
591 .get = ad198x_mux_enum_get,
592 .put = ad198x_mux_enum_put,
594 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
595 { } /* end */
598 /* additional mixers for 3stack mode */
599 static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
601 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
602 .name = "Channel Mode",
603 .info = ad198x_ch_mode_info,
604 .get = ad198x_ch_mode_get,
605 .put = ad198x_ch_mode_put,
607 { } /* end */
610 /* laptop model - 2ch only */
611 static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
613 /* master controls both pins 0x1a and 0x1b */
614 static struct hda_bind_ctls ad1986a_laptop_master_vol = {
615 .ops = &snd_hda_bind_vol,
616 .values = {
617 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
618 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
623 static struct hda_bind_ctls ad1986a_laptop_master_sw = {
624 .ops = &snd_hda_bind_sw,
625 .values = {
626 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
627 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
632 static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
633 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
634 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
635 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
636 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
637 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
638 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
639 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
640 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
641 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
642 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
643 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
644 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
645 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
647 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
648 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
649 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
650 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
652 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
653 .name = "Capture Source",
654 .info = ad198x_mux_enum_info,
655 .get = ad198x_mux_enum_get,
656 .put = ad198x_mux_enum_put,
658 { } /* end */
661 /* laptop-eapd model - 2ch only */
663 static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
664 .num_items = 3,
665 .items = {
666 { "Mic", 0x0 },
667 { "Internal Mic", 0x4 },
668 { "Mix", 0x5 },
672 static struct hda_input_mux ad1986a_automic_capture_source = {
673 .num_items = 2,
674 .items = {
675 { "Mic", 0x0 },
676 { "Mix", 0x5 },
680 static struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
681 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
682 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
683 { } /* end */
686 static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
687 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
688 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
689 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
690 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
691 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
692 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
693 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
695 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
696 .name = "Capture Source",
697 .info = ad198x_mux_enum_info,
698 .get = ad198x_mux_enum_get,
699 .put = ad198x_mux_enum_put,
702 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
703 .name = "External Amplifier",
704 .info = ad198x_eapd_info,
705 .get = ad198x_eapd_get,
706 .put = ad198x_eapd_put,
707 .private_value = 0x1b, /* port-D */
709 { } /* end */
712 static struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
713 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
714 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
715 { } /* end */
718 /* re-connect the mic boost input according to the jack sensing */
719 static void ad1986a_automic(struct hda_codec *codec)
721 unsigned int present;
722 present = snd_hda_jack_detect(codec, 0x1f);
723 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
724 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
725 present ? 0 : 2);
728 #define AD1986A_MIC_EVENT 0x36
730 static void ad1986a_automic_unsol_event(struct hda_codec *codec,
731 unsigned int res)
733 if ((res >> 26) != AD1986A_MIC_EVENT)
734 return;
735 ad1986a_automic(codec);
738 static int ad1986a_automic_init(struct hda_codec *codec)
740 ad198x_init(codec);
741 ad1986a_automic(codec);
742 return 0;
745 /* laptop-automute - 2ch only */
747 static void ad1986a_update_hp(struct hda_codec *codec)
749 struct ad198x_spec *spec = codec->spec;
750 unsigned int mute;
752 if (spec->jack_present)
753 mute = HDA_AMP_MUTE; /* mute internal speaker */
754 else
755 /* unmute internal speaker if necessary */
756 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
757 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
758 HDA_AMP_MUTE, mute);
761 static void ad1986a_hp_automute(struct hda_codec *codec)
763 struct ad198x_spec *spec = codec->spec;
765 spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
766 if (spec->inv_jack_detect)
767 spec->jack_present = !spec->jack_present;
768 ad1986a_update_hp(codec);
771 #define AD1986A_HP_EVENT 0x37
773 static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
775 if ((res >> 26) != AD1986A_HP_EVENT)
776 return;
777 ad1986a_hp_automute(codec);
780 static int ad1986a_hp_init(struct hda_codec *codec)
782 ad198x_init(codec);
783 ad1986a_hp_automute(codec);
784 return 0;
787 /* bind hp and internal speaker mute (with plug check) */
788 static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
789 struct snd_ctl_elem_value *ucontrol)
791 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
792 long *valp = ucontrol->value.integer.value;
793 int change;
795 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
796 HDA_AMP_MUTE,
797 valp[0] ? 0 : HDA_AMP_MUTE);
798 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
799 HDA_AMP_MUTE,
800 valp[1] ? 0 : HDA_AMP_MUTE);
801 if (change)
802 ad1986a_update_hp(codec);
803 return change;
806 static struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
807 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
810 .name = "Master Playback Switch",
811 .info = snd_hda_mixer_amp_switch_info,
812 .get = snd_hda_mixer_amp_switch_get,
813 .put = ad1986a_hp_master_sw_put,
814 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
816 { } /* end */
821 * initialization verbs
823 static struct hda_verb ad1986a_init_verbs[] = {
824 /* Front, Surround, CLFE DAC; mute as default */
825 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
826 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
827 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
828 /* Downmix - off */
829 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
830 /* HP, Line-Out, Surround, CLFE selectors */
831 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
832 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
833 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
834 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
835 /* Mono selector */
836 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
837 /* Mic selector: Mic 1/2 pin */
838 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
839 /* Line-in selector: Line-in */
840 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
841 /* Mic 1/2 swap */
842 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
843 /* Record selector: mic */
844 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
845 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
846 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
847 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
848 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
849 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
850 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
851 /* PC beep */
852 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
853 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
854 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
855 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
856 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
857 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
858 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
859 /* HP Pin */
860 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
861 /* Front, Surround, CLFE Pins */
862 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
863 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
864 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
865 /* Mono Pin */
866 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
867 /* Mic Pin */
868 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
869 /* Line, Aux, CD, Beep-In Pin */
870 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
871 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
872 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
873 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
874 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
875 { } /* end */
878 static struct hda_verb ad1986a_ch2_init[] = {
879 /* Surround out -> Line In */
880 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
881 /* Line-in selectors */
882 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
883 /* CLFE -> Mic in */
884 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
885 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
886 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
887 { } /* end */
890 static struct hda_verb ad1986a_ch4_init[] = {
891 /* Surround out -> Surround */
892 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
893 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
894 /* CLFE -> Mic in */
895 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
896 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
897 { } /* end */
900 static struct hda_verb ad1986a_ch6_init[] = {
901 /* Surround out -> Surround out */
902 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
903 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
904 /* CLFE -> CLFE */
905 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
906 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
907 { } /* end */
910 static struct hda_channel_mode ad1986a_modes[3] = {
911 { 2, ad1986a_ch2_init },
912 { 4, ad1986a_ch4_init },
913 { 6, ad1986a_ch6_init },
916 /* eapd initialization */
917 static struct hda_verb ad1986a_eapd_init_verbs[] = {
918 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
922 static struct hda_verb ad1986a_automic_verbs[] = {
923 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
924 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
925 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
926 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
927 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
931 /* Ultra initialization */
932 static struct hda_verb ad1986a_ultra_init[] = {
933 /* eapd initialization */
934 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
935 /* CLFE -> Mic in */
936 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
937 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
938 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
939 { } /* end */
942 /* pin sensing on HP jack */
943 static struct hda_verb ad1986a_hp_init_verbs[] = {
944 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
948 static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
949 unsigned int res)
951 switch (res >> 26) {
952 case AD1986A_HP_EVENT:
953 ad1986a_hp_automute(codec);
954 break;
955 case AD1986A_MIC_EVENT:
956 ad1986a_automic(codec);
957 break;
961 static int ad1986a_samsung_p50_init(struct hda_codec *codec)
963 ad198x_init(codec);
964 ad1986a_hp_automute(codec);
965 ad1986a_automic(codec);
966 return 0;
970 /* models */
971 enum {
972 AD1986A_6STACK,
973 AD1986A_3STACK,
974 AD1986A_LAPTOP,
975 AD1986A_LAPTOP_EAPD,
976 AD1986A_LAPTOP_AUTOMUTE,
977 AD1986A_ULTRA,
978 AD1986A_SAMSUNG,
979 AD1986A_SAMSUNG_P50,
980 AD1986A_MODELS
983 static const char *ad1986a_models[AD1986A_MODELS] = {
984 [AD1986A_6STACK] = "6stack",
985 [AD1986A_3STACK] = "3stack",
986 [AD1986A_LAPTOP] = "laptop",
987 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
988 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
989 [AD1986A_ULTRA] = "ultra",
990 [AD1986A_SAMSUNG] = "samsung",
991 [AD1986A_SAMSUNG_P50] = "samsung-p50",
994 static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
995 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
996 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
997 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
998 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
999 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
1000 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
1001 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
1002 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
1003 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
1004 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
1005 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
1006 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
1007 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
1008 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
1009 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
1010 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
1011 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40-10Q", AD1986A_3STACK),
1012 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
1013 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
1014 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
1015 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
1016 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
1017 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
1018 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
1019 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
1020 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
1021 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
1025 #ifdef CONFIG_SND_HDA_POWER_SAVE
1026 static struct hda_amp_list ad1986a_loopbacks[] = {
1027 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
1028 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
1029 { 0x15, HDA_OUTPUT, 0 }, /* CD */
1030 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
1031 { 0x17, HDA_OUTPUT, 0 }, /* Line */
1032 { } /* end */
1034 #endif
1036 static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1038 unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
1039 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1042 static int patch_ad1986a(struct hda_codec *codec)
1044 struct ad198x_spec *spec;
1045 int err, board_config;
1047 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1048 if (spec == NULL)
1049 return -ENOMEM;
1051 codec->spec = spec;
1053 err = snd_hda_attach_beep_device(codec, 0x19);
1054 if (err < 0) {
1055 ad198x_free(codec);
1056 return err;
1058 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1060 spec->multiout.max_channels = 6;
1061 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
1062 spec->multiout.dac_nids = ad1986a_dac_nids;
1063 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
1064 spec->num_adc_nids = 1;
1065 spec->adc_nids = ad1986a_adc_nids;
1066 spec->capsrc_nids = ad1986a_capsrc_nids;
1067 spec->input_mux = &ad1986a_capture_source;
1068 spec->num_mixers = 1;
1069 spec->mixers[0] = ad1986a_mixers;
1070 spec->num_init_verbs = 1;
1071 spec->init_verbs[0] = ad1986a_init_verbs;
1072 #ifdef CONFIG_SND_HDA_POWER_SAVE
1073 spec->loopback.amplist = ad1986a_loopbacks;
1074 #endif
1075 spec->vmaster_nid = 0x1b;
1076 spec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
1078 codec->patch_ops = ad198x_patch_ops;
1080 /* override some parameters */
1081 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1082 ad1986a_models,
1083 ad1986a_cfg_tbl);
1084 switch (board_config) {
1085 case AD1986A_3STACK:
1086 spec->num_mixers = 2;
1087 spec->mixers[1] = ad1986a_3st_mixers;
1088 spec->num_init_verbs = 2;
1089 spec->init_verbs[1] = ad1986a_ch2_init;
1090 spec->channel_mode = ad1986a_modes;
1091 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
1092 spec->need_dac_fix = 1;
1093 spec->multiout.max_channels = 2;
1094 spec->multiout.num_dacs = 1;
1095 break;
1096 case AD1986A_LAPTOP:
1097 spec->mixers[0] = ad1986a_laptop_mixers;
1098 spec->multiout.max_channels = 2;
1099 spec->multiout.num_dacs = 1;
1100 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1101 break;
1102 case AD1986A_LAPTOP_EAPD:
1103 spec->num_mixers = 3;
1104 spec->mixers[0] = ad1986a_laptop_master_mixers;
1105 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1106 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
1107 spec->num_init_verbs = 2;
1108 spec->init_verbs[1] = ad1986a_eapd_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 break;
1116 case AD1986A_SAMSUNG:
1117 spec->num_mixers = 2;
1118 spec->mixers[0] = ad1986a_laptop_master_mixers;
1119 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1120 spec->num_init_verbs = 3;
1121 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1122 spec->init_verbs[2] = ad1986a_automic_verbs;
1123 spec->multiout.max_channels = 2;
1124 spec->multiout.num_dacs = 1;
1125 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1126 if (!is_jack_available(codec, 0x25))
1127 spec->multiout.dig_out_nid = 0;
1128 spec->input_mux = &ad1986a_automic_capture_source;
1129 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1130 codec->patch_ops.init = ad1986a_automic_init;
1131 break;
1132 case AD1986A_SAMSUNG_P50:
1133 spec->num_mixers = 2;
1134 spec->mixers[0] = ad1986a_automute_master_mixers;
1135 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1136 spec->num_init_verbs = 4;
1137 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1138 spec->init_verbs[2] = ad1986a_automic_verbs;
1139 spec->init_verbs[3] = ad1986a_hp_init_verbs;
1140 spec->multiout.max_channels = 2;
1141 spec->multiout.num_dacs = 1;
1142 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1143 if (!is_jack_available(codec, 0x25))
1144 spec->multiout.dig_out_nid = 0;
1145 spec->input_mux = &ad1986a_automic_capture_source;
1146 codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
1147 codec->patch_ops.init = ad1986a_samsung_p50_init;
1148 break;
1149 case AD1986A_LAPTOP_AUTOMUTE:
1150 spec->num_mixers = 3;
1151 spec->mixers[0] = ad1986a_automute_master_mixers;
1152 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1153 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
1154 spec->num_init_verbs = 3;
1155 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1156 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1157 spec->multiout.max_channels = 2;
1158 spec->multiout.num_dacs = 1;
1159 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1160 if (!is_jack_available(codec, 0x25))
1161 spec->multiout.dig_out_nid = 0;
1162 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1163 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1164 codec->patch_ops.init = ad1986a_hp_init;
1165 /* Lenovo N100 seems to report the reversed bit
1166 * for HP jack-sensing
1168 spec->inv_jack_detect = 1;
1169 break;
1170 case AD1986A_ULTRA:
1171 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1172 spec->num_init_verbs = 2;
1173 spec->init_verbs[1] = ad1986a_ultra_init;
1174 spec->multiout.max_channels = 2;
1175 spec->multiout.num_dacs = 1;
1176 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1177 spec->multiout.dig_out_nid = 0;
1178 break;
1181 /* AD1986A has a hardware problem that it can't share a stream
1182 * with multiple output pins. The copy of front to surrounds
1183 * causes noisy or silent outputs at a certain timing, e.g.
1184 * changing the volume.
1185 * So, let's disable the shared stream.
1187 spec->multiout.no_share_stream = 1;
1189 codec->no_trigger_sense = 1;
1191 return 0;
1195 * AD1983 specific
1198 #define AD1983_SPDIF_OUT 0x02
1199 #define AD1983_DAC 0x03
1200 #define AD1983_ADC 0x04
1202 static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
1203 static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
1204 static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
1206 static struct hda_input_mux ad1983_capture_source = {
1207 .num_items = 4,
1208 .items = {
1209 { "Mic", 0x0 },
1210 { "Line", 0x1 },
1211 { "Mix", 0x2 },
1212 { "Mix Mono", 0x3 },
1217 * SPDIF playback route
1219 static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1221 static char *texts[] = { "PCM", "ADC" };
1223 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1224 uinfo->count = 1;
1225 uinfo->value.enumerated.items = 2;
1226 if (uinfo->value.enumerated.item > 1)
1227 uinfo->value.enumerated.item = 1;
1228 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1229 return 0;
1232 static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1234 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1235 struct ad198x_spec *spec = codec->spec;
1237 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1238 return 0;
1241 static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1243 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1244 struct ad198x_spec *spec = codec->spec;
1246 if (ucontrol->value.enumerated.item[0] > 1)
1247 return -EINVAL;
1248 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1249 spec->spdif_route = ucontrol->value.enumerated.item[0];
1250 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1251 AC_VERB_SET_CONNECT_SEL,
1252 spec->spdif_route);
1253 return 1;
1255 return 0;
1258 static struct snd_kcontrol_new ad1983_mixers[] = {
1259 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1260 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1261 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1262 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1263 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1264 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1265 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1266 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1267 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1268 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1269 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1270 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1271 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1272 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1273 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1275 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1276 .name = "Capture Source",
1277 .info = ad198x_mux_enum_info,
1278 .get = ad198x_mux_enum_get,
1279 .put = ad198x_mux_enum_put,
1282 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1283 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1284 .info = ad1983_spdif_route_info,
1285 .get = ad1983_spdif_route_get,
1286 .put = ad1983_spdif_route_put,
1288 { } /* end */
1291 static struct hda_verb ad1983_init_verbs[] = {
1292 /* Front, HP, Mono; mute as default */
1293 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1294 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1295 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1296 /* Beep, PCM, Mic, Line-In: mute */
1297 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1298 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1299 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1300 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1301 /* Front, HP selectors; from Mix */
1302 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1303 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1304 /* Mono selector; from Mix */
1305 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1306 /* Mic selector; Mic */
1307 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1308 /* Line-in selector: Line-in */
1309 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1310 /* Mic boost: 0dB */
1311 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1312 /* Record selector: mic */
1313 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1314 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1315 /* SPDIF route: PCM */
1316 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1317 /* Front Pin */
1318 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1319 /* HP Pin */
1320 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1321 /* Mono Pin */
1322 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1323 /* Mic Pin */
1324 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1325 /* Line Pin */
1326 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1327 { } /* end */
1330 #ifdef CONFIG_SND_HDA_POWER_SAVE
1331 static struct hda_amp_list ad1983_loopbacks[] = {
1332 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1333 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1334 { } /* end */
1336 #endif
1338 static int patch_ad1983(struct hda_codec *codec)
1340 struct ad198x_spec *spec;
1341 int err;
1343 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1344 if (spec == NULL)
1345 return -ENOMEM;
1347 codec->spec = spec;
1349 err = snd_hda_attach_beep_device(codec, 0x10);
1350 if (err < 0) {
1351 ad198x_free(codec);
1352 return err;
1354 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1356 spec->multiout.max_channels = 2;
1357 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1358 spec->multiout.dac_nids = ad1983_dac_nids;
1359 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
1360 spec->num_adc_nids = 1;
1361 spec->adc_nids = ad1983_adc_nids;
1362 spec->capsrc_nids = ad1983_capsrc_nids;
1363 spec->input_mux = &ad1983_capture_source;
1364 spec->num_mixers = 1;
1365 spec->mixers[0] = ad1983_mixers;
1366 spec->num_init_verbs = 1;
1367 spec->init_verbs[0] = ad1983_init_verbs;
1368 spec->spdif_route = 0;
1369 #ifdef CONFIG_SND_HDA_POWER_SAVE
1370 spec->loopback.amplist = ad1983_loopbacks;
1371 #endif
1372 spec->vmaster_nid = 0x05;
1374 codec->patch_ops = ad198x_patch_ops;
1376 codec->no_trigger_sense = 1;
1378 return 0;
1383 * AD1981 HD specific
1386 #define AD1981_SPDIF_OUT 0x02
1387 #define AD1981_DAC 0x03
1388 #define AD1981_ADC 0x04
1390 static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
1391 static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
1392 static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
1394 /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1395 static struct hda_input_mux ad1981_capture_source = {
1396 .num_items = 7,
1397 .items = {
1398 { "Front Mic", 0x0 },
1399 { "Line", 0x1 },
1400 { "Mix", 0x2 },
1401 { "Mix Mono", 0x3 },
1402 { "CD", 0x4 },
1403 { "Mic", 0x6 },
1404 { "Aux", 0x7 },
1408 static struct snd_kcontrol_new ad1981_mixers[] = {
1409 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1410 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1411 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1412 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1413 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1414 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1415 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1416 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1417 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1418 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1420 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1421 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1422 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1423 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1424 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1425 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1426 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1427 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1428 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1429 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1432 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1433 .name = "Capture Source",
1434 .info = ad198x_mux_enum_info,
1435 .get = ad198x_mux_enum_get,
1436 .put = ad198x_mux_enum_put,
1438 /* identical with AD1983 */
1440 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1441 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1442 .info = ad1983_spdif_route_info,
1443 .get = ad1983_spdif_route_get,
1444 .put = ad1983_spdif_route_put,
1446 { } /* end */
1449 static struct hda_verb ad1981_init_verbs[] = {
1450 /* Front, HP, Mono; mute as default */
1451 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1452 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1453 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1454 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1455 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1456 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1457 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1458 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1459 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1460 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1461 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1462 /* Front, HP selectors; from Mix */
1463 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1464 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1465 /* Mono selector; from Mix */
1466 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1467 /* Mic Mixer; select Front Mic */
1468 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1469 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1470 /* Mic boost: 0dB */
1471 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1472 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1473 /* Record selector: Front mic */
1474 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1475 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1476 /* SPDIF route: PCM */
1477 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1478 /* Front Pin */
1479 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1480 /* HP Pin */
1481 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1482 /* Mono Pin */
1483 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1484 /* Front & Rear Mic Pins */
1485 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1486 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1487 /* Line Pin */
1488 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1489 /* Digital Beep */
1490 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1491 /* Line-Out as Input: disabled */
1492 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1493 { } /* end */
1496 #ifdef CONFIG_SND_HDA_POWER_SAVE
1497 static struct hda_amp_list ad1981_loopbacks[] = {
1498 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1499 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1500 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1501 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1502 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1503 { } /* end */
1505 #endif
1508 * Patch for HP nx6320
1510 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
1511 * speaker output enabled _and_ mute-LED off.
1514 #define AD1981_HP_EVENT 0x37
1515 #define AD1981_MIC_EVENT 0x38
1517 static struct hda_verb ad1981_hp_init_verbs[] = {
1518 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1519 /* pin sensing on HP and Mic jacks */
1520 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1521 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1525 /* turn on/off EAPD (+ mute HP) as a master switch */
1526 static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1527 struct snd_ctl_elem_value *ucontrol)
1529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1530 struct ad198x_spec *spec = codec->spec;
1532 if (! ad198x_eapd_put(kcontrol, ucontrol))
1533 return 0;
1534 /* change speaker pin appropriately */
1535 snd_hda_codec_write(codec, 0x05, 0,
1536 AC_VERB_SET_PIN_WIDGET_CONTROL,
1537 spec->cur_eapd ? PIN_OUT : 0);
1538 /* toggle HP mute appropriately */
1539 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1540 HDA_AMP_MUTE,
1541 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
1542 return 1;
1545 /* bind volumes of both NID 0x05 and 0x06 */
1546 static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1547 .ops = &snd_hda_bind_vol,
1548 .values = {
1549 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1550 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1555 /* mute internal speaker if HP is plugged */
1556 static void ad1981_hp_automute(struct hda_codec *codec)
1558 unsigned int present;
1560 present = snd_hda_jack_detect(codec, 0x06);
1561 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1562 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1565 /* toggle input of built-in and mic jack appropriately */
1566 static void ad1981_hp_automic(struct hda_codec *codec)
1568 static struct hda_verb mic_jack_on[] = {
1569 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1570 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1573 static struct hda_verb mic_jack_off[] = {
1574 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1575 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1578 unsigned int present;
1580 present = snd_hda_jack_detect(codec, 0x08);
1581 if (present)
1582 snd_hda_sequence_write(codec, mic_jack_on);
1583 else
1584 snd_hda_sequence_write(codec, mic_jack_off);
1587 /* unsolicited event for HP jack sensing */
1588 static void ad1981_hp_unsol_event(struct hda_codec *codec,
1589 unsigned int res)
1591 res >>= 26;
1592 switch (res) {
1593 case AD1981_HP_EVENT:
1594 ad1981_hp_automute(codec);
1595 break;
1596 case AD1981_MIC_EVENT:
1597 ad1981_hp_automic(codec);
1598 break;
1602 static struct hda_input_mux ad1981_hp_capture_source = {
1603 .num_items = 3,
1604 .items = {
1605 { "Mic", 0x0 },
1606 { "Docking-Station", 0x1 },
1607 { "Mix", 0x2 },
1611 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1612 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
1614 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1615 .name = "Master Playback Switch",
1616 .info = ad198x_eapd_info,
1617 .get = ad198x_eapd_get,
1618 .put = ad1981_hp_master_sw_put,
1619 .private_value = 0x05,
1621 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1622 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1623 #if 0
1624 /* FIXME: analog mic/line loopback doesn't work with my tests...
1625 * (although recording is OK)
1627 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1628 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1629 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1630 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1631 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1632 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1633 /* FIXME: does this laptop have analog CD connection? */
1634 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1635 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1636 #endif
1637 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1638 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1639 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1640 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1642 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1643 .name = "Capture Source",
1644 .info = ad198x_mux_enum_info,
1645 .get = ad198x_mux_enum_get,
1646 .put = ad198x_mux_enum_put,
1648 { } /* end */
1651 /* initialize jack-sensing, too */
1652 static int ad1981_hp_init(struct hda_codec *codec)
1654 ad198x_init(codec);
1655 ad1981_hp_automute(codec);
1656 ad1981_hp_automic(codec);
1657 return 0;
1660 /* configuration for Toshiba Laptops */
1661 static struct hda_verb ad1981_toshiba_init_verbs[] = {
1662 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1663 /* pin sensing on HP and Mic jacks */
1664 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1665 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1669 static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1670 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1671 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1675 /* configuration for Lenovo Thinkpad T60 */
1676 static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1677 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1678 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1679 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1680 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1681 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1682 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1683 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1684 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1685 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1686 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1687 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1689 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1690 .name = "Capture Source",
1691 .info = ad198x_mux_enum_info,
1692 .get = ad198x_mux_enum_get,
1693 .put = ad198x_mux_enum_put,
1695 /* identical with AD1983 */
1697 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1698 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1699 .info = ad1983_spdif_route_info,
1700 .get = ad1983_spdif_route_get,
1701 .put = ad1983_spdif_route_put,
1703 { } /* end */
1706 static struct hda_input_mux ad1981_thinkpad_capture_source = {
1707 .num_items = 3,
1708 .items = {
1709 { "Mic", 0x0 },
1710 { "Mix", 0x2 },
1711 { "CD", 0x4 },
1715 /* models */
1716 enum {
1717 AD1981_BASIC,
1718 AD1981_HP,
1719 AD1981_THINKPAD,
1720 AD1981_TOSHIBA,
1721 AD1981_MODELS
1724 static const char *ad1981_models[AD1981_MODELS] = {
1725 [AD1981_HP] = "hp",
1726 [AD1981_THINKPAD] = "thinkpad",
1727 [AD1981_BASIC] = "basic",
1728 [AD1981_TOSHIBA] = "toshiba"
1731 static struct snd_pci_quirk ad1981_cfg_tbl[] = {
1732 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
1733 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
1734 /* All HP models */
1735 SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
1736 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
1737 /* Lenovo Thinkpad T60/X60/Z6xx */
1738 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
1739 /* HP nx6320 (reversed SSID, H/W bug) */
1740 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
1744 static int patch_ad1981(struct hda_codec *codec)
1746 struct ad198x_spec *spec;
1747 int err, board_config;
1749 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1750 if (spec == NULL)
1751 return -ENOMEM;
1753 codec->spec = spec;
1755 err = snd_hda_attach_beep_device(codec, 0x10);
1756 if (err < 0) {
1757 ad198x_free(codec);
1758 return err;
1760 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
1762 spec->multiout.max_channels = 2;
1763 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1764 spec->multiout.dac_nids = ad1981_dac_nids;
1765 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
1766 spec->num_adc_nids = 1;
1767 spec->adc_nids = ad1981_adc_nids;
1768 spec->capsrc_nids = ad1981_capsrc_nids;
1769 spec->input_mux = &ad1981_capture_source;
1770 spec->num_mixers = 1;
1771 spec->mixers[0] = ad1981_mixers;
1772 spec->num_init_verbs = 1;
1773 spec->init_verbs[0] = ad1981_init_verbs;
1774 spec->spdif_route = 0;
1775 #ifdef CONFIG_SND_HDA_POWER_SAVE
1776 spec->loopback.amplist = ad1981_loopbacks;
1777 #endif
1778 spec->vmaster_nid = 0x05;
1780 codec->patch_ops = ad198x_patch_ops;
1782 /* override some parameters */
1783 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1784 ad1981_models,
1785 ad1981_cfg_tbl);
1786 switch (board_config) {
1787 case AD1981_HP:
1788 spec->mixers[0] = ad1981_hp_mixers;
1789 spec->num_init_verbs = 2;
1790 spec->init_verbs[1] = ad1981_hp_init_verbs;
1791 spec->multiout.dig_out_nid = 0;
1792 spec->input_mux = &ad1981_hp_capture_source;
1794 codec->patch_ops.init = ad1981_hp_init;
1795 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1796 /* set the upper-limit for mixer amp to 0dB for avoiding the
1797 * possible damage by overloading
1799 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1800 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1801 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1802 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1803 (1 << AC_AMPCAP_MUTE_SHIFT));
1804 break;
1805 case AD1981_THINKPAD:
1806 spec->mixers[0] = ad1981_thinkpad_mixers;
1807 spec->input_mux = &ad1981_thinkpad_capture_source;
1808 /* set the upper-limit for mixer amp to 0dB for avoiding the
1809 * possible damage by overloading
1811 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1812 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1813 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1814 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1815 (1 << AC_AMPCAP_MUTE_SHIFT));
1816 break;
1817 case AD1981_TOSHIBA:
1818 spec->mixers[0] = ad1981_hp_mixers;
1819 spec->mixers[1] = ad1981_toshiba_mixers;
1820 spec->num_init_verbs = 2;
1821 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1822 spec->multiout.dig_out_nid = 0;
1823 spec->input_mux = &ad1981_hp_capture_source;
1824 codec->patch_ops.init = ad1981_hp_init;
1825 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1826 break;
1829 codec->no_trigger_sense = 1;
1831 return 0;
1836 * AD1988
1838 * Output pins and routes
1840 * Pin Mix Sel DAC (*)
1841 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1842 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1843 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1844 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1845 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1846 * port-F 0x16 (mute) <- 0x2a <- 06
1847 * port-G 0x24 (mute) <- 0x27 <- 05
1848 * port-H 0x25 (mute) <- 0x28 <- 0a
1849 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1851 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1852 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
1854 * Input pins and routes
1856 * pin boost mix input # / adc input #
1857 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1858 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1859 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1860 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1861 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1862 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1863 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1864 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1867 * DAC assignment
1868 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
1869 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
1871 * Inputs of Analog Mix (0x20)
1872 * 0:Port-B (front mic)
1873 * 1:Port-C/G/H (line-in)
1874 * 2:Port-A
1875 * 3:Port-D (line-in/2)
1876 * 4:Port-E/G/H (mic-in)
1877 * 5:Port-F (mic2-in)
1878 * 6:CD
1879 * 7:Beep
1881 * ADC selection
1882 * 0:Port-A
1883 * 1:Port-B (front mic-in)
1884 * 2:Port-C (line-in)
1885 * 3:Port-F (mic2-in)
1886 * 4:Port-E (mic-in)
1887 * 5:CD
1888 * 6:Port-G
1889 * 7:Port-H
1890 * 8:Port-D (line-in/2)
1891 * 9:Mix
1893 * Proposed pin assignments by the datasheet
1895 * 6-stack
1896 * Port-A front headphone
1897 * B front mic-in
1898 * C rear line-in
1899 * D rear front-out
1900 * E rear mic-in
1901 * F rear surround
1902 * G rear CLFE
1903 * H rear side
1905 * 3-stack
1906 * Port-A front headphone
1907 * B front mic
1908 * C rear line-in/surround
1909 * D rear front-out
1910 * E rear mic-in/CLFE
1912 * laptop
1913 * Port-A headphone
1914 * B mic-in
1915 * C docking station
1916 * D internal speaker (with EAPD)
1917 * E/F quad mic array
1921 /* models */
1922 enum {
1923 AD1988_6STACK,
1924 AD1988_6STACK_DIG,
1925 AD1988_3STACK,
1926 AD1988_3STACK_DIG,
1927 AD1988_LAPTOP,
1928 AD1988_LAPTOP_DIG,
1929 AD1988_AUTO,
1930 AD1988_MODEL_LAST,
1933 /* reivision id to check workarounds */
1934 #define AD1988A_REV2 0x100200
1936 #define is_rev2(codec) \
1937 ((codec)->vendor_id == 0x11d41988 && \
1938 (codec)->revision_id == AD1988A_REV2)
1941 * mixers
1944 static hda_nid_t ad1988_6stack_dac_nids[4] = {
1945 0x04, 0x06, 0x05, 0x0a
1948 static hda_nid_t ad1988_3stack_dac_nids[3] = {
1949 0x04, 0x05, 0x0a
1952 /* for AD1988A revision-2, DAC2-4 are swapped */
1953 static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1954 0x04, 0x05, 0x0a, 0x06
1957 static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
1958 0x04, 0x0a, 0x06
1961 static hda_nid_t ad1988_adc_nids[3] = {
1962 0x08, 0x09, 0x0f
1965 static hda_nid_t ad1988_capsrc_nids[3] = {
1966 0x0c, 0x0d, 0x0e
1969 #define AD1988_SPDIF_OUT 0x02
1970 #define AD1988_SPDIF_OUT_HDMI 0x0b
1971 #define AD1988_SPDIF_IN 0x07
1973 static hda_nid_t ad1989b_slave_dig_outs[] = {
1974 AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
1977 static struct hda_input_mux ad1988_6stack_capture_source = {
1978 .num_items = 5,
1979 .items = {
1980 { "Front Mic", 0x1 }, /* port-B */
1981 { "Line", 0x2 }, /* port-C */
1982 { "Mic", 0x4 }, /* port-E */
1983 { "CD", 0x5 },
1984 { "Mix", 0x9 },
1988 static struct hda_input_mux ad1988_laptop_capture_source = {
1989 .num_items = 3,
1990 .items = {
1991 { "Mic/Line", 0x1 }, /* port-B */
1992 { "CD", 0x5 },
1993 { "Mix", 0x9 },
1999 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
2000 struct snd_ctl_elem_info *uinfo)
2002 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2003 struct ad198x_spec *spec = codec->spec;
2004 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
2005 spec->num_channel_mode);
2008 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
2009 struct snd_ctl_elem_value *ucontrol)
2011 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2012 struct ad198x_spec *spec = codec->spec;
2013 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
2014 spec->num_channel_mode, spec->multiout.max_channels);
2017 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
2018 struct snd_ctl_elem_value *ucontrol)
2020 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2021 struct ad198x_spec *spec = codec->spec;
2022 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
2023 spec->num_channel_mode,
2024 &spec->multiout.max_channels);
2025 if (err >= 0 && spec->need_dac_fix)
2026 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
2027 return err;
2030 /* 6-stack mode */
2031 static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
2032 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2033 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
2034 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2035 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2036 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2037 { } /* end */
2040 static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
2041 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2042 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
2043 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2044 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
2045 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
2046 { } /* end */
2049 static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
2050 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2051 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
2052 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
2053 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
2054 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
2055 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2056 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2058 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2059 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2060 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2061 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2062 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2063 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2064 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2065 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2067 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2068 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2070 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2071 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2073 { } /* end */
2076 /* 3-stack mode */
2077 static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
2078 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2079 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2080 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2081 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2082 { } /* end */
2085 static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
2086 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2087 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2088 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
2089 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
2090 { } /* end */
2093 static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
2094 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2095 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
2096 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
2097 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
2098 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2099 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2101 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2102 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2103 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2104 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2105 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2106 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2107 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2108 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2110 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2111 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2113 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2114 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2116 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2117 .name = "Channel Mode",
2118 .info = ad198x_ch_mode_info,
2119 .get = ad198x_ch_mode_get,
2120 .put = ad198x_ch_mode_put,
2123 { } /* end */
2126 /* laptop mode */
2127 static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2128 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2129 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
2130 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2132 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2133 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2134 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2135 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2136 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2137 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2139 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2140 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2142 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2145 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2146 .name = "External Amplifier",
2147 .info = ad198x_eapd_info,
2148 .get = ad198x_eapd_get,
2149 .put = ad198x_eapd_put,
2150 .private_value = 0x12, /* port-D */
2153 { } /* end */
2156 /* capture */
2157 static struct snd_kcontrol_new ad1988_capture_mixers[] = {
2158 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2159 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2160 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2161 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2162 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2163 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2165 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2166 /* The multiple "Capture Source" controls confuse alsamixer
2167 * So call somewhat different..
2169 /* .name = "Capture Source", */
2170 .name = "Input Source",
2171 .count = 3,
2172 .info = ad198x_mux_enum_info,
2173 .get = ad198x_mux_enum_get,
2174 .put = ad198x_mux_enum_put,
2176 { } /* end */
2179 static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2180 struct snd_ctl_elem_info *uinfo)
2182 static char *texts[] = {
2183 "PCM", "ADC1", "ADC2", "ADC3"
2185 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2186 uinfo->count = 1;
2187 uinfo->value.enumerated.items = 4;
2188 if (uinfo->value.enumerated.item >= 4)
2189 uinfo->value.enumerated.item = 3;
2190 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2191 return 0;
2194 static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2195 struct snd_ctl_elem_value *ucontrol)
2197 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2198 unsigned int sel;
2200 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2201 AC_AMP_GET_INPUT);
2202 if (!(sel & 0x80))
2203 ucontrol->value.enumerated.item[0] = 0;
2204 else {
2205 sel = snd_hda_codec_read(codec, 0x0b, 0,
2206 AC_VERB_GET_CONNECT_SEL, 0);
2207 if (sel < 3)
2208 sel++;
2209 else
2210 sel = 0;
2211 ucontrol->value.enumerated.item[0] = sel;
2213 return 0;
2216 static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2217 struct snd_ctl_elem_value *ucontrol)
2219 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2220 unsigned int val, sel;
2221 int change;
2223 val = ucontrol->value.enumerated.item[0];
2224 if (val > 3)
2225 return -EINVAL;
2226 if (!val) {
2227 sel = snd_hda_codec_read(codec, 0x1d, 0,
2228 AC_VERB_GET_AMP_GAIN_MUTE,
2229 AC_AMP_GET_INPUT);
2230 change = sel & 0x80;
2231 if (change) {
2232 snd_hda_codec_write_cache(codec, 0x1d, 0,
2233 AC_VERB_SET_AMP_GAIN_MUTE,
2234 AMP_IN_UNMUTE(0));
2235 snd_hda_codec_write_cache(codec, 0x1d, 0,
2236 AC_VERB_SET_AMP_GAIN_MUTE,
2237 AMP_IN_MUTE(1));
2239 } else {
2240 sel = snd_hda_codec_read(codec, 0x1d, 0,
2241 AC_VERB_GET_AMP_GAIN_MUTE,
2242 AC_AMP_GET_INPUT | 0x01);
2243 change = sel & 0x80;
2244 if (change) {
2245 snd_hda_codec_write_cache(codec, 0x1d, 0,
2246 AC_VERB_SET_AMP_GAIN_MUTE,
2247 AMP_IN_MUTE(0));
2248 snd_hda_codec_write_cache(codec, 0x1d, 0,
2249 AC_VERB_SET_AMP_GAIN_MUTE,
2250 AMP_IN_UNMUTE(1));
2252 sel = snd_hda_codec_read(codec, 0x0b, 0,
2253 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2254 change |= sel != val;
2255 if (change)
2256 snd_hda_codec_write_cache(codec, 0x0b, 0,
2257 AC_VERB_SET_CONNECT_SEL,
2258 val - 1);
2260 return change;
2263 static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2264 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2266 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2267 .name = "IEC958 Playback Source",
2268 .info = ad1988_spdif_playback_source_info,
2269 .get = ad1988_spdif_playback_source_get,
2270 .put = ad1988_spdif_playback_source_put,
2272 { } /* end */
2275 static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2276 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2277 { } /* end */
2280 static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2281 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2282 HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
2283 { } /* end */
2287 * initialization verbs
2291 * for 6-stack (+dig)
2293 static struct hda_verb ad1988_6stack_init_verbs[] = {
2294 /* Front, Surround, CLFE, side DAC; unmute as default */
2295 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2296 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2297 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2298 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2299 /* Port-A front headphon path */
2300 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2301 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2302 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2303 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2304 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2305 /* Port-D line-out path */
2306 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2307 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2308 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2309 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2310 /* Port-F surround path */
2311 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2312 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2313 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2314 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2315 /* Port-G CLFE path */
2316 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2317 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2318 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2319 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2320 /* Port-H side path */
2321 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2322 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2323 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2324 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2325 /* Mono out path */
2326 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2327 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2328 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2329 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2330 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2331 /* Port-B front mic-in path */
2332 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2333 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2334 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2335 /* Port-C line-in path */
2336 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2337 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2338 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2339 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2340 /* Port-E mic-in path */
2341 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2342 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2343 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2344 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2345 /* Analog CD Input */
2346 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2347 /* Analog Mix output amp */
2348 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2353 static struct hda_verb ad1988_capture_init_verbs[] = {
2354 /* mute analog mix */
2355 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2356 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2357 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2358 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2359 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2360 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2361 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2362 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2363 /* select ADCs - front-mic */
2364 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2365 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2366 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2371 static struct hda_verb ad1988_spdif_init_verbs[] = {
2372 /* SPDIF out sel */
2373 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2374 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2375 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2376 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2377 /* SPDIF out pin */
2378 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2383 /* AD1989 has no ADC -> SPDIF route */
2384 static struct hda_verb ad1989_spdif_init_verbs[] = {
2385 /* SPDIF-1 out pin */
2386 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2387 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2388 /* SPDIF-2/HDMI out pin */
2389 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2390 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2395 * verbs for 3stack (+dig)
2397 static struct hda_verb ad1988_3stack_ch2_init[] = {
2398 /* set port-C to line-in */
2399 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2400 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2401 /* set port-E to mic-in */
2402 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2403 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2404 { } /* end */
2407 static struct hda_verb ad1988_3stack_ch6_init[] = {
2408 /* set port-C to surround out */
2409 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2410 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2411 /* set port-E to CLFE out */
2412 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2413 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2414 { } /* end */
2417 static struct hda_channel_mode ad1988_3stack_modes[2] = {
2418 { 2, ad1988_3stack_ch2_init },
2419 { 6, ad1988_3stack_ch6_init },
2422 static struct hda_verb ad1988_3stack_init_verbs[] = {
2423 /* Front, Surround, CLFE, side DAC; unmute as default */
2424 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2425 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2426 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2427 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2428 /* Port-A front headphon path */
2429 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2430 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2431 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2432 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2433 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2434 /* Port-D line-out path */
2435 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2436 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2437 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2438 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2439 /* Mono out path */
2440 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2441 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2442 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2443 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2444 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2445 /* Port-B front mic-in path */
2446 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2447 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2448 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2449 /* Port-C line-in/surround path - 6ch mode as default */
2450 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2451 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2452 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2453 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
2454 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2455 /* Port-E mic-in/CLFE path - 6ch mode as default */
2456 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2457 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2458 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2459 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
2460 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2461 /* mute analog mix */
2462 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2463 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2464 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2465 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2466 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2467 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2468 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2469 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2470 /* select ADCs - front-mic */
2471 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2472 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2473 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2474 /* Analog Mix output amp */
2475 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2480 * verbs for laptop mode (+dig)
2482 static struct hda_verb ad1988_laptop_hp_on[] = {
2483 /* unmute port-A and mute port-D */
2484 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2485 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2486 { } /* end */
2488 static struct hda_verb ad1988_laptop_hp_off[] = {
2489 /* mute port-A and unmute port-D */
2490 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2491 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2492 { } /* end */
2495 #define AD1988_HP_EVENT 0x01
2497 static struct hda_verb ad1988_laptop_init_verbs[] = {
2498 /* Front, Surround, CLFE, side DAC; unmute as default */
2499 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2500 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2501 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2502 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2503 /* Port-A front headphon path */
2504 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2505 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2506 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2507 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2508 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2509 /* unsolicited event for pin-sense */
2510 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2511 /* Port-D line-out path + EAPD */
2512 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2513 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2514 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2515 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2516 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2517 /* Mono out path */
2518 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2519 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2520 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2521 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2522 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2523 /* Port-B mic-in path */
2524 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2525 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2526 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2527 /* Port-C docking station - try to output */
2528 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2529 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2530 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2531 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2532 /* mute analog mix */
2533 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2534 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2535 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2536 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2537 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2538 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2539 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2540 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2541 /* select ADCs - mic */
2542 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2543 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2544 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2545 /* Analog Mix output amp */
2546 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2550 static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2552 if ((res >> 26) != AD1988_HP_EVENT)
2553 return;
2554 if (snd_hda_jack_detect(codec, 0x11))
2555 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2556 else
2557 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2560 #ifdef CONFIG_SND_HDA_POWER_SAVE
2561 static struct hda_amp_list ad1988_loopbacks[] = {
2562 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2563 { 0x20, HDA_INPUT, 1 }, /* Line */
2564 { 0x20, HDA_INPUT, 4 }, /* Mic */
2565 { 0x20, HDA_INPUT, 6 }, /* CD */
2566 { } /* end */
2568 #endif
2571 * Automatic parse of I/O pins from the BIOS configuration
2574 enum {
2575 AD_CTL_WIDGET_VOL,
2576 AD_CTL_WIDGET_MUTE,
2577 AD_CTL_BIND_MUTE,
2579 static struct snd_kcontrol_new ad1988_control_templates[] = {
2580 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2581 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2582 HDA_BIND_MUTE(NULL, 0, 0, 0),
2585 /* add dynamic controls */
2586 static int add_control(struct ad198x_spec *spec, int type, const char *name,
2587 unsigned long val)
2589 struct snd_kcontrol_new *knew;
2591 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2592 knew = snd_array_new(&spec->kctls);
2593 if (!knew)
2594 return -ENOMEM;
2595 *knew = ad1988_control_templates[type];
2596 knew->name = kstrdup(name, GFP_KERNEL);
2597 if (! knew->name)
2598 return -ENOMEM;
2599 if (get_amp_nid_(val))
2600 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
2601 knew->private_value = val;
2602 return 0;
2605 #define AD1988_PIN_CD_NID 0x18
2606 #define AD1988_PIN_BEEP_NID 0x10
2608 static hda_nid_t ad1988_mixer_nids[8] = {
2609 /* A B C D E F G H */
2610 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2613 static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2615 static hda_nid_t idx_to_dac[8] = {
2616 /* A B C D E F G H */
2617 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
2619 static hda_nid_t idx_to_dac_rev2[8] = {
2620 /* A B C D E F G H */
2621 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
2623 if (is_rev2(codec))
2624 return idx_to_dac_rev2[idx];
2625 else
2626 return idx_to_dac[idx];
2629 static hda_nid_t ad1988_boost_nids[8] = {
2630 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2633 static int ad1988_pin_idx(hda_nid_t nid)
2635 static hda_nid_t ad1988_io_pins[8] = {
2636 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2638 int i;
2639 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2640 if (ad1988_io_pins[i] == nid)
2641 return i;
2642 return 0; /* should be -1 */
2645 static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2647 static int loopback_idx[8] = {
2648 2, 0, 1, 3, 4, 5, 1, 4
2650 switch (nid) {
2651 case AD1988_PIN_CD_NID:
2652 return 6;
2653 default:
2654 return loopback_idx[ad1988_pin_idx(nid)];
2658 static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2660 static int adc_idx[8] = {
2661 0, 1, 2, 8, 4, 3, 6, 7
2663 switch (nid) {
2664 case AD1988_PIN_CD_NID:
2665 return 5;
2666 default:
2667 return adc_idx[ad1988_pin_idx(nid)];
2671 /* fill in the dac_nids table from the parsed pin configuration */
2672 static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2673 const struct auto_pin_cfg *cfg)
2675 struct ad198x_spec *spec = codec->spec;
2676 int i, idx;
2678 spec->multiout.dac_nids = spec->private_dac_nids;
2680 /* check the pins hardwired to audio widget */
2681 for (i = 0; i < cfg->line_outs; i++) {
2682 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2683 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2685 spec->multiout.num_dacs = cfg->line_outs;
2686 return 0;
2689 /* add playback controls from the parsed DAC table */
2690 static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2691 const struct auto_pin_cfg *cfg)
2693 char name[32];
2694 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2695 hda_nid_t nid;
2696 int i, err;
2698 for (i = 0; i < cfg->line_outs; i++) {
2699 hda_nid_t dac = spec->multiout.dac_nids[i];
2700 if (! dac)
2701 continue;
2702 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2703 if (i == 2) {
2704 /* Center/LFE */
2705 err = add_control(spec, AD_CTL_WIDGET_VOL,
2706 "Center Playback Volume",
2707 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2708 if (err < 0)
2709 return err;
2710 err = add_control(spec, AD_CTL_WIDGET_VOL,
2711 "LFE Playback Volume",
2712 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2713 if (err < 0)
2714 return err;
2715 err = add_control(spec, AD_CTL_BIND_MUTE,
2716 "Center Playback Switch",
2717 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2718 if (err < 0)
2719 return err;
2720 err = add_control(spec, AD_CTL_BIND_MUTE,
2721 "LFE Playback Switch",
2722 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2723 if (err < 0)
2724 return err;
2725 } else {
2726 sprintf(name, "%s Playback Volume", chname[i]);
2727 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2728 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2729 if (err < 0)
2730 return err;
2731 sprintf(name, "%s Playback Switch", chname[i]);
2732 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2733 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2734 if (err < 0)
2735 return err;
2738 return 0;
2741 /* add playback controls for speaker and HP outputs */
2742 static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2743 const char *pfx)
2745 struct ad198x_spec *spec = codec->spec;
2746 hda_nid_t nid;
2747 int i, idx, err;
2748 char name[32];
2750 if (! pin)
2751 return 0;
2753 idx = ad1988_pin_idx(pin);
2754 nid = ad1988_idx_to_dac(codec, idx);
2755 /* check whether the corresponding DAC was already taken */
2756 for (i = 0; i < spec->autocfg.line_outs; i++) {
2757 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2758 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
2759 if (dac == nid)
2760 break;
2762 if (i >= spec->autocfg.line_outs) {
2763 /* specify the DAC as the extra output */
2764 if (!spec->multiout.hp_nid)
2765 spec->multiout.hp_nid = nid;
2766 else
2767 spec->multiout.extra_out_nid[0] = nid;
2768 /* control HP volume/switch on the output mixer amp */
2769 sprintf(name, "%s Playback Volume", pfx);
2770 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2771 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2772 if (err < 0)
2773 return err;
2775 nid = ad1988_mixer_nids[idx];
2776 sprintf(name, "%s Playback Switch", pfx);
2777 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2778 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2779 return err;
2780 return 0;
2783 /* create input playback/capture controls for the given pin */
2784 static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2785 const char *ctlname, int boost)
2787 char name[32];
2788 int err, idx;
2790 sprintf(name, "%s Playback Volume", ctlname);
2791 idx = ad1988_pin_to_loopback_idx(pin);
2792 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2793 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2794 return err;
2795 sprintf(name, "%s Playback Switch", ctlname);
2796 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2797 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2798 return err;
2799 if (boost) {
2800 hda_nid_t bnid;
2801 idx = ad1988_pin_idx(pin);
2802 bnid = ad1988_boost_nids[idx];
2803 if (bnid) {
2804 sprintf(name, "%s Boost", ctlname);
2805 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2806 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2810 return 0;
2813 /* create playback/capture controls for input pins */
2814 static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2815 const struct auto_pin_cfg *cfg)
2817 struct hda_input_mux *imux = &spec->private_imux;
2818 int i, err;
2820 for (i = 0; i < AUTO_PIN_LAST; i++) {
2821 err = new_analog_input(spec, cfg->input_pins[i],
2822 auto_pin_cfg_labels[i],
2823 i <= AUTO_PIN_FRONT_MIC);
2824 if (err < 0)
2825 return err;
2826 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2827 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2828 imux->num_items++;
2830 imux->items[imux->num_items].label = "Mix";
2831 imux->items[imux->num_items].index = 9;
2832 imux->num_items++;
2834 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2835 "Analog Mix Playback Volume",
2836 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2837 return err;
2838 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2839 "Analog Mix Playback Switch",
2840 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2841 return err;
2843 return 0;
2846 static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2847 hda_nid_t nid, int pin_type,
2848 int dac_idx)
2850 /* set as output */
2851 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2852 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2853 switch (nid) {
2854 case 0x11: /* port-A - DAC 04 */
2855 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2856 break;
2857 case 0x14: /* port-B - DAC 06 */
2858 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2859 break;
2860 case 0x15: /* port-C - DAC 05 */
2861 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2862 break;
2863 case 0x17: /* port-E - DAC 0a */
2864 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2865 break;
2866 case 0x13: /* mono - DAC 04 */
2867 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2868 break;
2872 static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2874 struct ad198x_spec *spec = codec->spec;
2875 int i;
2877 for (i = 0; i < spec->autocfg.line_outs; i++) {
2878 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2879 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2883 static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2885 struct ad198x_spec *spec = codec->spec;
2886 hda_nid_t pin;
2888 pin = spec->autocfg.speaker_pins[0];
2889 if (pin) /* connect to front */
2890 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2891 pin = spec->autocfg.hp_pins[0];
2892 if (pin) /* connect to front */
2893 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2896 static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2898 struct ad198x_spec *spec = codec->spec;
2899 int i, idx;
2901 for (i = 0; i < AUTO_PIN_LAST; i++) {
2902 hda_nid_t nid = spec->autocfg.input_pins[i];
2903 if (! nid)
2904 continue;
2905 switch (nid) {
2906 case 0x15: /* port-C */
2907 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2908 break;
2909 case 0x17: /* port-E */
2910 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2911 break;
2913 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2914 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2915 if (nid != AD1988_PIN_CD_NID)
2916 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2917 AMP_OUT_MUTE);
2918 idx = ad1988_pin_idx(nid);
2919 if (ad1988_boost_nids[idx])
2920 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2921 AC_VERB_SET_AMP_GAIN_MUTE,
2922 AMP_OUT_ZERO);
2926 /* parse the BIOS configuration and set up the alc_spec */
2927 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2928 static int ad1988_parse_auto_config(struct hda_codec *codec)
2930 struct ad198x_spec *spec = codec->spec;
2931 int err;
2933 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2934 return err;
2935 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2936 return err;
2937 if (! spec->autocfg.line_outs)
2938 return 0; /* can't find valid BIOS pin config */
2939 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2940 (err = ad1988_auto_create_extra_out(codec,
2941 spec->autocfg.speaker_pins[0],
2942 "Speaker")) < 0 ||
2943 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
2944 "Headphone")) < 0 ||
2945 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2946 return err;
2948 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2950 if (spec->autocfg.dig_outs)
2951 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2952 if (spec->autocfg.dig_in_pin)
2953 spec->dig_in_nid = AD1988_SPDIF_IN;
2955 if (spec->kctls.list)
2956 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2958 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2960 spec->input_mux = &spec->private_imux;
2962 return 1;
2965 /* init callback for auto-configuration model -- overriding the default init */
2966 static int ad1988_auto_init(struct hda_codec *codec)
2968 ad198x_init(codec);
2969 ad1988_auto_init_multi_out(codec);
2970 ad1988_auto_init_extra_out(codec);
2971 ad1988_auto_init_analog_input(codec);
2972 return 0;
2979 static const char *ad1988_models[AD1988_MODEL_LAST] = {
2980 [AD1988_6STACK] = "6stack",
2981 [AD1988_6STACK_DIG] = "6stack-dig",
2982 [AD1988_3STACK] = "3stack",
2983 [AD1988_3STACK_DIG] = "3stack-dig",
2984 [AD1988_LAPTOP] = "laptop",
2985 [AD1988_LAPTOP_DIG] = "laptop-dig",
2986 [AD1988_AUTO] = "auto",
2989 static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2990 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
2991 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
2992 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
2993 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
2997 static int patch_ad1988(struct hda_codec *codec)
2999 struct ad198x_spec *spec;
3000 int err, board_config;
3002 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3003 if (spec == NULL)
3004 return -ENOMEM;
3006 codec->spec = spec;
3008 if (is_rev2(codec))
3009 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
3011 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
3012 ad1988_models, ad1988_cfg_tbl);
3013 if (board_config < 0) {
3014 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3015 codec->chip_name);
3016 board_config = AD1988_AUTO;
3019 if (board_config == AD1988_AUTO) {
3020 /* automatic parse from the BIOS config */
3021 err = ad1988_parse_auto_config(codec);
3022 if (err < 0) {
3023 ad198x_free(codec);
3024 return err;
3025 } else if (! err) {
3026 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
3027 board_config = AD1988_6STACK;
3031 err = snd_hda_attach_beep_device(codec, 0x10);
3032 if (err < 0) {
3033 ad198x_free(codec);
3034 return err;
3036 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3038 switch (board_config) {
3039 case AD1988_6STACK:
3040 case AD1988_6STACK_DIG:
3041 spec->multiout.max_channels = 8;
3042 spec->multiout.num_dacs = 4;
3043 if (is_rev2(codec))
3044 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
3045 else
3046 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
3047 spec->input_mux = &ad1988_6stack_capture_source;
3048 spec->num_mixers = 2;
3049 if (is_rev2(codec))
3050 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
3051 else
3052 spec->mixers[0] = ad1988_6stack_mixers1;
3053 spec->mixers[1] = ad1988_6stack_mixers2;
3054 spec->num_init_verbs = 1;
3055 spec->init_verbs[0] = ad1988_6stack_init_verbs;
3056 if (board_config == AD1988_6STACK_DIG) {
3057 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3058 spec->dig_in_nid = AD1988_SPDIF_IN;
3060 break;
3061 case AD1988_3STACK:
3062 case AD1988_3STACK_DIG:
3063 spec->multiout.max_channels = 6;
3064 spec->multiout.num_dacs = 3;
3065 if (is_rev2(codec))
3066 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
3067 else
3068 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
3069 spec->input_mux = &ad1988_6stack_capture_source;
3070 spec->channel_mode = ad1988_3stack_modes;
3071 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
3072 spec->num_mixers = 2;
3073 if (is_rev2(codec))
3074 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
3075 else
3076 spec->mixers[0] = ad1988_3stack_mixers1;
3077 spec->mixers[1] = ad1988_3stack_mixers2;
3078 spec->num_init_verbs = 1;
3079 spec->init_verbs[0] = ad1988_3stack_init_verbs;
3080 if (board_config == AD1988_3STACK_DIG)
3081 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3082 break;
3083 case AD1988_LAPTOP:
3084 case AD1988_LAPTOP_DIG:
3085 spec->multiout.max_channels = 2;
3086 spec->multiout.num_dacs = 1;
3087 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
3088 spec->input_mux = &ad1988_laptop_capture_source;
3089 spec->num_mixers = 1;
3090 spec->mixers[0] = ad1988_laptop_mixers;
3091 spec->inv_eapd = 1; /* inverted EAPD */
3092 spec->num_init_verbs = 1;
3093 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3094 if (board_config == AD1988_LAPTOP_DIG)
3095 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3096 break;
3099 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3100 spec->adc_nids = ad1988_adc_nids;
3101 spec->capsrc_nids = ad1988_capsrc_nids;
3102 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
3103 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
3104 if (spec->multiout.dig_out_nid) {
3105 if (codec->vendor_id >= 0x11d4989a) {
3106 spec->mixers[spec->num_mixers++] =
3107 ad1989_spdif_out_mixers;
3108 spec->init_verbs[spec->num_init_verbs++] =
3109 ad1989_spdif_init_verbs;
3110 codec->slave_dig_outs = ad1989b_slave_dig_outs;
3111 } else {
3112 spec->mixers[spec->num_mixers++] =
3113 ad1988_spdif_out_mixers;
3114 spec->init_verbs[spec->num_init_verbs++] =
3115 ad1988_spdif_init_verbs;
3118 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
3119 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
3121 codec->patch_ops = ad198x_patch_ops;
3122 switch (board_config) {
3123 case AD1988_AUTO:
3124 codec->patch_ops.init = ad1988_auto_init;
3125 break;
3126 case AD1988_LAPTOP:
3127 case AD1988_LAPTOP_DIG:
3128 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
3129 break;
3131 #ifdef CONFIG_SND_HDA_POWER_SAVE
3132 spec->loopback.amplist = ad1988_loopbacks;
3133 #endif
3134 spec->vmaster_nid = 0x04;
3136 codec->no_trigger_sense = 1;
3138 return 0;
3143 * AD1884 / AD1984
3145 * port-B - front line/mic-in
3146 * port-E - aux in/out
3147 * port-F - aux in/out
3148 * port-C - rear line/mic-in
3149 * port-D - rear line/hp-out
3150 * port-A - front line/hp-out
3152 * AD1984 = AD1884 + two digital mic-ins
3154 * FIXME:
3155 * For simplicity, we share the single DAC for both HP and line-outs
3156 * right now. The inidividual playbacks could be easily implemented,
3157 * but no build-up framework is given, so far.
3160 static hda_nid_t ad1884_dac_nids[1] = {
3161 0x04,
3164 static hda_nid_t ad1884_adc_nids[2] = {
3165 0x08, 0x09,
3168 static hda_nid_t ad1884_capsrc_nids[2] = {
3169 0x0c, 0x0d,
3172 #define AD1884_SPDIF_OUT 0x02
3174 static struct hda_input_mux ad1884_capture_source = {
3175 .num_items = 4,
3176 .items = {
3177 { "Front Mic", 0x0 },
3178 { "Mic", 0x1 },
3179 { "CD", 0x2 },
3180 { "Mix", 0x3 },
3184 static struct snd_kcontrol_new ad1884_base_mixers[] = {
3185 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3186 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3187 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3188 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3189 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3190 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3191 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3192 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3193 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3194 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3195 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3196 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3197 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3198 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3199 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3200 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3201 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3202 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3204 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3205 /* The multiple "Capture Source" controls confuse alsamixer
3206 * So call somewhat different..
3208 /* .name = "Capture Source", */
3209 .name = "Input Source",
3210 .count = 2,
3211 .info = ad198x_mux_enum_info,
3212 .get = ad198x_mux_enum_get,
3213 .put = ad198x_mux_enum_put,
3215 /* SPDIF controls */
3216 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3218 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3219 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3220 /* identical with ad1983 */
3221 .info = ad1983_spdif_route_info,
3222 .get = ad1983_spdif_route_get,
3223 .put = ad1983_spdif_route_put,
3225 { } /* end */
3228 static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3229 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3230 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3231 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
3232 HDA_INPUT),
3233 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
3234 HDA_INPUT),
3235 { } /* end */
3239 * initialization verbs
3241 static struct hda_verb ad1884_init_verbs[] = {
3242 /* DACs; mute as default */
3243 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3244 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3245 /* Port-A (HP) mixer */
3246 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3247 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3248 /* Port-A pin */
3249 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3250 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3251 /* HP selector - select DAC2 */
3252 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3253 /* Port-D (Line-out) mixer */
3254 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3255 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3256 /* Port-D pin */
3257 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3258 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3259 /* Mono-out mixer */
3260 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3261 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3262 /* Mono-out pin */
3263 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3264 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3265 /* Mono selector */
3266 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3267 /* Port-B (front mic) pin */
3268 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3269 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3270 /* Port-C (rear mic) pin */
3271 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3272 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3273 /* Analog mixer; mute as default */
3274 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3275 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3276 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3277 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3278 /* Analog Mix output amp */
3279 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3280 /* SPDIF output selector */
3281 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3282 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3283 { } /* end */
3286 #ifdef CONFIG_SND_HDA_POWER_SAVE
3287 static struct hda_amp_list ad1884_loopbacks[] = {
3288 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3289 { 0x20, HDA_INPUT, 1 }, /* Mic */
3290 { 0x20, HDA_INPUT, 2 }, /* CD */
3291 { 0x20, HDA_INPUT, 4 }, /* Docking */
3292 { } /* end */
3294 #endif
3296 static const char *ad1884_slave_vols[] = {
3297 "PCM Playback Volume",
3298 "Mic Playback Volume",
3299 "Mono Playback Volume",
3300 "Front Mic Playback Volume",
3301 "Mic Playback Volume",
3302 "CD Playback Volume",
3303 "Internal Mic Playback Volume",
3304 "Docking Mic Playback Volume",
3305 /* "Beep Playback Volume", */
3306 "IEC958 Playback Volume",
3307 NULL
3310 static int patch_ad1884(struct hda_codec *codec)
3312 struct ad198x_spec *spec;
3313 int err;
3315 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3316 if (spec == NULL)
3317 return -ENOMEM;
3319 codec->spec = spec;
3321 err = snd_hda_attach_beep_device(codec, 0x10);
3322 if (err < 0) {
3323 ad198x_free(codec);
3324 return err;
3326 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3328 spec->multiout.max_channels = 2;
3329 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3330 spec->multiout.dac_nids = ad1884_dac_nids;
3331 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3332 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3333 spec->adc_nids = ad1884_adc_nids;
3334 spec->capsrc_nids = ad1884_capsrc_nids;
3335 spec->input_mux = &ad1884_capture_source;
3336 spec->num_mixers = 1;
3337 spec->mixers[0] = ad1884_base_mixers;
3338 spec->num_init_verbs = 1;
3339 spec->init_verbs[0] = ad1884_init_verbs;
3340 spec->spdif_route = 0;
3341 #ifdef CONFIG_SND_HDA_POWER_SAVE
3342 spec->loopback.amplist = ad1884_loopbacks;
3343 #endif
3344 spec->vmaster_nid = 0x04;
3345 /* we need to cover all playback volumes */
3346 spec->slave_vols = ad1884_slave_vols;
3348 codec->patch_ops = ad198x_patch_ops;
3350 codec->no_trigger_sense = 1;
3352 return 0;
3356 * Lenovo Thinkpad T61/X61
3358 static struct hda_input_mux ad1984_thinkpad_capture_source = {
3359 .num_items = 4,
3360 .items = {
3361 { "Mic", 0x0 },
3362 { "Internal Mic", 0x1 },
3363 { "Mix", 0x3 },
3364 { "Docking-Station", 0x4 },
3370 * Dell Precision T3400
3372 static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3373 .num_items = 3,
3374 .items = {
3375 { "Front Mic", 0x0 },
3376 { "Line-In", 0x1 },
3377 { "Mix", 0x3 },
3382 static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3383 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3384 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3385 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3386 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3387 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3388 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3389 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3390 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3391 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3392 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3393 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3394 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3395 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3396 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3397 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3398 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3399 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3401 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3402 /* The multiple "Capture Source" controls confuse alsamixer
3403 * So call somewhat different..
3405 /* .name = "Capture Source", */
3406 .name = "Input Source",
3407 .count = 2,
3408 .info = ad198x_mux_enum_info,
3409 .get = ad198x_mux_enum_get,
3410 .put = ad198x_mux_enum_put,
3412 /* SPDIF controls */
3413 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3415 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3416 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3417 /* identical with ad1983 */
3418 .info = ad1983_spdif_route_info,
3419 .get = ad1983_spdif_route_get,
3420 .put = ad1983_spdif_route_put,
3422 { } /* end */
3425 /* additional verbs */
3426 static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3427 /* Port-E (docking station mic) pin */
3428 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3429 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3430 /* docking mic boost */
3431 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3432 /* Analog mixer - docking mic; mute as default */
3433 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3434 /* enable EAPD bit */
3435 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3436 { } /* end */
3440 * Dell Precision T3400
3442 static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3443 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3444 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3445 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3446 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3447 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3448 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3449 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3450 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3451 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
3452 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3453 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3454 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3455 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3456 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3457 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3459 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3460 /* The multiple "Capture Source" controls confuse alsamixer
3461 * So call somewhat different..
3463 /* .name = "Capture Source", */
3464 .name = "Input Source",
3465 .count = 2,
3466 .info = ad198x_mux_enum_info,
3467 .get = ad198x_mux_enum_get,
3468 .put = ad198x_mux_enum_put,
3470 { } /* end */
3473 /* Digial MIC ADC NID 0x05 + 0x06 */
3474 static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3475 struct hda_codec *codec,
3476 unsigned int stream_tag,
3477 unsigned int format,
3478 struct snd_pcm_substream *substream)
3480 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3481 stream_tag, 0, format);
3482 return 0;
3485 static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3486 struct hda_codec *codec,
3487 struct snd_pcm_substream *substream)
3489 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
3490 return 0;
3493 static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3494 .substreams = 2,
3495 .channels_min = 2,
3496 .channels_max = 2,
3497 .nid = 0x05,
3498 .ops = {
3499 .prepare = ad1984_pcm_dmic_prepare,
3500 .cleanup = ad1984_pcm_dmic_cleanup
3504 static int ad1984_build_pcms(struct hda_codec *codec)
3506 struct ad198x_spec *spec = codec->spec;
3507 struct hda_pcm *info;
3508 int err;
3510 err = ad198x_build_pcms(codec);
3511 if (err < 0)
3512 return err;
3514 info = spec->pcm_rec + codec->num_pcms;
3515 codec->num_pcms++;
3516 info->name = "AD1984 Digital Mic";
3517 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3518 return 0;
3521 /* models */
3522 enum {
3523 AD1984_BASIC,
3524 AD1984_THINKPAD,
3525 AD1984_DELL_DESKTOP,
3526 AD1984_MODELS
3529 static const char *ad1984_models[AD1984_MODELS] = {
3530 [AD1984_BASIC] = "basic",
3531 [AD1984_THINKPAD] = "thinkpad",
3532 [AD1984_DELL_DESKTOP] = "dell_desktop",
3535 static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3536 /* Lenovo Thinkpad T61/X61 */
3537 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
3538 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
3539 SND_PCI_QUIRK(0x1028, 0x0233, "Dell Latitude E6400", AD1984_DELL_DESKTOP),
3543 static int patch_ad1984(struct hda_codec *codec)
3545 struct ad198x_spec *spec;
3546 int board_config, err;
3548 err = patch_ad1884(codec);
3549 if (err < 0)
3550 return err;
3551 spec = codec->spec;
3552 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3553 ad1984_models, ad1984_cfg_tbl);
3554 switch (board_config) {
3555 case AD1984_BASIC:
3556 /* additional digital mics */
3557 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3558 codec->patch_ops.build_pcms = ad1984_build_pcms;
3559 break;
3560 case AD1984_THINKPAD:
3561 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3562 spec->input_mux = &ad1984_thinkpad_capture_source;
3563 spec->mixers[0] = ad1984_thinkpad_mixers;
3564 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3565 break;
3566 case AD1984_DELL_DESKTOP:
3567 spec->multiout.dig_out_nid = 0;
3568 spec->input_mux = &ad1984_dell_desktop_capture_source;
3569 spec->mixers[0] = ad1984_dell_desktop_mixers;
3570 break;
3572 return 0;
3577 * AD1883 / AD1884A / AD1984A / AD1984B
3579 * port-B (0x14) - front mic-in
3580 * port-E (0x1c) - rear mic-in
3581 * port-F (0x16) - CD / ext out
3582 * port-C (0x15) - rear line-in
3583 * port-D (0x12) - rear line-out
3584 * port-A (0x11) - front hp-out
3586 * AD1984A = AD1884A + digital-mic
3587 * AD1883 = equivalent with AD1984A
3588 * AD1984B = AD1984A + extra SPDIF-out
3590 * FIXME:
3591 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3594 static hda_nid_t ad1884a_dac_nids[1] = {
3595 0x03,
3598 #define ad1884a_adc_nids ad1884_adc_nids
3599 #define ad1884a_capsrc_nids ad1884_capsrc_nids
3601 #define AD1884A_SPDIF_OUT 0x02
3603 static struct hda_input_mux ad1884a_capture_source = {
3604 .num_items = 5,
3605 .items = {
3606 { "Front Mic", 0x0 },
3607 { "Mic", 0x4 },
3608 { "Line", 0x1 },
3609 { "CD", 0x2 },
3610 { "Mix", 0x3 },
3614 static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3615 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3616 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3617 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3618 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3619 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3620 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3621 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3622 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3623 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3624 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3625 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3626 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3627 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3628 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3629 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3630 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3631 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3632 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3633 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3634 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3635 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3636 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3637 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3639 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3640 /* The multiple "Capture Source" controls confuse alsamixer
3641 * So call somewhat different..
3643 /* .name = "Capture Source", */
3644 .name = "Input Source",
3645 .count = 2,
3646 .info = ad198x_mux_enum_info,
3647 .get = ad198x_mux_enum_get,
3648 .put = ad198x_mux_enum_put,
3650 /* SPDIF controls */
3651 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3653 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3654 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3655 /* identical with ad1983 */
3656 .info = ad1983_spdif_route_info,
3657 .get = ad1983_spdif_route_get,
3658 .put = ad1983_spdif_route_put,
3660 { } /* end */
3664 * initialization verbs
3666 static struct hda_verb ad1884a_init_verbs[] = {
3667 /* DACs; unmute as default */
3668 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3669 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3670 /* Port-A (HP) mixer - route only from analog mixer */
3671 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3672 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3673 /* Port-A pin */
3674 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3675 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3676 /* Port-D (Line-out) mixer - route only from analog mixer */
3677 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3678 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3679 /* Port-D pin */
3680 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3681 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3682 /* Mono-out mixer - route only from analog mixer */
3683 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3684 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3685 /* Mono-out pin */
3686 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3687 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3688 /* Port-B (front mic) pin */
3689 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3690 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3691 /* Port-C (rear line-in) pin */
3692 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3693 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3694 /* Port-E (rear mic) pin */
3695 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3696 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3697 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3698 /* Port-F (CD) pin */
3699 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3700 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3701 /* Analog mixer; mute as default */
3702 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3703 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3704 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3705 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3706 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3707 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3708 /* Analog Mix output amp */
3709 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3710 /* capture sources */
3711 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3712 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3713 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3714 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3715 /* SPDIF output amp */
3716 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3717 { } /* end */
3720 #ifdef CONFIG_SND_HDA_POWER_SAVE
3721 static struct hda_amp_list ad1884a_loopbacks[] = {
3722 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3723 { 0x20, HDA_INPUT, 1 }, /* Mic */
3724 { 0x20, HDA_INPUT, 2 }, /* CD */
3725 { 0x20, HDA_INPUT, 4 }, /* Docking */
3726 { } /* end */
3728 #endif
3731 * Laptop model
3733 * Port A: Headphone jack
3734 * Port B: MIC jack
3735 * Port C: Internal MIC
3736 * Port D: Dock Line Out (if enabled)
3737 * Port E: Dock Line In (if enabled)
3738 * Port F: Internal speakers
3741 static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
3742 struct snd_ctl_elem_value *ucontrol)
3744 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3745 int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3746 int mute = (!ucontrol->value.integer.value[0] &&
3747 !ucontrol->value.integer.value[1]);
3748 /* toggle GPIO1 according to the mute state */
3749 snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3750 mute ? 0x02 : 0x0);
3751 return ret;
3754 static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3755 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3757 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3758 .name = "Master Playback Switch",
3759 .info = snd_hda_mixer_amp_switch_info,
3760 .get = snd_hda_mixer_amp_switch_get,
3761 .put = ad1884a_mobile_master_sw_put,
3762 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3764 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3765 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3766 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3767 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3768 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3769 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3770 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3771 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3772 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3773 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3774 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3775 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3776 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3777 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3778 { } /* end */
3781 static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3782 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3783 /*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
3785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3786 .name = "Master Playback Switch",
3787 .info = snd_hda_mixer_amp_switch_info,
3788 .get = snd_hda_mixer_amp_switch_get,
3789 .put = ad1884a_mobile_master_sw_put,
3790 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3792 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3793 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3794 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
3795 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
3796 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3797 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3798 { } /* end */
3801 /* mute internal speaker if HP is plugged */
3802 static void ad1884a_hp_automute(struct hda_codec *codec)
3804 unsigned int present;
3806 present = snd_hda_jack_detect(codec, 0x11);
3807 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3808 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3809 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3810 present ? 0x00 : 0x02);
3813 /* switch to external mic if plugged */
3814 static void ad1884a_hp_automic(struct hda_codec *codec)
3816 unsigned int present;
3818 present = snd_hda_jack_detect(codec, 0x14);
3819 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3820 present ? 0 : 1);
3823 #define AD1884A_HP_EVENT 0x37
3824 #define AD1884A_MIC_EVENT 0x36
3826 /* unsolicited event for HP jack sensing */
3827 static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3829 switch (res >> 26) {
3830 case AD1884A_HP_EVENT:
3831 ad1884a_hp_automute(codec);
3832 break;
3833 case AD1884A_MIC_EVENT:
3834 ad1884a_hp_automic(codec);
3835 break;
3839 /* initialize jack-sensing, too */
3840 static int ad1884a_hp_init(struct hda_codec *codec)
3842 ad198x_init(codec);
3843 ad1884a_hp_automute(codec);
3844 ad1884a_hp_automic(codec);
3845 return 0;
3848 /* mute internal speaker if HP or docking HP is plugged */
3849 static void ad1884a_laptop_automute(struct hda_codec *codec)
3851 unsigned int present;
3853 present = snd_hda_jack_detect(codec, 0x11);
3854 if (!present)
3855 present = snd_hda_jack_detect(codec, 0x12);
3856 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3857 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3858 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3859 present ? 0x00 : 0x02);
3862 /* switch to external mic if plugged */
3863 static void ad1884a_laptop_automic(struct hda_codec *codec)
3865 unsigned int idx;
3867 if (snd_hda_jack_detect(codec, 0x14))
3868 idx = 0;
3869 else if (snd_hda_jack_detect(codec, 0x1c))
3870 idx = 4;
3871 else
3872 idx = 1;
3873 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, idx);
3876 /* unsolicited event for HP jack sensing */
3877 static void ad1884a_laptop_unsol_event(struct hda_codec *codec,
3878 unsigned int res)
3880 switch (res >> 26) {
3881 case AD1884A_HP_EVENT:
3882 ad1884a_laptop_automute(codec);
3883 break;
3884 case AD1884A_MIC_EVENT:
3885 ad1884a_laptop_automic(codec);
3886 break;
3890 /* initialize jack-sensing, too */
3891 static int ad1884a_laptop_init(struct hda_codec *codec)
3893 ad198x_init(codec);
3894 ad1884a_laptop_automute(codec);
3895 ad1884a_laptop_automic(codec);
3896 return 0;
3899 /* additional verbs for laptop model */
3900 static struct hda_verb ad1884a_laptop_verbs[] = {
3901 /* Port-A (HP) pin - always unmuted */
3902 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3903 /* Port-F (int speaker) mixer - route only from analog mixer */
3904 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3905 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3906 /* Port-F (int speaker) pin */
3907 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3908 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3909 /* required for compaq 6530s/6531s speaker output */
3910 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3911 /* Port-C pin - internal mic-in */
3912 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3913 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3914 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3915 /* Port-D (docking line-out) pin - default unmuted */
3916 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3917 /* analog mix */
3918 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3919 /* unsolicited event for pin-sense */
3920 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3921 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3922 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3923 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3924 /* allow to touch GPIO1 (for mute control) */
3925 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3926 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3927 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
3928 { } /* end */
3931 static struct hda_verb ad1884a_mobile_verbs[] = {
3932 /* DACs; unmute as default */
3933 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3934 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3935 /* Port-A (HP) mixer - route only from analog mixer */
3936 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3937 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3938 /* Port-A pin */
3939 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3940 /* Port-A (HP) pin - always unmuted */
3941 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3942 /* Port-B (mic jack) pin */
3943 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3944 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3945 /* Port-C (int mic) pin */
3946 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3947 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3948 /* Port-F (int speaker) mixer - route only from analog mixer */
3949 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3950 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3951 /* Port-F pin */
3952 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3953 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3954 /* Analog mixer; mute as default */
3955 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3956 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3957 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3958 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3959 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3960 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3961 /* Analog Mix output amp */
3962 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3963 /* capture sources */
3964 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
3965 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3966 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3967 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3968 /* unsolicited event for pin-sense */
3969 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3970 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3971 /* allow to touch GPIO1 (for mute control) */
3972 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3973 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3974 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
3975 { } /* end */
3979 * Thinkpad X300
3980 * 0x11 - HP
3981 * 0x12 - speaker
3982 * 0x14 - mic-in
3983 * 0x17 - built-in mic
3986 static struct hda_verb ad1984a_thinkpad_verbs[] = {
3987 /* HP unmute */
3988 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3989 /* analog mix */
3990 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3991 /* turn on EAPD */
3992 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3993 /* unsolicited event for pin-sense */
3994 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3995 /* internal mic - dmic */
3996 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3997 /* set magic COEFs for dmic */
3998 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3999 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
4000 { } /* end */
4003 static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
4004 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4005 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
4006 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4007 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4008 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4009 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4010 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
4011 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
4012 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4013 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4015 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4016 .name = "Capture Source",
4017 .info = ad198x_mux_enum_info,
4018 .get = ad198x_mux_enum_get,
4019 .put = ad198x_mux_enum_put,
4021 { } /* end */
4024 static struct hda_input_mux ad1984a_thinkpad_capture_source = {
4025 .num_items = 3,
4026 .items = {
4027 { "Mic", 0x0 },
4028 { "Internal Mic", 0x5 },
4029 { "Mix", 0x3 },
4033 /* mute internal speaker if HP is plugged */
4034 static void ad1984a_thinkpad_automute(struct hda_codec *codec)
4036 unsigned int present;
4038 present = snd_hda_jack_detect(codec, 0x11);
4039 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
4040 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4043 /* unsolicited event for HP jack sensing */
4044 static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
4045 unsigned int res)
4047 if ((res >> 26) != AD1884A_HP_EVENT)
4048 return;
4049 ad1984a_thinkpad_automute(codec);
4052 /* initialize jack-sensing, too */
4053 static int ad1984a_thinkpad_init(struct hda_codec *codec)
4055 ad198x_init(codec);
4056 ad1984a_thinkpad_automute(codec);
4057 return 0;
4061 * HP Touchsmart
4062 * port-A (0x11) - front hp-out
4063 * port-B (0x14) - unused
4064 * port-C (0x15) - unused
4065 * port-D (0x12) - rear line out
4066 * port-E (0x1c) - front mic-in
4067 * port-F (0x16) - Internal speakers
4068 * digital-mic (0x17) - Internal mic
4071 static struct hda_verb ad1984a_touchsmart_verbs[] = {
4072 /* DACs; unmute as default */
4073 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4074 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4075 /* Port-A (HP) mixer - route only from analog mixer */
4076 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4077 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4078 /* Port-A pin */
4079 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4080 /* Port-A (HP) pin - always unmuted */
4081 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4082 /* Port-E (int speaker) mixer - route only from analog mixer */
4083 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, 0x03},
4084 /* Port-E pin */
4085 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4086 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4087 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4088 /* Port-F (int speaker) mixer - route only from analog mixer */
4089 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4090 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4091 /* Port-F pin */
4092 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4093 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4094 /* Analog mixer; mute as default */
4095 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4096 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4097 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4098 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4099 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4100 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4101 /* Analog Mix output amp */
4102 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4103 /* capture sources */
4104 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
4105 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4106 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4107 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4108 /* unsolicited event for pin-sense */
4109 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4110 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
4111 /* allow to touch GPIO1 (for mute control) */
4112 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4113 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4114 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
4115 /* internal mic - dmic */
4116 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4117 /* set magic COEFs for dmic */
4118 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
4119 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
4120 { } /* end */
4123 static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4124 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4125 /* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
4127 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4128 .name = "Master Playback Switch",
4129 .info = snd_hda_mixer_amp_switch_info,
4130 .get = snd_hda_mixer_amp_switch_get,
4131 .put = ad1884a_mobile_master_sw_put,
4132 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
4134 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4135 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4136 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4137 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4138 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
4139 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
4140 { } /* end */
4143 /* switch to external mic if plugged */
4144 static void ad1984a_touchsmart_automic(struct hda_codec *codec)
4146 if (snd_hda_jack_detect(codec, 0x1c))
4147 snd_hda_codec_write(codec, 0x0c, 0,
4148 AC_VERB_SET_CONNECT_SEL, 0x4);
4149 else
4150 snd_hda_codec_write(codec, 0x0c, 0,
4151 AC_VERB_SET_CONNECT_SEL, 0x5);
4155 /* unsolicited event for HP jack sensing */
4156 static void ad1984a_touchsmart_unsol_event(struct hda_codec *codec,
4157 unsigned int res)
4159 switch (res >> 26) {
4160 case AD1884A_HP_EVENT:
4161 ad1884a_hp_automute(codec);
4162 break;
4163 case AD1884A_MIC_EVENT:
4164 ad1984a_touchsmart_automic(codec);
4165 break;
4169 /* initialize jack-sensing, too */
4170 static int ad1984a_touchsmart_init(struct hda_codec *codec)
4172 ad198x_init(codec);
4173 ad1884a_hp_automute(codec);
4174 ad1984a_touchsmart_automic(codec);
4175 return 0;
4182 enum {
4183 AD1884A_DESKTOP,
4184 AD1884A_LAPTOP,
4185 AD1884A_MOBILE,
4186 AD1884A_THINKPAD,
4187 AD1984A_TOUCHSMART,
4188 AD1884A_MODELS
4191 static const char *ad1884a_models[AD1884A_MODELS] = {
4192 [AD1884A_DESKTOP] = "desktop",
4193 [AD1884A_LAPTOP] = "laptop",
4194 [AD1884A_MOBILE] = "mobile",
4195 [AD1884A_THINKPAD] = "thinkpad",
4196 [AD1984A_TOUCHSMART] = "touchsmart",
4199 static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
4200 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
4201 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
4202 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
4203 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
4204 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
4205 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
4206 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
4207 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
4208 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
4209 SND_PCI_QUIRK(0x103c, 0x2a82, "Touchsmart", AD1984A_TOUCHSMART),
4213 static int patch_ad1884a(struct hda_codec *codec)
4215 struct ad198x_spec *spec;
4216 int err, board_config;
4218 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4219 if (spec == NULL)
4220 return -ENOMEM;
4222 codec->spec = spec;
4224 err = snd_hda_attach_beep_device(codec, 0x10);
4225 if (err < 0) {
4226 ad198x_free(codec);
4227 return err;
4229 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4231 spec->multiout.max_channels = 2;
4232 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
4233 spec->multiout.dac_nids = ad1884a_dac_nids;
4234 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
4235 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
4236 spec->adc_nids = ad1884a_adc_nids;
4237 spec->capsrc_nids = ad1884a_capsrc_nids;
4238 spec->input_mux = &ad1884a_capture_source;
4239 spec->num_mixers = 1;
4240 spec->mixers[0] = ad1884a_base_mixers;
4241 spec->num_init_verbs = 1;
4242 spec->init_verbs[0] = ad1884a_init_verbs;
4243 spec->spdif_route = 0;
4244 #ifdef CONFIG_SND_HDA_POWER_SAVE
4245 spec->loopback.amplist = ad1884a_loopbacks;
4246 #endif
4247 codec->patch_ops = ad198x_patch_ops;
4249 /* override some parameters */
4250 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
4251 ad1884a_models,
4252 ad1884a_cfg_tbl);
4253 switch (board_config) {
4254 case AD1884A_LAPTOP:
4255 spec->mixers[0] = ad1884a_laptop_mixers;
4256 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
4257 spec->multiout.dig_out_nid = 0;
4258 codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
4259 codec->patch_ops.init = ad1884a_laptop_init;
4260 /* set the upper-limit for mixer amp to 0dB for avoiding the
4261 * possible damage by overloading
4263 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4264 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4265 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4266 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4267 (1 << AC_AMPCAP_MUTE_SHIFT));
4268 break;
4269 case AD1884A_MOBILE:
4270 spec->mixers[0] = ad1884a_mobile_mixers;
4271 spec->init_verbs[0] = ad1884a_mobile_verbs;
4272 spec->multiout.dig_out_nid = 0;
4273 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
4274 codec->patch_ops.init = ad1884a_hp_init;
4275 /* set the upper-limit for mixer amp to 0dB for avoiding the
4276 * possible damage by overloading
4278 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4279 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4280 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4281 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4282 (1 << AC_AMPCAP_MUTE_SHIFT));
4283 break;
4284 case AD1884A_THINKPAD:
4285 spec->mixers[0] = ad1984a_thinkpad_mixers;
4286 spec->init_verbs[spec->num_init_verbs++] =
4287 ad1984a_thinkpad_verbs;
4288 spec->multiout.dig_out_nid = 0;
4289 spec->input_mux = &ad1984a_thinkpad_capture_source;
4290 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
4291 codec->patch_ops.init = ad1984a_thinkpad_init;
4292 break;
4293 case AD1984A_TOUCHSMART:
4294 spec->mixers[0] = ad1984a_touchsmart_mixers;
4295 spec->init_verbs[0] = ad1984a_touchsmart_verbs;
4296 spec->multiout.dig_out_nid = 0;
4297 codec->patch_ops.unsol_event = ad1984a_touchsmart_unsol_event;
4298 codec->patch_ops.init = ad1984a_touchsmart_init;
4299 /* set the upper-limit for mixer amp to 0dB for avoiding the
4300 * possible damage by overloading
4302 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4303 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4304 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4305 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4306 (1 << AC_AMPCAP_MUTE_SHIFT));
4307 break;
4310 codec->no_trigger_sense = 1;
4312 return 0;
4317 * AD1882 / AD1882A
4319 * port-A - front hp-out
4320 * port-B - front mic-in
4321 * port-C - rear line-in, shared surr-out (3stack)
4322 * port-D - rear line-out
4323 * port-E - rear mic-in, shared clfe-out (3stack)
4324 * port-F - rear surr-out (6stack)
4325 * port-G - rear clfe-out (6stack)
4328 static hda_nid_t ad1882_dac_nids[3] = {
4329 0x04, 0x03, 0x05
4332 static hda_nid_t ad1882_adc_nids[2] = {
4333 0x08, 0x09,
4336 static hda_nid_t ad1882_capsrc_nids[2] = {
4337 0x0c, 0x0d,
4340 #define AD1882_SPDIF_OUT 0x02
4342 /* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
4343 static struct hda_input_mux ad1882_capture_source = {
4344 .num_items = 5,
4345 .items = {
4346 { "Front Mic", 0x1 },
4347 { "Mic", 0x4 },
4348 { "Line", 0x2 },
4349 { "CD", 0x3 },
4350 { "Mix", 0x7 },
4354 /* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
4355 static struct hda_input_mux ad1882a_capture_source = {
4356 .num_items = 5,
4357 .items = {
4358 { "Front Mic", 0x1 },
4359 { "Mic", 0x4},
4360 { "Line", 0x2 },
4361 { "Digital Mic", 0x06 },
4362 { "Mix", 0x7 },
4366 static struct snd_kcontrol_new ad1882_base_mixers[] = {
4367 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
4368 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
4369 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
4370 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
4371 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
4372 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4373 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4374 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
4376 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
4377 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
4378 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
4379 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4380 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4381 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
4382 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
4384 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4385 /* The multiple "Capture Source" controls confuse alsamixer
4386 * So call somewhat different..
4388 /* .name = "Capture Source", */
4389 .name = "Input Source",
4390 .count = 2,
4391 .info = ad198x_mux_enum_info,
4392 .get = ad198x_mux_enum_get,
4393 .put = ad198x_mux_enum_put,
4395 /* SPDIF controls */
4396 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
4398 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4399 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4400 /* identical with ad1983 */
4401 .info = ad1983_spdif_route_info,
4402 .get = ad1983_spdif_route_get,
4403 .put = ad1983_spdif_route_put,
4405 { } /* end */
4408 static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4409 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4410 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4411 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4412 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4413 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4414 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4415 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4416 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4417 { } /* end */
4420 static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4421 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4422 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4423 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4424 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4425 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4426 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4427 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4428 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4429 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT),
4430 { } /* end */
4433 static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
4434 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4435 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
4436 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
4438 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4439 .name = "Channel Mode",
4440 .info = ad198x_ch_mode_info,
4441 .get = ad198x_ch_mode_get,
4442 .put = ad198x_ch_mode_put,
4444 { } /* end */
4447 static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
4448 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4449 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4450 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4451 { } /* end */
4454 static struct hda_verb ad1882_ch2_init[] = {
4455 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4456 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4457 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4458 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4459 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4460 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4461 { } /* end */
4464 static struct hda_verb ad1882_ch4_init[] = {
4465 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4466 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4467 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4468 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4469 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4470 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4471 { } /* end */
4474 static struct hda_verb ad1882_ch6_init[] = {
4475 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4476 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4477 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4478 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4479 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4480 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4481 { } /* end */
4484 static struct hda_channel_mode ad1882_modes[3] = {
4485 { 2, ad1882_ch2_init },
4486 { 4, ad1882_ch4_init },
4487 { 6, ad1882_ch6_init },
4491 * initialization verbs
4493 static struct hda_verb ad1882_init_verbs[] = {
4494 /* DACs; mute as default */
4495 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4496 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4497 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4498 /* Port-A (HP) mixer */
4499 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4500 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4501 /* Port-A pin */
4502 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4503 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4504 /* HP selector - select DAC2 */
4505 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4506 /* Port-D (Line-out) mixer */
4507 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4508 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4509 /* Port-D pin */
4510 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4511 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4512 /* Mono-out mixer */
4513 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4514 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4515 /* Mono-out pin */
4516 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4517 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4518 /* Port-B (front mic) pin */
4519 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4520 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4521 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4522 /* Port-C (line-in) pin */
4523 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4524 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4525 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4526 /* Port-C mixer - mute as input */
4527 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4528 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4529 /* Port-E (mic-in) pin */
4530 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4531 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4532 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4533 /* Port-E mixer - mute as input */
4534 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4535 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4536 /* Port-F (surround) */
4537 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4538 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4539 /* Port-G (CLFE) */
4540 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4541 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4542 /* Analog mixer; mute as default */
4543 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4544 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4545 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4546 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4547 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4548 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4549 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4550 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4551 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4552 /* Analog Mix output amp */
4553 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4554 /* SPDIF output selector */
4555 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4556 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4557 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4558 { } /* end */
4561 #ifdef CONFIG_SND_HDA_POWER_SAVE
4562 static struct hda_amp_list ad1882_loopbacks[] = {
4563 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4564 { 0x20, HDA_INPUT, 1 }, /* Mic */
4565 { 0x20, HDA_INPUT, 4 }, /* Line */
4566 { 0x20, HDA_INPUT, 6 }, /* CD */
4567 { } /* end */
4569 #endif
4571 /* models */
4572 enum {
4573 AD1882_3STACK,
4574 AD1882_6STACK,
4575 AD1882_MODELS
4578 static const char *ad1882_models[AD1986A_MODELS] = {
4579 [AD1882_3STACK] = "3stack",
4580 [AD1882_6STACK] = "6stack",
4584 static int patch_ad1882(struct hda_codec *codec)
4586 struct ad198x_spec *spec;
4587 int err, board_config;
4589 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4590 if (spec == NULL)
4591 return -ENOMEM;
4593 codec->spec = spec;
4595 err = snd_hda_attach_beep_device(codec, 0x10);
4596 if (err < 0) {
4597 ad198x_free(codec);
4598 return err;
4600 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4602 spec->multiout.max_channels = 6;
4603 spec->multiout.num_dacs = 3;
4604 spec->multiout.dac_nids = ad1882_dac_nids;
4605 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4606 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4607 spec->adc_nids = ad1882_adc_nids;
4608 spec->capsrc_nids = ad1882_capsrc_nids;
4609 if (codec->vendor_id == 0x11d41882)
4610 spec->input_mux = &ad1882_capture_source;
4611 else
4612 spec->input_mux = &ad1882a_capture_source;
4613 spec->num_mixers = 2;
4614 spec->mixers[0] = ad1882_base_mixers;
4615 if (codec->vendor_id == 0x11d41882)
4616 spec->mixers[1] = ad1882_loopback_mixers;
4617 else
4618 spec->mixers[1] = ad1882a_loopback_mixers;
4619 spec->num_init_verbs = 1;
4620 spec->init_verbs[0] = ad1882_init_verbs;
4621 spec->spdif_route = 0;
4622 #ifdef CONFIG_SND_HDA_POWER_SAVE
4623 spec->loopback.amplist = ad1882_loopbacks;
4624 #endif
4625 spec->vmaster_nid = 0x04;
4627 codec->patch_ops = ad198x_patch_ops;
4629 /* override some parameters */
4630 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4631 ad1882_models, NULL);
4632 switch (board_config) {
4633 default:
4634 case AD1882_3STACK:
4635 spec->num_mixers = 3;
4636 spec->mixers[2] = ad1882_3stack_mixers;
4637 spec->channel_mode = ad1882_modes;
4638 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4639 spec->need_dac_fix = 1;
4640 spec->multiout.max_channels = 2;
4641 spec->multiout.num_dacs = 1;
4642 break;
4643 case AD1882_6STACK:
4644 spec->num_mixers = 3;
4645 spec->mixers[2] = ad1882_6stack_mixers;
4646 break;
4649 codec->no_trigger_sense = 1;
4651 return 0;
4656 * patch entries
4658 static struct hda_codec_preset snd_hda_preset_analog[] = {
4659 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
4660 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
4661 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
4662 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
4663 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4664 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
4665 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4666 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
4667 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
4668 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
4669 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
4670 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
4671 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
4672 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4673 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
4674 {} /* terminator */
4677 MODULE_ALIAS("snd-hda-codec-id:11d4*");
4679 MODULE_LICENSE("GPL");
4680 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
4682 static struct hda_codec_preset_list analog_list = {
4683 .preset = snd_hda_preset_analog,
4684 .owner = THIS_MODULE,
4687 static int __init patch_analog_init(void)
4689 return snd_hda_add_codec_preset(&analog_list);
4692 static void __exit patch_analog_exit(void)
4694 snd_hda_delete_codec_preset(&analog_list);
4697 module_init(patch_analog_init)
4698 module_exit(patch_analog_exit)