Linux Audio

Check our new training course

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