patch_analog.c 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973
  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. /* Ultra initialization */
  943. static const struct hda_verb ad1986a_ultra_init[] = {
  944. /* eapd initialization */
  945. { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
  946. /* CLFE -> Mic in */
  947. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
  948. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  949. { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
  950. { } /* end */
  951. };
  952. /* pin sensing on HP jack */
  953. static const struct hda_verb ad1986a_hp_init_verbs[] = {
  954. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
  955. {}
  956. };
  957. static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
  958. unsigned int res)
  959. {
  960. switch (res >> 26) {
  961. case AD1986A_HP_EVENT:
  962. ad1986a_hp_automute(codec);
  963. break;
  964. case AD1986A_MIC_EVENT:
  965. ad1986a_automic(codec);
  966. break;
  967. }
  968. }
  969. static int ad1986a_samsung_p50_init(struct hda_codec *codec)
  970. {
  971. ad198x_init(codec);
  972. ad1986a_hp_automute(codec);
  973. ad1986a_automic(codec);
  974. return 0;
  975. }
  976. /* models */
  977. enum {
  978. AD1986A_AUTO,
  979. AD1986A_6STACK,
  980. AD1986A_3STACK,
  981. AD1986A_LAPTOP,
  982. AD1986A_LAPTOP_EAPD,
  983. AD1986A_LAPTOP_AUTOMUTE,
  984. AD1986A_ULTRA,
  985. AD1986A_SAMSUNG,
  986. AD1986A_SAMSUNG_P50,
  987. AD1986A_MODELS
  988. };
  989. static const char * const ad1986a_models[AD1986A_MODELS] = {
  990. [AD1986A_AUTO] = "auto",
  991. [AD1986A_6STACK] = "6stack",
  992. [AD1986A_3STACK] = "3stack",
  993. [AD1986A_LAPTOP] = "laptop",
  994. [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
  995. [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
  996. [AD1986A_ULTRA] = "ultra",
  997. [AD1986A_SAMSUNG] = "samsung",
  998. [AD1986A_SAMSUNG_P50] = "samsung-p50",
  999. };
  1000. static const struct snd_pci_quirk ad1986a_cfg_tbl[] = {
  1001. SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
  1002. SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
  1003. SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
  1004. SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
  1005. SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
  1006. SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
  1007. SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
  1008. SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
  1009. SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
  1010. SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
  1011. SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
  1012. SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
  1013. SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
  1014. SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
  1015. SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
  1016. SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
  1017. SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40-10Q", AD1986A_3STACK),
  1018. SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
  1019. SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
  1020. SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
  1021. SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
  1022. SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
  1023. SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
  1024. SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
  1025. SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
  1026. SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
  1027. SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
  1028. {}
  1029. };
  1030. #ifdef CONFIG_PM
  1031. static const struct hda_amp_list ad1986a_loopbacks[] = {
  1032. { 0x13, HDA_OUTPUT, 0 }, /* Mic */
  1033. { 0x14, HDA_OUTPUT, 0 }, /* Phone */
  1034. { 0x15, HDA_OUTPUT, 0 }, /* CD */
  1035. { 0x16, HDA_OUTPUT, 0 }, /* Aux */
  1036. { 0x17, HDA_OUTPUT, 0 }, /* Line */
  1037. { } /* end */
  1038. };
  1039. #endif
  1040. static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
  1041. {
  1042. unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
  1043. return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
  1044. }
  1045. #endif /* ENABLE_AD_STATIC_QUIRKS */
  1046. static int alloc_ad_spec(struct hda_codec *codec)
  1047. {
  1048. struct ad198x_spec *spec;
  1049. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1050. if (!spec)
  1051. return -ENOMEM;
  1052. codec->spec = spec;
  1053. snd_hda_gen_spec_init(&spec->gen);
  1054. return 0;
  1055. }
  1056. /*
  1057. * AD1986A fixup codes
  1058. */
  1059. /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
  1060. static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
  1061. const struct hda_fixup *fix, int action)
  1062. {
  1063. if (action == HDA_FIXUP_ACT_PRE_PROBE)
  1064. codec->inv_jack_detect = 1;
  1065. }
  1066. enum {
  1067. AD1986A_FIXUP_INV_JACK_DETECT,
  1068. };
  1069. static const struct hda_fixup ad1986a_fixups[] = {
  1070. [AD1986A_FIXUP_INV_JACK_DETECT] = {
  1071. .type = HDA_FIXUP_FUNC,
  1072. .v.func = ad_fixup_inv_jack_detect,
  1073. },
  1074. };
  1075. static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
  1076. SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
  1077. {}
  1078. };
  1079. /*
  1080. */
  1081. static int ad1986a_parse_auto_config(struct hda_codec *codec)
  1082. {
  1083. int err;
  1084. struct ad198x_spec *spec;
  1085. err = alloc_ad_spec(codec);
  1086. if (err < 0)
  1087. return err;
  1088. spec = codec->spec;
  1089. /* AD1986A has the inverted EAPD implementation */
  1090. codec->inv_eapd = 1;
  1091. spec->gen.mixer_nid = 0x07;
  1092. spec->gen.beep_nid = 0x19;
  1093. set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
  1094. /* AD1986A has a hardware problem that it can't share a stream
  1095. * with multiple output pins. The copy of front to surrounds
  1096. * causes noisy or silent outputs at a certain timing, e.g.
  1097. * changing the volume.
  1098. * So, let's disable the shared stream.
  1099. */
  1100. spec->gen.multiout.no_share_stream = 1;
  1101. snd_hda_pick_fixup(codec, NULL, ad1986a_fixup_tbl, ad1986a_fixups);
  1102. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  1103. err = ad198x_parse_auto_config(codec);
  1104. if (err < 0) {
  1105. snd_hda_gen_free(codec);
  1106. return err;
  1107. }
  1108. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  1109. return 0;
  1110. }
  1111. #ifdef ENABLE_AD_STATIC_QUIRKS
  1112. static int patch_ad1986a(struct hda_codec *codec)
  1113. {
  1114. struct ad198x_spec *spec;
  1115. int err, board_config;
  1116. board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
  1117. ad1986a_models,
  1118. ad1986a_cfg_tbl);
  1119. if (board_config < 0) {
  1120. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  1121. codec->chip_name);
  1122. board_config = AD1986A_AUTO;
  1123. }
  1124. if (board_config == AD1986A_AUTO)
  1125. return ad1986a_parse_auto_config(codec);
  1126. err = alloc_ad_spec(codec);
  1127. if (err < 0)
  1128. return err;
  1129. spec = codec->spec;
  1130. err = snd_hda_attach_beep_device(codec, 0x19);
  1131. if (err < 0) {
  1132. ad198x_free(codec);
  1133. return err;
  1134. }
  1135. set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
  1136. spec->multiout.max_channels = 6;
  1137. spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
  1138. spec->multiout.dac_nids = ad1986a_dac_nids;
  1139. spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
  1140. spec->num_adc_nids = 1;
  1141. spec->adc_nids = ad1986a_adc_nids;
  1142. spec->capsrc_nids = ad1986a_capsrc_nids;
  1143. spec->input_mux = &ad1986a_capture_source;
  1144. spec->num_mixers = 1;
  1145. spec->mixers[0] = ad1986a_mixers;
  1146. spec->num_init_verbs = 1;
  1147. spec->init_verbs[0] = ad1986a_init_verbs;
  1148. #ifdef CONFIG_PM
  1149. spec->loopback.amplist = ad1986a_loopbacks;
  1150. #endif
  1151. spec->vmaster_nid = 0x1b;
  1152. codec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
  1153. codec->patch_ops = ad198x_patch_ops;
  1154. /* override some parameters */
  1155. switch (board_config) {
  1156. case AD1986A_3STACK:
  1157. spec->num_mixers = 2;
  1158. spec->mixers[1] = ad1986a_3st_mixers;
  1159. spec->num_init_verbs = 2;
  1160. spec->init_verbs[1] = ad1986a_ch2_init;
  1161. spec->channel_mode = ad1986a_modes;
  1162. spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
  1163. spec->need_dac_fix = 1;
  1164. spec->multiout.max_channels = 2;
  1165. spec->multiout.num_dacs = 1;
  1166. break;
  1167. case AD1986A_LAPTOP:
  1168. spec->mixers[0] = ad1986a_laptop_mixers;
  1169. spec->multiout.max_channels = 2;
  1170. spec->multiout.num_dacs = 1;
  1171. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1172. break;
  1173. case AD1986A_LAPTOP_EAPD:
  1174. spec->num_mixers = 3;
  1175. spec->mixers[0] = ad1986a_laptop_master_mixers;
  1176. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1177. spec->mixers[2] = ad1986a_laptop_intmic_mixers;
  1178. spec->num_init_verbs = 2;
  1179. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1180. spec->multiout.max_channels = 2;
  1181. spec->multiout.num_dacs = 1;
  1182. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1183. if (!is_jack_available(codec, 0x25))
  1184. spec->multiout.dig_out_nid = 0;
  1185. spec->input_mux = &ad1986a_laptop_eapd_capture_source;
  1186. break;
  1187. case AD1986A_SAMSUNG:
  1188. spec->num_mixers = 2;
  1189. spec->mixers[0] = ad1986a_laptop_master_mixers;
  1190. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1191. spec->num_init_verbs = 3;
  1192. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1193. spec->init_verbs[2] = ad1986a_automic_verbs;
  1194. spec->multiout.max_channels = 2;
  1195. spec->multiout.num_dacs = 1;
  1196. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1197. if (!is_jack_available(codec, 0x25))
  1198. spec->multiout.dig_out_nid = 0;
  1199. spec->input_mux = &ad1986a_automic_capture_source;
  1200. codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
  1201. codec->patch_ops.init = ad1986a_automic_init;
  1202. break;
  1203. case AD1986A_SAMSUNG_P50:
  1204. spec->num_mixers = 2;
  1205. spec->mixers[0] = ad1986a_automute_master_mixers;
  1206. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1207. spec->num_init_verbs = 4;
  1208. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1209. spec->init_verbs[2] = ad1986a_automic_verbs;
  1210. spec->init_verbs[3] = ad1986a_hp_init_verbs;
  1211. spec->multiout.max_channels = 2;
  1212. spec->multiout.num_dacs = 1;
  1213. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1214. if (!is_jack_available(codec, 0x25))
  1215. spec->multiout.dig_out_nid = 0;
  1216. spec->input_mux = &ad1986a_automic_capture_source;
  1217. codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
  1218. codec->patch_ops.init = ad1986a_samsung_p50_init;
  1219. break;
  1220. case AD1986A_LAPTOP_AUTOMUTE:
  1221. spec->num_mixers = 3;
  1222. spec->mixers[0] = ad1986a_automute_master_mixers;
  1223. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1224. spec->mixers[2] = ad1986a_laptop_intmic_mixers;
  1225. spec->num_init_verbs = 3;
  1226. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1227. spec->init_verbs[2] = ad1986a_hp_init_verbs;
  1228. spec->multiout.max_channels = 2;
  1229. spec->multiout.num_dacs = 1;
  1230. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1231. if (!is_jack_available(codec, 0x25))
  1232. spec->multiout.dig_out_nid = 0;
  1233. spec->input_mux = &ad1986a_laptop_eapd_capture_source;
  1234. codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
  1235. codec->patch_ops.init = ad1986a_hp_init;
  1236. /* Lenovo N100 seems to report the reversed bit
  1237. * for HP jack-sensing
  1238. */
  1239. spec->inv_jack_detect = 1;
  1240. break;
  1241. case AD1986A_ULTRA:
  1242. spec->mixers[0] = ad1986a_laptop_eapd_mixers;
  1243. spec->num_init_verbs = 2;
  1244. spec->init_verbs[1] = ad1986a_ultra_init;
  1245. spec->multiout.max_channels = 2;
  1246. spec->multiout.num_dacs = 1;
  1247. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1248. spec->multiout.dig_out_nid = 0;
  1249. break;
  1250. }
  1251. /* AD1986A has a hardware problem that it can't share a stream
  1252. * with multiple output pins. The copy of front to surrounds
  1253. * causes noisy or silent outputs at a certain timing, e.g.
  1254. * changing the volume.
  1255. * So, let's disable the shared stream.
  1256. */
  1257. spec->multiout.no_share_stream = 1;
  1258. codec->no_trigger_sense = 1;
  1259. codec->no_sticky_stream = 1;
  1260. return 0;
  1261. }
  1262. #else /* ENABLE_AD_STATIC_QUIRKS */
  1263. #define patch_ad1986a ad1986a_parse_auto_config
  1264. #endif /* ENABLE_AD_STATIC_QUIRKS */
  1265. /*
  1266. * AD1983 specific
  1267. */
  1268. /*
  1269. * SPDIF mux control for AD1983 auto-parser
  1270. */
  1271. static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
  1272. struct snd_ctl_elem_info *uinfo)
  1273. {
  1274. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1275. struct ad198x_spec *spec = codec->spec;
  1276. static const char * const texts2[] = { "PCM", "ADC" };
  1277. static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
  1278. hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
  1279. int num_conns = snd_hda_get_num_conns(codec, dig_out);
  1280. if (num_conns == 2)
  1281. return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
  1282. else if (num_conns == 3)
  1283. return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
  1284. else
  1285. return -EINVAL;
  1286. }
  1287. static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
  1288. struct snd_ctl_elem_value *ucontrol)
  1289. {
  1290. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1291. struct ad198x_spec *spec = codec->spec;
  1292. ucontrol->value.enumerated.item[0] = spec->cur_smux;
  1293. return 0;
  1294. }
  1295. static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
  1296. struct snd_ctl_elem_value *ucontrol)
  1297. {
  1298. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1299. struct ad198x_spec *spec = codec->spec;
  1300. unsigned int val = ucontrol->value.enumerated.item[0];
  1301. hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
  1302. int num_conns = snd_hda_get_num_conns(codec, dig_out);
  1303. if (val >= num_conns)
  1304. return -EINVAL;
  1305. if (spec->cur_smux == val)
  1306. return 0;
  1307. spec->cur_smux = val;
  1308. snd_hda_codec_write_cache(codec, dig_out, 0,
  1309. AC_VERB_SET_CONNECT_SEL, val);
  1310. return 1;
  1311. }
  1312. static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
  1313. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1314. .name = "IEC958 Playback Source",
  1315. .info = ad1983_auto_smux_enum_info,
  1316. .get = ad1983_auto_smux_enum_get,
  1317. .put = ad1983_auto_smux_enum_put,
  1318. };
  1319. static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
  1320. {
  1321. struct ad198x_spec *spec = codec->spec;
  1322. hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
  1323. int num_conns;
  1324. if (!dig_out)
  1325. return 0;
  1326. num_conns = snd_hda_get_num_conns(codec, dig_out);
  1327. if (num_conns != 2 && num_conns != 3)
  1328. return 0;
  1329. if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
  1330. return -ENOMEM;
  1331. return 0;
  1332. }
  1333. static int patch_ad1983(struct hda_codec *codec)
  1334. {
  1335. struct ad198x_spec *spec;
  1336. int err;
  1337. err = alloc_ad_spec(codec);
  1338. if (err < 0)
  1339. return err;
  1340. spec = codec->spec;
  1341. spec->gen.beep_nid = 0x10;
  1342. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  1343. err = ad198x_parse_auto_config(codec);
  1344. if (err < 0)
  1345. goto error;
  1346. err = ad1983_add_spdif_mux_ctl(codec);
  1347. if (err < 0)
  1348. goto error;
  1349. return 0;
  1350. error:
  1351. snd_hda_gen_free(codec);
  1352. return err;
  1353. }
  1354. /*
  1355. * AD1981 HD specific
  1356. */
  1357. /* follow EAPD via vmaster hook */
  1358. static void ad_vmaster_eapd_hook(void *private_data, int enabled)
  1359. {
  1360. struct hda_codec *codec = private_data;
  1361. struct ad198x_spec *spec = codec->spec;
  1362. if (!spec->eapd_nid)
  1363. return;
  1364. snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
  1365. AC_VERB_SET_EAPD_BTLENABLE,
  1366. enabled ? 0x02 : 0x00);
  1367. }
  1368. static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
  1369. const struct hda_fixup *fix, int action)
  1370. {
  1371. struct ad198x_spec *spec = codec->spec;
  1372. if (action == HDA_FIXUP_ACT_PRE_PROBE) {
  1373. spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
  1374. spec->eapd_nid = 0x05;
  1375. }
  1376. }
  1377. /* set the upper-limit for mixer amp to 0dB for avoiding the possible
  1378. * damage by overloading
  1379. */
  1380. static void ad1981_fixup_amp_override(struct hda_codec *codec,
  1381. const struct hda_fixup *fix, int action)
  1382. {
  1383. if (action == HDA_FIXUP_ACT_PRE_PROBE)
  1384. snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
  1385. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1386. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1387. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1388. (1 << AC_AMPCAP_MUTE_SHIFT));
  1389. }
  1390. enum {
  1391. AD1981_FIXUP_AMP_OVERRIDE,
  1392. AD1981_FIXUP_HP_EAPD,
  1393. };
  1394. static const struct hda_fixup ad1981_fixups[] = {
  1395. [AD1981_FIXUP_AMP_OVERRIDE] = {
  1396. .type = HDA_FIXUP_FUNC,
  1397. .v.func = ad1981_fixup_amp_override,
  1398. },
  1399. [AD1981_FIXUP_HP_EAPD] = {
  1400. .type = HDA_FIXUP_FUNC,
  1401. .v.func = ad1981_fixup_hp_eapd,
  1402. .chained = true,
  1403. .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
  1404. },
  1405. };
  1406. static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
  1407. SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
  1408. SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
  1409. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
  1410. /* HP nx6320 (reversed SSID, H/W bug) */
  1411. SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
  1412. {}
  1413. };
  1414. static int patch_ad1981(struct hda_codec *codec)
  1415. {
  1416. struct ad198x_spec *spec;
  1417. int err;
  1418. err = alloc_ad_spec(codec);
  1419. if (err < 0)
  1420. return -ENOMEM;
  1421. spec = codec->spec;
  1422. spec->gen.mixer_nid = 0x0e;
  1423. spec->gen.beep_nid = 0x10;
  1424. set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
  1425. snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
  1426. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  1427. err = ad198x_parse_auto_config(codec);
  1428. if (err < 0)
  1429. goto error;
  1430. err = ad1983_add_spdif_mux_ctl(codec);
  1431. if (err < 0)
  1432. goto error;
  1433. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  1434. return 0;
  1435. error:
  1436. snd_hda_gen_free(codec);
  1437. return err;
  1438. }
  1439. /*
  1440. * AD1988
  1441. *
  1442. * Output pins and routes
  1443. *
  1444. * Pin Mix Sel DAC (*)
  1445. * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
  1446. * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
  1447. * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
  1448. * port-D 0x12 (mute/hp) <- 0x29 <- 04
  1449. * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
  1450. * port-F 0x16 (mute) <- 0x2a <- 06
  1451. * port-G 0x24 (mute) <- 0x27 <- 05
  1452. * port-H 0x25 (mute) <- 0x28 <- 0a
  1453. * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
  1454. *
  1455. * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
  1456. * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
  1457. *
  1458. * Input pins and routes
  1459. *
  1460. * pin boost mix input # / adc input #
  1461. * port-A 0x11 -> 0x38 -> mix 2, ADC 0
  1462. * port-B 0x14 -> 0x39 -> mix 0, ADC 1
  1463. * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
  1464. * port-D 0x12 -> 0x3d -> mix 3, ADC 8
  1465. * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
  1466. * port-F 0x16 -> 0x3b -> mix 5, ADC 3
  1467. * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
  1468. * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
  1469. *
  1470. *
  1471. * DAC assignment
  1472. * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
  1473. * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
  1474. *
  1475. * Inputs of Analog Mix (0x20)
  1476. * 0:Port-B (front mic)
  1477. * 1:Port-C/G/H (line-in)
  1478. * 2:Port-A
  1479. * 3:Port-D (line-in/2)
  1480. * 4:Port-E/G/H (mic-in)
  1481. * 5:Port-F (mic2-in)
  1482. * 6:CD
  1483. * 7:Beep
  1484. *
  1485. * ADC selection
  1486. * 0:Port-A
  1487. * 1:Port-B (front mic-in)
  1488. * 2:Port-C (line-in)
  1489. * 3:Port-F (mic2-in)
  1490. * 4:Port-E (mic-in)
  1491. * 5:CD
  1492. * 6:Port-G
  1493. * 7:Port-H
  1494. * 8:Port-D (line-in/2)
  1495. * 9:Mix
  1496. *
  1497. * Proposed pin assignments by the datasheet
  1498. *
  1499. * 6-stack
  1500. * Port-A front headphone
  1501. * B front mic-in
  1502. * C rear line-in
  1503. * D rear front-out
  1504. * E rear mic-in
  1505. * F rear surround
  1506. * G rear CLFE
  1507. * H rear side
  1508. *
  1509. * 3-stack
  1510. * Port-A front headphone
  1511. * B front mic
  1512. * C rear line-in/surround
  1513. * D rear front-out
  1514. * E rear mic-in/CLFE
  1515. *
  1516. * laptop
  1517. * Port-A headphone
  1518. * B mic-in
  1519. * C docking station
  1520. * D internal speaker (with EAPD)
  1521. * E/F quad mic array
  1522. */
  1523. #ifdef ENABLE_AD_STATIC_QUIRKS
  1524. /* models */
  1525. enum {
  1526. AD1988_AUTO,
  1527. AD1988_6STACK,
  1528. AD1988_6STACK_DIG,
  1529. AD1988_3STACK,
  1530. AD1988_3STACK_DIG,
  1531. AD1988_LAPTOP,
  1532. AD1988_LAPTOP_DIG,
  1533. AD1988_MODEL_LAST,
  1534. };
  1535. /* reivision id to check workarounds */
  1536. #define AD1988A_REV2 0x100200
  1537. #define is_rev2(codec) \
  1538. ((codec)->vendor_id == 0x11d41988 && \
  1539. (codec)->revision_id == AD1988A_REV2)
  1540. /*
  1541. * mixers
  1542. */
  1543. static const hda_nid_t ad1988_6stack_dac_nids[4] = {
  1544. 0x04, 0x06, 0x05, 0x0a
  1545. };
  1546. static const hda_nid_t ad1988_3stack_dac_nids[3] = {
  1547. 0x04, 0x05, 0x0a
  1548. };
  1549. /* for AD1988A revision-2, DAC2-4 are swapped */
  1550. static const hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
  1551. 0x04, 0x05, 0x0a, 0x06
  1552. };
  1553. static const hda_nid_t ad1988_alt_dac_nid[1] = {
  1554. 0x03
  1555. };
  1556. static const hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
  1557. 0x04, 0x0a, 0x06
  1558. };
  1559. static const hda_nid_t ad1988_adc_nids[3] = {
  1560. 0x08, 0x09, 0x0f
  1561. };
  1562. static const hda_nid_t ad1988_capsrc_nids[3] = {
  1563. 0x0c, 0x0d, 0x0e
  1564. };
  1565. #define AD1988_SPDIF_OUT 0x02
  1566. #define AD1988_SPDIF_OUT_HDMI 0x0b
  1567. #define AD1988_SPDIF_IN 0x07
  1568. static const hda_nid_t ad1989b_slave_dig_outs[] = {
  1569. AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
  1570. };
  1571. static const struct hda_input_mux ad1988_6stack_capture_source = {
  1572. .num_items = 5,
  1573. .items = {
  1574. { "Front Mic", 0x1 }, /* port-B */
  1575. { "Line", 0x2 }, /* port-C */
  1576. { "Mic", 0x4 }, /* port-E */
  1577. { "CD", 0x5 },
  1578. { "Mix", 0x9 },
  1579. },
  1580. };
  1581. static const struct hda_input_mux ad1988_laptop_capture_source = {
  1582. .num_items = 3,
  1583. .items = {
  1584. { "Mic/Line", 0x1 }, /* port-B */
  1585. { "CD", 0x5 },
  1586. { "Mix", 0x9 },
  1587. },
  1588. };
  1589. /*
  1590. */
  1591. static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
  1592. struct snd_ctl_elem_info *uinfo)
  1593. {
  1594. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1595. struct ad198x_spec *spec = codec->spec;
  1596. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  1597. spec->num_channel_mode);
  1598. }
  1599. static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
  1600. struct snd_ctl_elem_value *ucontrol)
  1601. {
  1602. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1603. struct ad198x_spec *spec = codec->spec;
  1604. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  1605. spec->num_channel_mode, spec->multiout.max_channels);
  1606. }
  1607. static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
  1608. struct snd_ctl_elem_value *ucontrol)
  1609. {
  1610. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1611. struct ad198x_spec *spec = codec->spec;
  1612. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  1613. spec->num_channel_mode,
  1614. &spec->multiout.max_channels);
  1615. if (err >= 0 && spec->need_dac_fix)
  1616. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  1617. return err;
  1618. }
  1619. /* 6-stack mode */
  1620. static const struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
  1621. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1622. HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  1623. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  1624. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  1625. HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  1626. { } /* end */
  1627. };
  1628. static const struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
  1629. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1630. HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  1631. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
  1632. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
  1633. HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  1634. { } /* end */
  1635. };
  1636. static const struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
  1637. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  1638. HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
  1639. HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
  1640. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
  1641. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
  1642. HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
  1643. HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
  1644. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  1645. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  1646. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  1647. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  1648. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  1649. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  1650. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  1651. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
  1652. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
  1653. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  1654. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  1655. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  1656. HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
  1657. { } /* end */
  1658. };
  1659. /* 3-stack mode */
  1660. static const struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
  1661. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1662. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  1663. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  1664. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  1665. { } /* end */
  1666. };
  1667. static const struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
  1668. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1669. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  1670. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
  1671. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
  1672. { } /* end */
  1673. };
  1674. static const struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
  1675. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  1676. HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
  1677. HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
  1678. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
  1679. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
  1680. HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
  1681. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  1682. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  1683. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  1684. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  1685. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  1686. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  1687. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  1688. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
  1689. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
  1690. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  1691. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  1692. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  1693. HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
  1694. {
  1695. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1696. .name = "Channel Mode",
  1697. .info = ad198x_ch_mode_info,
  1698. .get = ad198x_ch_mode_get,
  1699. .put = ad198x_ch_mode_put,
  1700. },
  1701. { } /* end */
  1702. };
  1703. /* laptop mode */
  1704. static const struct snd_kcontrol_new ad1988_laptop_mixers[] = {
  1705. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  1706. HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1707. HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
  1708. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  1709. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  1710. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  1711. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  1712. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  1713. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  1714. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  1715. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  1716. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  1717. HDA_CODEC_VOLUME("Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  1718. {
  1719. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1720. .name = "External Amplifier",
  1721. .subdevice = HDA_SUBDEV_NID_FLAG | 0x12,
  1722. .info = ad198x_eapd_info,
  1723. .get = ad198x_eapd_get,
  1724. .put = ad198x_eapd_put,
  1725. .private_value = 0x12, /* port-D */
  1726. },
  1727. { } /* end */
  1728. };
  1729. /* capture */
  1730. static const struct snd_kcontrol_new ad1988_capture_mixers[] = {
  1731. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  1732. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  1733. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  1734. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  1735. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
  1736. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
  1737. {
  1738. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1739. /* The multiple "Capture Source" controls confuse alsamixer
  1740. * So call somewhat different..
  1741. */
  1742. /* .name = "Capture Source", */
  1743. .name = "Input Source",
  1744. .count = 3,
  1745. .info = ad198x_mux_enum_info,
  1746. .get = ad198x_mux_enum_get,
  1747. .put = ad198x_mux_enum_put,
  1748. },
  1749. { } /* end */
  1750. };
  1751. static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
  1752. struct snd_ctl_elem_info *uinfo)
  1753. {
  1754. static const char * const texts[] = {
  1755. "PCM", "ADC1", "ADC2", "ADC3"
  1756. };
  1757. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1758. uinfo->count = 1;
  1759. uinfo->value.enumerated.items = 4;
  1760. if (uinfo->value.enumerated.item >= 4)
  1761. uinfo->value.enumerated.item = 3;
  1762. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1763. return 0;
  1764. }
  1765. static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
  1766. struct snd_ctl_elem_value *ucontrol)
  1767. {
  1768. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1769. unsigned int sel;
  1770. sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
  1771. AC_AMP_GET_INPUT);
  1772. if (!(sel & 0x80))
  1773. ucontrol->value.enumerated.item[0] = 0;
  1774. else {
  1775. sel = snd_hda_codec_read(codec, 0x0b, 0,
  1776. AC_VERB_GET_CONNECT_SEL, 0);
  1777. if (sel < 3)
  1778. sel++;
  1779. else
  1780. sel = 0;
  1781. ucontrol->value.enumerated.item[0] = sel;
  1782. }
  1783. return 0;
  1784. }
  1785. static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
  1786. struct snd_ctl_elem_value *ucontrol)
  1787. {
  1788. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1789. unsigned int val, sel;
  1790. int change;
  1791. val = ucontrol->value.enumerated.item[0];
  1792. if (val > 3)
  1793. return -EINVAL;
  1794. if (!val) {
  1795. sel = snd_hda_codec_read(codec, 0x1d, 0,
  1796. AC_VERB_GET_AMP_GAIN_MUTE,
  1797. AC_AMP_GET_INPUT);
  1798. change = sel & 0x80;
  1799. if (change) {
  1800. snd_hda_codec_write_cache(codec, 0x1d, 0,
  1801. AC_VERB_SET_AMP_GAIN_MUTE,
  1802. AMP_IN_UNMUTE(0));
  1803. snd_hda_codec_write_cache(codec, 0x1d, 0,
  1804. AC_VERB_SET_AMP_GAIN_MUTE,
  1805. AMP_IN_MUTE(1));
  1806. }
  1807. } else {
  1808. sel = snd_hda_codec_read(codec, 0x1d, 0,
  1809. AC_VERB_GET_AMP_GAIN_MUTE,
  1810. AC_AMP_GET_INPUT | 0x01);
  1811. change = sel & 0x80;
  1812. if (change) {
  1813. snd_hda_codec_write_cache(codec, 0x1d, 0,
  1814. AC_VERB_SET_AMP_GAIN_MUTE,
  1815. AMP_IN_MUTE(0));
  1816. snd_hda_codec_write_cache(codec, 0x1d, 0,
  1817. AC_VERB_SET_AMP_GAIN_MUTE,
  1818. AMP_IN_UNMUTE(1));
  1819. }
  1820. sel = snd_hda_codec_read(codec, 0x0b, 0,
  1821. AC_VERB_GET_CONNECT_SEL, 0) + 1;
  1822. change |= sel != val;
  1823. if (change)
  1824. snd_hda_codec_write_cache(codec, 0x0b, 0,
  1825. AC_VERB_SET_CONNECT_SEL,
  1826. val - 1);
  1827. }
  1828. return change;
  1829. }
  1830. static const struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
  1831. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  1832. {
  1833. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1834. .name = "IEC958 Playback Source",
  1835. .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
  1836. .info = ad1988_spdif_playback_source_info,
  1837. .get = ad1988_spdif_playback_source_get,
  1838. .put = ad1988_spdif_playback_source_put,
  1839. },
  1840. { } /* end */
  1841. };
  1842. static const struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
  1843. HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
  1844. { } /* end */
  1845. };
  1846. static const struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
  1847. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  1848. HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1849. { } /* end */
  1850. };
  1851. /*
  1852. * initialization verbs
  1853. */
  1854. /*
  1855. * for 6-stack (+dig)
  1856. */
  1857. static const struct hda_verb ad1988_6stack_init_verbs[] = {
  1858. /* Front, Surround, CLFE, side DAC; unmute as default */
  1859. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1860. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1861. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1862. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1863. /* Port-A front headphon path */
  1864. {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  1865. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1866. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1867. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1868. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1869. /* Port-D line-out path */
  1870. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1871. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1872. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1873. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1874. /* Port-F surround path */
  1875. {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1876. {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1877. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1878. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1879. /* Port-G CLFE path */
  1880. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1881. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1882. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1883. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1884. /* Port-H side path */
  1885. {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1886. {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1887. {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1888. {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1889. /* Mono out path */
  1890. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  1891. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1892. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1893. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1894. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  1895. /* Port-B front mic-in path */
  1896. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1897. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1898. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1899. /* Port-C line-in path */
  1900. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1901. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1902. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1903. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  1904. /* Port-E mic-in path */
  1905. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1906. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1907. {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1908. {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
  1909. /* Analog CD Input */
  1910. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1911. /* Analog Mix output amp */
  1912. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  1913. { }
  1914. };
  1915. static const struct hda_verb ad1988_6stack_fp_init_verbs[] = {
  1916. /* Headphone; unmute as default */
  1917. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1918. /* Port-A front headphon path */
  1919. {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  1920. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1921. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1922. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1923. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1924. { }
  1925. };
  1926. static const struct hda_verb ad1988_capture_init_verbs[] = {
  1927. /* mute analog mix */
  1928. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1929. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1930. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  1931. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1932. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  1933. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  1934. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  1935. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  1936. /* select ADCs - front-mic */
  1937. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  1938. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  1939. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  1940. { }
  1941. };
  1942. static const struct hda_verb ad1988_spdif_init_verbs[] = {
  1943. /* SPDIF out sel */
  1944. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
  1945. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
  1946. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1947. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1948. /* SPDIF out pin */
  1949. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  1950. { }
  1951. };
  1952. static const struct hda_verb ad1988_spdif_in_init_verbs[] = {
  1953. /* unmute SPDIF input pin */
  1954. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1955. { }
  1956. };
  1957. /* AD1989 has no ADC -> SPDIF route */
  1958. static const struct hda_verb ad1989_spdif_init_verbs[] = {
  1959. /* SPDIF-1 out pin */
  1960. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  1961. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  1962. /* SPDIF-2/HDMI out pin */
  1963. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  1964. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  1965. { }
  1966. };
  1967. /*
  1968. * verbs for 3stack (+dig)
  1969. */
  1970. static const struct hda_verb ad1988_3stack_ch2_init[] = {
  1971. /* set port-C to line-in */
  1972. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  1973. { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1974. /* set port-E to mic-in */
  1975. { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  1976. { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  1977. { } /* end */
  1978. };
  1979. static const struct hda_verb ad1988_3stack_ch6_init[] = {
  1980. /* set port-C to surround out */
  1981. { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  1982. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  1983. /* set port-E to CLFE out */
  1984. { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  1985. { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  1986. { } /* end */
  1987. };
  1988. static const struct hda_channel_mode ad1988_3stack_modes[2] = {
  1989. { 2, ad1988_3stack_ch2_init },
  1990. { 6, ad1988_3stack_ch6_init },
  1991. };
  1992. static const struct hda_verb ad1988_3stack_init_verbs[] = {
  1993. /* Front, Surround, CLFE, side DAC; unmute as default */
  1994. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1995. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1996. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1997. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1998. /* Port-A front headphon path */
  1999. {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  2000. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2001. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2002. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2003. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2004. /* Port-D line-out path */
  2005. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2006. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2007. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2008. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2009. /* Mono out path */
  2010. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  2011. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2012. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2013. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2014. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  2015. /* Port-B front mic-in path */
  2016. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2017. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2018. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2019. /* Port-C line-in/surround path - 6ch mode as default */
  2020. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2021. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2022. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2023. {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
  2024. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  2025. /* Port-E mic-in/CLFE path - 6ch mode as default */
  2026. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2027. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2028. {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2029. {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
  2030. {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
  2031. /* mute analog mix */
  2032. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2033. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2034. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2035. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2036. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2037. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  2038. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  2039. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  2040. /* select ADCs - front-mic */
  2041. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  2042. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  2043. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  2044. /* Analog Mix output amp */
  2045. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  2046. { }
  2047. };
  2048. /*
  2049. * verbs for laptop mode (+dig)
  2050. */
  2051. static const struct hda_verb ad1988_laptop_hp_on[] = {
  2052. /* unmute port-A and mute port-D */
  2053. { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  2054. { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2055. { } /* end */
  2056. };
  2057. static const struct hda_verb ad1988_laptop_hp_off[] = {
  2058. /* mute port-A and unmute port-D */
  2059. { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2060. { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  2061. { } /* end */
  2062. };
  2063. #define AD1988_HP_EVENT 0x01
  2064. static const struct hda_verb ad1988_laptop_init_verbs[] = {
  2065. /* Front, Surround, CLFE, side DAC; unmute as default */
  2066. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2067. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2068. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2069. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2070. /* Port-A front headphon path */
  2071. {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  2072. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2073. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2074. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2075. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2076. /* unsolicited event for pin-sense */
  2077. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
  2078. /* Port-D line-out path + EAPD */
  2079. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2080. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2081. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2082. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2083. {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
  2084. /* Mono out path */
  2085. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  2086. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2087. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2088. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2089. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  2090. /* Port-B mic-in path */
  2091. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2092. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2093. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2094. /* Port-C docking station - try to output */
  2095. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2096. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2097. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2098. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  2099. /* mute analog mix */
  2100. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2101. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2102. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2103. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2104. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2105. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  2106. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  2107. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  2108. /* select ADCs - mic */
  2109. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  2110. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  2111. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  2112. /* Analog Mix output amp */
  2113. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  2114. { }
  2115. };
  2116. static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
  2117. {
  2118. if ((res >> 26) != AD1988_HP_EVENT)
  2119. return;
  2120. if (snd_hda_jack_detect(codec, 0x11))
  2121. snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
  2122. else
  2123. snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
  2124. }
  2125. #ifdef CONFIG_PM
  2126. static const struct hda_amp_list ad1988_loopbacks[] = {
  2127. { 0x20, HDA_INPUT, 0 }, /* Front Mic */
  2128. { 0x20, HDA_INPUT, 1 }, /* Line */
  2129. { 0x20, HDA_INPUT, 4 }, /* Mic */
  2130. { 0x20, HDA_INPUT, 6 }, /* CD */
  2131. { } /* end */
  2132. };
  2133. #endif
  2134. #endif /* ENABLE_AD_STATIC_QUIRKS */
  2135. static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
  2136. struct snd_ctl_elem_info *uinfo)
  2137. {
  2138. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2139. static const char * const texts[] = {
  2140. "PCM", "ADC1", "ADC2", "ADC3",
  2141. };
  2142. int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
  2143. if (num_conns > 4)
  2144. num_conns = 4;
  2145. return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
  2146. }
  2147. static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
  2148. struct snd_ctl_elem_value *ucontrol)
  2149. {
  2150. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2151. struct ad198x_spec *spec = codec->spec;
  2152. ucontrol->value.enumerated.item[0] = spec->cur_smux;
  2153. return 0;
  2154. }
  2155. static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
  2156. struct snd_ctl_elem_value *ucontrol)
  2157. {
  2158. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2159. struct ad198x_spec *spec = codec->spec;
  2160. unsigned int val = ucontrol->value.enumerated.item[0];
  2161. struct nid_path *path;
  2162. int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
  2163. if (val >= num_conns)
  2164. return -EINVAL;
  2165. if (spec->cur_smux == val)
  2166. return 0;
  2167. mutex_lock(&codec->control_mutex);
  2168. codec->cached_write = 1;
  2169. path = snd_hda_get_path_from_idx(codec,
  2170. spec->smux_paths[spec->cur_smux]);
  2171. if (path)
  2172. snd_hda_activate_path(codec, path, false, true);
  2173. path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
  2174. if (path)
  2175. snd_hda_activate_path(codec, path, true, true);
  2176. spec->cur_smux = val;
  2177. codec->cached_write = 0;
  2178. mutex_unlock(&codec->control_mutex);
  2179. snd_hda_codec_flush_cache(codec); /* flush the updates */
  2180. return 1;
  2181. }
  2182. static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
  2183. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2184. .name = "IEC958 Playback Source",
  2185. .info = ad1988_auto_smux_enum_info,
  2186. .get = ad1988_auto_smux_enum_get,
  2187. .put = ad1988_auto_smux_enum_put,
  2188. };
  2189. static int ad1988_auto_init(struct hda_codec *codec)
  2190. {
  2191. struct ad198x_spec *spec = codec->spec;
  2192. int i, err;
  2193. err = snd_hda_gen_init(codec);
  2194. if (err < 0)
  2195. return err;
  2196. if (!spec->gen.autocfg.dig_outs)
  2197. return 0;
  2198. for (i = 0; i < 4; i++) {
  2199. struct nid_path *path;
  2200. path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
  2201. if (path)
  2202. snd_hda_activate_path(codec, path, path->active, false);
  2203. }
  2204. return 0;
  2205. }
  2206. static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
  2207. {
  2208. struct ad198x_spec *spec = codec->spec;
  2209. int i, num_conns;
  2210. /* we create four static faked paths, since AD codecs have odd
  2211. * widget connections regarding the SPDIF out source
  2212. */
  2213. static struct nid_path fake_paths[4] = {
  2214. {
  2215. .depth = 3,
  2216. .path = { 0x02, 0x1d, 0x1b },
  2217. .idx = { 0, 0, 0 },
  2218. .multi = { 0, 0, 0 },
  2219. },
  2220. {
  2221. .depth = 4,
  2222. .path = { 0x08, 0x0b, 0x1d, 0x1b },
  2223. .idx = { 0, 0, 1, 0 },
  2224. .multi = { 0, 1, 0, 0 },
  2225. },
  2226. {
  2227. .depth = 4,
  2228. .path = { 0x09, 0x0b, 0x1d, 0x1b },
  2229. .idx = { 0, 1, 1, 0 },
  2230. .multi = { 0, 1, 0, 0 },
  2231. },
  2232. {
  2233. .depth = 4,
  2234. .path = { 0x0f, 0x0b, 0x1d, 0x1b },
  2235. .idx = { 0, 2, 1, 0 },
  2236. .multi = { 0, 1, 0, 0 },
  2237. },
  2238. };
  2239. /* SPDIF source mux appears to be present only on AD1988A */
  2240. if (!spec->gen.autocfg.dig_outs ||
  2241. get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
  2242. return 0;
  2243. num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
  2244. if (num_conns != 3 && num_conns != 4)
  2245. return 0;
  2246. for (i = 0; i < num_conns; i++) {
  2247. struct nid_path *path = snd_array_new(&spec->gen.paths);
  2248. if (!path)
  2249. return -ENOMEM;
  2250. *path = fake_paths[i];
  2251. if (!i)
  2252. path->active = 1;
  2253. spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
  2254. }
  2255. if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
  2256. return -ENOMEM;
  2257. codec->patch_ops.init = ad1988_auto_init;
  2258. return 0;
  2259. }
  2260. /*
  2261. */
  2262. static int ad1988_parse_auto_config(struct hda_codec *codec)
  2263. {
  2264. struct ad198x_spec *spec;
  2265. int err;
  2266. err = alloc_ad_spec(codec);
  2267. if (err < 0)
  2268. return err;
  2269. spec = codec->spec;
  2270. spec->gen.mixer_nid = 0x20;
  2271. spec->gen.mixer_merge_nid = 0x21;
  2272. spec->gen.beep_nid = 0x10;
  2273. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  2274. err = ad198x_parse_auto_config(codec);
  2275. if (err < 0)
  2276. goto error;
  2277. err = ad1988_add_spdif_mux_ctl(codec);
  2278. if (err < 0)
  2279. goto error;
  2280. return 0;
  2281. error:
  2282. snd_hda_gen_free(codec);
  2283. return err;
  2284. }
  2285. /*
  2286. */
  2287. #ifdef ENABLE_AD_STATIC_QUIRKS
  2288. static const char * const ad1988_models[AD1988_MODEL_LAST] = {
  2289. [AD1988_6STACK] = "6stack",
  2290. [AD1988_6STACK_DIG] = "6stack-dig",
  2291. [AD1988_3STACK] = "3stack",
  2292. [AD1988_3STACK_DIG] = "3stack-dig",
  2293. [AD1988_LAPTOP] = "laptop",
  2294. [AD1988_LAPTOP_DIG] = "laptop-dig",
  2295. [AD1988_AUTO] = "auto",
  2296. };
  2297. static const struct snd_pci_quirk ad1988_cfg_tbl[] = {
  2298. SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
  2299. SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
  2300. SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
  2301. SND_PCI_QUIRK(0x1043, 0x82c0, "Asus M3N-HT Deluxe", AD1988_6STACK_DIG),
  2302. SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
  2303. {}
  2304. };
  2305. static int patch_ad1988(struct hda_codec *codec)
  2306. {
  2307. struct ad198x_spec *spec;
  2308. int err, board_config;
  2309. board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
  2310. ad1988_models, ad1988_cfg_tbl);
  2311. if (board_config < 0) {
  2312. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  2313. codec->chip_name);
  2314. board_config = AD1988_AUTO;
  2315. }
  2316. if (board_config == AD1988_AUTO)
  2317. return ad1988_parse_auto_config(codec);
  2318. err = alloc_ad_spec(codec);
  2319. if (err < 0)
  2320. return err;
  2321. spec = codec->spec;
  2322. if (is_rev2(codec))
  2323. snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
  2324. err = snd_hda_attach_beep_device(codec, 0x10);
  2325. if (err < 0) {
  2326. ad198x_free(codec);
  2327. return err;
  2328. }
  2329. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  2330. if (!spec->multiout.hp_nid)
  2331. spec->multiout.hp_nid = ad1988_alt_dac_nid[0];
  2332. switch (board_config) {
  2333. case AD1988_6STACK:
  2334. case AD1988_6STACK_DIG:
  2335. spec->multiout.max_channels = 8;
  2336. spec->multiout.num_dacs = 4;
  2337. if (is_rev2(codec))
  2338. spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
  2339. else
  2340. spec->multiout.dac_nids = ad1988_6stack_dac_nids;
  2341. spec->input_mux = &ad1988_6stack_capture_source;
  2342. spec->num_mixers = 2;
  2343. if (is_rev2(codec))
  2344. spec->mixers[0] = ad1988_6stack_mixers1_rev2;
  2345. else
  2346. spec->mixers[0] = ad1988_6stack_mixers1;
  2347. spec->mixers[1] = ad1988_6stack_mixers2;
  2348. spec->num_init_verbs = 1;
  2349. spec->init_verbs[0] = ad1988_6stack_init_verbs;
  2350. if (board_config == AD1988_6STACK_DIG) {
  2351. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2352. spec->dig_in_nid = AD1988_SPDIF_IN;
  2353. }
  2354. break;
  2355. case AD1988_3STACK:
  2356. case AD1988_3STACK_DIG:
  2357. spec->multiout.max_channels = 6;
  2358. spec->multiout.num_dacs = 3;
  2359. if (is_rev2(codec))
  2360. spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
  2361. else
  2362. spec->multiout.dac_nids = ad1988_3stack_dac_nids;
  2363. spec->input_mux = &ad1988_6stack_capture_source;
  2364. spec->channel_mode = ad1988_3stack_modes;
  2365. spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
  2366. spec->num_mixers = 2;
  2367. if (is_rev2(codec))
  2368. spec->mixers[0] = ad1988_3stack_mixers1_rev2;
  2369. else
  2370. spec->mixers[0] = ad1988_3stack_mixers1;
  2371. spec->mixers[1] = ad1988_3stack_mixers2;
  2372. spec->num_init_verbs = 1;
  2373. spec->init_verbs[0] = ad1988_3stack_init_verbs;
  2374. if (board_config == AD1988_3STACK_DIG)
  2375. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2376. break;
  2377. case AD1988_LAPTOP:
  2378. case AD1988_LAPTOP_DIG:
  2379. spec->multiout.max_channels = 2;
  2380. spec->multiout.num_dacs = 1;
  2381. spec->multiout.dac_nids = ad1988_3stack_dac_nids;
  2382. spec->input_mux = &ad1988_laptop_capture_source;
  2383. spec->num_mixers = 1;
  2384. spec->mixers[0] = ad1988_laptop_mixers;
  2385. codec->inv_eapd = 1; /* inverted EAPD */
  2386. spec->num_init_verbs = 1;
  2387. spec->init_verbs[0] = ad1988_laptop_init_verbs;
  2388. if (board_config == AD1988_LAPTOP_DIG)
  2389. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2390. break;
  2391. }
  2392. spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
  2393. spec->adc_nids = ad1988_adc_nids;
  2394. spec->capsrc_nids = ad1988_capsrc_nids;
  2395. spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
  2396. spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
  2397. if (spec->multiout.dig_out_nid) {
  2398. if (codec->vendor_id >= 0x11d4989a) {
  2399. spec->mixers[spec->num_mixers++] =
  2400. ad1989_spdif_out_mixers;
  2401. spec->init_verbs[spec->num_init_verbs++] =
  2402. ad1989_spdif_init_verbs;
  2403. codec->slave_dig_outs = ad1989b_slave_dig_outs;
  2404. } else {
  2405. spec->mixers[spec->num_mixers++] =
  2406. ad1988_spdif_out_mixers;
  2407. spec->init_verbs[spec->num_init_verbs++] =
  2408. ad1988_spdif_init_verbs;
  2409. }
  2410. }
  2411. if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a) {
  2412. spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
  2413. spec->init_verbs[spec->num_init_verbs++] =
  2414. ad1988_spdif_in_init_verbs;
  2415. }
  2416. codec->patch_ops = ad198x_patch_ops;
  2417. switch (board_config) {
  2418. case AD1988_LAPTOP:
  2419. case AD1988_LAPTOP_DIG:
  2420. codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
  2421. break;
  2422. }
  2423. #ifdef CONFIG_PM
  2424. spec->loopback.amplist = ad1988_loopbacks;
  2425. #endif
  2426. spec->vmaster_nid = 0x04;
  2427. codec->no_trigger_sense = 1;
  2428. codec->no_sticky_stream = 1;
  2429. return 0;
  2430. }
  2431. #else /* ENABLE_AD_STATIC_QUIRKS */
  2432. #define patch_ad1988 ad1988_parse_auto_config
  2433. #endif /* ENABLE_AD_STATIC_QUIRKS */
  2434. /*
  2435. * AD1884 / AD1984
  2436. *
  2437. * port-B - front line/mic-in
  2438. * port-E - aux in/out
  2439. * port-F - aux in/out
  2440. * port-C - rear line/mic-in
  2441. * port-D - rear line/hp-out
  2442. * port-A - front line/hp-out
  2443. *
  2444. * AD1984 = AD1884 + two digital mic-ins
  2445. *
  2446. * AD1883 / AD1884A / AD1984A / AD1984B
  2447. *
  2448. * port-B (0x14) - front mic-in
  2449. * port-E (0x1c) - rear mic-in
  2450. * port-F (0x16) - CD / ext out
  2451. * port-C (0x15) - rear line-in
  2452. * port-D (0x12) - rear line-out
  2453. * port-A (0x11) - front hp-out
  2454. *
  2455. * AD1984A = AD1884A + digital-mic
  2456. * AD1883 = equivalent with AD1984A
  2457. * AD1984B = AD1984A + extra SPDIF-out
  2458. */
  2459. /* set the upper-limit for mixer amp to 0dB for avoiding the possible
  2460. * damage by overloading
  2461. */
  2462. static void ad1884_fixup_amp_override(struct hda_codec *codec,
  2463. const struct hda_fixup *fix, int action)
  2464. {
  2465. if (action == HDA_FIXUP_ACT_PRE_PROBE)
  2466. snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
  2467. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  2468. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2469. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2470. (1 << AC_AMPCAP_MUTE_SHIFT));
  2471. }
  2472. /* toggle GPIO1 according to the mute state */
  2473. static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
  2474. {
  2475. struct hda_codec *codec = private_data;
  2476. struct ad198x_spec *spec = codec->spec;
  2477. if (spec->eapd_nid)
  2478. ad_vmaster_eapd_hook(private_data, enabled);
  2479. snd_hda_codec_update_cache(codec, 0x01, 0,
  2480. AC_VERB_SET_GPIO_DATA,
  2481. enabled ? 0x00 : 0x02);
  2482. }
  2483. static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
  2484. const struct hda_fixup *fix, int action)
  2485. {
  2486. struct ad198x_spec *spec = codec->spec;
  2487. static const struct hda_verb gpio_init_verbs[] = {
  2488. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  2489. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  2490. {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
  2491. {},
  2492. };
  2493. switch (action) {
  2494. case HDA_FIXUP_ACT_PRE_PROBE:
  2495. spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
  2496. snd_hda_sequence_write_cache(codec, gpio_init_verbs);
  2497. break;
  2498. case HDA_FIXUP_ACT_PROBE:
  2499. if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
  2500. spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
  2501. else
  2502. spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
  2503. break;
  2504. }
  2505. }
  2506. /* set magic COEFs for dmic */
  2507. static const struct hda_verb ad1884_dmic_init_verbs[] = {
  2508. {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
  2509. {0x01, AC_VERB_SET_PROC_COEF, 0x08},
  2510. {}
  2511. };
  2512. enum {
  2513. AD1884_FIXUP_AMP_OVERRIDE,
  2514. AD1884_FIXUP_HP_EAPD,
  2515. AD1884_FIXUP_DMIC_COEF,
  2516. AD1884_FIXUP_HP_TOUCHSMART,
  2517. };
  2518. static const struct hda_fixup ad1884_fixups[] = {
  2519. [AD1884_FIXUP_AMP_OVERRIDE] = {
  2520. .type = HDA_FIXUP_FUNC,
  2521. .v.func = ad1884_fixup_amp_override,
  2522. },
  2523. [AD1884_FIXUP_HP_EAPD] = {
  2524. .type = HDA_FIXUP_FUNC,
  2525. .v.func = ad1884_fixup_hp_eapd,
  2526. .chained = true,
  2527. .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
  2528. },
  2529. [AD1884_FIXUP_DMIC_COEF] = {
  2530. .type = HDA_FIXUP_VERBS,
  2531. .v.verbs = ad1884_dmic_init_verbs,
  2532. },
  2533. [AD1884_FIXUP_HP_TOUCHSMART] = {
  2534. .type = HDA_FIXUP_VERBS,
  2535. .v.verbs = ad1884_dmic_init_verbs,
  2536. .chained = true,
  2537. .chain_id = AD1884_FIXUP_HP_EAPD,
  2538. },
  2539. };
  2540. static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
  2541. SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
  2542. SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
  2543. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_DMIC_COEF),
  2544. {}
  2545. };
  2546. static int patch_ad1884(struct hda_codec *codec)
  2547. {
  2548. struct ad198x_spec *spec;
  2549. int err;
  2550. err = alloc_ad_spec(codec);
  2551. if (err < 0)
  2552. return err;
  2553. spec = codec->spec;
  2554. spec->gen.mixer_nid = 0x20;
  2555. spec->gen.beep_nid = 0x10;
  2556. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  2557. snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
  2558. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  2559. err = ad198x_parse_auto_config(codec);
  2560. if (err < 0)
  2561. goto error;
  2562. err = ad1983_add_spdif_mux_ctl(codec);
  2563. if (err < 0)
  2564. goto error;
  2565. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  2566. return 0;
  2567. error:
  2568. snd_hda_gen_free(codec);
  2569. return err;
  2570. }
  2571. /*
  2572. * AD1882 / AD1882A
  2573. *
  2574. * port-A - front hp-out
  2575. * port-B - front mic-in
  2576. * port-C - rear line-in, shared surr-out (3stack)
  2577. * port-D - rear line-out
  2578. * port-E - rear mic-in, shared clfe-out (3stack)
  2579. * port-F - rear surr-out (6stack)
  2580. * port-G - rear clfe-out (6stack)
  2581. */
  2582. static int patch_ad1882(struct hda_codec *codec)
  2583. {
  2584. struct ad198x_spec *spec;
  2585. int err;
  2586. err = alloc_ad_spec(codec);
  2587. if (err < 0)
  2588. return err;
  2589. spec = codec->spec;
  2590. spec->gen.mixer_nid = 0x20;
  2591. spec->gen.mixer_merge_nid = 0x21;
  2592. spec->gen.beep_nid = 0x10;
  2593. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  2594. err = ad198x_parse_auto_config(codec);
  2595. if (err < 0)
  2596. goto error;
  2597. err = ad1988_add_spdif_mux_ctl(codec);
  2598. if (err < 0)
  2599. goto error;
  2600. return 0;
  2601. error:
  2602. snd_hda_gen_free(codec);
  2603. return err;
  2604. }
  2605. /*
  2606. * patch entries
  2607. */
  2608. static const struct hda_codec_preset snd_hda_preset_analog[] = {
  2609. { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
  2610. { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
  2611. { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
  2612. { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
  2613. { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
  2614. { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
  2615. { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
  2616. { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
  2617. { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
  2618. { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
  2619. { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
  2620. { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
  2621. { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
  2622. { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
  2623. { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
  2624. {} /* terminator */
  2625. };
  2626. MODULE_ALIAS("snd-hda-codec-id:11d4*");
  2627. MODULE_LICENSE("GPL");
  2628. MODULE_DESCRIPTION("Analog Devices HD-audio codec");
  2629. static struct hda_codec_preset_list analog_list = {
  2630. .preset = snd_hda_preset_analog,
  2631. .owner = THIS_MODULE,
  2632. };
  2633. static int __init patch_analog_init(void)
  2634. {
  2635. return snd_hda_add_codec_preset(&analog_list);
  2636. }
  2637. static void __exit patch_analog_exit(void)
  2638. {
  2639. snd_hda_delete_codec_preset(&analog_list);
  2640. }
  2641. module_init(patch_analog_init)
  2642. module_exit(patch_analog_exit)