patch_analog.c 30 KB

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