patch_analog.c 30 KB

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