patch_analog.c 28 KB

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