Linux 3.12.39
[linux/fpc-iii.git] / sound / pci / hda / patch_analog.c
blob10dc0c8fbb873425ad6c91c1eadb4761167f3e52
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/slab.h>
24 #include <linux/pci.h>
25 #include <linux/module.h>
27 #include <sound/core.h>
28 #include "hda_codec.h"
29 #include "hda_local.h"
30 #include "hda_auto_parser.h"
31 #include "hda_beep.h"
32 #include "hda_jack.h"
33 #include "hda_generic.h"
36 struct ad198x_spec {
37 struct hda_gen_spec gen;
39 /* for auto parser */
40 int smux_paths[4];
41 unsigned int cur_smux;
42 hda_nid_t eapd_nid;
44 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
48 #ifdef CONFIG_SND_HDA_INPUT_BEEP
49 /* additional beep mixers; the actual parameters are overwritten at build */
50 static const struct snd_kcontrol_new ad_beep_mixer[] = {
51 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
52 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
53 { } /* end */
56 #define set_beep_amp(spec, nid, idx, dir) \
57 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
58 #else
59 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
60 #endif
62 #ifdef CONFIG_SND_HDA_INPUT_BEEP
63 static int create_beep_ctls(struct hda_codec *codec)
65 struct ad198x_spec *spec = codec->spec;
66 const struct snd_kcontrol_new *knew;
68 if (!spec->beep_amp)
69 return 0;
71 for (knew = ad_beep_mixer ; knew->name; knew++) {
72 int err;
73 struct snd_kcontrol *kctl;
74 kctl = snd_ctl_new1(knew, codec);
75 if (!kctl)
76 return -ENOMEM;
77 kctl->private_value = spec->beep_amp;
78 err = snd_hda_ctl_add(codec, 0, kctl);
79 if (err < 0)
80 return err;
82 return 0;
84 #else
85 #define create_beep_ctls(codec) 0
86 #endif
89 static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
90 hda_nid_t hp)
92 if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
93 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
94 !codec->inv_eapd ? 0x00 : 0x02);
95 if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
96 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
97 !codec->inv_eapd ? 0x00 : 0x02);
100 static void ad198x_power_eapd(struct hda_codec *codec)
102 /* We currently only handle front, HP */
103 switch (codec->vendor_id) {
104 case 0x11d41882:
105 case 0x11d4882a:
106 case 0x11d41884:
107 case 0x11d41984:
108 case 0x11d41883:
109 case 0x11d4184a:
110 case 0x11d4194a:
111 case 0x11d4194b:
112 case 0x11d41988:
113 case 0x11d4198b:
114 case 0x11d4989a:
115 case 0x11d4989b:
116 ad198x_power_eapd_write(codec, 0x12, 0x11);
117 break;
118 case 0x11d41981:
119 case 0x11d41983:
120 ad198x_power_eapd_write(codec, 0x05, 0x06);
121 break;
122 case 0x11d41986:
123 ad198x_power_eapd_write(codec, 0x1b, 0x1a);
124 break;
128 static void ad198x_shutup(struct hda_codec *codec)
130 snd_hda_shutup_pins(codec);
131 ad198x_power_eapd(codec);
134 #ifdef CONFIG_PM
135 static int ad198x_suspend(struct hda_codec *codec)
137 ad198x_shutup(codec);
138 return 0;
140 #endif
144 * Automatic parse of I/O pins from the BIOS configuration
147 static int ad198x_auto_build_controls(struct hda_codec *codec)
149 int err;
151 err = snd_hda_gen_build_controls(codec);
152 if (err < 0)
153 return err;
154 err = create_beep_ctls(codec);
155 if (err < 0)
156 return err;
157 return 0;
160 static const struct hda_codec_ops ad198x_auto_patch_ops = {
161 .build_controls = ad198x_auto_build_controls,
162 .build_pcms = snd_hda_gen_build_pcms,
163 .init = snd_hda_gen_init,
164 .free = snd_hda_gen_free,
165 .unsol_event = snd_hda_jack_unsol_event,
166 #ifdef CONFIG_PM
167 .check_power_status = snd_hda_gen_check_power_status,
168 .suspend = ad198x_suspend,
169 #endif
170 .reboot_notify = ad198x_shutup,
174 static int ad198x_parse_auto_config(struct hda_codec *codec, bool indep_hp)
176 struct ad198x_spec *spec = codec->spec;
177 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
178 int err;
180 codec->spdif_status_reset = 1;
181 codec->no_trigger_sense = 1;
182 codec->no_sticky_stream = 1;
184 spec->gen.indep_hp = indep_hp;
186 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
187 if (err < 0)
188 return err;
189 err = snd_hda_gen_parse_auto_config(codec, cfg);
190 if (err < 0)
191 return err;
193 codec->patch_ops = ad198x_auto_patch_ops;
195 return 0;
199 * AD1986A specific
202 static int alloc_ad_spec(struct hda_codec *codec)
204 struct ad198x_spec *spec;
206 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
207 if (!spec)
208 return -ENOMEM;
209 codec->spec = spec;
210 snd_hda_gen_spec_init(&spec->gen);
211 return 0;
215 * AD1986A fixup codes
218 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
219 static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
220 const struct hda_fixup *fix, int action)
222 struct ad198x_spec *spec = codec->spec;
224 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
225 codec->inv_jack_detect = 1;
226 spec->gen.keep_eapd_on = 1;
230 /* Toshiba Satellite L40 implements EAPD in a standard way unlike others */
231 static void ad1986a_fixup_eapd(struct hda_codec *codec,
232 const struct hda_fixup *fix, int action)
234 struct ad198x_spec *spec = codec->spec;
236 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
237 codec->inv_eapd = 0;
238 spec->gen.keep_eapd_on = 1;
239 spec->eapd_nid = 0x1b;
243 enum {
244 AD1986A_FIXUP_INV_JACK_DETECT,
245 AD1986A_FIXUP_ULTRA,
246 AD1986A_FIXUP_SAMSUNG,
247 AD1986A_FIXUP_3STACK,
248 AD1986A_FIXUP_LAPTOP,
249 AD1986A_FIXUP_LAPTOP_IMIC,
250 AD1986A_FIXUP_EAPD,
253 static const struct hda_fixup ad1986a_fixups[] = {
254 [AD1986A_FIXUP_INV_JACK_DETECT] = {
255 .type = HDA_FIXUP_FUNC,
256 .v.func = ad_fixup_inv_jack_detect,
258 [AD1986A_FIXUP_ULTRA] = {
259 .type = HDA_FIXUP_PINS,
260 .v.pins = (const struct hda_pintbl[]) {
261 { 0x1b, 0x90170110 }, /* speaker */
262 { 0x1d, 0x90a7013e }, /* int mic */
266 [AD1986A_FIXUP_SAMSUNG] = {
267 .type = HDA_FIXUP_PINS,
268 .v.pins = (const struct hda_pintbl[]) {
269 { 0x1b, 0x90170110 }, /* speaker */
270 { 0x1d, 0x90a7013e }, /* int mic */
271 { 0x20, 0x411111f0 }, /* N/A */
272 { 0x24, 0x411111f0 }, /* N/A */
276 [AD1986A_FIXUP_3STACK] = {
277 .type = HDA_FIXUP_PINS,
278 .v.pins = (const struct hda_pintbl[]) {
279 { 0x1a, 0x02214021 }, /* headphone */
280 { 0x1b, 0x01014011 }, /* front */
281 { 0x1c, 0x01813030 }, /* line-in */
282 { 0x1d, 0x01a19020 }, /* rear mic */
283 { 0x1e, 0x411111f0 }, /* N/A */
284 { 0x1f, 0x02a190f0 }, /* mic */
285 { 0x20, 0x411111f0 }, /* N/A */
289 [AD1986A_FIXUP_LAPTOP] = {
290 .type = HDA_FIXUP_PINS,
291 .v.pins = (const struct hda_pintbl[]) {
292 { 0x1a, 0x02214021 }, /* headphone */
293 { 0x1b, 0x90170110 }, /* speaker */
294 { 0x1c, 0x411111f0 }, /* N/A */
295 { 0x1d, 0x411111f0 }, /* N/A */
296 { 0x1e, 0x411111f0 }, /* N/A */
297 { 0x1f, 0x02a191f0 }, /* mic */
298 { 0x20, 0x411111f0 }, /* N/A */
302 [AD1986A_FIXUP_LAPTOP_IMIC] = {
303 .type = HDA_FIXUP_PINS,
304 .v.pins = (const struct hda_pintbl[]) {
305 { 0x1d, 0x90a7013e }, /* int mic */
308 .chained_before = 1,
309 .chain_id = AD1986A_FIXUP_LAPTOP,
311 [AD1986A_FIXUP_EAPD] = {
312 .type = HDA_FIXUP_FUNC,
313 .v.func = ad1986a_fixup_eapd,
317 static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
318 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC),
319 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS Z99He", AD1986A_FIXUP_EAPD),
320 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8JN", AD1986A_FIXUP_EAPD),
321 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
322 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
323 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK),
324 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD),
325 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
326 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
327 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
328 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
329 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK),
330 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK),
334 static const struct hda_model_fixup ad1986a_fixup_models[] = {
335 { .id = AD1986A_FIXUP_3STACK, .name = "3stack" },
336 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" },
337 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" },
338 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */
344 static int patch_ad1986a(struct hda_codec *codec)
346 int err;
347 struct ad198x_spec *spec;
348 static hda_nid_t preferred_pairs[] = {
349 0x1a, 0x03,
350 0x1b, 0x03,
351 0x1c, 0x04,
352 0x1d, 0x05,
353 0x1e, 0x03,
357 err = alloc_ad_spec(codec);
358 if (err < 0)
359 return err;
360 spec = codec->spec;
362 /* AD1986A has the inverted EAPD implementation */
363 codec->inv_eapd = 1;
365 spec->gen.mixer_nid = 0x07;
366 spec->gen.beep_nid = 0x19;
367 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
369 /* AD1986A has a hardware problem that it can't share a stream
370 * with multiple output pins. The copy of front to surrounds
371 * causes noisy or silent outputs at a certain timing, e.g.
372 * changing the volume.
373 * So, let's disable the shared stream.
375 spec->gen.multiout.no_share_stream = 1;
376 /* give fixed DAC/pin pairs */
377 spec->gen.preferred_dacs = preferred_pairs;
379 /* AD1986A can't manage the dynamic pin on/off smoothly */
380 spec->gen.auto_mute_via_amp = 1;
382 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
383 ad1986a_fixups);
384 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
386 err = ad198x_parse_auto_config(codec, false);
387 if (err < 0) {
388 snd_hda_gen_free(codec);
389 return err;
392 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
394 return 0;
399 * AD1983 specific
403 * SPDIF mux control for AD1983 auto-parser
405 static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
406 struct snd_ctl_elem_info *uinfo)
408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
409 struct ad198x_spec *spec = codec->spec;
410 static const char * const texts2[] = { "PCM", "ADC" };
411 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
412 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
413 int num_conns = snd_hda_get_num_conns(codec, dig_out);
415 if (num_conns == 2)
416 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
417 else if (num_conns == 3)
418 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
419 else
420 return -EINVAL;
423 static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
424 struct snd_ctl_elem_value *ucontrol)
426 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
427 struct ad198x_spec *spec = codec->spec;
429 ucontrol->value.enumerated.item[0] = spec->cur_smux;
430 return 0;
433 static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
434 struct snd_ctl_elem_value *ucontrol)
436 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
437 struct ad198x_spec *spec = codec->spec;
438 unsigned int val = ucontrol->value.enumerated.item[0];
439 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
440 int num_conns = snd_hda_get_num_conns(codec, dig_out);
442 if (val >= num_conns)
443 return -EINVAL;
444 if (spec->cur_smux == val)
445 return 0;
446 spec->cur_smux = val;
447 snd_hda_codec_write_cache(codec, dig_out, 0,
448 AC_VERB_SET_CONNECT_SEL, val);
449 return 1;
452 static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
453 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
454 .name = "IEC958 Playback Source",
455 .info = ad1983_auto_smux_enum_info,
456 .get = ad1983_auto_smux_enum_get,
457 .put = ad1983_auto_smux_enum_put,
460 static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
462 struct ad198x_spec *spec = codec->spec;
463 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
464 int num_conns;
466 if (!dig_out)
467 return 0;
468 num_conns = snd_hda_get_num_conns(codec, dig_out);
469 if (num_conns != 2 && num_conns != 3)
470 return 0;
471 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
472 return -ENOMEM;
473 return 0;
476 static int patch_ad1983(struct hda_codec *codec)
478 struct ad198x_spec *spec;
479 static hda_nid_t conn_0c[] = { 0x08 };
480 static hda_nid_t conn_0d[] = { 0x09 };
481 int err;
483 err = alloc_ad_spec(codec);
484 if (err < 0)
485 return err;
486 spec = codec->spec;
488 spec->gen.mixer_nid = 0x0e;
489 spec->gen.beep_nid = 0x10;
490 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
492 /* limit the loopback routes not to confuse the parser */
493 snd_hda_override_conn_list(codec, 0x0c, ARRAY_SIZE(conn_0c), conn_0c);
494 snd_hda_override_conn_list(codec, 0x0d, ARRAY_SIZE(conn_0d), conn_0d);
496 err = ad198x_parse_auto_config(codec, false);
497 if (err < 0)
498 goto error;
499 err = ad1983_add_spdif_mux_ctl(codec);
500 if (err < 0)
501 goto error;
502 return 0;
504 error:
505 snd_hda_gen_free(codec);
506 return err;
511 * AD1981 HD specific
514 /* follow EAPD via vmaster hook */
515 static void ad_vmaster_eapd_hook(void *private_data, int enabled)
517 struct hda_codec *codec = private_data;
518 struct ad198x_spec *spec = codec->spec;
520 if (!spec->eapd_nid)
521 return;
522 snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
523 AC_VERB_SET_EAPD_BTLENABLE,
524 enabled ? 0x02 : 0x00);
527 static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
528 const struct hda_fixup *fix, int action)
530 struct ad198x_spec *spec = codec->spec;
532 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
533 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
534 spec->eapd_nid = 0x05;
538 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
539 * damage by overloading
541 static void ad1981_fixup_amp_override(struct hda_codec *codec,
542 const struct hda_fixup *fix, int action)
544 if (action == HDA_FIXUP_ACT_PRE_PROBE)
545 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
546 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
547 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
548 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
549 (1 << AC_AMPCAP_MUTE_SHIFT));
552 enum {
553 AD1981_FIXUP_AMP_OVERRIDE,
554 AD1981_FIXUP_HP_EAPD,
557 static const struct hda_fixup ad1981_fixups[] = {
558 [AD1981_FIXUP_AMP_OVERRIDE] = {
559 .type = HDA_FIXUP_FUNC,
560 .v.func = ad1981_fixup_amp_override,
562 [AD1981_FIXUP_HP_EAPD] = {
563 .type = HDA_FIXUP_FUNC,
564 .v.func = ad1981_fixup_hp_eapd,
565 .chained = true,
566 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
570 static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
571 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
572 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
573 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
574 /* HP nx6320 (reversed SSID, H/W bug) */
575 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
579 static int patch_ad1981(struct hda_codec *codec)
581 struct ad198x_spec *spec;
582 int err;
584 err = alloc_ad_spec(codec);
585 if (err < 0)
586 return -ENOMEM;
587 spec = codec->spec;
589 spec->gen.mixer_nid = 0x0e;
590 spec->gen.beep_nid = 0x10;
591 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
593 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
594 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
596 err = ad198x_parse_auto_config(codec, false);
597 if (err < 0)
598 goto error;
599 err = ad1983_add_spdif_mux_ctl(codec);
600 if (err < 0)
601 goto error;
603 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
605 return 0;
607 error:
608 snd_hda_gen_free(codec);
609 return err;
614 * AD1988
616 * Output pins and routes
618 * Pin Mix Sel DAC (*)
619 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
620 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
621 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
622 * port-D 0x12 (mute/hp) <- 0x29 <- 04
623 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
624 * port-F 0x16 (mute) <- 0x2a <- 06
625 * port-G 0x24 (mute) <- 0x27 <- 05
626 * port-H 0x25 (mute) <- 0x28 <- 0a
627 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
629 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
630 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
632 * Input pins and routes
634 * pin boost mix input # / adc input #
635 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
636 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
637 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
638 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
639 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
640 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
641 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
642 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
645 * DAC assignment
646 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
647 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
649 * Inputs of Analog Mix (0x20)
650 * 0:Port-B (front mic)
651 * 1:Port-C/G/H (line-in)
652 * 2:Port-A
653 * 3:Port-D (line-in/2)
654 * 4:Port-E/G/H (mic-in)
655 * 5:Port-F (mic2-in)
656 * 6:CD
657 * 7:Beep
659 * ADC selection
660 * 0:Port-A
661 * 1:Port-B (front mic-in)
662 * 2:Port-C (line-in)
663 * 3:Port-F (mic2-in)
664 * 4:Port-E (mic-in)
665 * 5:CD
666 * 6:Port-G
667 * 7:Port-H
668 * 8:Port-D (line-in/2)
669 * 9:Mix
671 * Proposed pin assignments by the datasheet
673 * 6-stack
674 * Port-A front headphone
675 * B front mic-in
676 * C rear line-in
677 * D rear front-out
678 * E rear mic-in
679 * F rear surround
680 * G rear CLFE
681 * H rear side
683 * 3-stack
684 * Port-A front headphone
685 * B front mic
686 * C rear line-in/surround
687 * D rear front-out
688 * E rear mic-in/CLFE
690 * laptop
691 * Port-A headphone
692 * B mic-in
693 * C docking station
694 * D internal speaker (with EAPD)
695 * E/F quad mic array
698 #ifdef ENABLE_AD_STATIC_QUIRKS
699 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
700 struct snd_ctl_elem_info *uinfo)
702 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
703 struct ad198x_spec *spec = codec->spec;
704 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
705 spec->num_channel_mode);
708 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
709 struct snd_ctl_elem_value *ucontrol)
711 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
712 struct ad198x_spec *spec = codec->spec;
713 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
714 spec->num_channel_mode, spec->multiout.max_channels);
717 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
718 struct snd_ctl_elem_value *ucontrol)
720 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
721 struct ad198x_spec *spec = codec->spec;
722 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
723 spec->num_channel_mode,
724 &spec->multiout.max_channels);
725 if (err >= 0 && spec->need_dac_fix)
726 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
727 return err;
729 #endif /* ENABLE_AD_STATIC_QUIRKS */
731 static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
732 struct snd_ctl_elem_info *uinfo)
734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
735 static const char * const texts[] = {
736 "PCM", "ADC1", "ADC2", "ADC3",
738 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
739 if (num_conns > 4)
740 num_conns = 4;
741 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
744 static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
745 struct snd_ctl_elem_value *ucontrol)
747 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
748 struct ad198x_spec *spec = codec->spec;
750 ucontrol->value.enumerated.item[0] = spec->cur_smux;
751 return 0;
754 static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
755 struct snd_ctl_elem_value *ucontrol)
757 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
758 struct ad198x_spec *spec = codec->spec;
759 unsigned int val = ucontrol->value.enumerated.item[0];
760 struct nid_path *path;
761 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
763 if (val >= num_conns)
764 return -EINVAL;
765 if (spec->cur_smux == val)
766 return 0;
768 mutex_lock(&codec->control_mutex);
769 codec->cached_write = 1;
770 path = snd_hda_get_path_from_idx(codec,
771 spec->smux_paths[spec->cur_smux]);
772 if (path)
773 snd_hda_activate_path(codec, path, false, true);
774 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
775 if (path)
776 snd_hda_activate_path(codec, path, true, true);
777 spec->cur_smux = val;
778 codec->cached_write = 0;
779 mutex_unlock(&codec->control_mutex);
780 snd_hda_codec_flush_cache(codec); /* flush the updates */
781 return 1;
784 static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
786 .name = "IEC958 Playback Source",
787 .info = ad1988_auto_smux_enum_info,
788 .get = ad1988_auto_smux_enum_get,
789 .put = ad1988_auto_smux_enum_put,
792 static int ad1988_auto_init(struct hda_codec *codec)
794 struct ad198x_spec *spec = codec->spec;
795 int i, err;
797 err = snd_hda_gen_init(codec);
798 if (err < 0)
799 return err;
800 if (!spec->gen.autocfg.dig_outs)
801 return 0;
803 for (i = 0; i < 4; i++) {
804 struct nid_path *path;
805 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
806 if (path)
807 snd_hda_activate_path(codec, path, path->active, false);
810 return 0;
813 static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
815 struct ad198x_spec *spec = codec->spec;
816 int i, num_conns;
817 /* we create four static faked paths, since AD codecs have odd
818 * widget connections regarding the SPDIF out source
820 static struct nid_path fake_paths[4] = {
822 .depth = 3,
823 .path = { 0x02, 0x1d, 0x1b },
824 .idx = { 0, 0, 0 },
825 .multi = { 0, 0, 0 },
828 .depth = 4,
829 .path = { 0x08, 0x0b, 0x1d, 0x1b },
830 .idx = { 0, 0, 1, 0 },
831 .multi = { 0, 1, 0, 0 },
834 .depth = 4,
835 .path = { 0x09, 0x0b, 0x1d, 0x1b },
836 .idx = { 0, 1, 1, 0 },
837 .multi = { 0, 1, 0, 0 },
840 .depth = 4,
841 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
842 .idx = { 0, 2, 1, 0 },
843 .multi = { 0, 1, 0, 0 },
847 /* SPDIF source mux appears to be present only on AD1988A */
848 if (!spec->gen.autocfg.dig_outs ||
849 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
850 return 0;
852 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
853 if (num_conns != 3 && num_conns != 4)
854 return 0;
856 for (i = 0; i < num_conns; i++) {
857 struct nid_path *path = snd_array_new(&spec->gen.paths);
858 if (!path)
859 return -ENOMEM;
860 *path = fake_paths[i];
861 if (!i)
862 path->active = 1;
863 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
866 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
867 return -ENOMEM;
869 codec->patch_ops.init = ad1988_auto_init;
871 return 0;
877 enum {
878 AD1988_FIXUP_6STACK_DIG,
881 static const struct hda_fixup ad1988_fixups[] = {
882 [AD1988_FIXUP_6STACK_DIG] = {
883 .type = HDA_FIXUP_PINS,
884 .v.pins = (const struct hda_pintbl[]) {
885 { 0x11, 0x02214130 }, /* front-hp */
886 { 0x12, 0x01014010 }, /* line-out */
887 { 0x14, 0x02a19122 }, /* front-mic */
888 { 0x15, 0x01813021 }, /* line-in */
889 { 0x16, 0x01011012 }, /* line-out */
890 { 0x17, 0x01a19020 }, /* mic */
891 { 0x1b, 0x0145f1f0 }, /* SPDIF */
892 { 0x24, 0x01016011 }, /* line-out */
893 { 0x25, 0x01012013 }, /* line-out */
899 static const struct hda_model_fixup ad1988_fixup_models[] = {
900 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
904 static int patch_ad1988(struct hda_codec *codec)
906 struct ad198x_spec *spec;
907 int err;
909 err = alloc_ad_spec(codec);
910 if (err < 0)
911 return err;
912 spec = codec->spec;
914 spec->gen.mixer_nid = 0x20;
915 spec->gen.mixer_merge_nid = 0x21;
916 spec->gen.beep_nid = 0x10;
917 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
919 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
920 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
922 err = ad198x_parse_auto_config(codec, true);
923 if (err < 0)
924 goto error;
925 err = ad1988_add_spdif_mux_ctl(codec);
926 if (err < 0)
927 goto error;
929 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
931 return 0;
933 error:
934 snd_hda_gen_free(codec);
935 return err;
940 * AD1884 / AD1984
942 * port-B - front line/mic-in
943 * port-E - aux in/out
944 * port-F - aux in/out
945 * port-C - rear line/mic-in
946 * port-D - rear line/hp-out
947 * port-A - front line/hp-out
949 * AD1984 = AD1884 + two digital mic-ins
951 * AD1883 / AD1884A / AD1984A / AD1984B
953 * port-B (0x14) - front mic-in
954 * port-E (0x1c) - rear mic-in
955 * port-F (0x16) - CD / ext out
956 * port-C (0x15) - rear line-in
957 * port-D (0x12) - rear line-out
958 * port-A (0x11) - front hp-out
960 * AD1984A = AD1884A + digital-mic
961 * AD1883 = equivalent with AD1984A
962 * AD1984B = AD1984A + extra SPDIF-out
965 /* set the upper-limit for mixer amp to 0dB for avoiding the possible
966 * damage by overloading
968 static void ad1884_fixup_amp_override(struct hda_codec *codec,
969 const struct hda_fixup *fix, int action)
971 if (action == HDA_FIXUP_ACT_PRE_PROBE)
972 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
973 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
974 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
975 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
976 (1 << AC_AMPCAP_MUTE_SHIFT));
979 /* toggle GPIO1 according to the mute state */
980 static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
982 struct hda_codec *codec = private_data;
983 struct ad198x_spec *spec = codec->spec;
985 if (spec->eapd_nid)
986 ad_vmaster_eapd_hook(private_data, enabled);
987 snd_hda_codec_update_cache(codec, 0x01, 0,
988 AC_VERB_SET_GPIO_DATA,
989 enabled ? 0x00 : 0x02);
992 static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
993 const struct hda_fixup *fix, int action)
995 struct ad198x_spec *spec = codec->spec;
996 static const struct hda_verb gpio_init_verbs[] = {
997 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
998 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
999 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
1003 switch (action) {
1004 case HDA_FIXUP_ACT_PRE_PROBE:
1005 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
1006 spec->gen.own_eapd_ctl = 1;
1007 snd_hda_sequence_write_cache(codec, gpio_init_verbs);
1008 break;
1009 case HDA_FIXUP_ACT_PROBE:
1010 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1011 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
1012 else
1013 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
1014 break;
1018 static void ad1884_fixup_thinkpad(struct hda_codec *codec,
1019 const struct hda_fixup *fix, int action)
1021 struct ad198x_spec *spec = codec->spec;
1023 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1024 spec->gen.keep_eapd_on = 1;
1027 /* set magic COEFs for dmic */
1028 static const struct hda_verb ad1884_dmic_init_verbs[] = {
1029 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
1030 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
1034 enum {
1035 AD1884_FIXUP_AMP_OVERRIDE,
1036 AD1884_FIXUP_HP_EAPD,
1037 AD1884_FIXUP_DMIC_COEF,
1038 AD1884_FIXUP_THINKPAD,
1039 AD1884_FIXUP_HP_TOUCHSMART,
1042 static const struct hda_fixup ad1884_fixups[] = {
1043 [AD1884_FIXUP_AMP_OVERRIDE] = {
1044 .type = HDA_FIXUP_FUNC,
1045 .v.func = ad1884_fixup_amp_override,
1047 [AD1884_FIXUP_HP_EAPD] = {
1048 .type = HDA_FIXUP_FUNC,
1049 .v.func = ad1884_fixup_hp_eapd,
1050 .chained = true,
1051 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
1053 [AD1884_FIXUP_DMIC_COEF] = {
1054 .type = HDA_FIXUP_VERBS,
1055 .v.verbs = ad1884_dmic_init_verbs,
1057 [AD1884_FIXUP_THINKPAD] = {
1058 .type = HDA_FIXUP_FUNC,
1059 .v.func = ad1884_fixup_thinkpad,
1060 .chained = true,
1061 .chain_id = AD1884_FIXUP_DMIC_COEF,
1063 [AD1884_FIXUP_HP_TOUCHSMART] = {
1064 .type = HDA_FIXUP_VERBS,
1065 .v.verbs = ad1884_dmic_init_verbs,
1066 .chained = true,
1067 .chain_id = AD1884_FIXUP_HP_EAPD,
1071 static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
1072 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
1073 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
1074 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
1079 static int patch_ad1884(struct hda_codec *codec)
1081 struct ad198x_spec *spec;
1082 int err;
1084 err = alloc_ad_spec(codec);
1085 if (err < 0)
1086 return err;
1087 spec = codec->spec;
1089 spec->gen.mixer_nid = 0x20;
1090 spec->gen.mixer_merge_nid = 0x21;
1091 spec->gen.beep_nid = 0x10;
1092 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1094 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
1095 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1097 err = ad198x_parse_auto_config(codec, true);
1098 if (err < 0)
1099 goto error;
1100 err = ad1983_add_spdif_mux_ctl(codec);
1101 if (err < 0)
1102 goto error;
1104 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1106 return 0;
1108 error:
1109 snd_hda_gen_free(codec);
1110 return err;
1114 * AD1882 / AD1882A
1116 * port-A - front hp-out
1117 * port-B - front mic-in
1118 * port-C - rear line-in, shared surr-out (3stack)
1119 * port-D - rear line-out
1120 * port-E - rear mic-in, shared clfe-out (3stack)
1121 * port-F - rear surr-out (6stack)
1122 * port-G - rear clfe-out (6stack)
1125 static int patch_ad1882(struct hda_codec *codec)
1127 struct ad198x_spec *spec;
1128 int err;
1130 err = alloc_ad_spec(codec);
1131 if (err < 0)
1132 return err;
1133 spec = codec->spec;
1135 spec->gen.mixer_nid = 0x20;
1136 spec->gen.mixer_merge_nid = 0x21;
1137 spec->gen.beep_nid = 0x10;
1138 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1139 err = ad198x_parse_auto_config(codec, true);
1140 if (err < 0)
1141 goto error;
1142 err = ad1988_add_spdif_mux_ctl(codec);
1143 if (err < 0)
1144 goto error;
1145 return 0;
1147 error:
1148 snd_hda_gen_free(codec);
1149 return err;
1154 * patch entries
1156 static const struct hda_codec_preset snd_hda_preset_analog[] = {
1157 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
1158 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
1159 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
1160 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
1161 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
1162 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
1163 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
1164 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
1165 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
1166 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
1167 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
1168 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
1169 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
1170 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
1171 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
1172 {} /* terminator */
1175 MODULE_ALIAS("snd-hda-codec-id:11d4*");
1177 MODULE_LICENSE("GPL");
1178 MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1180 static struct hda_codec_preset_list analog_list = {
1181 .preset = snd_hda_preset_analog,
1182 .owner = THIS_MODULE,
1185 static int __init patch_analog_init(void)
1187 return snd_hda_add_codec_preset(&analog_list);
1190 static void __exit patch_analog_exit(void)
1192 snd_hda_delete_codec_preset(&analog_list);
1195 module_init(patch_analog_init)
1196 module_exit(patch_analog_exit)