patch_analog.c 30 KB

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