patch_analog.c 31 KB

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