Linux Audio

Check our new training course

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