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, 0x1443, "ASUS Z99He", AD1986A_FIXUP_EAPD),
  332. SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8JN", AD1986A_FIXUP_EAPD),
  333. SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
  334. SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
  335. SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK),
  336. SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD),
  337. SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
  338. SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
  339. SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
  340. SND_PCI_QUIRK(0x1631, 0xc022, "PackardBell EasyNote MX65", AD1986A_FIXUP_EASYNOTE),
  341. SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
  342. SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK),
  343. SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK),
  344. {}
  345. };
  346. static const struct hda_model_fixup ad1986a_fixup_models[] = {
  347. { .id = AD1986A_FIXUP_3STACK, .name = "3stack" },
  348. { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" },
  349. { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" },
  350. { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */
  351. { .id = AD1986A_FIXUP_EAPD, .name = "eapd" },
  352. {}
  353. };
  354. /*
  355. */
  356. static int patch_ad1986a(struct hda_codec *codec)
  357. {
  358. int err;
  359. struct ad198x_spec *spec;
  360. static hda_nid_t preferred_pairs[] = {
  361. 0x1a, 0x03,
  362. 0x1b, 0x03,
  363. 0x1c, 0x04,
  364. 0x1d, 0x05,
  365. 0x1e, 0x03,
  366. 0
  367. };
  368. err = alloc_ad_spec(codec);
  369. if (err < 0)
  370. return err;
  371. spec = codec->spec;
  372. /* AD1986A has the inverted EAPD implementation */
  373. codec->inv_eapd = 1;
  374. spec->gen.mixer_nid = 0x07;
  375. spec->gen.beep_nid = 0x19;
  376. set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
  377. /* AD1986A has a hardware problem that it can't share a stream
  378. * with multiple output pins. The copy of front to surrounds
  379. * causes noisy or silent outputs at a certain timing, e.g.
  380. * changing the volume.
  381. * So, let's disable the shared stream.
  382. */
  383. spec->gen.multiout.no_share_stream = 1;
  384. /* give fixed DAC/pin pairs */
  385. spec->gen.preferred_dacs = preferred_pairs;
  386. /* AD1986A can't manage the dynamic pin on/off smoothly */
  387. spec->gen.auto_mute_via_amp = 1;
  388. snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
  389. ad1986a_fixups);
  390. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  391. err = ad198x_parse_auto_config(codec, false);
  392. if (err < 0) {
  393. snd_hda_gen_free(codec);
  394. return err;
  395. }
  396. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  397. return 0;
  398. }
  399. /*
  400. * AD1983 specific
  401. */
  402. /*
  403. * SPDIF mux control for AD1983 auto-parser
  404. */
  405. static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
  406. struct snd_ctl_elem_info *uinfo)
  407. {
  408. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  409. struct ad198x_spec *spec = codec->spec;
  410. static const char * const texts2[] = { "PCM", "ADC" };
  411. static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
  412. hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
  413. int num_conns = snd_hda_get_num_conns(codec, dig_out);
  414. if (num_conns == 2)
  415. return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
  416. else if (num_conns == 3)
  417. return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
  418. else
  419. return -EINVAL;
  420. }
  421. static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
  422. struct snd_ctl_elem_value *ucontrol)
  423. {
  424. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  425. struct ad198x_spec *spec = codec->spec;
  426. ucontrol->value.enumerated.item[0] = spec->cur_smux;
  427. return 0;
  428. }
  429. static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
  430. struct snd_ctl_elem_value *ucontrol)
  431. {
  432. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  433. struct ad198x_spec *spec = codec->spec;
  434. unsigned int val = ucontrol->value.enumerated.item[0];
  435. hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
  436. int num_conns = snd_hda_get_num_conns(codec, dig_out);
  437. if (val >= num_conns)
  438. return -EINVAL;
  439. if (spec->cur_smux == val)
  440. return 0;
  441. spec->cur_smux = val;
  442. snd_hda_codec_write_cache(codec, dig_out, 0,
  443. AC_VERB_SET_CONNECT_SEL, val);
  444. return 1;
  445. }
  446. static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
  447. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  448. .name = "IEC958 Playback Source",
  449. .info = ad1983_auto_smux_enum_info,
  450. .get = ad1983_auto_smux_enum_get,
  451. .put = ad1983_auto_smux_enum_put,
  452. };
  453. static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
  454. {
  455. struct ad198x_spec *spec = codec->spec;
  456. hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
  457. int num_conns;
  458. if (!dig_out)
  459. return 0;
  460. num_conns = snd_hda_get_num_conns(codec, dig_out);
  461. if (num_conns != 2 && num_conns != 3)
  462. return 0;
  463. if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
  464. return -ENOMEM;
  465. return 0;
  466. }
  467. static int patch_ad1983(struct hda_codec *codec)
  468. {
  469. struct ad198x_spec *spec;
  470. static hda_nid_t conn_0c[] = { 0x08 };
  471. static hda_nid_t conn_0d[] = { 0x09 };
  472. int err;
  473. err = alloc_ad_spec(codec);
  474. if (err < 0)
  475. return err;
  476. spec = codec->spec;
  477. spec->gen.mixer_nid = 0x0e;
  478. spec->gen.beep_nid = 0x10;
  479. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  480. /* limit the loopback routes not to confuse the parser */
  481. snd_hda_override_conn_list(codec, 0x0c, ARRAY_SIZE(conn_0c), conn_0c);
  482. snd_hda_override_conn_list(codec, 0x0d, ARRAY_SIZE(conn_0d), conn_0d);
  483. err = ad198x_parse_auto_config(codec, false);
  484. if (err < 0)
  485. goto error;
  486. err = ad1983_add_spdif_mux_ctl(codec);
  487. if (err < 0)
  488. goto error;
  489. return 0;
  490. error:
  491. snd_hda_gen_free(codec);
  492. return err;
  493. }
  494. /*
  495. * AD1981 HD specific
  496. */
  497. static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
  498. const struct hda_fixup *fix, int action)
  499. {
  500. struct ad198x_spec *spec = codec->spec;
  501. if (action == HDA_FIXUP_ACT_PRE_PROBE) {
  502. spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
  503. spec->eapd_nid = 0x05;
  504. }
  505. }
  506. /* set the upper-limit for mixer amp to 0dB for avoiding the possible
  507. * damage by overloading
  508. */
  509. static void ad1981_fixup_amp_override(struct hda_codec *codec,
  510. const struct hda_fixup *fix, int action)
  511. {
  512. if (action == HDA_FIXUP_ACT_PRE_PROBE)
  513. snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
  514. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  515. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  516. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  517. (1 << AC_AMPCAP_MUTE_SHIFT));
  518. }
  519. enum {
  520. AD1981_FIXUP_AMP_OVERRIDE,
  521. AD1981_FIXUP_HP_EAPD,
  522. };
  523. static const struct hda_fixup ad1981_fixups[] = {
  524. [AD1981_FIXUP_AMP_OVERRIDE] = {
  525. .type = HDA_FIXUP_FUNC,
  526. .v.func = ad1981_fixup_amp_override,
  527. },
  528. [AD1981_FIXUP_HP_EAPD] = {
  529. .type = HDA_FIXUP_FUNC,
  530. .v.func = ad1981_fixup_hp_eapd,
  531. .chained = true,
  532. .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
  533. },
  534. };
  535. static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
  536. SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
  537. SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
  538. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
  539. /* HP nx6320 (reversed SSID, H/W bug) */
  540. SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
  541. {}
  542. };
  543. static int patch_ad1981(struct hda_codec *codec)
  544. {
  545. struct ad198x_spec *spec;
  546. int err;
  547. err = alloc_ad_spec(codec);
  548. if (err < 0)
  549. return -ENOMEM;
  550. spec = codec->spec;
  551. spec->gen.mixer_nid = 0x0e;
  552. spec->gen.beep_nid = 0x10;
  553. set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
  554. snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
  555. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  556. err = ad198x_parse_auto_config(codec, false);
  557. if (err < 0)
  558. goto error;
  559. err = ad1983_add_spdif_mux_ctl(codec);
  560. if (err < 0)
  561. goto error;
  562. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  563. return 0;
  564. error:
  565. snd_hda_gen_free(codec);
  566. return err;
  567. }
  568. /*
  569. * AD1988
  570. *
  571. * Output pins and routes
  572. *
  573. * Pin Mix Sel DAC (*)
  574. * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
  575. * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
  576. * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
  577. * port-D 0x12 (mute/hp) <- 0x29 <- 04
  578. * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
  579. * port-F 0x16 (mute) <- 0x2a <- 06
  580. * port-G 0x24 (mute) <- 0x27 <- 05
  581. * port-H 0x25 (mute) <- 0x28 <- 0a
  582. * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
  583. *
  584. * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
  585. * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
  586. *
  587. * Input pins and routes
  588. *
  589. * pin boost mix input # / adc input #
  590. * port-A 0x11 -> 0x38 -> mix 2, ADC 0
  591. * port-B 0x14 -> 0x39 -> mix 0, ADC 1
  592. * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
  593. * port-D 0x12 -> 0x3d -> mix 3, ADC 8
  594. * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
  595. * port-F 0x16 -> 0x3b -> mix 5, ADC 3
  596. * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
  597. * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
  598. *
  599. *
  600. * DAC assignment
  601. * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
  602. * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
  603. *
  604. * Inputs of Analog Mix (0x20)
  605. * 0:Port-B (front mic)
  606. * 1:Port-C/G/H (line-in)
  607. * 2:Port-A
  608. * 3:Port-D (line-in/2)
  609. * 4:Port-E/G/H (mic-in)
  610. * 5:Port-F (mic2-in)
  611. * 6:CD
  612. * 7:Beep
  613. *
  614. * ADC selection
  615. * 0:Port-A
  616. * 1:Port-B (front mic-in)
  617. * 2:Port-C (line-in)
  618. * 3:Port-F (mic2-in)
  619. * 4:Port-E (mic-in)
  620. * 5:CD
  621. * 6:Port-G
  622. * 7:Port-H
  623. * 8:Port-D (line-in/2)
  624. * 9:Mix
  625. *
  626. * Proposed pin assignments by the datasheet
  627. *
  628. * 6-stack
  629. * Port-A front headphone
  630. * B front mic-in
  631. * C rear line-in
  632. * D rear front-out
  633. * E rear mic-in
  634. * F rear surround
  635. * G rear CLFE
  636. * H rear side
  637. *
  638. * 3-stack
  639. * Port-A front headphone
  640. * B front mic
  641. * C rear line-in/surround
  642. * D rear front-out
  643. * E rear mic-in/CLFE
  644. *
  645. * laptop
  646. * Port-A headphone
  647. * B mic-in
  648. * C docking station
  649. * D internal speaker (with EAPD)
  650. * E/F quad mic array
  651. */
  652. static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
  653. struct snd_ctl_elem_info *uinfo)
  654. {
  655. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  656. static const char * const texts[] = {
  657. "PCM", "ADC1", "ADC2", "ADC3",
  658. };
  659. int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
  660. if (num_conns > 4)
  661. num_conns = 4;
  662. return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
  663. }
  664. static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
  665. struct snd_ctl_elem_value *ucontrol)
  666. {
  667. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  668. struct ad198x_spec *spec = codec->spec;
  669. ucontrol->value.enumerated.item[0] = spec->cur_smux;
  670. return 0;
  671. }
  672. static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
  673. struct snd_ctl_elem_value *ucontrol)
  674. {
  675. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  676. struct ad198x_spec *spec = codec->spec;
  677. unsigned int val = ucontrol->value.enumerated.item[0];
  678. struct nid_path *path;
  679. int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
  680. if (val >= num_conns)
  681. return -EINVAL;
  682. if (spec->cur_smux == val)
  683. return 0;
  684. mutex_lock(&codec->control_mutex);
  685. path = snd_hda_get_path_from_idx(codec,
  686. spec->smux_paths[spec->cur_smux]);
  687. if (path)
  688. snd_hda_activate_path(codec, path, false, true);
  689. path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
  690. if (path)
  691. snd_hda_activate_path(codec, path, true, true);
  692. spec->cur_smux = val;
  693. mutex_unlock(&codec->control_mutex);
  694. return 1;
  695. }
  696. static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
  697. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  698. .name = "IEC958 Playback Source",
  699. .info = ad1988_auto_smux_enum_info,
  700. .get = ad1988_auto_smux_enum_get,
  701. .put = ad1988_auto_smux_enum_put,
  702. };
  703. static int ad1988_auto_init(struct hda_codec *codec)
  704. {
  705. struct ad198x_spec *spec = codec->spec;
  706. int i, err;
  707. err = snd_hda_gen_init(codec);
  708. if (err < 0)
  709. return err;
  710. if (!spec->gen.autocfg.dig_outs)
  711. return 0;
  712. for (i = 0; i < 4; i++) {
  713. struct nid_path *path;
  714. path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
  715. if (path)
  716. snd_hda_activate_path(codec, path, path->active, false);
  717. }
  718. return 0;
  719. }
  720. static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
  721. {
  722. struct ad198x_spec *spec = codec->spec;
  723. int i, num_conns;
  724. /* we create four static faked paths, since AD codecs have odd
  725. * widget connections regarding the SPDIF out source
  726. */
  727. static struct nid_path fake_paths[4] = {
  728. {
  729. .depth = 3,
  730. .path = { 0x02, 0x1d, 0x1b },
  731. .idx = { 0, 0, 0 },
  732. .multi = { 0, 0, 0 },
  733. },
  734. {
  735. .depth = 4,
  736. .path = { 0x08, 0x0b, 0x1d, 0x1b },
  737. .idx = { 0, 0, 1, 0 },
  738. .multi = { 0, 1, 0, 0 },
  739. },
  740. {
  741. .depth = 4,
  742. .path = { 0x09, 0x0b, 0x1d, 0x1b },
  743. .idx = { 0, 1, 1, 0 },
  744. .multi = { 0, 1, 0, 0 },
  745. },
  746. {
  747. .depth = 4,
  748. .path = { 0x0f, 0x0b, 0x1d, 0x1b },
  749. .idx = { 0, 2, 1, 0 },
  750. .multi = { 0, 1, 0, 0 },
  751. },
  752. };
  753. /* SPDIF source mux appears to be present only on AD1988A */
  754. if (!spec->gen.autocfg.dig_outs ||
  755. get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
  756. return 0;
  757. num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
  758. if (num_conns != 3 && num_conns != 4)
  759. return 0;
  760. for (i = 0; i < num_conns; i++) {
  761. struct nid_path *path = snd_array_new(&spec->gen.paths);
  762. if (!path)
  763. return -ENOMEM;
  764. *path = fake_paths[i];
  765. if (!i)
  766. path->active = 1;
  767. spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
  768. }
  769. if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
  770. return -ENOMEM;
  771. codec->patch_ops.init = ad1988_auto_init;
  772. return 0;
  773. }
  774. /*
  775. */
  776. enum {
  777. AD1988_FIXUP_6STACK_DIG,
  778. };
  779. static const struct hda_fixup ad1988_fixups[] = {
  780. [AD1988_FIXUP_6STACK_DIG] = {
  781. .type = HDA_FIXUP_PINS,
  782. .v.pins = (const struct hda_pintbl[]) {
  783. { 0x11, 0x02214130 }, /* front-hp */
  784. { 0x12, 0x01014010 }, /* line-out */
  785. { 0x14, 0x02a19122 }, /* front-mic */
  786. { 0x15, 0x01813021 }, /* line-in */
  787. { 0x16, 0x01011012 }, /* line-out */
  788. { 0x17, 0x01a19020 }, /* mic */
  789. { 0x1b, 0x0145f1f0 }, /* SPDIF */
  790. { 0x24, 0x01016011 }, /* line-out */
  791. { 0x25, 0x01012013 }, /* line-out */
  792. { }
  793. }
  794. },
  795. };
  796. static const struct hda_model_fixup ad1988_fixup_models[] = {
  797. { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
  798. {}
  799. };
  800. static int patch_ad1988(struct hda_codec *codec)
  801. {
  802. struct ad198x_spec *spec;
  803. int err;
  804. err = alloc_ad_spec(codec);
  805. if (err < 0)
  806. return err;
  807. spec = codec->spec;
  808. spec->gen.mixer_nid = 0x20;
  809. spec->gen.mixer_merge_nid = 0x21;
  810. spec->gen.beep_nid = 0x10;
  811. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  812. snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
  813. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  814. err = ad198x_parse_auto_config(codec, true);
  815. if (err < 0)
  816. goto error;
  817. err = ad1988_add_spdif_mux_ctl(codec);
  818. if (err < 0)
  819. goto error;
  820. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  821. return 0;
  822. error:
  823. snd_hda_gen_free(codec);
  824. return err;
  825. }
  826. /*
  827. * AD1884 / AD1984
  828. *
  829. * port-B - front line/mic-in
  830. * port-E - aux in/out
  831. * port-F - aux in/out
  832. * port-C - rear line/mic-in
  833. * port-D - rear line/hp-out
  834. * port-A - front line/hp-out
  835. *
  836. * AD1984 = AD1884 + two digital mic-ins
  837. *
  838. * AD1883 / AD1884A / AD1984A / AD1984B
  839. *
  840. * port-B (0x14) - front mic-in
  841. * port-E (0x1c) - rear mic-in
  842. * port-F (0x16) - CD / ext out
  843. * port-C (0x15) - rear line-in
  844. * port-D (0x12) - rear line-out
  845. * port-A (0x11) - front hp-out
  846. *
  847. * AD1984A = AD1884A + digital-mic
  848. * AD1883 = equivalent with AD1984A
  849. * AD1984B = AD1984A + extra SPDIF-out
  850. */
  851. /* set the upper-limit for mixer amp to 0dB for avoiding the possible
  852. * damage by overloading
  853. */
  854. static void ad1884_fixup_amp_override(struct hda_codec *codec,
  855. const struct hda_fixup *fix, int action)
  856. {
  857. if (action == HDA_FIXUP_ACT_PRE_PROBE)
  858. snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
  859. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  860. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  861. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  862. (1 << AC_AMPCAP_MUTE_SHIFT));
  863. }
  864. /* toggle GPIO1 according to the mute state */
  865. static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
  866. {
  867. struct hda_codec *codec = private_data;
  868. struct ad198x_spec *spec = codec->spec;
  869. if (spec->eapd_nid)
  870. ad_vmaster_eapd_hook(private_data, enabled);
  871. snd_hda_codec_update_cache(codec, 0x01, 0,
  872. AC_VERB_SET_GPIO_DATA,
  873. enabled ? 0x00 : 0x02);
  874. }
  875. static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
  876. const struct hda_fixup *fix, int action)
  877. {
  878. struct ad198x_spec *spec = codec->spec;
  879. switch (action) {
  880. case HDA_FIXUP_ACT_PRE_PROBE:
  881. spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
  882. spec->gen.own_eapd_ctl = 1;
  883. snd_hda_codec_write_cache(codec, 0x01, 0,
  884. AC_VERB_SET_GPIO_MASK, 0x02);
  885. snd_hda_codec_write_cache(codec, 0x01, 0,
  886. AC_VERB_SET_GPIO_DIRECTION, 0x02);
  887. snd_hda_codec_write_cache(codec, 0x01, 0,
  888. AC_VERB_SET_GPIO_DATA, 0x02);
  889. break;
  890. case HDA_FIXUP_ACT_PROBE:
  891. if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
  892. spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
  893. else
  894. spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
  895. break;
  896. }
  897. }
  898. static void ad1884_fixup_thinkpad(struct hda_codec *codec,
  899. const struct hda_fixup *fix, int action)
  900. {
  901. struct ad198x_spec *spec = codec->spec;
  902. if (action == HDA_FIXUP_ACT_PRE_PROBE) {
  903. spec->gen.keep_eapd_on = 1;
  904. spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
  905. spec->eapd_nid = 0x12;
  906. /* Analog PC Beeper - allow firmware/ACPI beeps */
  907. spec->beep_amp = HDA_COMPOSE_AMP_VAL(0x20, 3, 3, HDA_INPUT);
  908. spec->gen.beep_nid = 0; /* no digital beep */
  909. }
  910. }
  911. /* set magic COEFs for dmic */
  912. static const struct hda_verb ad1884_dmic_init_verbs[] = {
  913. {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
  914. {0x01, AC_VERB_SET_PROC_COEF, 0x08},
  915. {}
  916. };
  917. enum {
  918. AD1884_FIXUP_AMP_OVERRIDE,
  919. AD1884_FIXUP_HP_EAPD,
  920. AD1884_FIXUP_DMIC_COEF,
  921. AD1884_FIXUP_THINKPAD,
  922. AD1884_FIXUP_HP_TOUCHSMART,
  923. };
  924. static const struct hda_fixup ad1884_fixups[] = {
  925. [AD1884_FIXUP_AMP_OVERRIDE] = {
  926. .type = HDA_FIXUP_FUNC,
  927. .v.func = ad1884_fixup_amp_override,
  928. },
  929. [AD1884_FIXUP_HP_EAPD] = {
  930. .type = HDA_FIXUP_FUNC,
  931. .v.func = ad1884_fixup_hp_eapd,
  932. .chained = true,
  933. .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
  934. },
  935. [AD1884_FIXUP_DMIC_COEF] = {
  936. .type = HDA_FIXUP_VERBS,
  937. .v.verbs = ad1884_dmic_init_verbs,
  938. },
  939. [AD1884_FIXUP_THINKPAD] = {
  940. .type = HDA_FIXUP_FUNC,
  941. .v.func = ad1884_fixup_thinkpad,
  942. .chained = true,
  943. .chain_id = AD1884_FIXUP_DMIC_COEF,
  944. },
  945. [AD1884_FIXUP_HP_TOUCHSMART] = {
  946. .type = HDA_FIXUP_VERBS,
  947. .v.verbs = ad1884_dmic_init_verbs,
  948. .chained = true,
  949. .chain_id = AD1884_FIXUP_HP_EAPD,
  950. },
  951. };
  952. static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
  953. SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
  954. SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
  955. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
  956. {}
  957. };
  958. static int patch_ad1884(struct hda_codec *codec)
  959. {
  960. struct ad198x_spec *spec;
  961. int err;
  962. err = alloc_ad_spec(codec);
  963. if (err < 0)
  964. return err;
  965. spec = codec->spec;
  966. spec->gen.mixer_nid = 0x20;
  967. spec->gen.mixer_merge_nid = 0x21;
  968. spec->gen.beep_nid = 0x10;
  969. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  970. snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
  971. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  972. err = ad198x_parse_auto_config(codec, true);
  973. if (err < 0)
  974. goto error;
  975. err = ad1983_add_spdif_mux_ctl(codec);
  976. if (err < 0)
  977. goto error;
  978. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  979. return 0;
  980. error:
  981. snd_hda_gen_free(codec);
  982. return err;
  983. }
  984. /*
  985. * AD1882 / AD1882A
  986. *
  987. * port-A - front hp-out
  988. * port-B - front mic-in
  989. * port-C - rear line-in, shared surr-out (3stack)
  990. * port-D - rear line-out
  991. * port-E - rear mic-in, shared clfe-out (3stack)
  992. * port-F - rear surr-out (6stack)
  993. * port-G - rear clfe-out (6stack)
  994. */
  995. static int patch_ad1882(struct hda_codec *codec)
  996. {
  997. struct ad198x_spec *spec;
  998. int err;
  999. err = alloc_ad_spec(codec);
  1000. if (err < 0)
  1001. return err;
  1002. spec = codec->spec;
  1003. spec->gen.mixer_nid = 0x20;
  1004. spec->gen.mixer_merge_nid = 0x21;
  1005. spec->gen.beep_nid = 0x10;
  1006. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  1007. err = ad198x_parse_auto_config(codec, true);
  1008. if (err < 0)
  1009. goto error;
  1010. err = ad1988_add_spdif_mux_ctl(codec);
  1011. if (err < 0)
  1012. goto error;
  1013. return 0;
  1014. error:
  1015. snd_hda_gen_free(codec);
  1016. return err;
  1017. }
  1018. /*
  1019. * patch entries
  1020. */
  1021. static const struct hda_codec_preset snd_hda_preset_analog[] = {
  1022. { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
  1023. { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
  1024. { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
  1025. { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
  1026. { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
  1027. { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
  1028. { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
  1029. { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
  1030. { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
  1031. { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
  1032. { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
  1033. { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
  1034. { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
  1035. { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
  1036. { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
  1037. {} /* terminator */
  1038. };
  1039. MODULE_ALIAS("snd-hda-codec-id:11d4*");
  1040. MODULE_LICENSE("GPL");
  1041. MODULE_DESCRIPTION("Analog Devices HD-audio codec");
  1042. static struct hda_codec_driver analog_driver = {
  1043. .preset = snd_hda_preset_analog,
  1044. };
  1045. module_hda_codec_driver(analog_driver);