patch_analog.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185
  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. #define ENABLE_AD_STATIC_QUIRKS
  33. struct ad198x_spec {
  34. struct hda_gen_spec gen;
  35. /* for auto parser */
  36. int smux_paths[4];
  37. unsigned int cur_smux;
  38. hda_nid_t eapd_nid;
  39. unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
  40. #ifdef ENABLE_AD_STATIC_QUIRKS
  41. const struct snd_kcontrol_new *mixers[6];
  42. int num_mixers;
  43. const struct hda_verb *init_verbs[6]; /* initialization verbs
  44. * don't forget NULL termination!
  45. */
  46. unsigned int num_init_verbs;
  47. /* playback */
  48. struct hda_multi_out multiout; /* playback set-up
  49. * max_channels, dacs must be set
  50. * dig_out_nid and hp_nid are optional
  51. */
  52. unsigned int cur_eapd;
  53. unsigned int need_dac_fix;
  54. /* capture */
  55. unsigned int num_adc_nids;
  56. const hda_nid_t *adc_nids;
  57. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  58. /* capture source */
  59. const struct hda_input_mux *input_mux;
  60. const hda_nid_t *capsrc_nids;
  61. unsigned int cur_mux[3];
  62. /* channel model */
  63. const struct hda_channel_mode *channel_mode;
  64. int num_channel_mode;
  65. /* PCM information */
  66. struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
  67. unsigned int spdif_route;
  68. unsigned int jack_present: 1;
  69. unsigned int inv_jack_detect: 1;/* inverted jack-detection */
  70. unsigned int analog_beep: 1; /* analog beep input present */
  71. unsigned int avoid_init_slave_vol:1;
  72. #ifdef CONFIG_PM
  73. struct hda_loopback_check loopback;
  74. #endif
  75. /* for virtual master */
  76. hda_nid_t vmaster_nid;
  77. const char * const *slave_vols;
  78. const char * const *slave_sws;
  79. #endif /* ENABLE_AD_STATIC_QUIRKS */
  80. };
  81. #ifdef ENABLE_AD_STATIC_QUIRKS
  82. /*
  83. * input MUX handling (common part)
  84. */
  85. static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  86. {
  87. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  88. struct ad198x_spec *spec = codec->spec;
  89. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  90. }
  91. static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  92. {
  93. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  94. struct ad198x_spec *spec = codec->spec;
  95. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  96. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  97. return 0;
  98. }
  99. static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  100. {
  101. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  102. struct ad198x_spec *spec = codec->spec;
  103. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  104. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  105. spec->capsrc_nids[adc_idx],
  106. &spec->cur_mux[adc_idx]);
  107. }
  108. /*
  109. * initialization (common callbacks)
  110. */
  111. static int ad198x_init(struct hda_codec *codec)
  112. {
  113. struct ad198x_spec *spec = codec->spec;
  114. int i;
  115. for (i = 0; i < spec->num_init_verbs; i++)
  116. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  117. return 0;
  118. }
  119. static const char * const ad_slave_pfxs[] = {
  120. "Front", "Surround", "Center", "LFE", "Side",
  121. "Headphone", "Mono", "Speaker", "IEC958",
  122. NULL
  123. };
  124. static const char * const ad1988_6stack_fp_slave_pfxs[] = {
  125. "Front", "Surround", "Center", "LFE", "Side", "IEC958",
  126. NULL
  127. };
  128. #endif /* ENABLE_AD_STATIC_QUIRKS */
  129. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  130. /* additional beep mixers; the actual parameters are overwritten at build */
  131. static const struct snd_kcontrol_new ad_beep_mixer[] = {
  132. HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
  133. HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
  134. { } /* end */
  135. };
  136. static const struct snd_kcontrol_new ad_beep2_mixer[] = {
  137. HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0, 0, HDA_OUTPUT),
  138. HDA_CODEC_MUTE_BEEP("Digital Beep Playback Switch", 0, 0, HDA_OUTPUT),
  139. { } /* end */
  140. };
  141. #define set_beep_amp(spec, nid, idx, dir) \
  142. ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
  143. #else
  144. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  145. #endif
  146. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  147. static int create_beep_ctls(struct hda_codec *codec)
  148. {
  149. struct ad198x_spec *spec = codec->spec;
  150. const struct snd_kcontrol_new *knew;
  151. if (!spec->beep_amp)
  152. return 0;
  153. knew = spec->analog_beep ? ad_beep2_mixer : ad_beep_mixer;
  154. for ( ; knew->name; knew++) {
  155. int err;
  156. struct snd_kcontrol *kctl;
  157. kctl = snd_ctl_new1(knew, codec);
  158. if (!kctl)
  159. return -ENOMEM;
  160. kctl->private_value = spec->beep_amp;
  161. err = snd_hda_ctl_add(codec, 0, kctl);
  162. if (err < 0)
  163. return err;
  164. }
  165. return 0;
  166. }
  167. #else
  168. #define create_beep_ctls(codec) 0
  169. #endif
  170. #ifdef ENABLE_AD_STATIC_QUIRKS
  171. static int ad198x_build_controls(struct hda_codec *codec)
  172. {
  173. struct ad198x_spec *spec = codec->spec;
  174. struct snd_kcontrol *kctl;
  175. unsigned int i;
  176. int err;
  177. for (i = 0; i < spec->num_mixers; i++) {
  178. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  179. if (err < 0)
  180. return err;
  181. }
  182. if (spec->multiout.dig_out_nid) {
  183. err = snd_hda_create_spdif_out_ctls(codec,
  184. spec->multiout.dig_out_nid,
  185. spec->multiout.dig_out_nid);
  186. if (err < 0)
  187. return err;
  188. err = snd_hda_create_spdif_share_sw(codec,
  189. &spec->multiout);
  190. if (err < 0)
  191. return err;
  192. spec->multiout.share_spdif = 1;
  193. }
  194. if (spec->dig_in_nid) {
  195. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  196. if (err < 0)
  197. return err;
  198. }
  199. /* create beep controls if needed */
  200. err = create_beep_ctls(codec);
  201. if (err < 0)
  202. return err;
  203. /* if we have no master control, let's create it */
  204. if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  205. unsigned int vmaster_tlv[4];
  206. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  207. HDA_OUTPUT, vmaster_tlv);
  208. err = __snd_hda_add_vmaster(codec, "Master Playback Volume",
  209. vmaster_tlv,
  210. (spec->slave_vols ?
  211. spec->slave_vols : ad_slave_pfxs),
  212. "Playback Volume",
  213. !spec->avoid_init_slave_vol, NULL);
  214. if (err < 0)
  215. return err;
  216. }
  217. if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  218. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  219. NULL,
  220. (spec->slave_sws ?
  221. spec->slave_sws : ad_slave_pfxs),
  222. "Playback Switch");
  223. if (err < 0)
  224. return err;
  225. }
  226. /* assign Capture Source enums to NID */
  227. kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
  228. if (!kctl)
  229. kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
  230. for (i = 0; kctl && i < kctl->count; i++) {
  231. err = snd_hda_add_nid(codec, kctl, i, spec->capsrc_nids[i]);
  232. if (err < 0)
  233. return err;
  234. }
  235. /* assign IEC958 enums to NID */
  236. kctl = snd_hda_find_mixer_ctl(codec,
  237. SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source");
  238. if (kctl) {
  239. err = snd_hda_add_nid(codec, kctl, 0,
  240. spec->multiout.dig_out_nid);
  241. if (err < 0)
  242. return err;
  243. }
  244. return 0;
  245. }
  246. #ifdef CONFIG_PM
  247. static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  248. {
  249. struct ad198x_spec *spec = codec->spec;
  250. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  251. }
  252. #endif
  253. /*
  254. * Analog playback callbacks
  255. */
  256. static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
  257. struct hda_codec *codec,
  258. struct snd_pcm_substream *substream)
  259. {
  260. struct ad198x_spec *spec = codec->spec;
  261. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  262. hinfo);
  263. }
  264. static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  265. struct hda_codec *codec,
  266. unsigned int stream_tag,
  267. unsigned int format,
  268. struct snd_pcm_substream *substream)
  269. {
  270. struct ad198x_spec *spec = codec->spec;
  271. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
  272. format, substream);
  273. }
  274. static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  275. struct hda_codec *codec,
  276. struct snd_pcm_substream *substream)
  277. {
  278. struct ad198x_spec *spec = codec->spec;
  279. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  280. }
  281. /*
  282. * Digital out
  283. */
  284. static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  285. struct hda_codec *codec,
  286. struct snd_pcm_substream *substream)
  287. {
  288. struct ad198x_spec *spec = codec->spec;
  289. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  290. }
  291. static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  292. struct hda_codec *codec,
  293. struct snd_pcm_substream *substream)
  294. {
  295. struct ad198x_spec *spec = codec->spec;
  296. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  297. }
  298. static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  299. struct hda_codec *codec,
  300. unsigned int stream_tag,
  301. unsigned int format,
  302. struct snd_pcm_substream *substream)
  303. {
  304. struct ad198x_spec *spec = codec->spec;
  305. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
  306. format, substream);
  307. }
  308. static int ad198x_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  309. struct hda_codec *codec,
  310. struct snd_pcm_substream *substream)
  311. {
  312. struct ad198x_spec *spec = codec->spec;
  313. return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  314. }
  315. /*
  316. * Analog capture
  317. */
  318. static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  319. struct hda_codec *codec,
  320. unsigned int stream_tag,
  321. unsigned int format,
  322. struct snd_pcm_substream *substream)
  323. {
  324. struct ad198x_spec *spec = codec->spec;
  325. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  326. stream_tag, 0, format);
  327. return 0;
  328. }
  329. static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  330. struct hda_codec *codec,
  331. struct snd_pcm_substream *substream)
  332. {
  333. struct ad198x_spec *spec = codec->spec;
  334. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  335. return 0;
  336. }
  337. /*
  338. */
  339. static const struct hda_pcm_stream ad198x_pcm_analog_playback = {
  340. .substreams = 1,
  341. .channels_min = 2,
  342. .channels_max = 6, /* changed later */
  343. .nid = 0, /* fill later */
  344. .ops = {
  345. .open = ad198x_playback_pcm_open,
  346. .prepare = ad198x_playback_pcm_prepare,
  347. .cleanup = ad198x_playback_pcm_cleanup,
  348. },
  349. };
  350. static const struct hda_pcm_stream ad198x_pcm_analog_capture = {
  351. .substreams = 1,
  352. .channels_min = 2,
  353. .channels_max = 2,
  354. .nid = 0, /* fill later */
  355. .ops = {
  356. .prepare = ad198x_capture_pcm_prepare,
  357. .cleanup = ad198x_capture_pcm_cleanup
  358. },
  359. };
  360. static const struct hda_pcm_stream ad198x_pcm_digital_playback = {
  361. .substreams = 1,
  362. .channels_min = 2,
  363. .channels_max = 2,
  364. .nid = 0, /* fill later */
  365. .ops = {
  366. .open = ad198x_dig_playback_pcm_open,
  367. .close = ad198x_dig_playback_pcm_close,
  368. .prepare = ad198x_dig_playback_pcm_prepare,
  369. .cleanup = ad198x_dig_playback_pcm_cleanup
  370. },
  371. };
  372. static const struct hda_pcm_stream ad198x_pcm_digital_capture = {
  373. .substreams = 1,
  374. .channels_min = 2,
  375. .channels_max = 2,
  376. /* NID is set in alc_build_pcms */
  377. };
  378. static int ad198x_build_pcms(struct hda_codec *codec)
  379. {
  380. struct ad198x_spec *spec = codec->spec;
  381. struct hda_pcm *info = spec->pcm_rec;
  382. codec->num_pcms = 1;
  383. codec->pcm_info = info;
  384. info->name = "AD198x Analog";
  385. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
  386. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
  387. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  388. info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
  389. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  390. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  391. if (spec->multiout.dig_out_nid) {
  392. info++;
  393. codec->num_pcms++;
  394. codec->spdif_status_reset = 1;
  395. info->name = "AD198x Digital";
  396. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  397. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
  398. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  399. if (spec->dig_in_nid) {
  400. info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
  401. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  402. }
  403. }
  404. return 0;
  405. }
  406. #endif /* ENABLE_AD_STATIC_QUIRKS */
  407. static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
  408. hda_nid_t hp)
  409. {
  410. if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
  411. snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
  412. !codec->inv_eapd ? 0x00 : 0x02);
  413. if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
  414. snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
  415. !codec->inv_eapd ? 0x00 : 0x02);
  416. }
  417. static void ad198x_power_eapd(struct hda_codec *codec)
  418. {
  419. /* We currently only handle front, HP */
  420. switch (codec->vendor_id) {
  421. case 0x11d41882:
  422. case 0x11d4882a:
  423. case 0x11d41884:
  424. case 0x11d41984:
  425. case 0x11d41883:
  426. case 0x11d4184a:
  427. case 0x11d4194a:
  428. case 0x11d4194b:
  429. case 0x11d41988:
  430. case 0x11d4198b:
  431. case 0x11d4989a:
  432. case 0x11d4989b:
  433. ad198x_power_eapd_write(codec, 0x12, 0x11);
  434. break;
  435. case 0x11d41981:
  436. case 0x11d41983:
  437. ad198x_power_eapd_write(codec, 0x05, 0x06);
  438. break;
  439. case 0x11d41986:
  440. ad198x_power_eapd_write(codec, 0x1b, 0x1a);
  441. break;
  442. }
  443. }
  444. static void ad198x_shutup(struct hda_codec *codec)
  445. {
  446. snd_hda_shutup_pins(codec);
  447. ad198x_power_eapd(codec);
  448. }
  449. static void ad198x_free(struct hda_codec *codec)
  450. {
  451. struct ad198x_spec *spec = codec->spec;
  452. if (!spec)
  453. return;
  454. snd_hda_gen_spec_free(&spec->gen);
  455. kfree(spec);
  456. snd_hda_detach_beep_device(codec);
  457. }
  458. #ifdef CONFIG_PM
  459. static int ad198x_suspend(struct hda_codec *codec)
  460. {
  461. ad198x_shutup(codec);
  462. return 0;
  463. }
  464. #endif
  465. #ifdef ENABLE_AD_STATIC_QUIRKS
  466. static const struct hda_codec_ops ad198x_patch_ops = {
  467. .build_controls = ad198x_build_controls,
  468. .build_pcms = ad198x_build_pcms,
  469. .init = ad198x_init,
  470. .free = ad198x_free,
  471. #ifdef CONFIG_PM
  472. .check_power_status = ad198x_check_power_status,
  473. .suspend = ad198x_suspend,
  474. #endif
  475. .reboot_notify = ad198x_shutup,
  476. };
  477. /*
  478. * EAPD control
  479. * the private value = nid
  480. */
  481. #define ad198x_eapd_info snd_ctl_boolean_mono_info
  482. static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
  483. struct snd_ctl_elem_value *ucontrol)
  484. {
  485. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  486. struct ad198x_spec *spec = codec->spec;
  487. if (codec->inv_eapd)
  488. ucontrol->value.integer.value[0] = ! spec->cur_eapd;
  489. else
  490. ucontrol->value.integer.value[0] = spec->cur_eapd;
  491. return 0;
  492. }
  493. static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
  494. struct snd_ctl_elem_value *ucontrol)
  495. {
  496. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  497. struct ad198x_spec *spec = codec->spec;
  498. hda_nid_t nid = kcontrol->private_value & 0xff;
  499. unsigned int eapd;
  500. eapd = !!ucontrol->value.integer.value[0];
  501. if (codec->inv_eapd)
  502. eapd = !eapd;
  503. if (eapd == spec->cur_eapd)
  504. return 0;
  505. spec->cur_eapd = eapd;
  506. snd_hda_codec_write_cache(codec, nid,
  507. 0, AC_VERB_SET_EAPD_BTLENABLE,
  508. eapd ? 0x02 : 0x00);
  509. return 1;
  510. }
  511. static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
  512. struct snd_ctl_elem_info *uinfo);
  513. static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
  514. struct snd_ctl_elem_value *ucontrol);
  515. static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
  516. struct snd_ctl_elem_value *ucontrol);
  517. #endif /* ENABLE_AD_STATIC_QUIRKS */
  518. /*
  519. * Automatic parse of I/O pins from the BIOS configuration
  520. */
  521. static int ad198x_auto_build_controls(struct hda_codec *codec)
  522. {
  523. int err;
  524. err = snd_hda_gen_build_controls(codec);
  525. if (err < 0)
  526. return err;
  527. err = create_beep_ctls(codec);
  528. if (err < 0)
  529. return err;
  530. return 0;
  531. }
  532. static const struct hda_codec_ops ad198x_auto_patch_ops = {
  533. .build_controls = ad198x_auto_build_controls,
  534. .build_pcms = snd_hda_gen_build_pcms,
  535. .init = snd_hda_gen_init,
  536. .free = snd_hda_gen_free,
  537. .unsol_event = snd_hda_jack_unsol_event,
  538. #ifdef CONFIG_PM
  539. .check_power_status = snd_hda_gen_check_power_status,
  540. .suspend = ad198x_suspend,
  541. #endif
  542. .reboot_notify = ad198x_shutup,
  543. };
  544. static int ad198x_parse_auto_config(struct hda_codec *codec)
  545. {
  546. struct ad198x_spec *spec = codec->spec;
  547. struct auto_pin_cfg *cfg = &spec->gen.autocfg;
  548. int err;
  549. codec->spdif_status_reset = 1;
  550. codec->no_trigger_sense = 1;
  551. codec->no_sticky_stream = 1;
  552. spec->gen.indep_hp = 1;
  553. err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
  554. if (err < 0)
  555. return err;
  556. err = snd_hda_gen_parse_auto_config(codec, cfg);
  557. if (err < 0)
  558. return err;
  559. codec->patch_ops = ad198x_auto_patch_ops;
  560. return 0;
  561. }
  562. /*
  563. * AD1986A specific
  564. */
  565. #ifdef ENABLE_AD_STATIC_QUIRKS
  566. #define AD1986A_SPDIF_OUT 0x02
  567. #define AD1986A_FRONT_DAC 0x03
  568. #define AD1986A_SURR_DAC 0x04
  569. #define AD1986A_CLFE_DAC 0x05
  570. #define AD1986A_ADC 0x06
  571. static const hda_nid_t ad1986a_dac_nids[3] = {
  572. AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
  573. };
  574. static const hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
  575. static const hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
  576. static const struct hda_input_mux ad1986a_capture_source = {
  577. .num_items = 7,
  578. .items = {
  579. { "Mic", 0x0 },
  580. { "CD", 0x1 },
  581. { "Aux", 0x3 },
  582. { "Line", 0x4 },
  583. { "Mix", 0x5 },
  584. { "Mono", 0x6 },
  585. { "Phone", 0x7 },
  586. },
  587. };
  588. static const struct hda_bind_ctls ad1986a_bind_pcm_vol = {
  589. .ops = &snd_hda_bind_vol,
  590. .values = {
  591. HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
  592. HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
  593. HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
  594. 0
  595. },
  596. };
  597. static const struct hda_bind_ctls ad1986a_bind_pcm_sw = {
  598. .ops = &snd_hda_bind_sw,
  599. .values = {
  600. HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
  601. HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
  602. HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
  603. 0
  604. },
  605. };
  606. /*
  607. * mixers
  608. */
  609. static const struct snd_kcontrol_new ad1986a_mixers[] = {
  610. /*
  611. * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
  612. */
  613. HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
  614. HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
  615. HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  616. HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  617. HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  618. HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  619. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
  620. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
  621. HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
  622. HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
  623. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
  624. HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
  625. HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  626. HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  627. HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
  628. HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
  629. HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
  630. HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  631. HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  632. HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  633. HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
  634. HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
  635. HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
  636. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  637. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  638. {
  639. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  640. .name = "Capture Source",
  641. .info = ad198x_mux_enum_info,
  642. .get = ad198x_mux_enum_get,
  643. .put = ad198x_mux_enum_put,
  644. },
  645. HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
  646. { } /* end */
  647. };
  648. /* additional mixers for 3stack mode */
  649. static const struct snd_kcontrol_new ad1986a_3st_mixers[] = {
  650. {
  651. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  652. .name = "Channel Mode",
  653. .info = ad198x_ch_mode_info,
  654. .get = ad198x_ch_mode_get,
  655. .put = ad198x_ch_mode_put,
  656. },
  657. { } /* end */
  658. };
  659. /* laptop model - 2ch only */
  660. static const hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
  661. /* master controls both pins 0x1a and 0x1b */
  662. static const struct hda_bind_ctls ad1986a_laptop_master_vol = {
  663. .ops = &snd_hda_bind_vol,
  664. .values = {
  665. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  666. HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
  667. 0,
  668. },
  669. };
  670. static const struct hda_bind_ctls ad1986a_laptop_master_sw = {
  671. .ops = &snd_hda_bind_sw,
  672. .values = {
  673. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  674. HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
  675. 0,
  676. },
  677. };
  678. static const struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
  679. HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  680. HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
  681. HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
  682. HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
  683. HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  684. HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  685. HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
  686. HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
  687. HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
  688. HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  689. HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  690. HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  691. HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
  692. /*
  693. HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
  694. HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
  695. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  696. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  697. {
  698. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  699. .name = "Capture Source",
  700. .info = ad198x_mux_enum_info,
  701. .get = ad198x_mux_enum_get,
  702. .put = ad198x_mux_enum_put,
  703. },
  704. { } /* end */
  705. };
  706. /* laptop-eapd model - 2ch only */
  707. static const struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
  708. .num_items = 3,
  709. .items = {
  710. { "Mic", 0x0 },
  711. { "Internal Mic", 0x4 },
  712. { "Mix", 0x5 },
  713. },
  714. };
  715. static const struct hda_input_mux ad1986a_automic_capture_source = {
  716. .num_items = 2,
  717. .items = {
  718. { "Mic", 0x0 },
  719. { "Mix", 0x5 },
  720. },
  721. };
  722. static const struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
  723. HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
  724. HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
  725. { } /* end */
  726. };
  727. static const struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
  728. HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  729. HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
  730. HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  731. HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  732. HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
  733. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  734. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  735. {
  736. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  737. .name = "Capture Source",
  738. .info = ad198x_mux_enum_info,
  739. .get = ad198x_mux_enum_get,
  740. .put = ad198x_mux_enum_put,
  741. },
  742. {
  743. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  744. .name = "External Amplifier",
  745. .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
  746. .info = ad198x_eapd_info,
  747. .get = ad198x_eapd_get,
  748. .put = ad198x_eapd_put,
  749. .private_value = 0x1b, /* port-D */
  750. },
  751. { } /* end */
  752. };
  753. static const struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
  754. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
  755. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
  756. { } /* end */
  757. };
  758. /* re-connect the mic boost input according to the jack sensing */
  759. static void ad1986a_automic(struct hda_codec *codec)
  760. {
  761. unsigned int present;
  762. present = snd_hda_jack_detect(codec, 0x1f);
  763. /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
  764. snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
  765. present ? 0 : 2);
  766. }
  767. #define AD1986A_MIC_EVENT 0x36
  768. static void ad1986a_automic_unsol_event(struct hda_codec *codec,
  769. unsigned int res)
  770. {
  771. if ((res >> 26) != AD1986A_MIC_EVENT)
  772. return;
  773. ad1986a_automic(codec);
  774. }
  775. static int ad1986a_automic_init(struct hda_codec *codec)
  776. {
  777. ad198x_init(codec);
  778. ad1986a_automic(codec);
  779. return 0;
  780. }
  781. /* laptop-automute - 2ch only */
  782. static void ad1986a_update_hp(struct hda_codec *codec)
  783. {
  784. struct ad198x_spec *spec = codec->spec;
  785. unsigned int mute;
  786. if (spec->jack_present)
  787. mute = HDA_AMP_MUTE; /* mute internal speaker */
  788. else
  789. /* unmute internal speaker if necessary */
  790. mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
  791. snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
  792. HDA_AMP_MUTE, mute);
  793. }
  794. static void ad1986a_hp_automute(struct hda_codec *codec)
  795. {
  796. struct ad198x_spec *spec = codec->spec;
  797. spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
  798. if (spec->inv_jack_detect)
  799. spec->jack_present = !spec->jack_present;
  800. ad1986a_update_hp(codec);
  801. }
  802. #define AD1986A_HP_EVENT 0x37
  803. static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
  804. {
  805. if ((res >> 26) != AD1986A_HP_EVENT)
  806. return;
  807. ad1986a_hp_automute(codec);
  808. }
  809. static int ad1986a_hp_init(struct hda_codec *codec)
  810. {
  811. ad198x_init(codec);
  812. ad1986a_hp_automute(codec);
  813. return 0;
  814. }
  815. /* bind hp and internal speaker mute (with plug check) */
  816. static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  817. struct snd_ctl_elem_value *ucontrol)
  818. {
  819. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  820. int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
  821. if (change)
  822. ad1986a_update_hp(codec);
  823. return change;
  824. }
  825. static const struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
  826. HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
  827. {
  828. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  829. .name = "Master Playback Switch",
  830. .subdevice = HDA_SUBDEV_AMP_FLAG,
  831. .info = snd_hda_mixer_amp_switch_info,
  832. .get = snd_hda_mixer_amp_switch_get,
  833. .put = ad1986a_hp_master_sw_put,
  834. .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  835. },
  836. { } /* end */
  837. };
  838. /*
  839. * initialization verbs
  840. */
  841. static const struct hda_verb ad1986a_init_verbs[] = {
  842. /* Front, Surround, CLFE DAC; mute as default */
  843. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  844. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  845. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  846. /* Downmix - off */
  847. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  848. /* HP, Line-Out, Surround, CLFE selectors */
  849. {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
  850. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
  851. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  852. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  853. /* Mono selector */
  854. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
  855. /* Mic selector: Mic 1/2 pin */
  856. {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
  857. /* Line-in selector: Line-in */
  858. {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
  859. /* Mic 1/2 swap */
  860. {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
  861. /* Record selector: mic */
  862. {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
  863. /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
  864. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  865. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  866. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  867. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  868. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  869. /* PC beep */
  870. {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
  871. /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
  872. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  873. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  874. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  875. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  876. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  877. /* HP Pin */
  878. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  879. /* Front, Surround, CLFE Pins */
  880. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  881. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  882. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  883. /* Mono Pin */
  884. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  885. /* Mic Pin */
  886. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  887. /* Line, Aux, CD, Beep-In Pin */
  888. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  889. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  890. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  891. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  892. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  893. { } /* end */
  894. };
  895. static const struct hda_verb ad1986a_ch2_init[] = {
  896. /* Surround out -> Line In */
  897. { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  898. /* Line-in selectors */
  899. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
  900. /* CLFE -> Mic in */
  901. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  902. /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
  903. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
  904. { } /* end */
  905. };
  906. static const struct hda_verb ad1986a_ch4_init[] = {
  907. /* Surround out -> Surround */
  908. { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  909. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  910. /* CLFE -> Mic in */
  911. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  912. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
  913. { } /* end */
  914. };
  915. static const struct hda_verb ad1986a_ch6_init[] = {
  916. /* Surround out -> Surround out */
  917. { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  918. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  919. /* CLFE -> CLFE */
  920. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  921. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
  922. { } /* end */
  923. };
  924. static const struct hda_channel_mode ad1986a_modes[3] = {
  925. { 2, ad1986a_ch2_init },
  926. { 4, ad1986a_ch4_init },
  927. { 6, ad1986a_ch6_init },
  928. };
  929. /* eapd initialization */
  930. static const struct hda_verb ad1986a_eapd_init_verbs[] = {
  931. {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
  932. {}
  933. };
  934. static const struct hda_verb ad1986a_automic_verbs[] = {
  935. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  936. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  937. /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
  938. {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
  939. {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
  940. {}
  941. };
  942. /* pin sensing on HP jack */
  943. static const struct hda_verb ad1986a_hp_init_verbs[] = {
  944. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
  945. {}
  946. };
  947. static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
  948. unsigned int res)
  949. {
  950. switch (res >> 26) {
  951. case AD1986A_HP_EVENT:
  952. ad1986a_hp_automute(codec);
  953. break;
  954. case AD1986A_MIC_EVENT:
  955. ad1986a_automic(codec);
  956. break;
  957. }
  958. }
  959. static int ad1986a_samsung_p50_init(struct hda_codec *codec)
  960. {
  961. ad198x_init(codec);
  962. ad1986a_hp_automute(codec);
  963. ad1986a_automic(codec);
  964. return 0;
  965. }
  966. /* models */
  967. enum {
  968. AD1986A_AUTO,
  969. AD1986A_6STACK,
  970. AD1986A_3STACK,
  971. AD1986A_LAPTOP,
  972. AD1986A_LAPTOP_EAPD,
  973. AD1986A_LAPTOP_AUTOMUTE,
  974. AD1986A_SAMSUNG,
  975. AD1986A_SAMSUNG_P50,
  976. AD1986A_MODELS
  977. };
  978. static const char * const ad1986a_models[AD1986A_MODELS] = {
  979. [AD1986A_AUTO] = "auto",
  980. [AD1986A_6STACK] = "6stack",
  981. [AD1986A_3STACK] = "3stack",
  982. [AD1986A_LAPTOP] = "laptop",
  983. [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
  984. [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
  985. [AD1986A_SAMSUNG] = "samsung",
  986. [AD1986A_SAMSUNG_P50] = "samsung-p50",
  987. };
  988. static const struct snd_pci_quirk ad1986a_cfg_tbl[] = {
  989. SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
  990. SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
  991. SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
  992. SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
  993. SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
  994. SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
  995. SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
  996. SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
  997. SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
  998. SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
  999. SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
  1000. SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
  1001. SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
  1002. SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
  1003. SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
  1004. SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
  1005. SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40-10Q", AD1986A_3STACK),
  1006. SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
  1007. SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
  1008. SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
  1009. SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
  1010. SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
  1011. SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
  1012. SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
  1013. SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
  1014. SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
  1015. {}
  1016. };
  1017. #ifdef CONFIG_PM
  1018. static const struct hda_amp_list ad1986a_loopbacks[] = {
  1019. { 0x13, HDA_OUTPUT, 0 }, /* Mic */
  1020. { 0x14, HDA_OUTPUT, 0 }, /* Phone */
  1021. { 0x15, HDA_OUTPUT, 0 }, /* CD */
  1022. { 0x16, HDA_OUTPUT, 0 }, /* Aux */
  1023. { 0x17, HDA_OUTPUT, 0 }, /* Line */
  1024. { } /* end */
  1025. };
  1026. #endif
  1027. static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
  1028. {
  1029. unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
  1030. return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
  1031. }
  1032. #endif /* ENABLE_AD_STATIC_QUIRKS */
  1033. static int alloc_ad_spec(struct hda_codec *codec)
  1034. {
  1035. struct ad198x_spec *spec;
  1036. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1037. if (!spec)
  1038. return -ENOMEM;
  1039. codec->spec = spec;
  1040. snd_hda_gen_spec_init(&spec->gen);
  1041. return 0;
  1042. }
  1043. /*
  1044. * AD1986A fixup codes
  1045. */
  1046. /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
  1047. static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
  1048. const struct hda_fixup *fix, int action)
  1049. {
  1050. if (action == HDA_FIXUP_ACT_PRE_PROBE)
  1051. codec->inv_jack_detect = 1;
  1052. }
  1053. enum {
  1054. AD1986A_FIXUP_INV_JACK_DETECT,
  1055. AD1986A_FIXUP_ULTRA,
  1056. };
  1057. static const struct hda_fixup ad1986a_fixups[] = {
  1058. [AD1986A_FIXUP_INV_JACK_DETECT] = {
  1059. .type = HDA_FIXUP_FUNC,
  1060. .v.func = ad_fixup_inv_jack_detect,
  1061. },
  1062. [AD1986A_FIXUP_ULTRA] = {
  1063. .type = HDA_FIXUP_PINS,
  1064. .v.pins = (const struct hda_pintbl[]) {
  1065. { 0x1b, 0x90170110 }, /* speaker */
  1066. { 0x1d, 0x90a7013e }, /* int mic */
  1067. {}
  1068. },
  1069. },
  1070. };
  1071. static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
  1072. SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
  1073. SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
  1074. {}
  1075. };
  1076. /*
  1077. */
  1078. static int ad1986a_parse_auto_config(struct hda_codec *codec)
  1079. {
  1080. int err;
  1081. struct ad198x_spec *spec;
  1082. err = alloc_ad_spec(codec);
  1083. if (err < 0)
  1084. return err;
  1085. spec = codec->spec;
  1086. /* AD1986A has the inverted EAPD implementation */
  1087. codec->inv_eapd = 1;
  1088. spec->gen.mixer_nid = 0x07;
  1089. spec->gen.beep_nid = 0x19;
  1090. set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
  1091. /* AD1986A has a hardware problem that it can't share a stream
  1092. * with multiple output pins. The copy of front to surrounds
  1093. * causes noisy or silent outputs at a certain timing, e.g.
  1094. * changing the volume.
  1095. * So, let's disable the shared stream.
  1096. */
  1097. spec->gen.multiout.no_share_stream = 1;
  1098. snd_hda_pick_fixup(codec, NULL, ad1986a_fixup_tbl, ad1986a_fixups);
  1099. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  1100. err = ad198x_parse_auto_config(codec);
  1101. if (err < 0) {
  1102. snd_hda_gen_free(codec);
  1103. return err;
  1104. }
  1105. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  1106. return 0;
  1107. }
  1108. #ifdef ENABLE_AD_STATIC_QUIRKS
  1109. static int patch_ad1986a(struct hda_codec *codec)
  1110. {
  1111. struct ad198x_spec *spec;
  1112. int err, board_config;
  1113. board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
  1114. ad1986a_models,
  1115. ad1986a_cfg_tbl);
  1116. if (board_config < 0) {
  1117. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  1118. codec->chip_name);
  1119. board_config = AD1986A_AUTO;
  1120. }
  1121. if (board_config == AD1986A_AUTO)
  1122. return ad1986a_parse_auto_config(codec);
  1123. err = alloc_ad_spec(codec);
  1124. if (err < 0)
  1125. return err;
  1126. spec = codec->spec;
  1127. err = snd_hda_attach_beep_device(codec, 0x19);
  1128. if (err < 0) {
  1129. ad198x_free(codec);
  1130. return err;
  1131. }
  1132. set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
  1133. spec->multiout.max_channels = 6;
  1134. spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
  1135. spec->multiout.dac_nids = ad1986a_dac_nids;
  1136. spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
  1137. spec->num_adc_nids = 1;
  1138. spec->adc_nids = ad1986a_adc_nids;
  1139. spec->capsrc_nids = ad1986a_capsrc_nids;
  1140. spec->input_mux = &ad1986a_capture_source;
  1141. spec->num_mixers = 1;
  1142. spec->mixers[0] = ad1986a_mixers;
  1143. spec->num_init_verbs = 1;
  1144. spec->init_verbs[0] = ad1986a_init_verbs;
  1145. #ifdef CONFIG_PM
  1146. spec->loopback.amplist = ad1986a_loopbacks;
  1147. #endif
  1148. spec->vmaster_nid = 0x1b;
  1149. codec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
  1150. codec->patch_ops = ad198x_patch_ops;
  1151. /* override some parameters */
  1152. switch (board_config) {
  1153. case AD1986A_3STACK:
  1154. spec->num_mixers = 2;
  1155. spec->mixers[1] = ad1986a_3st_mixers;
  1156. spec->num_init_verbs = 2;
  1157. spec->init_verbs[1] = ad1986a_ch2_init;
  1158. spec->channel_mode = ad1986a_modes;
  1159. spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
  1160. spec->need_dac_fix = 1;
  1161. spec->multiout.max_channels = 2;
  1162. spec->multiout.num_dacs = 1;
  1163. break;
  1164. case AD1986A_LAPTOP:
  1165. spec->mixers[0] = ad1986a_laptop_mixers;
  1166. spec->multiout.max_channels = 2;
  1167. spec->multiout.num_dacs = 1;
  1168. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1169. break;
  1170. case AD1986A_LAPTOP_EAPD:
  1171. spec->num_mixers = 3;
  1172. spec->mixers[0] = ad1986a_laptop_master_mixers;
  1173. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1174. spec->mixers[2] = ad1986a_laptop_intmic_mixers;
  1175. spec->num_init_verbs = 2;
  1176. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1177. spec->multiout.max_channels = 2;
  1178. spec->multiout.num_dacs = 1;
  1179. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1180. if (!is_jack_available(codec, 0x25))
  1181. spec->multiout.dig_out_nid = 0;
  1182. spec->input_mux = &ad1986a_laptop_eapd_capture_source;
  1183. break;
  1184. case AD1986A_SAMSUNG:
  1185. spec->num_mixers = 2;
  1186. spec->mixers[0] = ad1986a_laptop_master_mixers;
  1187. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1188. spec->num_init_verbs = 3;
  1189. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1190. spec->init_verbs[2] = ad1986a_automic_verbs;
  1191. spec->multiout.max_channels = 2;
  1192. spec->multiout.num_dacs = 1;
  1193. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1194. if (!is_jack_available(codec, 0x25))
  1195. spec->multiout.dig_out_nid = 0;
  1196. spec->input_mux = &ad1986a_automic_capture_source;
  1197. codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
  1198. codec->patch_ops.init = ad1986a_automic_init;
  1199. break;
  1200. case AD1986A_SAMSUNG_P50:
  1201. spec->num_mixers = 2;
  1202. spec->mixers[0] = ad1986a_automute_master_mixers;
  1203. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1204. spec->num_init_verbs = 4;
  1205. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1206. spec->init_verbs[2] = ad1986a_automic_verbs;
  1207. spec->init_verbs[3] = ad1986a_hp_init_verbs;
  1208. spec->multiout.max_channels = 2;
  1209. spec->multiout.num_dacs = 1;
  1210. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1211. if (!is_jack_available(codec, 0x25))
  1212. spec->multiout.dig_out_nid = 0;
  1213. spec->input_mux = &ad1986a_automic_capture_source;
  1214. codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
  1215. codec->patch_ops.init = ad1986a_samsung_p50_init;
  1216. break;
  1217. case AD1986A_LAPTOP_AUTOMUTE:
  1218. spec->num_mixers = 3;
  1219. spec->mixers[0] = ad1986a_automute_master_mixers;
  1220. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1221. spec->mixers[2] = ad1986a_laptop_intmic_mixers;
  1222. spec->num_init_verbs = 3;
  1223. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1224. spec->init_verbs[2] = ad1986a_hp_init_verbs;
  1225. spec->multiout.max_channels = 2;
  1226. spec->multiout.num_dacs = 1;
  1227. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1228. if (!is_jack_available(codec, 0x25))
  1229. spec->multiout.dig_out_nid = 0;
  1230. spec->input_mux = &ad1986a_laptop_eapd_capture_source;
  1231. codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
  1232. codec->patch_ops.init = ad1986a_hp_init;
  1233. /* Lenovo N100 seems to report the reversed bit
  1234. * for HP jack-sensing
  1235. */
  1236. spec->inv_jack_detect = 1;
  1237. break;
  1238. }
  1239. /* AD1986A has a hardware problem that it can't share a stream
  1240. * with multiple output pins. The copy of front to surrounds
  1241. * causes noisy or silent outputs at a certain timing, e.g.
  1242. * changing the volume.
  1243. * So, let's disable the shared stream.
  1244. */
  1245. spec->multiout.no_share_stream = 1;
  1246. codec->no_trigger_sense = 1;
  1247. codec->no_sticky_stream = 1;
  1248. return 0;
  1249. }
  1250. #else /* ENABLE_AD_STATIC_QUIRKS */
  1251. #define patch_ad1986a ad1986a_parse_auto_config
  1252. #endif /* ENABLE_AD_STATIC_QUIRKS */
  1253. /*
  1254. * AD1983 specific
  1255. */
  1256. /*
  1257. * SPDIF mux control for AD1983 auto-parser
  1258. */
  1259. static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
  1260. struct snd_ctl_elem_info *uinfo)
  1261. {
  1262. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1263. struct ad198x_spec *spec = codec->spec;
  1264. static const char * const texts2[] = { "PCM", "ADC" };
  1265. static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
  1266. hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
  1267. int num_conns = snd_hda_get_num_conns(codec, dig_out);
  1268. if (num_conns == 2)
  1269. return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
  1270. else if (num_conns == 3)
  1271. return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
  1272. else
  1273. return -EINVAL;
  1274. }
  1275. static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
  1276. struct snd_ctl_elem_value *ucontrol)
  1277. {
  1278. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1279. struct ad198x_spec *spec = codec->spec;
  1280. ucontrol->value.enumerated.item[0] = spec->cur_smux;
  1281. return 0;
  1282. }
  1283. static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
  1284. struct snd_ctl_elem_value *ucontrol)
  1285. {
  1286. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1287. struct ad198x_spec *spec = codec->spec;
  1288. unsigned int val = ucontrol->value.enumerated.item[0];
  1289. hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
  1290. int num_conns = snd_hda_get_num_conns(codec, dig_out);
  1291. if (val >= num_conns)
  1292. return -EINVAL;
  1293. if (spec->cur_smux == val)
  1294. return 0;
  1295. spec->cur_smux = val;
  1296. snd_hda_codec_write_cache(codec, dig_out, 0,
  1297. AC_VERB_SET_CONNECT_SEL, val);
  1298. return 1;
  1299. }
  1300. static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
  1301. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1302. .name = "IEC958 Playback Source",
  1303. .info = ad1983_auto_smux_enum_info,
  1304. .get = ad1983_auto_smux_enum_get,
  1305. .put = ad1983_auto_smux_enum_put,
  1306. };
  1307. static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
  1308. {
  1309. struct ad198x_spec *spec = codec->spec;
  1310. hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
  1311. int num_conns;
  1312. if (!dig_out)
  1313. return 0;
  1314. num_conns = snd_hda_get_num_conns(codec, dig_out);
  1315. if (num_conns != 2 && num_conns != 3)
  1316. return 0;
  1317. if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
  1318. return -ENOMEM;
  1319. return 0;
  1320. }
  1321. static int patch_ad1983(struct hda_codec *codec)
  1322. {
  1323. struct ad198x_spec *spec;
  1324. int err;
  1325. err = alloc_ad_spec(codec);
  1326. if (err < 0)
  1327. return err;
  1328. spec = codec->spec;
  1329. spec->gen.beep_nid = 0x10;
  1330. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  1331. err = ad198x_parse_auto_config(codec);
  1332. if (err < 0)
  1333. goto error;
  1334. err = ad1983_add_spdif_mux_ctl(codec);
  1335. if (err < 0)
  1336. goto error;
  1337. return 0;
  1338. error:
  1339. snd_hda_gen_free(codec);
  1340. return err;
  1341. }
  1342. /*
  1343. * AD1981 HD specific
  1344. */
  1345. /* follow EAPD via vmaster hook */
  1346. static void ad_vmaster_eapd_hook(void *private_data, int enabled)
  1347. {
  1348. struct hda_codec *codec = private_data;
  1349. struct ad198x_spec *spec = codec->spec;
  1350. if (!spec->eapd_nid)
  1351. return;
  1352. snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
  1353. AC_VERB_SET_EAPD_BTLENABLE,
  1354. enabled ? 0x02 : 0x00);
  1355. }
  1356. static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
  1357. const struct hda_fixup *fix, int action)
  1358. {
  1359. struct ad198x_spec *spec = codec->spec;
  1360. if (action == HDA_FIXUP_ACT_PRE_PROBE) {
  1361. spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
  1362. spec->eapd_nid = 0x05;
  1363. }
  1364. }
  1365. /* set the upper-limit for mixer amp to 0dB for avoiding the possible
  1366. * damage by overloading
  1367. */
  1368. static void ad1981_fixup_amp_override(struct hda_codec *codec,
  1369. const struct hda_fixup *fix, int action)
  1370. {
  1371. if (action == HDA_FIXUP_ACT_PRE_PROBE)
  1372. snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
  1373. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1374. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1375. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1376. (1 << AC_AMPCAP_MUTE_SHIFT));
  1377. }
  1378. enum {
  1379. AD1981_FIXUP_AMP_OVERRIDE,
  1380. AD1981_FIXUP_HP_EAPD,
  1381. };
  1382. static const struct hda_fixup ad1981_fixups[] = {
  1383. [AD1981_FIXUP_AMP_OVERRIDE] = {
  1384. .type = HDA_FIXUP_FUNC,
  1385. .v.func = ad1981_fixup_amp_override,
  1386. },
  1387. [AD1981_FIXUP_HP_EAPD] = {
  1388. .type = HDA_FIXUP_FUNC,
  1389. .v.func = ad1981_fixup_hp_eapd,
  1390. .chained = true,
  1391. .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
  1392. },
  1393. };
  1394. static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
  1395. SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
  1396. SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
  1397. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
  1398. /* HP nx6320 (reversed SSID, H/W bug) */
  1399. SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
  1400. {}
  1401. };
  1402. static int patch_ad1981(struct hda_codec *codec)
  1403. {
  1404. struct ad198x_spec *spec;
  1405. int err;
  1406. err = alloc_ad_spec(codec);
  1407. if (err < 0)
  1408. return -ENOMEM;
  1409. spec = codec->spec;
  1410. spec->gen.mixer_nid = 0x0e;
  1411. spec->gen.beep_nid = 0x10;
  1412. set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
  1413. snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
  1414. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  1415. err = ad198x_parse_auto_config(codec);
  1416. if (err < 0)
  1417. goto error;
  1418. err = ad1983_add_spdif_mux_ctl(codec);
  1419. if (err < 0)
  1420. goto error;
  1421. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  1422. return 0;
  1423. error:
  1424. snd_hda_gen_free(codec);
  1425. return err;
  1426. }
  1427. /*
  1428. * AD1988
  1429. *
  1430. * Output pins and routes
  1431. *
  1432. * Pin Mix Sel DAC (*)
  1433. * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
  1434. * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
  1435. * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
  1436. * port-D 0x12 (mute/hp) <- 0x29 <- 04
  1437. * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
  1438. * port-F 0x16 (mute) <- 0x2a <- 06
  1439. * port-G 0x24 (mute) <- 0x27 <- 05
  1440. * port-H 0x25 (mute) <- 0x28 <- 0a
  1441. * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
  1442. *
  1443. * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
  1444. * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
  1445. *
  1446. * Input pins and routes
  1447. *
  1448. * pin boost mix input # / adc input #
  1449. * port-A 0x11 -> 0x38 -> mix 2, ADC 0
  1450. * port-B 0x14 -> 0x39 -> mix 0, ADC 1
  1451. * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
  1452. * port-D 0x12 -> 0x3d -> mix 3, ADC 8
  1453. * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
  1454. * port-F 0x16 -> 0x3b -> mix 5, ADC 3
  1455. * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
  1456. * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
  1457. *
  1458. *
  1459. * DAC assignment
  1460. * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
  1461. * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
  1462. *
  1463. * Inputs of Analog Mix (0x20)
  1464. * 0:Port-B (front mic)
  1465. * 1:Port-C/G/H (line-in)
  1466. * 2:Port-A
  1467. * 3:Port-D (line-in/2)
  1468. * 4:Port-E/G/H (mic-in)
  1469. * 5:Port-F (mic2-in)
  1470. * 6:CD
  1471. * 7:Beep
  1472. *
  1473. * ADC selection
  1474. * 0:Port-A
  1475. * 1:Port-B (front mic-in)
  1476. * 2:Port-C (line-in)
  1477. * 3:Port-F (mic2-in)
  1478. * 4:Port-E (mic-in)
  1479. * 5:CD
  1480. * 6:Port-G
  1481. * 7:Port-H
  1482. * 8:Port-D (line-in/2)
  1483. * 9:Mix
  1484. *
  1485. * Proposed pin assignments by the datasheet
  1486. *
  1487. * 6-stack
  1488. * Port-A front headphone
  1489. * B front mic-in
  1490. * C rear line-in
  1491. * D rear front-out
  1492. * E rear mic-in
  1493. * F rear surround
  1494. * G rear CLFE
  1495. * H rear side
  1496. *
  1497. * 3-stack
  1498. * Port-A front headphone
  1499. * B front mic
  1500. * C rear line-in/surround
  1501. * D rear front-out
  1502. * E rear mic-in/CLFE
  1503. *
  1504. * laptop
  1505. * Port-A headphone
  1506. * B mic-in
  1507. * C docking station
  1508. * D internal speaker (with EAPD)
  1509. * E/F quad mic array
  1510. */
  1511. #ifdef ENABLE_AD_STATIC_QUIRKS
  1512. static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
  1513. struct snd_ctl_elem_info *uinfo)
  1514. {
  1515. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1516. struct ad198x_spec *spec = codec->spec;
  1517. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  1518. spec->num_channel_mode);
  1519. }
  1520. static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
  1521. struct snd_ctl_elem_value *ucontrol)
  1522. {
  1523. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1524. struct ad198x_spec *spec = codec->spec;
  1525. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  1526. spec->num_channel_mode, spec->multiout.max_channels);
  1527. }
  1528. static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
  1529. struct snd_ctl_elem_value *ucontrol)
  1530. {
  1531. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1532. struct ad198x_spec *spec = codec->spec;
  1533. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  1534. spec->num_channel_mode,
  1535. &spec->multiout.max_channels);
  1536. if (err >= 0 && spec->need_dac_fix)
  1537. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  1538. return err;
  1539. }
  1540. #endif /* ENABLE_AD_STATIC_QUIRKS */
  1541. static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
  1542. struct snd_ctl_elem_info *uinfo)
  1543. {
  1544. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1545. static const char * const texts[] = {
  1546. "PCM", "ADC1", "ADC2", "ADC3",
  1547. };
  1548. int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
  1549. if (num_conns > 4)
  1550. num_conns = 4;
  1551. return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
  1552. }
  1553. static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
  1554. struct snd_ctl_elem_value *ucontrol)
  1555. {
  1556. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1557. struct ad198x_spec *spec = codec->spec;
  1558. ucontrol->value.enumerated.item[0] = spec->cur_smux;
  1559. return 0;
  1560. }
  1561. static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
  1562. struct snd_ctl_elem_value *ucontrol)
  1563. {
  1564. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1565. struct ad198x_spec *spec = codec->spec;
  1566. unsigned int val = ucontrol->value.enumerated.item[0];
  1567. struct nid_path *path;
  1568. int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
  1569. if (val >= num_conns)
  1570. return -EINVAL;
  1571. if (spec->cur_smux == val)
  1572. return 0;
  1573. mutex_lock(&codec->control_mutex);
  1574. codec->cached_write = 1;
  1575. path = snd_hda_get_path_from_idx(codec,
  1576. spec->smux_paths[spec->cur_smux]);
  1577. if (path)
  1578. snd_hda_activate_path(codec, path, false, true);
  1579. path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
  1580. if (path)
  1581. snd_hda_activate_path(codec, path, true, true);
  1582. spec->cur_smux = val;
  1583. codec->cached_write = 0;
  1584. mutex_unlock(&codec->control_mutex);
  1585. snd_hda_codec_flush_cache(codec); /* flush the updates */
  1586. return 1;
  1587. }
  1588. static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
  1589. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1590. .name = "IEC958 Playback Source",
  1591. .info = ad1988_auto_smux_enum_info,
  1592. .get = ad1988_auto_smux_enum_get,
  1593. .put = ad1988_auto_smux_enum_put,
  1594. };
  1595. static int ad1988_auto_init(struct hda_codec *codec)
  1596. {
  1597. struct ad198x_spec *spec = codec->spec;
  1598. int i, err;
  1599. err = snd_hda_gen_init(codec);
  1600. if (err < 0)
  1601. return err;
  1602. if (!spec->gen.autocfg.dig_outs)
  1603. return 0;
  1604. for (i = 0; i < 4; i++) {
  1605. struct nid_path *path;
  1606. path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
  1607. if (path)
  1608. snd_hda_activate_path(codec, path, path->active, false);
  1609. }
  1610. return 0;
  1611. }
  1612. static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
  1613. {
  1614. struct ad198x_spec *spec = codec->spec;
  1615. int i, num_conns;
  1616. /* we create four static faked paths, since AD codecs have odd
  1617. * widget connections regarding the SPDIF out source
  1618. */
  1619. static struct nid_path fake_paths[4] = {
  1620. {
  1621. .depth = 3,
  1622. .path = { 0x02, 0x1d, 0x1b },
  1623. .idx = { 0, 0, 0 },
  1624. .multi = { 0, 0, 0 },
  1625. },
  1626. {
  1627. .depth = 4,
  1628. .path = { 0x08, 0x0b, 0x1d, 0x1b },
  1629. .idx = { 0, 0, 1, 0 },
  1630. .multi = { 0, 1, 0, 0 },
  1631. },
  1632. {
  1633. .depth = 4,
  1634. .path = { 0x09, 0x0b, 0x1d, 0x1b },
  1635. .idx = { 0, 1, 1, 0 },
  1636. .multi = { 0, 1, 0, 0 },
  1637. },
  1638. {
  1639. .depth = 4,
  1640. .path = { 0x0f, 0x0b, 0x1d, 0x1b },
  1641. .idx = { 0, 2, 1, 0 },
  1642. .multi = { 0, 1, 0, 0 },
  1643. },
  1644. };
  1645. /* SPDIF source mux appears to be present only on AD1988A */
  1646. if (!spec->gen.autocfg.dig_outs ||
  1647. get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
  1648. return 0;
  1649. num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
  1650. if (num_conns != 3 && num_conns != 4)
  1651. return 0;
  1652. for (i = 0; i < num_conns; i++) {
  1653. struct nid_path *path = snd_array_new(&spec->gen.paths);
  1654. if (!path)
  1655. return -ENOMEM;
  1656. *path = fake_paths[i];
  1657. if (!i)
  1658. path->active = 1;
  1659. spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
  1660. }
  1661. if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
  1662. return -ENOMEM;
  1663. codec->patch_ops.init = ad1988_auto_init;
  1664. return 0;
  1665. }
  1666. /*
  1667. */
  1668. enum {
  1669. AD1988_FIXUP_6STACK_DIG,
  1670. };
  1671. static const struct hda_fixup ad1988_fixups[] = {
  1672. [AD1988_FIXUP_6STACK_DIG] = {
  1673. .type = HDA_FIXUP_PINS,
  1674. .v.pins = (const struct hda_pintbl[]) {
  1675. { 0x11, 0x02214130 }, /* front-hp */
  1676. { 0x12, 0x01014010 }, /* line-out */
  1677. { 0x14, 0x02a19122 }, /* front-mic */
  1678. { 0x15, 0x01813021 }, /* line-in */
  1679. { 0x16, 0x01011012 }, /* line-out */
  1680. { 0x17, 0x01a19020 }, /* mic */
  1681. { 0x1b, 0x0145f1f0 }, /* SPDIF */
  1682. { 0x24, 0x01016011 }, /* line-out */
  1683. { 0x25, 0x01012013 }, /* line-out */
  1684. { }
  1685. }
  1686. },
  1687. };
  1688. static const struct hda_model_fixup ad1988_fixup_models[] = {
  1689. { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
  1690. {}
  1691. };
  1692. static int patch_ad1988(struct hda_codec *codec)
  1693. {
  1694. struct ad198x_spec *spec;
  1695. int err;
  1696. err = alloc_ad_spec(codec);
  1697. if (err < 0)
  1698. return err;
  1699. spec = codec->spec;
  1700. spec->gen.mixer_nid = 0x20;
  1701. spec->gen.mixer_merge_nid = 0x21;
  1702. spec->gen.beep_nid = 0x10;
  1703. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  1704. snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
  1705. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  1706. err = ad198x_parse_auto_config(codec);
  1707. if (err < 0)
  1708. goto error;
  1709. err = ad1988_add_spdif_mux_ctl(codec);
  1710. if (err < 0)
  1711. goto error;
  1712. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  1713. return 0;
  1714. error:
  1715. snd_hda_gen_free(codec);
  1716. return err;
  1717. }
  1718. /*
  1719. * AD1884 / AD1984
  1720. *
  1721. * port-B - front line/mic-in
  1722. * port-E - aux in/out
  1723. * port-F - aux in/out
  1724. * port-C - rear line/mic-in
  1725. * port-D - rear line/hp-out
  1726. * port-A - front line/hp-out
  1727. *
  1728. * AD1984 = AD1884 + two digital mic-ins
  1729. *
  1730. * AD1883 / AD1884A / AD1984A / AD1984B
  1731. *
  1732. * port-B (0x14) - front mic-in
  1733. * port-E (0x1c) - rear mic-in
  1734. * port-F (0x16) - CD / ext out
  1735. * port-C (0x15) - rear line-in
  1736. * port-D (0x12) - rear line-out
  1737. * port-A (0x11) - front hp-out
  1738. *
  1739. * AD1984A = AD1884A + digital-mic
  1740. * AD1883 = equivalent with AD1984A
  1741. * AD1984B = AD1984A + extra SPDIF-out
  1742. */
  1743. /* set the upper-limit for mixer amp to 0dB for avoiding the possible
  1744. * damage by overloading
  1745. */
  1746. static void ad1884_fixup_amp_override(struct hda_codec *codec,
  1747. const struct hda_fixup *fix, int action)
  1748. {
  1749. if (action == HDA_FIXUP_ACT_PRE_PROBE)
  1750. snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
  1751. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1752. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1753. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1754. (1 << AC_AMPCAP_MUTE_SHIFT));
  1755. }
  1756. /* toggle GPIO1 according to the mute state */
  1757. static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
  1758. {
  1759. struct hda_codec *codec = private_data;
  1760. struct ad198x_spec *spec = codec->spec;
  1761. if (spec->eapd_nid)
  1762. ad_vmaster_eapd_hook(private_data, enabled);
  1763. snd_hda_codec_update_cache(codec, 0x01, 0,
  1764. AC_VERB_SET_GPIO_DATA,
  1765. enabled ? 0x00 : 0x02);
  1766. }
  1767. static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
  1768. const struct hda_fixup *fix, int action)
  1769. {
  1770. struct ad198x_spec *spec = codec->spec;
  1771. static const struct hda_verb gpio_init_verbs[] = {
  1772. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  1773. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  1774. {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
  1775. {},
  1776. };
  1777. switch (action) {
  1778. case HDA_FIXUP_ACT_PRE_PROBE:
  1779. spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
  1780. snd_hda_sequence_write_cache(codec, gpio_init_verbs);
  1781. break;
  1782. case HDA_FIXUP_ACT_PROBE:
  1783. if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
  1784. spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
  1785. else
  1786. spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
  1787. break;
  1788. }
  1789. }
  1790. /* set magic COEFs for dmic */
  1791. static const struct hda_verb ad1884_dmic_init_verbs[] = {
  1792. {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
  1793. {0x01, AC_VERB_SET_PROC_COEF, 0x08},
  1794. {}
  1795. };
  1796. enum {
  1797. AD1884_FIXUP_AMP_OVERRIDE,
  1798. AD1884_FIXUP_HP_EAPD,
  1799. AD1884_FIXUP_DMIC_COEF,
  1800. AD1884_FIXUP_HP_TOUCHSMART,
  1801. };
  1802. static const struct hda_fixup ad1884_fixups[] = {
  1803. [AD1884_FIXUP_AMP_OVERRIDE] = {
  1804. .type = HDA_FIXUP_FUNC,
  1805. .v.func = ad1884_fixup_amp_override,
  1806. },
  1807. [AD1884_FIXUP_HP_EAPD] = {
  1808. .type = HDA_FIXUP_FUNC,
  1809. .v.func = ad1884_fixup_hp_eapd,
  1810. .chained = true,
  1811. .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
  1812. },
  1813. [AD1884_FIXUP_DMIC_COEF] = {
  1814. .type = HDA_FIXUP_VERBS,
  1815. .v.verbs = ad1884_dmic_init_verbs,
  1816. },
  1817. [AD1884_FIXUP_HP_TOUCHSMART] = {
  1818. .type = HDA_FIXUP_VERBS,
  1819. .v.verbs = ad1884_dmic_init_verbs,
  1820. .chained = true,
  1821. .chain_id = AD1884_FIXUP_HP_EAPD,
  1822. },
  1823. };
  1824. static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
  1825. SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
  1826. SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
  1827. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_DMIC_COEF),
  1828. {}
  1829. };
  1830. static int patch_ad1884(struct hda_codec *codec)
  1831. {
  1832. struct ad198x_spec *spec;
  1833. int err;
  1834. err = alloc_ad_spec(codec);
  1835. if (err < 0)
  1836. return err;
  1837. spec = codec->spec;
  1838. spec->gen.mixer_nid = 0x20;
  1839. spec->gen.beep_nid = 0x10;
  1840. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  1841. snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
  1842. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  1843. err = ad198x_parse_auto_config(codec);
  1844. if (err < 0)
  1845. goto error;
  1846. err = ad1983_add_spdif_mux_ctl(codec);
  1847. if (err < 0)
  1848. goto error;
  1849. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  1850. return 0;
  1851. error:
  1852. snd_hda_gen_free(codec);
  1853. return err;
  1854. }
  1855. /*
  1856. * AD1882 / AD1882A
  1857. *
  1858. * port-A - front hp-out
  1859. * port-B - front mic-in
  1860. * port-C - rear line-in, shared surr-out (3stack)
  1861. * port-D - rear line-out
  1862. * port-E - rear mic-in, shared clfe-out (3stack)
  1863. * port-F - rear surr-out (6stack)
  1864. * port-G - rear clfe-out (6stack)
  1865. */
  1866. static int patch_ad1882(struct hda_codec *codec)
  1867. {
  1868. struct ad198x_spec *spec;
  1869. int err;
  1870. err = alloc_ad_spec(codec);
  1871. if (err < 0)
  1872. return err;
  1873. spec = codec->spec;
  1874. spec->gen.mixer_nid = 0x20;
  1875. spec->gen.mixer_merge_nid = 0x21;
  1876. spec->gen.beep_nid = 0x10;
  1877. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  1878. err = ad198x_parse_auto_config(codec);
  1879. if (err < 0)
  1880. goto error;
  1881. err = ad1988_add_spdif_mux_ctl(codec);
  1882. if (err < 0)
  1883. goto error;
  1884. return 0;
  1885. error:
  1886. snd_hda_gen_free(codec);
  1887. return err;
  1888. }
  1889. /*
  1890. * patch entries
  1891. */
  1892. static const struct hda_codec_preset snd_hda_preset_analog[] = {
  1893. { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
  1894. { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
  1895. { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
  1896. { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
  1897. { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
  1898. { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
  1899. { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
  1900. { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
  1901. { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
  1902. { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
  1903. { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
  1904. { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
  1905. { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
  1906. { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
  1907. { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
  1908. {} /* terminator */
  1909. };
  1910. MODULE_ALIAS("snd-hda-codec-id:11d4*");
  1911. MODULE_LICENSE("GPL");
  1912. MODULE_DESCRIPTION("Analog Devices HD-audio codec");
  1913. static struct hda_codec_preset_list analog_list = {
  1914. .preset = snd_hda_preset_analog,
  1915. .owner = THIS_MODULE,
  1916. };
  1917. static int __init patch_analog_init(void)
  1918. {
  1919. return snd_hda_add_codec_preset(&analog_list);
  1920. }
  1921. static void __exit patch_analog_exit(void)
  1922. {
  1923. snd_hda_delete_codec_preset(&analog_list);
  1924. }
  1925. module_init(patch_analog_init)
  1926. module_exit(patch_analog_exit)