1 /* 2 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984, 3 * AD1986A, AD1988 4 * 5 * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de> 6 * 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. 11 * 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. 16 * 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 20 */ 21 22 #include <linux/init.h> 23 #include <linux/slab.h> 24 #include <linux/module.h> 25 26 #include <sound/core.h> 27 #include "hda_codec.h" 28 #include "hda_local.h" 29 #include "hda_auto_parser.h" 30 #include "hda_beep.h" 31 #include "hda_jack.h" 32 #include "hda_generic.h" 33 34 35 struct ad198x_spec { 36 struct hda_gen_spec gen; 37 38 /* for auto parser */ 39 int smux_paths[4]; 40 unsigned int cur_smux; 41 hda_nid_t eapd_nid; 42 43 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ 44 }; 45 46 47 #ifdef CONFIG_SND_HDA_INPUT_BEEP 48 /* additional beep mixers; the actual parameters are overwritten at build */ 49 static const struct snd_kcontrol_new ad_beep_mixer[] = { 50 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT), 51 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT), 52 { } /* end */ 53 }; 54 55 #define set_beep_amp(spec, nid, idx, dir) \ 56 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */ 57 #else 58 #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 59 #endif 60 61 #ifdef CONFIG_SND_HDA_INPUT_BEEP 62 static int create_beep_ctls(struct hda_codec *codec) 63 { 64 struct ad198x_spec *spec = codec->spec; 65 const struct snd_kcontrol_new *knew; 66 67 if (!spec->beep_amp) 68 return 0; 69 70 for (knew = ad_beep_mixer ; knew->name; knew++) { 71 int err; 72 struct snd_kcontrol *kctl; 73 kctl = snd_ctl_new1(knew, codec); 74 if (!kctl) 75 return -ENOMEM; 76 kctl->private_value = spec->beep_amp; 77 err = snd_hda_ctl_add(codec, 0, kctl); 78 if (err < 0) 79 return err; 80 } 81 return 0; 82 } 83 #else 84 #define create_beep_ctls(codec) 0 85 #endif 86 87 88 static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front, 89 hda_nid_t hp) 90 { 91 if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD) 92 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE, 93 !codec->inv_eapd ? 0x00 : 0x02); 94 if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD) 95 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE, 96 !codec->inv_eapd ? 0x00 : 0x02); 97 } 98 99 static void ad198x_power_eapd(struct hda_codec *codec) 100 { 101 /* We currently only handle front, HP */ 102 switch (codec->vendor_id) { 103 case 0x11d41882: 104 case 0x11d4882a: 105 case 0x11d41884: 106 case 0x11d41984: 107 case 0x11d41883: 108 case 0x11d4184a: 109 case 0x11d4194a: 110 case 0x11d4194b: 111 case 0x11d41988: 112 case 0x11d4198b: 113 case 0x11d4989a: 114 case 0x11d4989b: 115 ad198x_power_eapd_write(codec, 0x12, 0x11); 116 break; 117 case 0x11d41981: 118 case 0x11d41983: 119 ad198x_power_eapd_write(codec, 0x05, 0x06); 120 break; 121 case 0x11d41986: 122 ad198x_power_eapd_write(codec, 0x1b, 0x1a); 123 break; 124 } 125 } 126 127 static void ad198x_shutup(struct hda_codec *codec) 128 { 129 snd_hda_shutup_pins(codec); 130 ad198x_power_eapd(codec); 131 } 132 133 #ifdef CONFIG_PM 134 static int ad198x_suspend(struct hda_codec *codec) 135 { 136 ad198x_shutup(codec); 137 return 0; 138 } 139 #endif 140 141 /* follow EAPD via vmaster hook */ 142 static void ad_vmaster_eapd_hook(void *private_data, int enabled) 143 { 144 struct hda_codec *codec = private_data; 145 struct ad198x_spec *spec = codec->spec; 146 147 if (!spec->eapd_nid) 148 return; 149 if (codec->inv_eapd) 150 enabled = !enabled; 151 snd_hda_codec_update_cache(codec, spec->eapd_nid, 0, 152 AC_VERB_SET_EAPD_BTLENABLE, 153 enabled ? 0x02 : 0x00); 154 } 155 156 /* 157 * Automatic parse of I/O pins from the BIOS configuration 158 */ 159 160 static int ad198x_auto_build_controls(struct hda_codec *codec) 161 { 162 int err; 163 164 err = snd_hda_gen_build_controls(codec); 165 if (err < 0) 166 return err; 167 err = create_beep_ctls(codec); 168 if (err < 0) 169 return err; 170 return 0; 171 } 172 173 static const struct hda_codec_ops ad198x_auto_patch_ops = { 174 .build_controls = ad198x_auto_build_controls, 175 .build_pcms = snd_hda_gen_build_pcms, 176 .init = snd_hda_gen_init, 177 .free = snd_hda_gen_free, 178 .unsol_event = snd_hda_jack_unsol_event, 179 #ifdef CONFIG_PM 180 .check_power_status = snd_hda_gen_check_power_status, 181 .suspend = ad198x_suspend, 182 #endif 183 .reboot_notify = ad198x_shutup, 184 }; 185 186 187 static int ad198x_parse_auto_config(struct hda_codec *codec, bool indep_hp) 188 { 189 struct ad198x_spec *spec = codec->spec; 190 struct auto_pin_cfg *cfg = &spec->gen.autocfg; 191 int err; 192 193 codec->spdif_status_reset = 1; 194 codec->no_trigger_sense = 1; 195 codec->no_sticky_stream = 1; 196 197 spec->gen.indep_hp = indep_hp; 198 spec->gen.add_stereo_mix_input = 1; 199 200 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0); 201 if (err < 0) 202 return err; 203 err = snd_hda_gen_parse_auto_config(codec, cfg); 204 if (err < 0) 205 return err; 206 207 codec->patch_ops = ad198x_auto_patch_ops; 208 209 return 0; 210 } 211 212 /* 213 * AD1986A specific 214 */ 215 216 static int alloc_ad_spec(struct hda_codec *codec) 217 { 218 struct ad198x_spec *spec; 219 220 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 221 if (!spec) 222 return -ENOMEM; 223 codec->spec = spec; 224 snd_hda_gen_spec_init(&spec->gen); 225 return 0; 226 } 227 228 /* 229 * AD1986A fixup codes 230 */ 231 232 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */ 233 static void ad_fixup_inv_jack_detect(struct hda_codec *codec, 234 const struct hda_fixup *fix, int action) 235 { 236 struct ad198x_spec *spec = codec->spec; 237 238 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 239 codec->inv_jack_detect = 1; 240 spec->gen.keep_eapd_on = 1; 241 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook; 242 spec->eapd_nid = 0x1b; 243 } 244 } 245 246 /* Toshiba Satellite L40 implements EAPD in a standard way unlike others */ 247 static void ad1986a_fixup_eapd(struct hda_codec *codec, 248 const struct hda_fixup *fix, int action) 249 { 250 struct ad198x_spec *spec = codec->spec; 251 252 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 253 codec->inv_eapd = 0; 254 spec->gen.keep_eapd_on = 1; 255 spec->eapd_nid = 0x1b; 256 } 257 } 258 259 enum { 260 AD1986A_FIXUP_INV_JACK_DETECT, 261 AD1986A_FIXUP_ULTRA, 262 AD1986A_FIXUP_SAMSUNG, 263 AD1986A_FIXUP_3STACK, 264 AD1986A_FIXUP_LAPTOP, 265 AD1986A_FIXUP_LAPTOP_IMIC, 266 AD1986A_FIXUP_EAPD, 267 }; 268 269 static const struct hda_fixup ad1986a_fixups[] = { 270 [AD1986A_FIXUP_INV_JACK_DETECT] = { 271 .type = HDA_FIXUP_FUNC, 272 .v.func = ad_fixup_inv_jack_detect, 273 }, 274 [AD1986A_FIXUP_ULTRA] = { 275 .type = HDA_FIXUP_PINS, 276 .v.pins = (const struct hda_pintbl[]) { 277 { 0x1b, 0x90170110 }, /* speaker */ 278 { 0x1d, 0x90a7013e }, /* int mic */ 279 {} 280 }, 281 }, 282 [AD1986A_FIXUP_SAMSUNG] = { 283 .type = HDA_FIXUP_PINS, 284 .v.pins = (const struct hda_pintbl[]) { 285 { 0x1b, 0x90170110 }, /* speaker */ 286 { 0x1d, 0x90a7013e }, /* int mic */ 287 { 0x20, 0x411111f0 }, /* N/A */ 288 { 0x24, 0x411111f0 }, /* N/A */ 289 {} 290 }, 291 }, 292 [AD1986A_FIXUP_3STACK] = { 293 .type = HDA_FIXUP_PINS, 294 .v.pins = (const struct hda_pintbl[]) { 295 { 0x1a, 0x02214021 }, /* headphone */ 296 { 0x1b, 0x01014011 }, /* front */ 297 { 0x1c, 0x01813030 }, /* line-in */ 298 { 0x1d, 0x01a19020 }, /* rear mic */ 299 { 0x1e, 0x411111f0 }, /* N/A */ 300 { 0x1f, 0x02a190f0 }, /* mic */ 301 { 0x20, 0x411111f0 }, /* N/A */ 302 {} 303 }, 304 }, 305 [AD1986A_FIXUP_LAPTOP] = { 306 .type = HDA_FIXUP_PINS, 307 .v.pins = (const struct hda_pintbl[]) { 308 { 0x1a, 0x02214021 }, /* headphone */ 309 { 0x1b, 0x90170110 }, /* speaker */ 310 { 0x1c, 0x411111f0 }, /* N/A */ 311 { 0x1d, 0x411111f0 }, /* N/A */ 312 { 0x1e, 0x411111f0 }, /* N/A */ 313 { 0x1f, 0x02a191f0 }, /* mic */ 314 { 0x20, 0x411111f0 }, /* N/A */ 315 {} 316 }, 317 }, 318 [AD1986A_FIXUP_LAPTOP_IMIC] = { 319 .type = HDA_FIXUP_PINS, 320 .v.pins = (const struct hda_pintbl[]) { 321 { 0x1d, 0x90a7013e }, /* int mic */ 322 {} 323 }, 324 .chained_before = 1, 325 .chain_id = AD1986A_FIXUP_LAPTOP, 326 }, 327 [AD1986A_FIXUP_EAPD] = { 328 .type = HDA_FIXUP_FUNC, 329 .v.func = ad1986a_fixup_eapd, 330 }, 331 }; 332 333 static const struct snd_pci_quirk ad1986a_fixup_tbl[] = { 334 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC), 335 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK), 336 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK), 337 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK), 338 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD), 339 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP), 340 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG), 341 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA), 342 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT), 343 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK), 344 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK), 345 {} 346 }; 347 348 static const struct hda_model_fixup ad1986a_fixup_models[] = { 349 { .id = AD1986A_FIXUP_3STACK, .name = "3stack" }, 350 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" }, 351 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" }, 352 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */ 353 {} 354 }; 355 356 /* 357 */ 358 static int patch_ad1986a(struct hda_codec *codec) 359 { 360 int err; 361 struct ad198x_spec *spec; 362 static hda_nid_t preferred_pairs[] = { 363 0x1a, 0x03, 364 0x1b, 0x03, 365 0x1c, 0x04, 366 0x1d, 0x05, 367 0x1e, 0x03, 368 0 369 }; 370 371 err = alloc_ad_spec(codec); 372 if (err < 0) 373 return err; 374 spec = codec->spec; 375 376 /* AD1986A has the inverted EAPD implementation */ 377 codec->inv_eapd = 1; 378 379 spec->gen.mixer_nid = 0x07; 380 spec->gen.beep_nid = 0x19; 381 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT); 382 383 /* AD1986A has a hardware problem that it can't share a stream 384 * with multiple output pins. The copy of front to surrounds 385 * causes noisy or silent outputs at a certain timing, e.g. 386 * changing the volume. 387 * So, let's disable the shared stream. 388 */ 389 spec->gen.multiout.no_share_stream = 1; 390 /* give fixed DAC/pin pairs */ 391 spec->gen.preferred_dacs = preferred_pairs; 392 393 /* AD1986A can't manage the dynamic pin on/off smoothly */ 394 spec->gen.auto_mute_via_amp = 1; 395 396 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl, 397 ad1986a_fixups); 398 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 399 400 err = ad198x_parse_auto_config(codec, false); 401 if (err < 0) { 402 snd_hda_gen_free(codec); 403 return err; 404 } 405 406 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); 407 408 return 0; 409 } 410 411 412 /* 413 * AD1983 specific 414 */ 415 416 /* 417 * SPDIF mux control for AD1983 auto-parser 418 */ 419 static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol, 420 struct snd_ctl_elem_info *uinfo) 421 { 422 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 423 struct ad198x_spec *spec = codec->spec; 424 static const char * const texts2[] = { "PCM", "ADC" }; 425 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" }; 426 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid; 427 int num_conns = snd_hda_get_num_conns(codec, dig_out); 428 429 if (num_conns == 2) 430 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2); 431 else if (num_conns == 3) 432 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3); 433 else 434 return -EINVAL; 435 } 436 437 static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol, 438 struct snd_ctl_elem_value *ucontrol) 439 { 440 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 441 struct ad198x_spec *spec = codec->spec; 442 443 ucontrol->value.enumerated.item[0] = spec->cur_smux; 444 return 0; 445 } 446 447 static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol, 448 struct snd_ctl_elem_value *ucontrol) 449 { 450 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 451 struct ad198x_spec *spec = codec->spec; 452 unsigned int val = ucontrol->value.enumerated.item[0]; 453 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid; 454 int num_conns = snd_hda_get_num_conns(codec, dig_out); 455 456 if (val >= num_conns) 457 return -EINVAL; 458 if (spec->cur_smux == val) 459 return 0; 460 spec->cur_smux = val; 461 snd_hda_codec_write_cache(codec, dig_out, 0, 462 AC_VERB_SET_CONNECT_SEL, val); 463 return 1; 464 } 465 466 static struct snd_kcontrol_new ad1983_auto_smux_mixer = { 467 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 468 .name = "IEC958 Playback Source", 469 .info = ad1983_auto_smux_enum_info, 470 .get = ad1983_auto_smux_enum_get, 471 .put = ad1983_auto_smux_enum_put, 472 }; 473 474 static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec) 475 { 476 struct ad198x_spec *spec = codec->spec; 477 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid; 478 int num_conns; 479 480 if (!dig_out) 481 return 0; 482 num_conns = snd_hda_get_num_conns(codec, dig_out); 483 if (num_conns != 2 && num_conns != 3) 484 return 0; 485 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer)) 486 return -ENOMEM; 487 return 0; 488 } 489 490 static int patch_ad1983(struct hda_codec *codec) 491 { 492 struct ad198x_spec *spec; 493 static hda_nid_t conn_0c[] = { 0x08 }; 494 static hda_nid_t conn_0d[] = { 0x09 }; 495 int err; 496 497 err = alloc_ad_spec(codec); 498 if (err < 0) 499 return err; 500 spec = codec->spec; 501 502 spec->gen.mixer_nid = 0x0e; 503 spec->gen.beep_nid = 0x10; 504 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); 505 506 /* limit the loopback routes not to confuse the parser */ 507 snd_hda_override_conn_list(codec, 0x0c, ARRAY_SIZE(conn_0c), conn_0c); 508 snd_hda_override_conn_list(codec, 0x0d, ARRAY_SIZE(conn_0d), conn_0d); 509 510 err = ad198x_parse_auto_config(codec, false); 511 if (err < 0) 512 goto error; 513 err = ad1983_add_spdif_mux_ctl(codec); 514 if (err < 0) 515 goto error; 516 return 0; 517 518 error: 519 snd_hda_gen_free(codec); 520 return err; 521 } 522 523 524 /* 525 * AD1981 HD specific 526 */ 527 528 static void ad1981_fixup_hp_eapd(struct hda_codec *codec, 529 const struct hda_fixup *fix, int action) 530 { 531 struct ad198x_spec *spec = codec->spec; 532 533 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 534 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook; 535 spec->eapd_nid = 0x05; 536 } 537 } 538 539 /* set the upper-limit for mixer amp to 0dB for avoiding the possible 540 * damage by overloading 541 */ 542 static void ad1981_fixup_amp_override(struct hda_codec *codec, 543 const struct hda_fixup *fix, int action) 544 { 545 if (action == HDA_FIXUP_ACT_PRE_PROBE) 546 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT, 547 (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 548 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 549 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 550 (1 << AC_AMPCAP_MUTE_SHIFT)); 551 } 552 553 enum { 554 AD1981_FIXUP_AMP_OVERRIDE, 555 AD1981_FIXUP_HP_EAPD, 556 }; 557 558 static const struct hda_fixup ad1981_fixups[] = { 559 [AD1981_FIXUP_AMP_OVERRIDE] = { 560 .type = HDA_FIXUP_FUNC, 561 .v.func = ad1981_fixup_amp_override, 562 }, 563 [AD1981_FIXUP_HP_EAPD] = { 564 .type = HDA_FIXUP_FUNC, 565 .v.func = ad1981_fixup_hp_eapd, 566 .chained = true, 567 .chain_id = AD1981_FIXUP_AMP_OVERRIDE, 568 }, 569 }; 570 571 static const struct snd_pci_quirk ad1981_fixup_tbl[] = { 572 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE), 573 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD), 574 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE), 575 /* HP nx6320 (reversed SSID, H/W bug) */ 576 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD), 577 {} 578 }; 579 580 static int patch_ad1981(struct hda_codec *codec) 581 { 582 struct ad198x_spec *spec; 583 int err; 584 585 err = alloc_ad_spec(codec); 586 if (err < 0) 587 return -ENOMEM; 588 spec = codec->spec; 589 590 spec->gen.mixer_nid = 0x0e; 591 spec->gen.beep_nid = 0x10; 592 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT); 593 594 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups); 595 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 596 597 err = ad198x_parse_auto_config(codec, false); 598 if (err < 0) 599 goto error; 600 err = ad1983_add_spdif_mux_ctl(codec); 601 if (err < 0) 602 goto error; 603 604 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); 605 606 return 0; 607 608 error: 609 snd_hda_gen_free(codec); 610 return err; 611 } 612 613 614 /* 615 * AD1988 616 * 617 * Output pins and routes 618 * 619 * Pin Mix Sel DAC (*) 620 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06 621 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06 622 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a 623 * port-D 0x12 (mute/hp) <- 0x29 <- 04 624 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a 625 * port-F 0x16 (mute) <- 0x2a <- 06 626 * port-G 0x24 (mute) <- 0x27 <- 05 627 * port-H 0x25 (mute) <- 0x28 <- 0a 628 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06 629 * 630 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah 631 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug. 632 * 633 * Input pins and routes 634 * 635 * pin boost mix input # / adc input # 636 * port-A 0x11 -> 0x38 -> mix 2, ADC 0 637 * port-B 0x14 -> 0x39 -> mix 0, ADC 1 638 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2 639 * port-D 0x12 -> 0x3d -> mix 3, ADC 8 640 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4 641 * port-F 0x16 -> 0x3b -> mix 5, ADC 3 642 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6 643 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7 644 * 645 * 646 * DAC assignment 647 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03 648 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03 649 * 650 * Inputs of Analog Mix (0x20) 651 * 0:Port-B (front mic) 652 * 1:Port-C/G/H (line-in) 653 * 2:Port-A 654 * 3:Port-D (line-in/2) 655 * 4:Port-E/G/H (mic-in) 656 * 5:Port-F (mic2-in) 657 * 6:CD 658 * 7:Beep 659 * 660 * ADC selection 661 * 0:Port-A 662 * 1:Port-B (front mic-in) 663 * 2:Port-C (line-in) 664 * 3:Port-F (mic2-in) 665 * 4:Port-E (mic-in) 666 * 5:CD 667 * 6:Port-G 668 * 7:Port-H 669 * 8:Port-D (line-in/2) 670 * 9:Mix 671 * 672 * Proposed pin assignments by the datasheet 673 * 674 * 6-stack 675 * Port-A front headphone 676 * B front mic-in 677 * C rear line-in 678 * D rear front-out 679 * E rear mic-in 680 * F rear surround 681 * G rear CLFE 682 * H rear side 683 * 684 * 3-stack 685 * Port-A front headphone 686 * B front mic 687 * C rear line-in/surround 688 * D rear front-out 689 * E rear mic-in/CLFE 690 * 691 * laptop 692 * Port-A headphone 693 * B mic-in 694 * C docking station 695 * D internal speaker (with EAPD) 696 * E/F quad mic array 697 */ 698 699 #ifdef ENABLE_AD_STATIC_QUIRKS 700 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol, 701 struct snd_ctl_elem_info *uinfo) 702 { 703 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 704 struct ad198x_spec *spec = codec->spec; 705 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 706 spec->num_channel_mode); 707 } 708 709 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol, 710 struct snd_ctl_elem_value *ucontrol) 711 { 712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 713 struct ad198x_spec *spec = codec->spec; 714 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 715 spec->num_channel_mode, spec->multiout.max_channels); 716 } 717 718 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol, 719 struct snd_ctl_elem_value *ucontrol) 720 { 721 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 722 struct ad198x_spec *spec = codec->spec; 723 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 724 spec->num_channel_mode, 725 &spec->multiout.max_channels); 726 if (err >= 0 && spec->need_dac_fix) 727 spec->multiout.num_dacs = spec->multiout.max_channels / 2; 728 return err; 729 } 730 #endif /* ENABLE_AD_STATIC_QUIRKS */ 731 732 static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol, 733 struct snd_ctl_elem_info *uinfo) 734 { 735 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 736 static const char * const texts[] = { 737 "PCM", "ADC1", "ADC2", "ADC3", 738 }; 739 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1; 740 if (num_conns > 4) 741 num_conns = 4; 742 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts); 743 } 744 745 static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol, 746 struct snd_ctl_elem_value *ucontrol) 747 { 748 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 749 struct ad198x_spec *spec = codec->spec; 750 751 ucontrol->value.enumerated.item[0] = spec->cur_smux; 752 return 0; 753 } 754 755 static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol, 756 struct snd_ctl_elem_value *ucontrol) 757 { 758 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 759 struct ad198x_spec *spec = codec->spec; 760 unsigned int val = ucontrol->value.enumerated.item[0]; 761 struct nid_path *path; 762 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1; 763 764 if (val >= num_conns) 765 return -EINVAL; 766 if (spec->cur_smux == val) 767 return 0; 768 769 mutex_lock(&codec->control_mutex); 770 codec->cached_write = 1; 771 path = snd_hda_get_path_from_idx(codec, 772 spec->smux_paths[spec->cur_smux]); 773 if (path) 774 snd_hda_activate_path(codec, path, false, true); 775 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]); 776 if (path) 777 snd_hda_activate_path(codec, path, true, true); 778 spec->cur_smux = val; 779 codec->cached_write = 0; 780 mutex_unlock(&codec->control_mutex); 781 snd_hda_codec_flush_cache(codec); /* flush the updates */ 782 return 1; 783 } 784 785 static struct snd_kcontrol_new ad1988_auto_smux_mixer = { 786 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 787 .name = "IEC958 Playback Source", 788 .info = ad1988_auto_smux_enum_info, 789 .get = ad1988_auto_smux_enum_get, 790 .put = ad1988_auto_smux_enum_put, 791 }; 792 793 static int ad1988_auto_init(struct hda_codec *codec) 794 { 795 struct ad198x_spec *spec = codec->spec; 796 int i, err; 797 798 err = snd_hda_gen_init(codec); 799 if (err < 0) 800 return err; 801 if (!spec->gen.autocfg.dig_outs) 802 return 0; 803 804 for (i = 0; i < 4; i++) { 805 struct nid_path *path; 806 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]); 807 if (path) 808 snd_hda_activate_path(codec, path, path->active, false); 809 } 810 811 return 0; 812 } 813 814 static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec) 815 { 816 struct ad198x_spec *spec = codec->spec; 817 int i, num_conns; 818 /* we create four static faked paths, since AD codecs have odd 819 * widget connections regarding the SPDIF out source 820 */ 821 static struct nid_path fake_paths[4] = { 822 { 823 .depth = 3, 824 .path = { 0x02, 0x1d, 0x1b }, 825 .idx = { 0, 0, 0 }, 826 .multi = { 0, 0, 0 }, 827 }, 828 { 829 .depth = 4, 830 .path = { 0x08, 0x0b, 0x1d, 0x1b }, 831 .idx = { 0, 0, 1, 0 }, 832 .multi = { 0, 1, 0, 0 }, 833 }, 834 { 835 .depth = 4, 836 .path = { 0x09, 0x0b, 0x1d, 0x1b }, 837 .idx = { 0, 1, 1, 0 }, 838 .multi = { 0, 1, 0, 0 }, 839 }, 840 { 841 .depth = 4, 842 .path = { 0x0f, 0x0b, 0x1d, 0x1b }, 843 .idx = { 0, 2, 1, 0 }, 844 .multi = { 0, 1, 0, 0 }, 845 }, 846 }; 847 848 /* SPDIF source mux appears to be present only on AD1988A */ 849 if (!spec->gen.autocfg.dig_outs || 850 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX) 851 return 0; 852 853 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1; 854 if (num_conns != 3 && num_conns != 4) 855 return 0; 856 857 for (i = 0; i < num_conns; i++) { 858 struct nid_path *path = snd_array_new(&spec->gen.paths); 859 if (!path) 860 return -ENOMEM; 861 *path = fake_paths[i]; 862 if (!i) 863 path->active = 1; 864 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path); 865 } 866 867 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer)) 868 return -ENOMEM; 869 870 codec->patch_ops.init = ad1988_auto_init; 871 872 return 0; 873 } 874 875 /* 876 */ 877 878 enum { 879 AD1988_FIXUP_6STACK_DIG, 880 }; 881 882 static const struct hda_fixup ad1988_fixups[] = { 883 [AD1988_FIXUP_6STACK_DIG] = { 884 .type = HDA_FIXUP_PINS, 885 .v.pins = (const struct hda_pintbl[]) { 886 { 0x11, 0x02214130 }, /* front-hp */ 887 { 0x12, 0x01014010 }, /* line-out */ 888 { 0x14, 0x02a19122 }, /* front-mic */ 889 { 0x15, 0x01813021 }, /* line-in */ 890 { 0x16, 0x01011012 }, /* line-out */ 891 { 0x17, 0x01a19020 }, /* mic */ 892 { 0x1b, 0x0145f1f0 }, /* SPDIF */ 893 { 0x24, 0x01016011 }, /* line-out */ 894 { 0x25, 0x01012013 }, /* line-out */ 895 { } 896 } 897 }, 898 }; 899 900 static const struct hda_model_fixup ad1988_fixup_models[] = { 901 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" }, 902 {} 903 }; 904 905 static int patch_ad1988(struct hda_codec *codec) 906 { 907 struct ad198x_spec *spec; 908 int err; 909 910 err = alloc_ad_spec(codec); 911 if (err < 0) 912 return err; 913 spec = codec->spec; 914 915 spec->gen.mixer_nid = 0x20; 916 spec->gen.mixer_merge_nid = 0x21; 917 spec->gen.beep_nid = 0x10; 918 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); 919 920 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups); 921 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 922 923 err = ad198x_parse_auto_config(codec, true); 924 if (err < 0) 925 goto error; 926 err = ad1988_add_spdif_mux_ctl(codec); 927 if (err < 0) 928 goto error; 929 930 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); 931 932 return 0; 933 934 error: 935 snd_hda_gen_free(codec); 936 return err; 937 } 938 939 940 /* 941 * AD1884 / AD1984 942 * 943 * port-B - front line/mic-in 944 * port-E - aux in/out 945 * port-F - aux in/out 946 * port-C - rear line/mic-in 947 * port-D - rear line/hp-out 948 * port-A - front line/hp-out 949 * 950 * AD1984 = AD1884 + two digital mic-ins 951 * 952 * AD1883 / AD1884A / AD1984A / AD1984B 953 * 954 * port-B (0x14) - front mic-in 955 * port-E (0x1c) - rear mic-in 956 * port-F (0x16) - CD / ext out 957 * port-C (0x15) - rear line-in 958 * port-D (0x12) - rear line-out 959 * port-A (0x11) - front hp-out 960 * 961 * AD1984A = AD1884A + digital-mic 962 * AD1883 = equivalent with AD1984A 963 * AD1984B = AD1984A + extra SPDIF-out 964 */ 965 966 /* set the upper-limit for mixer amp to 0dB for avoiding the possible 967 * damage by overloading 968 */ 969 static void ad1884_fixup_amp_override(struct hda_codec *codec, 970 const struct hda_fixup *fix, int action) 971 { 972 if (action == HDA_FIXUP_ACT_PRE_PROBE) 973 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT, 974 (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 975 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 976 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 977 (1 << AC_AMPCAP_MUTE_SHIFT)); 978 } 979 980 /* toggle GPIO1 according to the mute state */ 981 static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled) 982 { 983 struct hda_codec *codec = private_data; 984 struct ad198x_spec *spec = codec->spec; 985 986 if (spec->eapd_nid) 987 ad_vmaster_eapd_hook(private_data, enabled); 988 snd_hda_codec_update_cache(codec, 0x01, 0, 989 AC_VERB_SET_GPIO_DATA, 990 enabled ? 0x00 : 0x02); 991 } 992 993 static void ad1884_fixup_hp_eapd(struct hda_codec *codec, 994 const struct hda_fixup *fix, int action) 995 { 996 struct ad198x_spec *spec = codec->spec; 997 static const struct hda_verb gpio_init_verbs[] = { 998 {0x01, AC_VERB_SET_GPIO_MASK, 0x02}, 999 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02}, 1000 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, 1001 {}, 1002 }; 1003 1004 switch (action) { 1005 case HDA_FIXUP_ACT_PRE_PROBE: 1006 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook; 1007 spec->gen.own_eapd_ctl = 1; 1008 snd_hda_sequence_write_cache(codec, gpio_init_verbs); 1009 break; 1010 case HDA_FIXUP_ACT_PROBE: 1011 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) 1012 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0]; 1013 else 1014 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0]; 1015 break; 1016 } 1017 } 1018 1019 static void ad1884_fixup_thinkpad(struct hda_codec *codec, 1020 const struct hda_fixup *fix, int action) 1021 { 1022 struct ad198x_spec *spec = codec->spec; 1023 1024 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 1025 spec->gen.keep_eapd_on = 1; 1026 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook; 1027 spec->eapd_nid = 0x12; 1028 /* Analog PC Beeper - allow firmware/ACPI beeps */ 1029 spec->beep_amp = HDA_COMPOSE_AMP_VAL(0x20, 3, 3, HDA_INPUT); 1030 spec->gen.beep_nid = 0; /* no digital beep */ 1031 } 1032 } 1033 1034 /* set magic COEFs for dmic */ 1035 static const struct hda_verb ad1884_dmic_init_verbs[] = { 1036 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7}, 1037 {0x01, AC_VERB_SET_PROC_COEF, 0x08}, 1038 {} 1039 }; 1040 1041 enum { 1042 AD1884_FIXUP_AMP_OVERRIDE, 1043 AD1884_FIXUP_HP_EAPD, 1044 AD1884_FIXUP_DMIC_COEF, 1045 AD1884_FIXUP_THINKPAD, 1046 AD1884_FIXUP_HP_TOUCHSMART, 1047 }; 1048 1049 static const struct hda_fixup ad1884_fixups[] = { 1050 [AD1884_FIXUP_AMP_OVERRIDE] = { 1051 .type = HDA_FIXUP_FUNC, 1052 .v.func = ad1884_fixup_amp_override, 1053 }, 1054 [AD1884_FIXUP_HP_EAPD] = { 1055 .type = HDA_FIXUP_FUNC, 1056 .v.func = ad1884_fixup_hp_eapd, 1057 .chained = true, 1058 .chain_id = AD1884_FIXUP_AMP_OVERRIDE, 1059 }, 1060 [AD1884_FIXUP_DMIC_COEF] = { 1061 .type = HDA_FIXUP_VERBS, 1062 .v.verbs = ad1884_dmic_init_verbs, 1063 }, 1064 [AD1884_FIXUP_THINKPAD] = { 1065 .type = HDA_FIXUP_FUNC, 1066 .v.func = ad1884_fixup_thinkpad, 1067 .chained = true, 1068 .chain_id = AD1884_FIXUP_DMIC_COEF, 1069 }, 1070 [AD1884_FIXUP_HP_TOUCHSMART] = { 1071 .type = HDA_FIXUP_VERBS, 1072 .v.verbs = ad1884_dmic_init_verbs, 1073 .chained = true, 1074 .chain_id = AD1884_FIXUP_HP_EAPD, 1075 }, 1076 }; 1077 1078 static const struct snd_pci_quirk ad1884_fixup_tbl[] = { 1079 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART), 1080 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD), 1081 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD), 1082 {} 1083 }; 1084 1085 1086 static int patch_ad1884(struct hda_codec *codec) 1087 { 1088 struct ad198x_spec *spec; 1089 int err; 1090 1091 err = alloc_ad_spec(codec); 1092 if (err < 0) 1093 return err; 1094 spec = codec->spec; 1095 1096 spec->gen.mixer_nid = 0x20; 1097 spec->gen.mixer_merge_nid = 0x21; 1098 spec->gen.beep_nid = 0x10; 1099 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); 1100 1101 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups); 1102 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 1103 1104 err = ad198x_parse_auto_config(codec, true); 1105 if (err < 0) 1106 goto error; 1107 err = ad1983_add_spdif_mux_ctl(codec); 1108 if (err < 0) 1109 goto error; 1110 1111 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); 1112 1113 return 0; 1114 1115 error: 1116 snd_hda_gen_free(codec); 1117 return err; 1118 } 1119 1120 /* 1121 * AD1882 / AD1882A 1122 * 1123 * port-A - front hp-out 1124 * port-B - front mic-in 1125 * port-C - rear line-in, shared surr-out (3stack) 1126 * port-D - rear line-out 1127 * port-E - rear mic-in, shared clfe-out (3stack) 1128 * port-F - rear surr-out (6stack) 1129 * port-G - rear clfe-out (6stack) 1130 */ 1131 1132 static int patch_ad1882(struct hda_codec *codec) 1133 { 1134 struct ad198x_spec *spec; 1135 int err; 1136 1137 err = alloc_ad_spec(codec); 1138 if (err < 0) 1139 return err; 1140 spec = codec->spec; 1141 1142 spec->gen.mixer_nid = 0x20; 1143 spec->gen.mixer_merge_nid = 0x21; 1144 spec->gen.beep_nid = 0x10; 1145 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); 1146 err = ad198x_parse_auto_config(codec, true); 1147 if (err < 0) 1148 goto error; 1149 err = ad1988_add_spdif_mux_ctl(codec); 1150 if (err < 0) 1151 goto error; 1152 return 0; 1153 1154 error: 1155 snd_hda_gen_free(codec); 1156 return err; 1157 } 1158 1159 1160 /* 1161 * patch entries 1162 */ 1163 static const struct hda_codec_preset snd_hda_preset_analog[] = { 1164 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 }, 1165 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 }, 1166 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 }, 1167 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 }, 1168 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 }, 1169 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 }, 1170 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 }, 1171 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 }, 1172 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 }, 1173 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a }, 1174 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 }, 1175 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 }, 1176 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 }, 1177 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 }, 1178 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 }, 1179 {} /* terminator */ 1180 }; 1181 1182 MODULE_ALIAS("snd-hda-codec-id:11d4*"); 1183 1184 MODULE_LICENSE("GPL"); 1185 MODULE_DESCRIPTION("Analog Devices HD-audio codec"); 1186 1187 static struct hda_codec_preset_list analog_list = { 1188 .preset = snd_hda_preset_analog, 1189 .owner = THIS_MODULE, 1190 }; 1191 1192 static int __init patch_analog_init(void) 1193 { 1194 return snd_hda_add_codec_preset(&analog_list); 1195 } 1196 1197 static void __exit patch_analog_exit(void) 1198 { 1199 snd_hda_delete_codec_preset(&analog_list); 1200 } 1201 1202 module_init(patch_analog_init) 1203 module_exit(patch_analog_exit) 1204