patch_analog.c 30 KB

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