patch_analog.c 30 KB

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