patch_analog.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  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_device_id snd_hda_id_analog[] = {
  1022. HDA_CODEC_ENTRY(0x11d4184a, "AD1884A", patch_ad1884),
  1023. HDA_CODEC_ENTRY(0x11d41882, "AD1882", patch_ad1882),
  1024. HDA_CODEC_ENTRY(0x11d41883, "AD1883", patch_ad1884),
  1025. HDA_CODEC_ENTRY(0x11d41884, "AD1884", patch_ad1884),
  1026. HDA_CODEC_ENTRY(0x11d4194a, "AD1984A", patch_ad1884),
  1027. HDA_CODEC_ENTRY(0x11d4194b, "AD1984B", patch_ad1884),
  1028. HDA_CODEC_ENTRY(0x11d41981, "AD1981", patch_ad1981),
  1029. HDA_CODEC_ENTRY(0x11d41983, "AD1983", patch_ad1983),
  1030. HDA_CODEC_ENTRY(0x11d41984, "AD1984", patch_ad1884),
  1031. HDA_CODEC_ENTRY(0x11d41986, "AD1986A", patch_ad1986a),
  1032. HDA_CODEC_ENTRY(0x11d41988, "AD1988", patch_ad1988),
  1033. HDA_CODEC_ENTRY(0x11d4198b, "AD1988B", patch_ad1988),
  1034. HDA_CODEC_ENTRY(0x11d4882a, "AD1882A", patch_ad1882),
  1035. HDA_CODEC_ENTRY(0x11d4989a, "AD1989A", patch_ad1988),
  1036. HDA_CODEC_ENTRY(0x11d4989b, "AD1989B", patch_ad1988),
  1037. {} /* terminator */
  1038. };
  1039. MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_analog);
  1040. MODULE_LICENSE("GPL");
  1041. MODULE_DESCRIPTION("Analog Devices HD-audio codec");
  1042. static struct hda_codec_driver analog_driver = {
  1043. .id = snd_hda_id_analog,
  1044. };
  1045. module_hda_codec_driver(analog_driver);