patch_analog.c 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787
  1. /*
  2. * HD audio interface patch for AD1981HD, AD1983, AD1986A, AD1988
  3. *
  4. * Copyright (c) 2005 Takashi Iwai <tiwai@suse.de>
  5. *
  6. * This driver is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This driver is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <sound/driver.h>
  21. #include <linux/init.h>
  22. #include <linux/delay.h>
  23. #include <linux/slab.h>
  24. #include <linux/pci.h>
  25. #include <linux/mutex.h>
  26. #include <sound/core.h>
  27. #include "hda_codec.h"
  28. #include "hda_local.h"
  29. struct ad198x_spec {
  30. struct snd_kcontrol_new *mixers[5];
  31. int num_mixers;
  32. const struct hda_verb *init_verbs[5]; /* initialization verbs
  33. * don't forget NULL termination!
  34. */
  35. unsigned int num_init_verbs;
  36. /* playback */
  37. struct hda_multi_out multiout; /* playback set-up
  38. * max_channels, dacs must be set
  39. * dig_out_nid and hp_nid are optional
  40. */
  41. unsigned int cur_eapd;
  42. unsigned int need_dac_fix;
  43. /* capture */
  44. unsigned int num_adc_nids;
  45. hda_nid_t *adc_nids;
  46. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  47. /* capture source */
  48. const struct hda_input_mux *input_mux;
  49. hda_nid_t *capsrc_nids;
  50. unsigned int cur_mux[3];
  51. /* channel model */
  52. const struct hda_channel_mode *channel_mode;
  53. int num_channel_mode;
  54. /* PCM information */
  55. struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */
  56. struct mutex amp_mutex; /* PCM volume/mute control mutex */
  57. unsigned int spdif_route;
  58. /* dynamic controls, init_verbs and input_mux */
  59. struct auto_pin_cfg autocfg;
  60. unsigned int num_kctl_alloc, num_kctl_used;
  61. struct snd_kcontrol_new *kctl_alloc;
  62. struct hda_input_mux private_imux;
  63. hda_nid_t private_dac_nids[4];
  64. };
  65. /*
  66. * input MUX handling (common part)
  67. */
  68. static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  69. {
  70. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  71. struct ad198x_spec *spec = codec->spec;
  72. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  73. }
  74. static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  75. {
  76. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  77. struct ad198x_spec *spec = codec->spec;
  78. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  79. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  80. return 0;
  81. }
  82. static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  83. {
  84. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  85. struct ad198x_spec *spec = codec->spec;
  86. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  87. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  88. spec->capsrc_nids[adc_idx],
  89. &spec->cur_mux[adc_idx]);
  90. }
  91. /*
  92. * initialization (common callbacks)
  93. */
  94. static int ad198x_init(struct hda_codec *codec)
  95. {
  96. struct ad198x_spec *spec = codec->spec;
  97. int i;
  98. for (i = 0; i < spec->num_init_verbs; i++)
  99. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  100. return 0;
  101. }
  102. static int ad198x_build_controls(struct hda_codec *codec)
  103. {
  104. struct ad198x_spec *spec = codec->spec;
  105. unsigned int i;
  106. int err;
  107. for (i = 0; i < spec->num_mixers; i++) {
  108. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  109. if (err < 0)
  110. return err;
  111. }
  112. if (spec->multiout.dig_out_nid) {
  113. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  114. if (err < 0)
  115. return err;
  116. }
  117. if (spec->dig_in_nid) {
  118. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  119. if (err < 0)
  120. return err;
  121. }
  122. return 0;
  123. }
  124. /*
  125. * Analog playback callbacks
  126. */
  127. static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
  128. struct hda_codec *codec,
  129. struct snd_pcm_substream *substream)
  130. {
  131. struct ad198x_spec *spec = codec->spec;
  132. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  133. }
  134. static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  135. struct hda_codec *codec,
  136. unsigned int stream_tag,
  137. unsigned int format,
  138. struct snd_pcm_substream *substream)
  139. {
  140. struct ad198x_spec *spec = codec->spec;
  141. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
  142. format, substream);
  143. }
  144. static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  145. struct hda_codec *codec,
  146. struct snd_pcm_substream *substream)
  147. {
  148. struct ad198x_spec *spec = codec->spec;
  149. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  150. }
  151. /*
  152. * Digital out
  153. */
  154. static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  155. struct hda_codec *codec,
  156. struct snd_pcm_substream *substream)
  157. {
  158. struct ad198x_spec *spec = codec->spec;
  159. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  160. }
  161. static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  162. struct hda_codec *codec,
  163. struct snd_pcm_substream *substream)
  164. {
  165. struct ad198x_spec *spec = codec->spec;
  166. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  167. }
  168. static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  169. struct hda_codec *codec,
  170. unsigned int stream_tag,
  171. unsigned int format,
  172. struct snd_pcm_substream *substream)
  173. {
  174. struct ad198x_spec *spec = codec->spec;
  175. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
  176. format, substream);
  177. }
  178. /*
  179. * Analog capture
  180. */
  181. static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  182. struct hda_codec *codec,
  183. unsigned int stream_tag,
  184. unsigned int format,
  185. struct snd_pcm_substream *substream)
  186. {
  187. struct ad198x_spec *spec = codec->spec;
  188. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  189. stream_tag, 0, format);
  190. return 0;
  191. }
  192. static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  193. struct hda_codec *codec,
  194. struct snd_pcm_substream *substream)
  195. {
  196. struct ad198x_spec *spec = codec->spec;
  197. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  198. 0, 0, 0);
  199. return 0;
  200. }
  201. /*
  202. */
  203. static struct hda_pcm_stream ad198x_pcm_analog_playback = {
  204. .substreams = 1,
  205. .channels_min = 2,
  206. .channels_max = 6, /* changed later */
  207. .nid = 0, /* fill later */
  208. .ops = {
  209. .open = ad198x_playback_pcm_open,
  210. .prepare = ad198x_playback_pcm_prepare,
  211. .cleanup = ad198x_playback_pcm_cleanup
  212. },
  213. };
  214. static struct hda_pcm_stream ad198x_pcm_analog_capture = {
  215. .substreams = 1,
  216. .channels_min = 2,
  217. .channels_max = 2,
  218. .nid = 0, /* fill later */
  219. .ops = {
  220. .prepare = ad198x_capture_pcm_prepare,
  221. .cleanup = ad198x_capture_pcm_cleanup
  222. },
  223. };
  224. static struct hda_pcm_stream ad198x_pcm_digital_playback = {
  225. .substreams = 1,
  226. .channels_min = 2,
  227. .channels_max = 2,
  228. .nid = 0, /* fill later */
  229. .ops = {
  230. .open = ad198x_dig_playback_pcm_open,
  231. .close = ad198x_dig_playback_pcm_close,
  232. .prepare = ad198x_dig_playback_pcm_prepare
  233. },
  234. };
  235. static struct hda_pcm_stream ad198x_pcm_digital_capture = {
  236. .substreams = 1,
  237. .channels_min = 2,
  238. .channels_max = 2,
  239. /* NID is set in alc_build_pcms */
  240. };
  241. static int ad198x_build_pcms(struct hda_codec *codec)
  242. {
  243. struct ad198x_spec *spec = codec->spec;
  244. struct hda_pcm *info = spec->pcm_rec;
  245. codec->num_pcms = 1;
  246. codec->pcm_info = info;
  247. info->name = "AD198x Analog";
  248. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
  249. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
  250. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  251. info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
  252. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  253. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  254. if (spec->multiout.dig_out_nid) {
  255. info++;
  256. codec->num_pcms++;
  257. info->name = "AD198x Digital";
  258. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
  259. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  260. if (spec->dig_in_nid) {
  261. info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
  262. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  263. }
  264. }
  265. return 0;
  266. }
  267. static void ad198x_free(struct hda_codec *codec)
  268. {
  269. struct ad198x_spec *spec = codec->spec;
  270. unsigned int i;
  271. if (spec->kctl_alloc) {
  272. for (i = 0; i < spec->num_kctl_used; i++)
  273. kfree(spec->kctl_alloc[i].name);
  274. kfree(spec->kctl_alloc);
  275. }
  276. kfree(codec->spec);
  277. }
  278. #ifdef CONFIG_PM
  279. static int ad198x_resume(struct hda_codec *codec)
  280. {
  281. struct ad198x_spec *spec = codec->spec;
  282. int i;
  283. codec->patch_ops.init(codec);
  284. for (i = 0; i < spec->num_mixers; i++)
  285. snd_hda_resume_ctls(codec, spec->mixers[i]);
  286. if (spec->multiout.dig_out_nid)
  287. snd_hda_resume_spdif_out(codec);
  288. if (spec->dig_in_nid)
  289. snd_hda_resume_spdif_in(codec);
  290. return 0;
  291. }
  292. #endif
  293. static struct hda_codec_ops ad198x_patch_ops = {
  294. .build_controls = ad198x_build_controls,
  295. .build_pcms = ad198x_build_pcms,
  296. .init = ad198x_init,
  297. .free = ad198x_free,
  298. #ifdef CONFIG_PM
  299. .resume = ad198x_resume,
  300. #endif
  301. };
  302. /*
  303. * EAPD control
  304. * the private value = nid | (invert << 8)
  305. */
  306. static int ad198x_eapd_info(struct snd_kcontrol *kcontrol,
  307. struct snd_ctl_elem_info *uinfo)
  308. {
  309. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  310. uinfo->count = 1;
  311. uinfo->value.integer.min = 0;
  312. uinfo->value.integer.max = 1;
  313. return 0;
  314. }
  315. static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
  316. struct snd_ctl_elem_value *ucontrol)
  317. {
  318. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  319. struct ad198x_spec *spec = codec->spec;
  320. int invert = (kcontrol->private_value >> 8) & 1;
  321. if (invert)
  322. ucontrol->value.integer.value[0] = ! spec->cur_eapd;
  323. else
  324. ucontrol->value.integer.value[0] = spec->cur_eapd;
  325. return 0;
  326. }
  327. static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
  328. struct snd_ctl_elem_value *ucontrol)
  329. {
  330. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  331. struct ad198x_spec *spec = codec->spec;
  332. int invert = (kcontrol->private_value >> 8) & 1;
  333. hda_nid_t nid = kcontrol->private_value & 0xff;
  334. unsigned int eapd;
  335. eapd = ucontrol->value.integer.value[0];
  336. if (invert)
  337. eapd = !eapd;
  338. if (eapd == spec->cur_eapd && ! codec->in_resume)
  339. return 0;
  340. spec->cur_eapd = eapd;
  341. snd_hda_codec_write(codec, nid,
  342. 0, AC_VERB_SET_EAPD_BTLENABLE,
  343. eapd ? 0x02 : 0x00);
  344. return 1;
  345. }
  346. static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
  347. struct snd_ctl_elem_info *uinfo);
  348. static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
  349. struct snd_ctl_elem_value *ucontrol);
  350. static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
  351. struct snd_ctl_elem_value *ucontrol);
  352. /*
  353. * AD1986A specific
  354. */
  355. #define AD1986A_SPDIF_OUT 0x02
  356. #define AD1986A_FRONT_DAC 0x03
  357. #define AD1986A_SURR_DAC 0x04
  358. #define AD1986A_CLFE_DAC 0x05
  359. #define AD1986A_ADC 0x06
  360. static hda_nid_t ad1986a_dac_nids[3] = {
  361. AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
  362. };
  363. static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
  364. static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
  365. static struct hda_input_mux ad1986a_capture_source = {
  366. .num_items = 7,
  367. .items = {
  368. { "Mic", 0x0 },
  369. { "CD", 0x1 },
  370. { "Aux", 0x3 },
  371. { "Line", 0x4 },
  372. { "Mix", 0x5 },
  373. { "Mono", 0x6 },
  374. { "Phone", 0x7 },
  375. },
  376. };
  377. /*
  378. * PCM control
  379. *
  380. * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
  381. */
  382. #define ad1986a_pcm_amp_vol_info snd_hda_mixer_amp_volume_info
  383. static int ad1986a_pcm_amp_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  384. {
  385. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  386. struct ad198x_spec *ad = codec->spec;
  387. mutex_lock(&ad->amp_mutex);
  388. snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
  389. mutex_unlock(&ad->amp_mutex);
  390. return 0;
  391. }
  392. static int ad1986a_pcm_amp_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  393. {
  394. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  395. struct ad198x_spec *ad = codec->spec;
  396. int i, change = 0;
  397. mutex_lock(&ad->amp_mutex);
  398. for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
  399. kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
  400. change |= snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
  401. }
  402. kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
  403. mutex_unlock(&ad->amp_mutex);
  404. return change;
  405. }
  406. #define ad1986a_pcm_amp_sw_info snd_hda_mixer_amp_switch_info
  407. static int ad1986a_pcm_amp_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  408. {
  409. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  410. struct ad198x_spec *ad = codec->spec;
  411. mutex_lock(&ad->amp_mutex);
  412. snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
  413. mutex_unlock(&ad->amp_mutex);
  414. return 0;
  415. }
  416. static int ad1986a_pcm_amp_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  417. {
  418. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  419. struct ad198x_spec *ad = codec->spec;
  420. int i, change = 0;
  421. mutex_lock(&ad->amp_mutex);
  422. for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
  423. kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
  424. change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
  425. }
  426. kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
  427. mutex_unlock(&ad->amp_mutex);
  428. return change;
  429. }
  430. /*
  431. * mixers
  432. */
  433. static struct snd_kcontrol_new ad1986a_mixers[] = {
  434. {
  435. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  436. .name = "PCM Playback Volume",
  437. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  438. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  439. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
  440. .info = ad1986a_pcm_amp_vol_info,
  441. .get = ad1986a_pcm_amp_vol_get,
  442. .put = ad1986a_pcm_amp_vol_put,
  443. .tlv = { .c = snd_hda_mixer_amp_tlv },
  444. .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
  445. },
  446. {
  447. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  448. .name = "PCM Playback Switch",
  449. .info = ad1986a_pcm_amp_sw_info,
  450. .get = ad1986a_pcm_amp_sw_get,
  451. .put = ad1986a_pcm_amp_sw_put,
  452. .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
  453. },
  454. HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  455. HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  456. HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  457. HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  458. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
  459. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
  460. HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
  461. HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
  462. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
  463. HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
  464. HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  465. HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  466. HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
  467. HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
  468. HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
  469. HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  470. HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  471. HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  472. HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
  473. HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
  474. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
  475. HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
  476. HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
  477. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  478. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  479. {
  480. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  481. .name = "Capture Source",
  482. .info = ad198x_mux_enum_info,
  483. .get = ad198x_mux_enum_get,
  484. .put = ad198x_mux_enum_put,
  485. },
  486. HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
  487. { } /* end */
  488. };
  489. /* additional mixers for 3stack mode */
  490. static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
  491. {
  492. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  493. .name = "Channel Mode",
  494. .info = ad198x_ch_mode_info,
  495. .get = ad198x_ch_mode_get,
  496. .put = ad198x_ch_mode_put,
  497. },
  498. { } /* end */
  499. };
  500. /* laptop model - 2ch only */
  501. static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
  502. static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
  503. HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  504. HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
  505. HDA_CODEC_VOLUME("Master Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  506. HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  507. /* HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
  508. HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), */
  509. HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  510. HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  511. HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
  512. HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
  513. HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
  514. HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  515. HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  516. HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  517. HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
  518. /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
  519. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
  520. HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
  521. HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
  522. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  523. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  524. {
  525. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  526. .name = "Capture Source",
  527. .info = ad198x_mux_enum_info,
  528. .get = ad198x_mux_enum_get,
  529. .put = ad198x_mux_enum_put,
  530. },
  531. { } /* end */
  532. };
  533. /* laptop-eapd model - 2ch only */
  534. /* master controls both pins 0x1a and 0x1b */
  535. static int ad1986a_laptop_master_vol_put(struct snd_kcontrol *kcontrol,
  536. struct snd_ctl_elem_value *ucontrol)
  537. {
  538. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  539. long *valp = ucontrol->value.integer.value;
  540. int change;
  541. change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
  542. 0x7f, valp[0] & 0x7f);
  543. change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
  544. 0x7f, valp[1] & 0x7f);
  545. snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
  546. 0x7f, valp[0] & 0x7f);
  547. snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
  548. 0x7f, valp[1] & 0x7f);
  549. return change;
  550. }
  551. static int ad1986a_laptop_master_sw_put(struct snd_kcontrol *kcontrol,
  552. struct snd_ctl_elem_value *ucontrol)
  553. {
  554. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  555. long *valp = ucontrol->value.integer.value;
  556. int change;
  557. change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
  558. 0x80, valp[0] ? 0 : 0x80);
  559. change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
  560. 0x80, valp[1] ? 0 : 0x80);
  561. snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
  562. 0x80, valp[0] ? 0 : 0x80);
  563. snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
  564. 0x80, valp[1] ? 0 : 0x80);
  565. return change;
  566. }
  567. static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
  568. .num_items = 3,
  569. .items = {
  570. { "Mic", 0x0 },
  571. { "Internal Mic", 0x4 },
  572. { "Mix", 0x5 },
  573. },
  574. };
  575. static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
  576. {
  577. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  578. .name = "Master Playback Volume",
  579. .info = snd_hda_mixer_amp_volume_info,
  580. .get = snd_hda_mixer_amp_volume_get,
  581. .put = ad1986a_laptop_master_vol_put,
  582. .tlv = { .c = snd_hda_mixer_amp_tlv },
  583. .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  584. },
  585. {
  586. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  587. .name = "Master Playback Switch",
  588. .info = snd_hda_mixer_amp_switch_info,
  589. .get = snd_hda_mixer_amp_switch_get,
  590. .put = ad1986a_laptop_master_sw_put,
  591. .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  592. },
  593. HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  594. HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
  595. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
  596. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
  597. HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  598. HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  599. HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
  600. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  601. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  602. {
  603. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  604. .name = "Capture Source",
  605. .info = ad198x_mux_enum_info,
  606. .get = ad198x_mux_enum_get,
  607. .put = ad198x_mux_enum_put,
  608. },
  609. {
  610. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  611. .name = "External Amplifier",
  612. .info = ad198x_eapd_info,
  613. .get = ad198x_eapd_get,
  614. .put = ad198x_eapd_put,
  615. .private_value = 0x1b | (1 << 8), /* port-D, inversed */
  616. },
  617. { } /* end */
  618. };
  619. /*
  620. * initialization verbs
  621. */
  622. static struct hda_verb ad1986a_init_verbs[] = {
  623. /* Front, Surround, CLFE DAC; mute as default */
  624. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  625. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  626. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  627. /* Downmix - off */
  628. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  629. /* HP, Line-Out, Surround, CLFE selectors */
  630. {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
  631. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
  632. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  633. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  634. /* Mono selector */
  635. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
  636. /* Mic selector: Mic 1/2 pin */
  637. {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
  638. /* Line-in selector: Line-in */
  639. {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
  640. /* Mic 1/2 swap */
  641. {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
  642. /* Record selector: mic */
  643. {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
  644. /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
  645. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  646. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  647. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  648. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  649. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  650. /* PC beep */
  651. {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
  652. /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
  653. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  654. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  655. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  656. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  657. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  658. /* HP Pin */
  659. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  660. /* Front, Surround, CLFE Pins */
  661. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  662. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  663. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  664. /* Mono Pin */
  665. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  666. /* Mic Pin */
  667. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  668. /* Line, Aux, CD, Beep-In Pin */
  669. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  670. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  671. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  672. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  673. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  674. { } /* end */
  675. };
  676. static struct hda_verb ad1986a_ch2_init[] = {
  677. /* Surround out -> Line In */
  678. { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  679. /* Line-in selectors */
  680. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
  681. /* CLFE -> Mic in */
  682. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  683. /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
  684. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
  685. { } /* end */
  686. };
  687. static struct hda_verb ad1986a_ch4_init[] = {
  688. /* Surround out -> Surround */
  689. { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  690. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  691. /* CLFE -> Mic in */
  692. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  693. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
  694. { } /* end */
  695. };
  696. static struct hda_verb ad1986a_ch6_init[] = {
  697. /* Surround out -> Surround out */
  698. { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  699. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  700. /* CLFE -> CLFE */
  701. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  702. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
  703. { } /* end */
  704. };
  705. static struct hda_channel_mode ad1986a_modes[3] = {
  706. { 2, ad1986a_ch2_init },
  707. { 4, ad1986a_ch4_init },
  708. { 6, ad1986a_ch6_init },
  709. };
  710. /* eapd initialization */
  711. static struct hda_verb ad1986a_eapd_init_verbs[] = {
  712. {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
  713. {}
  714. };
  715. /* Ultra initialization */
  716. static struct hda_verb ad1986a_ultra_init[] = {
  717. /* eapd initialization */
  718. { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
  719. /* CLFE -> Mic in */
  720. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
  721. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  722. { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
  723. { } /* end */
  724. };
  725. /* models */
  726. enum {
  727. AD1986A_6STACK,
  728. AD1986A_3STACK,
  729. AD1986A_LAPTOP,
  730. AD1986A_LAPTOP_EAPD,
  731. AD1986A_ULTRA,
  732. AD1986A_MODELS
  733. };
  734. static const char *ad1986a_models[AD1986A_MODELS] = {
  735. [AD1986A_6STACK] = "6stack",
  736. [AD1986A_3STACK] = "3stack",
  737. [AD1986A_LAPTOP] = "laptop",
  738. [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
  739. [AD1986A_ULTRA] = "ultra",
  740. };
  741. static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
  742. SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
  743. SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
  744. SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
  745. SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
  746. SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
  747. SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
  748. SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
  749. SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
  750. SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
  751. SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
  752. SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
  753. SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
  754. SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
  755. SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
  756. SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
  757. SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
  758. SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
  759. SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
  760. SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
  761. SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
  762. SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
  763. SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
  764. SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
  765. SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
  766. SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_EAPD),
  767. SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
  768. {}
  769. };
  770. static int patch_ad1986a(struct hda_codec *codec)
  771. {
  772. struct ad198x_spec *spec;
  773. int board_config;
  774. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  775. if (spec == NULL)
  776. return -ENOMEM;
  777. mutex_init(&spec->amp_mutex);
  778. codec->spec = spec;
  779. spec->multiout.max_channels = 6;
  780. spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
  781. spec->multiout.dac_nids = ad1986a_dac_nids;
  782. spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
  783. spec->num_adc_nids = 1;
  784. spec->adc_nids = ad1986a_adc_nids;
  785. spec->capsrc_nids = ad1986a_capsrc_nids;
  786. spec->input_mux = &ad1986a_capture_source;
  787. spec->num_mixers = 1;
  788. spec->mixers[0] = ad1986a_mixers;
  789. spec->num_init_verbs = 1;
  790. spec->init_verbs[0] = ad1986a_init_verbs;
  791. codec->patch_ops = ad198x_patch_ops;
  792. /* override some parameters */
  793. board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
  794. ad1986a_models,
  795. ad1986a_cfg_tbl);
  796. switch (board_config) {
  797. case AD1986A_3STACK:
  798. spec->num_mixers = 2;
  799. spec->mixers[1] = ad1986a_3st_mixers;
  800. spec->num_init_verbs = 2;
  801. spec->init_verbs[1] = ad1986a_ch2_init;
  802. spec->channel_mode = ad1986a_modes;
  803. spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
  804. spec->need_dac_fix = 1;
  805. spec->multiout.max_channels = 2;
  806. spec->multiout.num_dacs = 1;
  807. break;
  808. case AD1986A_LAPTOP:
  809. spec->mixers[0] = ad1986a_laptop_mixers;
  810. spec->multiout.max_channels = 2;
  811. spec->multiout.num_dacs = 1;
  812. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  813. break;
  814. case AD1986A_LAPTOP_EAPD:
  815. spec->mixers[0] = ad1986a_laptop_eapd_mixers;
  816. spec->num_init_verbs = 2;
  817. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  818. spec->multiout.max_channels = 2;
  819. spec->multiout.num_dacs = 1;
  820. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  821. spec->multiout.dig_out_nid = 0;
  822. spec->input_mux = &ad1986a_laptop_eapd_capture_source;
  823. break;
  824. case AD1986A_ULTRA:
  825. spec->mixers[0] = ad1986a_laptop_eapd_mixers;
  826. spec->num_init_verbs = 2;
  827. spec->init_verbs[1] = ad1986a_ultra_init;
  828. spec->multiout.max_channels = 2;
  829. spec->multiout.num_dacs = 1;
  830. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  831. spec->multiout.dig_out_nid = 0;
  832. break;
  833. }
  834. return 0;
  835. }
  836. /*
  837. * AD1983 specific
  838. */
  839. #define AD1983_SPDIF_OUT 0x02
  840. #define AD1983_DAC 0x03
  841. #define AD1983_ADC 0x04
  842. static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
  843. static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
  844. static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
  845. static struct hda_input_mux ad1983_capture_source = {
  846. .num_items = 4,
  847. .items = {
  848. { "Mic", 0x0 },
  849. { "Line", 0x1 },
  850. { "Mix", 0x2 },
  851. { "Mix Mono", 0x3 },
  852. },
  853. };
  854. /*
  855. * SPDIF playback route
  856. */
  857. static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  858. {
  859. static char *texts[] = { "PCM", "ADC" };
  860. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  861. uinfo->count = 1;
  862. uinfo->value.enumerated.items = 2;
  863. if (uinfo->value.enumerated.item > 1)
  864. uinfo->value.enumerated.item = 1;
  865. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  866. return 0;
  867. }
  868. static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  869. {
  870. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  871. struct ad198x_spec *spec = codec->spec;
  872. ucontrol->value.enumerated.item[0] = spec->spdif_route;
  873. return 0;
  874. }
  875. static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  876. {
  877. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  878. struct ad198x_spec *spec = codec->spec;
  879. if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
  880. spec->spdif_route = ucontrol->value.enumerated.item[0];
  881. snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
  882. AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
  883. return 1;
  884. }
  885. return 0;
  886. }
  887. static struct snd_kcontrol_new ad1983_mixers[] = {
  888. HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  889. HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  890. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  891. HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  892. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
  893. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
  894. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  895. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  896. HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  897. HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  898. HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  899. HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  900. HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
  901. HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
  902. HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
  903. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  904. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  905. {
  906. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  907. .name = "Capture Source",
  908. .info = ad198x_mux_enum_info,
  909. .get = ad198x_mux_enum_get,
  910. .put = ad198x_mux_enum_put,
  911. },
  912. {
  913. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  914. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  915. .info = ad1983_spdif_route_info,
  916. .get = ad1983_spdif_route_get,
  917. .put = ad1983_spdif_route_put,
  918. },
  919. { } /* end */
  920. };
  921. static struct hda_verb ad1983_init_verbs[] = {
  922. /* Front, HP, Mono; mute as default */
  923. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  924. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  925. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  926. /* Beep, PCM, Mic, Line-In: mute */
  927. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  928. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  929. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  930. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  931. /* Front, HP selectors; from Mix */
  932. {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
  933. {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
  934. /* Mono selector; from Mix */
  935. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
  936. /* Mic selector; Mic */
  937. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  938. /* Line-in selector: Line-in */
  939. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  940. /* Mic boost: 0dB */
  941. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  942. /* Record selector: mic */
  943. {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
  944. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  945. /* SPDIF route: PCM */
  946. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
  947. /* Front Pin */
  948. {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  949. /* HP Pin */
  950. {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  951. /* Mono Pin */
  952. {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  953. /* Mic Pin */
  954. {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  955. /* Line Pin */
  956. {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  957. { } /* end */
  958. };
  959. static int patch_ad1983(struct hda_codec *codec)
  960. {
  961. struct ad198x_spec *spec;
  962. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  963. if (spec == NULL)
  964. return -ENOMEM;
  965. mutex_init(&spec->amp_mutex);
  966. codec->spec = spec;
  967. spec->multiout.max_channels = 2;
  968. spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
  969. spec->multiout.dac_nids = ad1983_dac_nids;
  970. spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
  971. spec->num_adc_nids = 1;
  972. spec->adc_nids = ad1983_adc_nids;
  973. spec->capsrc_nids = ad1983_capsrc_nids;
  974. spec->input_mux = &ad1983_capture_source;
  975. spec->num_mixers = 1;
  976. spec->mixers[0] = ad1983_mixers;
  977. spec->num_init_verbs = 1;
  978. spec->init_verbs[0] = ad1983_init_verbs;
  979. spec->spdif_route = 0;
  980. codec->patch_ops = ad198x_patch_ops;
  981. return 0;
  982. }
  983. /*
  984. * AD1981 HD specific
  985. */
  986. #define AD1981_SPDIF_OUT 0x02
  987. #define AD1981_DAC 0x03
  988. #define AD1981_ADC 0x04
  989. static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
  990. static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
  991. static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
  992. /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
  993. static struct hda_input_mux ad1981_capture_source = {
  994. .num_items = 7,
  995. .items = {
  996. { "Front Mic", 0x0 },
  997. { "Line", 0x1 },
  998. { "Mix", 0x2 },
  999. { "Mix Mono", 0x3 },
  1000. { "CD", 0x4 },
  1001. { "Mic", 0x6 },
  1002. { "Aux", 0x7 },
  1003. },
  1004. };
  1005. static struct snd_kcontrol_new ad1981_mixers[] = {
  1006. HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  1007. HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  1008. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  1009. HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  1010. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
  1011. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
  1012. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  1013. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  1014. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  1015. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  1016. HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1017. HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1018. HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  1019. HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  1020. HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  1021. HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  1022. HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1023. HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1024. HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
  1025. HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
  1026. HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
  1027. HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
  1028. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  1029. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  1030. {
  1031. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1032. .name = "Capture Source",
  1033. .info = ad198x_mux_enum_info,
  1034. .get = ad198x_mux_enum_get,
  1035. .put = ad198x_mux_enum_put,
  1036. },
  1037. /* identical with AD1983 */
  1038. {
  1039. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1040. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  1041. .info = ad1983_spdif_route_info,
  1042. .get = ad1983_spdif_route_get,
  1043. .put = ad1983_spdif_route_put,
  1044. },
  1045. { } /* end */
  1046. };
  1047. static struct hda_verb ad1981_init_verbs[] = {
  1048. /* Front, HP, Mono; mute as default */
  1049. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1050. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1051. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1052. /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
  1053. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1054. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1055. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1056. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1057. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1058. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1059. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1060. /* Front, HP selectors; from Mix */
  1061. {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
  1062. {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
  1063. /* Mono selector; from Mix */
  1064. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
  1065. /* Mic Mixer; select Front Mic */
  1066. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1067. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1068. /* Mic boost: 0dB */
  1069. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1070. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1071. /* Record selector: Front mic */
  1072. {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
  1073. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1074. /* SPDIF route: PCM */
  1075. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
  1076. /* Front Pin */
  1077. {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  1078. /* HP Pin */
  1079. {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  1080. /* Mono Pin */
  1081. {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  1082. /* Front & Rear Mic Pins */
  1083. {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  1084. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  1085. /* Line Pin */
  1086. {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  1087. /* Digital Beep */
  1088. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
  1089. /* Line-Out as Input: disabled */
  1090. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1091. { } /* end */
  1092. };
  1093. /*
  1094. * Patch for HP nx6320
  1095. *
  1096. * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
  1097. * speaker output enabled _and_ mute-LED off.
  1098. */
  1099. #define AD1981_HP_EVENT 0x37
  1100. #define AD1981_MIC_EVENT 0x38
  1101. static struct hda_verb ad1981_hp_init_verbs[] = {
  1102. {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
  1103. /* pin sensing on HP and Mic jacks */
  1104. {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
  1105. {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
  1106. {}
  1107. };
  1108. /* turn on/off EAPD (+ mute HP) as a master switch */
  1109. static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1110. struct snd_ctl_elem_value *ucontrol)
  1111. {
  1112. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1113. struct ad198x_spec *spec = codec->spec;
  1114. if (! ad198x_eapd_put(kcontrol, ucontrol))
  1115. return 0;
  1116. /* toggle HP mute appropriately */
  1117. snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
  1118. 0x80, spec->cur_eapd ? 0 : 0x80);
  1119. snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
  1120. 0x80, spec->cur_eapd ? 0 : 0x80);
  1121. return 1;
  1122. }
  1123. /* bind volumes of both NID 0x05 and 0x06 */
  1124. static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
  1125. struct snd_ctl_elem_value *ucontrol)
  1126. {
  1127. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1128. long *valp = ucontrol->value.integer.value;
  1129. int change;
  1130. change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
  1131. 0x7f, valp[0] & 0x7f);
  1132. change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
  1133. 0x7f, valp[1] & 0x7f);
  1134. snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
  1135. 0x7f, valp[0] & 0x7f);
  1136. snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
  1137. 0x7f, valp[1] & 0x7f);
  1138. return change;
  1139. }
  1140. /* mute internal speaker if HP is plugged */
  1141. static void ad1981_hp_automute(struct hda_codec *codec)
  1142. {
  1143. unsigned int present;
  1144. present = snd_hda_codec_read(codec, 0x06, 0,
  1145. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1146. snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
  1147. 0x80, present ? 0x80 : 0);
  1148. snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
  1149. 0x80, present ? 0x80 : 0);
  1150. }
  1151. /* toggle input of built-in and mic jack appropriately */
  1152. static void ad1981_hp_automic(struct hda_codec *codec)
  1153. {
  1154. static struct hda_verb mic_jack_on[] = {
  1155. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1156. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1157. {}
  1158. };
  1159. static struct hda_verb mic_jack_off[] = {
  1160. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1161. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1162. {}
  1163. };
  1164. unsigned int present;
  1165. present = snd_hda_codec_read(codec, 0x08, 0,
  1166. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1167. if (present)
  1168. snd_hda_sequence_write(codec, mic_jack_on);
  1169. else
  1170. snd_hda_sequence_write(codec, mic_jack_off);
  1171. }
  1172. /* unsolicited event for HP jack sensing */
  1173. static void ad1981_hp_unsol_event(struct hda_codec *codec,
  1174. unsigned int res)
  1175. {
  1176. res >>= 26;
  1177. switch (res) {
  1178. case AD1981_HP_EVENT:
  1179. ad1981_hp_automute(codec);
  1180. break;
  1181. case AD1981_MIC_EVENT:
  1182. ad1981_hp_automic(codec);
  1183. break;
  1184. }
  1185. }
  1186. static struct hda_input_mux ad1981_hp_capture_source = {
  1187. .num_items = 3,
  1188. .items = {
  1189. { "Mic", 0x0 },
  1190. { "Docking-Station", 0x1 },
  1191. { "Mix", 0x2 },
  1192. },
  1193. };
  1194. static struct snd_kcontrol_new ad1981_hp_mixers[] = {
  1195. {
  1196. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1197. .name = "Master Playback Volume",
  1198. .info = snd_hda_mixer_amp_volume_info,
  1199. .get = snd_hda_mixer_amp_volume_get,
  1200. .put = ad1981_hp_master_vol_put,
  1201. .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  1202. },
  1203. {
  1204. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1205. .name = "Master Playback Switch",
  1206. .info = ad198x_eapd_info,
  1207. .get = ad198x_eapd_get,
  1208. .put = ad1981_hp_master_sw_put,
  1209. .private_value = 0x05,
  1210. },
  1211. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  1212. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  1213. #if 0
  1214. /* FIXME: analog mic/line loopback doesn't work with my tests...
  1215. * (although recording is OK)
  1216. */
  1217. HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  1218. HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  1219. HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1220. HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1221. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  1222. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  1223. /* FIXME: does this laptop have analog CD connection? */
  1224. HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1225. HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1226. #endif
  1227. HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
  1228. HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
  1229. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  1230. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  1231. {
  1232. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1233. .name = "Capture Source",
  1234. .info = ad198x_mux_enum_info,
  1235. .get = ad198x_mux_enum_get,
  1236. .put = ad198x_mux_enum_put,
  1237. },
  1238. { } /* end */
  1239. };
  1240. /* initialize jack-sensing, too */
  1241. static int ad1981_hp_init(struct hda_codec *codec)
  1242. {
  1243. ad198x_init(codec);
  1244. ad1981_hp_automute(codec);
  1245. ad1981_hp_automic(codec);
  1246. return 0;
  1247. }
  1248. /* configuration for Toshiba Laptops */
  1249. static struct hda_verb ad1981_toshiba_init_verbs[] = {
  1250. {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
  1251. /* pin sensing on HP and Mic jacks */
  1252. {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
  1253. {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
  1254. {}
  1255. };
  1256. static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
  1257. HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
  1258. HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
  1259. { }
  1260. };
  1261. /* configuration for Lenovo Thinkpad T60 */
  1262. static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
  1263. HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  1264. HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  1265. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  1266. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  1267. HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  1268. HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  1269. HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1270. HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1271. HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
  1272. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  1273. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  1274. {
  1275. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1276. .name = "Capture Source",
  1277. .info = ad198x_mux_enum_info,
  1278. .get = ad198x_mux_enum_get,
  1279. .put = ad198x_mux_enum_put,
  1280. },
  1281. /* identical with AD1983 */
  1282. {
  1283. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1284. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  1285. .info = ad1983_spdif_route_info,
  1286. .get = ad1983_spdif_route_get,
  1287. .put = ad1983_spdif_route_put,
  1288. },
  1289. { } /* end */
  1290. };
  1291. static struct hda_input_mux ad1981_thinkpad_capture_source = {
  1292. .num_items = 3,
  1293. .items = {
  1294. { "Mic", 0x0 },
  1295. { "Mix", 0x2 },
  1296. { "CD", 0x4 },
  1297. },
  1298. };
  1299. /* models */
  1300. enum {
  1301. AD1981_BASIC,
  1302. AD1981_HP,
  1303. AD1981_THINKPAD,
  1304. AD1981_TOSHIBA,
  1305. AD1981_MODELS
  1306. };
  1307. static const char *ad1981_models[AD1981_MODELS] = {
  1308. [AD1981_HP] = "hp",
  1309. [AD1981_THINKPAD] = "thinkpad",
  1310. [AD1981_BASIC] = "basic",
  1311. [AD1981_TOSHIBA] = "toshiba"
  1312. };
  1313. static struct snd_pci_quirk ad1981_cfg_tbl[] = {
  1314. /* All HP models */
  1315. SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
  1316. /* HP nx6320 (reversed SSID, H/W bug) */
  1317. SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
  1318. /* Lenovo Thinkpad T60/X60/Z6xx */
  1319. SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
  1320. SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
  1321. SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
  1322. {}
  1323. };
  1324. static int patch_ad1981(struct hda_codec *codec)
  1325. {
  1326. struct ad198x_spec *spec;
  1327. int board_config;
  1328. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1329. if (spec == NULL)
  1330. return -ENOMEM;
  1331. mutex_init(&spec->amp_mutex);
  1332. codec->spec = spec;
  1333. spec->multiout.max_channels = 2;
  1334. spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
  1335. spec->multiout.dac_nids = ad1981_dac_nids;
  1336. spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
  1337. spec->num_adc_nids = 1;
  1338. spec->adc_nids = ad1981_adc_nids;
  1339. spec->capsrc_nids = ad1981_capsrc_nids;
  1340. spec->input_mux = &ad1981_capture_source;
  1341. spec->num_mixers = 1;
  1342. spec->mixers[0] = ad1981_mixers;
  1343. spec->num_init_verbs = 1;
  1344. spec->init_verbs[0] = ad1981_init_verbs;
  1345. spec->spdif_route = 0;
  1346. codec->patch_ops = ad198x_patch_ops;
  1347. /* override some parameters */
  1348. board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
  1349. ad1981_models,
  1350. ad1981_cfg_tbl);
  1351. switch (board_config) {
  1352. case AD1981_HP:
  1353. spec->mixers[0] = ad1981_hp_mixers;
  1354. spec->num_init_verbs = 2;
  1355. spec->init_verbs[1] = ad1981_hp_init_verbs;
  1356. spec->multiout.dig_out_nid = 0;
  1357. spec->input_mux = &ad1981_hp_capture_source;
  1358. codec->patch_ops.init = ad1981_hp_init;
  1359. codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
  1360. break;
  1361. case AD1981_THINKPAD:
  1362. spec->mixers[0] = ad1981_thinkpad_mixers;
  1363. spec->input_mux = &ad1981_thinkpad_capture_source;
  1364. break;
  1365. case AD1981_TOSHIBA:
  1366. spec->mixers[0] = ad1981_hp_mixers;
  1367. spec->mixers[1] = ad1981_toshiba_mixers;
  1368. spec->num_init_verbs = 2;
  1369. spec->init_verbs[1] = ad1981_toshiba_init_verbs;
  1370. spec->multiout.dig_out_nid = 0;
  1371. spec->input_mux = &ad1981_hp_capture_source;
  1372. codec->patch_ops.init = ad1981_hp_init;
  1373. codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
  1374. break;
  1375. }
  1376. return 0;
  1377. }
  1378. /*
  1379. * AD1988
  1380. *
  1381. * Output pins and routes
  1382. *
  1383. * Pin Mix Sel DAC (*)
  1384. * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
  1385. * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
  1386. * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
  1387. * port-D 0x12 (mute/hp) <- 0x29 <- 04
  1388. * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
  1389. * port-F 0x16 (mute) <- 0x2a <- 06
  1390. * port-G 0x24 (mute) <- 0x27 <- 05
  1391. * port-H 0x25 (mute) <- 0x28 <- 0a
  1392. * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
  1393. *
  1394. * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
  1395. * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
  1396. *
  1397. * Input pins and routes
  1398. *
  1399. * pin boost mix input # / adc input #
  1400. * port-A 0x11 -> 0x38 -> mix 2, ADC 0
  1401. * port-B 0x14 -> 0x39 -> mix 0, ADC 1
  1402. * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
  1403. * port-D 0x12 -> 0x3d -> mix 3, ADC 8
  1404. * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
  1405. * port-F 0x16 -> 0x3b -> mix 5, ADC 3
  1406. * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
  1407. * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
  1408. *
  1409. *
  1410. * DAC assignment
  1411. * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
  1412. * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
  1413. *
  1414. * Inputs of Analog Mix (0x20)
  1415. * 0:Port-B (front mic)
  1416. * 1:Port-C/G/H (line-in)
  1417. * 2:Port-A
  1418. * 3:Port-D (line-in/2)
  1419. * 4:Port-E/G/H (mic-in)
  1420. * 5:Port-F (mic2-in)
  1421. * 6:CD
  1422. * 7:Beep
  1423. *
  1424. * ADC selection
  1425. * 0:Port-A
  1426. * 1:Port-B (front mic-in)
  1427. * 2:Port-C (line-in)
  1428. * 3:Port-F (mic2-in)
  1429. * 4:Port-E (mic-in)
  1430. * 5:CD
  1431. * 6:Port-G
  1432. * 7:Port-H
  1433. * 8:Port-D (line-in/2)
  1434. * 9:Mix
  1435. *
  1436. * Proposed pin assignments by the datasheet
  1437. *
  1438. * 6-stack
  1439. * Port-A front headphone
  1440. * B front mic-in
  1441. * C rear line-in
  1442. * D rear front-out
  1443. * E rear mic-in
  1444. * F rear surround
  1445. * G rear CLFE
  1446. * H rear side
  1447. *
  1448. * 3-stack
  1449. * Port-A front headphone
  1450. * B front mic
  1451. * C rear line-in/surround
  1452. * D rear front-out
  1453. * E rear mic-in/CLFE
  1454. *
  1455. * laptop
  1456. * Port-A headphone
  1457. * B mic-in
  1458. * C docking station
  1459. * D internal speaker (with EAPD)
  1460. * E/F quad mic array
  1461. */
  1462. /* models */
  1463. enum {
  1464. AD1988_6STACK,
  1465. AD1988_6STACK_DIG,
  1466. AD1988_3STACK,
  1467. AD1988_3STACK_DIG,
  1468. AD1988_LAPTOP,
  1469. AD1988_LAPTOP_DIG,
  1470. AD1988_AUTO,
  1471. AD1988_MODEL_LAST,
  1472. };
  1473. /* reivision id to check workarounds */
  1474. #define AD1988A_REV2 0x100200
  1475. #define is_rev2(codec) \
  1476. ((codec)->vendor_id == 0x11d41988 && \
  1477. (codec)->revision_id == AD1988A_REV2)
  1478. /*
  1479. * mixers
  1480. */
  1481. static hda_nid_t ad1988_6stack_dac_nids[4] = {
  1482. 0x04, 0x06, 0x05, 0x0a
  1483. };
  1484. static hda_nid_t ad1988_3stack_dac_nids[3] = {
  1485. 0x04, 0x05, 0x0a
  1486. };
  1487. /* for AD1988A revision-2, DAC2-4 are swapped */
  1488. static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
  1489. 0x04, 0x05, 0x0a, 0x06
  1490. };
  1491. static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
  1492. 0x04, 0x0a, 0x06
  1493. };
  1494. static hda_nid_t ad1988_adc_nids[3] = {
  1495. 0x08, 0x09, 0x0f
  1496. };
  1497. static hda_nid_t ad1988_capsrc_nids[3] = {
  1498. 0x0c, 0x0d, 0x0e
  1499. };
  1500. #define AD1988_SPDIF_OUT 0x02
  1501. #define AD1988_SPDIF_IN 0x07
  1502. static struct hda_input_mux ad1988_6stack_capture_source = {
  1503. .num_items = 5,
  1504. .items = {
  1505. { "Front Mic", 0x0 },
  1506. { "Line", 0x1 },
  1507. { "Mic", 0x4 },
  1508. { "CD", 0x5 },
  1509. { "Mix", 0x9 },
  1510. },
  1511. };
  1512. static struct hda_input_mux ad1988_laptop_capture_source = {
  1513. .num_items = 3,
  1514. .items = {
  1515. { "Mic/Line", 0x0 },
  1516. { "CD", 0x5 },
  1517. { "Mix", 0x9 },
  1518. },
  1519. };
  1520. /*
  1521. */
  1522. static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
  1523. struct snd_ctl_elem_info *uinfo)
  1524. {
  1525. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1526. struct ad198x_spec *spec = codec->spec;
  1527. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  1528. spec->num_channel_mode);
  1529. }
  1530. static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
  1531. struct snd_ctl_elem_value *ucontrol)
  1532. {
  1533. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1534. struct ad198x_spec *spec = codec->spec;
  1535. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  1536. spec->num_channel_mode, spec->multiout.max_channels);
  1537. }
  1538. static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
  1539. struct snd_ctl_elem_value *ucontrol)
  1540. {
  1541. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1542. struct ad198x_spec *spec = codec->spec;
  1543. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  1544. spec->num_channel_mode,
  1545. &spec->multiout.max_channels);
  1546. if (err >= 0 && spec->need_dac_fix)
  1547. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  1548. return err;
  1549. }
  1550. /* 6-stack mode */
  1551. static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
  1552. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1553. HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  1554. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  1555. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  1556. HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  1557. { } /* end */
  1558. };
  1559. static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
  1560. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1561. HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  1562. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
  1563. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
  1564. HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  1565. { } /* end */
  1566. };
  1567. static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
  1568. HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
  1569. HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
  1570. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
  1571. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
  1572. HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
  1573. HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
  1574. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  1575. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  1576. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  1577. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  1578. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  1579. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  1580. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  1581. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
  1582. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
  1583. HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  1584. HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  1585. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  1586. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  1587. HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
  1588. HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
  1589. { } /* end */
  1590. };
  1591. /* 3-stack mode */
  1592. static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
  1593. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1594. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  1595. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  1596. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  1597. { } /* end */
  1598. };
  1599. static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
  1600. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1601. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  1602. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
  1603. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
  1604. { } /* end */
  1605. };
  1606. static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
  1607. HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
  1608. HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
  1609. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
  1610. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
  1611. HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
  1612. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  1613. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  1614. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  1615. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  1616. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  1617. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  1618. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  1619. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
  1620. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
  1621. HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  1622. HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  1623. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  1624. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  1625. HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
  1626. HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
  1627. {
  1628. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1629. .name = "Channel Mode",
  1630. .info = ad198x_ch_mode_info,
  1631. .get = ad198x_ch_mode_get,
  1632. .put = ad198x_ch_mode_put,
  1633. },
  1634. { } /* end */
  1635. };
  1636. /* laptop mode */
  1637. static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
  1638. HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1639. HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
  1640. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  1641. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  1642. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  1643. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  1644. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  1645. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  1646. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  1647. HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  1648. HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  1649. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  1650. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  1651. HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
  1652. {
  1653. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1654. .name = "External Amplifier",
  1655. .info = ad198x_eapd_info,
  1656. .get = ad198x_eapd_get,
  1657. .put = ad198x_eapd_put,
  1658. .private_value = 0x12 | (1 << 8), /* port-D, inversed */
  1659. },
  1660. { } /* end */
  1661. };
  1662. /* capture */
  1663. static struct snd_kcontrol_new ad1988_capture_mixers[] = {
  1664. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  1665. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  1666. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  1667. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  1668. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
  1669. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
  1670. {
  1671. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1672. /* The multiple "Capture Source" controls confuse alsamixer
  1673. * So call somewhat different..
  1674. * FIXME: the controls appear in the "playback" view!
  1675. */
  1676. /* .name = "Capture Source", */
  1677. .name = "Input Source",
  1678. .count = 3,
  1679. .info = ad198x_mux_enum_info,
  1680. .get = ad198x_mux_enum_get,
  1681. .put = ad198x_mux_enum_put,
  1682. },
  1683. { } /* end */
  1684. };
  1685. static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
  1686. struct snd_ctl_elem_info *uinfo)
  1687. {
  1688. static char *texts[] = {
  1689. "PCM", "ADC1", "ADC2", "ADC3"
  1690. };
  1691. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1692. uinfo->count = 1;
  1693. uinfo->value.enumerated.items = 4;
  1694. if (uinfo->value.enumerated.item >= 4)
  1695. uinfo->value.enumerated.item = 3;
  1696. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1697. return 0;
  1698. }
  1699. static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
  1700. struct snd_ctl_elem_value *ucontrol)
  1701. {
  1702. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1703. unsigned int sel;
  1704. sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
  1705. if (sel > 0) {
  1706. sel = snd_hda_codec_read(codec, 0x0b, 0,
  1707. AC_VERB_GET_CONNECT_SEL, 0);
  1708. if (sel < 3)
  1709. sel++;
  1710. else
  1711. sel = 0;
  1712. }
  1713. ucontrol->value.enumerated.item[0] = sel;
  1714. return 0;
  1715. }
  1716. static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
  1717. struct snd_ctl_elem_value *ucontrol)
  1718. {
  1719. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1720. unsigned int val, sel;
  1721. int change;
  1722. val = ucontrol->value.enumerated.item[0];
  1723. sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
  1724. if (!val) {
  1725. change = sel != 0;
  1726. if (change || codec->in_resume)
  1727. snd_hda_codec_write(codec, 0x02, 0,
  1728. AC_VERB_SET_CONNECT_SEL, 0);
  1729. } else {
  1730. change = sel == 0;
  1731. if (change || codec->in_resume)
  1732. snd_hda_codec_write(codec, 0x02, 0,
  1733. AC_VERB_SET_CONNECT_SEL, 1);
  1734. sel = snd_hda_codec_read(codec, 0x0b, 0,
  1735. AC_VERB_GET_CONNECT_SEL, 0) + 1;
  1736. change |= sel != val;
  1737. if (change || codec->in_resume)
  1738. snd_hda_codec_write(codec, 0x0b, 0,
  1739. AC_VERB_SET_CONNECT_SEL, val - 1);
  1740. }
  1741. return change;
  1742. }
  1743. static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
  1744. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  1745. {
  1746. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1747. .name = "IEC958 Playback Source",
  1748. .info = ad1988_spdif_playback_source_info,
  1749. .get = ad1988_spdif_playback_source_get,
  1750. .put = ad1988_spdif_playback_source_put,
  1751. },
  1752. { } /* end */
  1753. };
  1754. static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
  1755. HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
  1756. { } /* end */
  1757. };
  1758. /*
  1759. * initialization verbs
  1760. */
  1761. /*
  1762. * for 6-stack (+dig)
  1763. */
  1764. static struct hda_verb ad1988_6stack_init_verbs[] = {
  1765. /* Front, Surround, CLFE, side DAC; unmute as default */
  1766. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1767. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1768. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1769. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1770. /* Port-A front headphon path */
  1771. {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
  1772. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1773. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1774. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1775. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1776. /* Port-D line-out path */
  1777. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1778. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1779. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1780. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1781. /* Port-F surround path */
  1782. {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1783. {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1784. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1785. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1786. /* Port-G CLFE path */
  1787. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1788. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1789. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1790. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1791. /* Port-H side path */
  1792. {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1793. {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1794. {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1795. {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1796. /* Mono out path */
  1797. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  1798. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1799. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1800. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1801. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  1802. /* Port-B front mic-in path */
  1803. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1804. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1805. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1806. /* Port-C line-in path */
  1807. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1808. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1809. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1810. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  1811. /* Port-E mic-in path */
  1812. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1813. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1814. {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1815. {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
  1816. { }
  1817. };
  1818. static struct hda_verb ad1988_capture_init_verbs[] = {
  1819. /* mute analog mix */
  1820. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1821. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1822. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  1823. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1824. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  1825. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  1826. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  1827. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  1828. /* select ADCs - front-mic */
  1829. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  1830. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  1831. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  1832. /* ADCs; muted */
  1833. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1834. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1835. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1836. { }
  1837. };
  1838. static struct hda_verb ad1988_spdif_init_verbs[] = {
  1839. /* SPDIF out sel */
  1840. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
  1841. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
  1842. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1843. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1844. /* SPDIF out pin */
  1845. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  1846. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x17}, /* 0dB */
  1847. { }
  1848. };
  1849. /*
  1850. * verbs for 3stack (+dig)
  1851. */
  1852. static struct hda_verb ad1988_3stack_ch2_init[] = {
  1853. /* set port-C to line-in */
  1854. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  1855. { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1856. /* set port-E to mic-in */
  1857. { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  1858. { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  1859. { } /* end */
  1860. };
  1861. static struct hda_verb ad1988_3stack_ch6_init[] = {
  1862. /* set port-C to surround out */
  1863. { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  1864. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  1865. /* set port-E to CLFE out */
  1866. { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  1867. { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  1868. { } /* end */
  1869. };
  1870. static struct hda_channel_mode ad1988_3stack_modes[2] = {
  1871. { 2, ad1988_3stack_ch2_init },
  1872. { 6, ad1988_3stack_ch6_init },
  1873. };
  1874. static struct hda_verb ad1988_3stack_init_verbs[] = {
  1875. /* Front, Surround, CLFE, side DAC; unmute as default */
  1876. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1877. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1878. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1879. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1880. /* Port-A front headphon path */
  1881. {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
  1882. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1883. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1884. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1885. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1886. /* Port-D line-out path */
  1887. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1888. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1889. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1890. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1891. /* Mono out path */
  1892. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  1893. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1894. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1895. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1896. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  1897. /* Port-B front mic-in path */
  1898. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1899. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1900. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1901. /* Port-C line-in/surround path - 6ch mode as default */
  1902. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1903. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1904. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1905. {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
  1906. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  1907. /* Port-E mic-in/CLFE path - 6ch mode as default */
  1908. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1909. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1910. {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1911. {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
  1912. {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
  1913. /* mute analog mix */
  1914. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1915. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1916. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  1917. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1918. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  1919. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  1920. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  1921. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  1922. /* select ADCs - front-mic */
  1923. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  1924. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  1925. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  1926. /* ADCs; muted */
  1927. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1928. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1929. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1930. { }
  1931. };
  1932. /*
  1933. * verbs for laptop mode (+dig)
  1934. */
  1935. static struct hda_verb ad1988_laptop_hp_on[] = {
  1936. /* unmute port-A and mute port-D */
  1937. { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  1938. { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  1939. { } /* end */
  1940. };
  1941. static struct hda_verb ad1988_laptop_hp_off[] = {
  1942. /* mute port-A and unmute port-D */
  1943. { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  1944. { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  1945. { } /* end */
  1946. };
  1947. #define AD1988_HP_EVENT 0x01
  1948. static struct hda_verb ad1988_laptop_init_verbs[] = {
  1949. /* Front, Surround, CLFE, side DAC; unmute as default */
  1950. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1951. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1952. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1953. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1954. /* Port-A front headphon path */
  1955. {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
  1956. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1957. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1958. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1959. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1960. /* unsolicited event for pin-sense */
  1961. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
  1962. /* Port-D line-out path + EAPD */
  1963. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1964. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1965. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1966. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1967. {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
  1968. /* Mono out path */
  1969. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  1970. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1971. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1972. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1973. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  1974. /* Port-B mic-in path */
  1975. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1976. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1977. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1978. /* Port-C docking station - try to output */
  1979. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1980. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1981. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1982. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  1983. /* mute analog mix */
  1984. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1985. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1986. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  1987. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1988. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  1989. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  1990. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  1991. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  1992. /* select ADCs - mic */
  1993. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  1994. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  1995. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  1996. /* ADCs; muted */
  1997. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1998. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1999. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2000. { }
  2001. };
  2002. static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
  2003. {
  2004. if ((res >> 26) != AD1988_HP_EVENT)
  2005. return;
  2006. if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
  2007. snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
  2008. else
  2009. snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
  2010. }
  2011. /*
  2012. * Automatic parse of I/O pins from the BIOS configuration
  2013. */
  2014. #define NUM_CONTROL_ALLOC 32
  2015. #define NUM_VERB_ALLOC 32
  2016. enum {
  2017. AD_CTL_WIDGET_VOL,
  2018. AD_CTL_WIDGET_MUTE,
  2019. AD_CTL_BIND_MUTE,
  2020. };
  2021. static struct snd_kcontrol_new ad1988_control_templates[] = {
  2022. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  2023. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  2024. HDA_BIND_MUTE(NULL, 0, 0, 0),
  2025. };
  2026. /* add dynamic controls */
  2027. static int add_control(struct ad198x_spec *spec, int type, const char *name,
  2028. unsigned long val)
  2029. {
  2030. struct snd_kcontrol_new *knew;
  2031. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  2032. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  2033. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
  2034. if (! knew)
  2035. return -ENOMEM;
  2036. if (spec->kctl_alloc) {
  2037. memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
  2038. kfree(spec->kctl_alloc);
  2039. }
  2040. spec->kctl_alloc = knew;
  2041. spec->num_kctl_alloc = num;
  2042. }
  2043. knew = &spec->kctl_alloc[spec->num_kctl_used];
  2044. *knew = ad1988_control_templates[type];
  2045. knew->name = kstrdup(name, GFP_KERNEL);
  2046. if (! knew->name)
  2047. return -ENOMEM;
  2048. knew->private_value = val;
  2049. spec->num_kctl_used++;
  2050. return 0;
  2051. }
  2052. #define AD1988_PIN_CD_NID 0x18
  2053. #define AD1988_PIN_BEEP_NID 0x10
  2054. static hda_nid_t ad1988_mixer_nids[8] = {
  2055. /* A B C D E F G H */
  2056. 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
  2057. };
  2058. static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
  2059. {
  2060. static hda_nid_t idx_to_dac[8] = {
  2061. /* A B C D E F G H */
  2062. 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
  2063. };
  2064. static hda_nid_t idx_to_dac_rev2[8] = {
  2065. /* A B C D E F G H */
  2066. 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
  2067. };
  2068. if (is_rev2(codec))
  2069. return idx_to_dac_rev2[idx];
  2070. else
  2071. return idx_to_dac[idx];
  2072. }
  2073. static hda_nid_t ad1988_boost_nids[8] = {
  2074. 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
  2075. };
  2076. static int ad1988_pin_idx(hda_nid_t nid)
  2077. {
  2078. static hda_nid_t ad1988_io_pins[8] = {
  2079. 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
  2080. };
  2081. int i;
  2082. for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
  2083. if (ad1988_io_pins[i] == nid)
  2084. return i;
  2085. return 0; /* should be -1 */
  2086. }
  2087. static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
  2088. {
  2089. static int loopback_idx[8] = {
  2090. 2, 0, 1, 3, 4, 5, 1, 4
  2091. };
  2092. switch (nid) {
  2093. case AD1988_PIN_CD_NID:
  2094. return 6;
  2095. default:
  2096. return loopback_idx[ad1988_pin_idx(nid)];
  2097. }
  2098. }
  2099. static int ad1988_pin_to_adc_idx(hda_nid_t nid)
  2100. {
  2101. static int adc_idx[8] = {
  2102. 0, 1, 2, 8, 4, 3, 6, 7
  2103. };
  2104. switch (nid) {
  2105. case AD1988_PIN_CD_NID:
  2106. return 5;
  2107. default:
  2108. return adc_idx[ad1988_pin_idx(nid)];
  2109. }
  2110. }
  2111. /* fill in the dac_nids table from the parsed pin configuration */
  2112. static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
  2113. const struct auto_pin_cfg *cfg)
  2114. {
  2115. struct ad198x_spec *spec = codec->spec;
  2116. int i, idx;
  2117. spec->multiout.dac_nids = spec->private_dac_nids;
  2118. /* check the pins hardwired to audio widget */
  2119. for (i = 0; i < cfg->line_outs; i++) {
  2120. idx = ad1988_pin_idx(cfg->line_out_pins[i]);
  2121. spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
  2122. }
  2123. spec->multiout.num_dacs = cfg->line_outs;
  2124. return 0;
  2125. }
  2126. /* add playback controls from the parsed DAC table */
  2127. static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
  2128. const struct auto_pin_cfg *cfg)
  2129. {
  2130. char name[32];
  2131. static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
  2132. hda_nid_t nid;
  2133. int i, err;
  2134. for (i = 0; i < cfg->line_outs; i++) {
  2135. hda_nid_t dac = spec->multiout.dac_nids[i];
  2136. if (! dac)
  2137. continue;
  2138. nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
  2139. if (i == 2) {
  2140. /* Center/LFE */
  2141. err = add_control(spec, AD_CTL_WIDGET_VOL,
  2142. "Center Playback Volume",
  2143. HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
  2144. if (err < 0)
  2145. return err;
  2146. err = add_control(spec, AD_CTL_WIDGET_VOL,
  2147. "LFE Playback Volume",
  2148. HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
  2149. if (err < 0)
  2150. return err;
  2151. err = add_control(spec, AD_CTL_BIND_MUTE,
  2152. "Center Playback Switch",
  2153. HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
  2154. if (err < 0)
  2155. return err;
  2156. err = add_control(spec, AD_CTL_BIND_MUTE,
  2157. "LFE Playback Switch",
  2158. HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
  2159. if (err < 0)
  2160. return err;
  2161. } else {
  2162. sprintf(name, "%s Playback Volume", chname[i]);
  2163. err = add_control(spec, AD_CTL_WIDGET_VOL, name,
  2164. HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
  2165. if (err < 0)
  2166. return err;
  2167. sprintf(name, "%s Playback Switch", chname[i]);
  2168. err = add_control(spec, AD_CTL_BIND_MUTE, name,
  2169. HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
  2170. if (err < 0)
  2171. return err;
  2172. }
  2173. }
  2174. return 0;
  2175. }
  2176. /* add playback controls for speaker and HP outputs */
  2177. static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
  2178. const char *pfx)
  2179. {
  2180. struct ad198x_spec *spec = codec->spec;
  2181. hda_nid_t nid;
  2182. int idx, err;
  2183. char name[32];
  2184. if (! pin)
  2185. return 0;
  2186. idx = ad1988_pin_idx(pin);
  2187. nid = ad1988_idx_to_dac(codec, idx);
  2188. /* specify the DAC as the extra output */
  2189. if (! spec->multiout.hp_nid)
  2190. spec->multiout.hp_nid = nid;
  2191. else
  2192. spec->multiout.extra_out_nid[0] = nid;
  2193. /* control HP volume/switch on the output mixer amp */
  2194. sprintf(name, "%s Playback Volume", pfx);
  2195. if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
  2196. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  2197. return err;
  2198. nid = ad1988_mixer_nids[idx];
  2199. sprintf(name, "%s Playback Switch", pfx);
  2200. if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
  2201. HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
  2202. return err;
  2203. return 0;
  2204. }
  2205. /* create input playback/capture controls for the given pin */
  2206. static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
  2207. const char *ctlname, int boost)
  2208. {
  2209. char name[32];
  2210. int err, idx;
  2211. sprintf(name, "%s Playback Volume", ctlname);
  2212. idx = ad1988_pin_to_loopback_idx(pin);
  2213. if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
  2214. HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
  2215. return err;
  2216. sprintf(name, "%s Playback Switch", ctlname);
  2217. if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
  2218. HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
  2219. return err;
  2220. if (boost) {
  2221. hda_nid_t bnid;
  2222. idx = ad1988_pin_idx(pin);
  2223. bnid = ad1988_boost_nids[idx];
  2224. if (bnid) {
  2225. sprintf(name, "%s Boost", ctlname);
  2226. return add_control(spec, AD_CTL_WIDGET_VOL, name,
  2227. HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
  2228. }
  2229. }
  2230. return 0;
  2231. }
  2232. /* create playback/capture controls for input pins */
  2233. static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
  2234. const struct auto_pin_cfg *cfg)
  2235. {
  2236. struct hda_input_mux *imux = &spec->private_imux;
  2237. int i, err;
  2238. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2239. err = new_analog_input(spec, cfg->input_pins[i],
  2240. auto_pin_cfg_labels[i],
  2241. i <= AUTO_PIN_FRONT_MIC);
  2242. if (err < 0)
  2243. return err;
  2244. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  2245. imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
  2246. imux->num_items++;
  2247. }
  2248. imux->items[imux->num_items].label = "Mix";
  2249. imux->items[imux->num_items].index = 9;
  2250. imux->num_items++;
  2251. if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
  2252. "Analog Mix Playback Volume",
  2253. HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
  2254. return err;
  2255. if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
  2256. "Analog Mix Playback Switch",
  2257. HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
  2258. return err;
  2259. return 0;
  2260. }
  2261. static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
  2262. hda_nid_t nid, int pin_type,
  2263. int dac_idx)
  2264. {
  2265. /* set as output */
  2266. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  2267. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  2268. switch (nid) {
  2269. case 0x11: /* port-A - DAC 04 */
  2270. snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
  2271. break;
  2272. case 0x14: /* port-B - DAC 06 */
  2273. snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
  2274. break;
  2275. case 0x15: /* port-C - DAC 05 */
  2276. snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
  2277. break;
  2278. case 0x17: /* port-E - DAC 0a */
  2279. snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
  2280. break;
  2281. case 0x13: /* mono - DAC 04 */
  2282. snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
  2283. break;
  2284. }
  2285. }
  2286. static void ad1988_auto_init_multi_out(struct hda_codec *codec)
  2287. {
  2288. struct ad198x_spec *spec = codec->spec;
  2289. int i;
  2290. for (i = 0; i < spec->autocfg.line_outs; i++) {
  2291. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  2292. ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
  2293. }
  2294. }
  2295. static void ad1988_auto_init_extra_out(struct hda_codec *codec)
  2296. {
  2297. struct ad198x_spec *spec = codec->spec;
  2298. hda_nid_t pin;
  2299. pin = spec->autocfg.speaker_pins[0];
  2300. if (pin) /* connect to front */
  2301. ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
  2302. pin = spec->autocfg.hp_pins[0];
  2303. if (pin) /* connect to front */
  2304. ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
  2305. }
  2306. static void ad1988_auto_init_analog_input(struct hda_codec *codec)
  2307. {
  2308. struct ad198x_spec *spec = codec->spec;
  2309. int i, idx;
  2310. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2311. hda_nid_t nid = spec->autocfg.input_pins[i];
  2312. if (! nid)
  2313. continue;
  2314. switch (nid) {
  2315. case 0x15: /* port-C */
  2316. snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
  2317. break;
  2318. case 0x17: /* port-E */
  2319. snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
  2320. break;
  2321. }
  2322. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  2323. i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
  2324. if (nid != AD1988_PIN_CD_NID)
  2325. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2326. AMP_OUT_MUTE);
  2327. idx = ad1988_pin_idx(nid);
  2328. if (ad1988_boost_nids[idx])
  2329. snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
  2330. AC_VERB_SET_AMP_GAIN_MUTE,
  2331. AMP_OUT_ZERO);
  2332. }
  2333. }
  2334. /* parse the BIOS configuration and set up the alc_spec */
  2335. /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
  2336. static int ad1988_parse_auto_config(struct hda_codec *codec)
  2337. {
  2338. struct ad198x_spec *spec = codec->spec;
  2339. int err;
  2340. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  2341. return err;
  2342. if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  2343. return err;
  2344. if (! spec->autocfg.line_outs)
  2345. return 0; /* can't find valid BIOS pin config */
  2346. if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
  2347. (err = ad1988_auto_create_extra_out(codec,
  2348. spec->autocfg.speaker_pins[0],
  2349. "Speaker")) < 0 ||
  2350. (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
  2351. "Headphone")) < 0 ||
  2352. (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
  2353. return err;
  2354. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2355. if (spec->autocfg.dig_out_pin)
  2356. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2357. if (spec->autocfg.dig_in_pin)
  2358. spec->dig_in_nid = AD1988_SPDIF_IN;
  2359. if (spec->kctl_alloc)
  2360. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  2361. spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
  2362. spec->input_mux = &spec->private_imux;
  2363. return 1;
  2364. }
  2365. /* init callback for auto-configuration model -- overriding the default init */
  2366. static int ad1988_auto_init(struct hda_codec *codec)
  2367. {
  2368. ad198x_init(codec);
  2369. ad1988_auto_init_multi_out(codec);
  2370. ad1988_auto_init_extra_out(codec);
  2371. ad1988_auto_init_analog_input(codec);
  2372. return 0;
  2373. }
  2374. /*
  2375. */
  2376. static const char *ad1988_models[AD1988_MODEL_LAST] = {
  2377. [AD1988_6STACK] = "6stack",
  2378. [AD1988_6STACK_DIG] = "6stack-dig",
  2379. [AD1988_3STACK] = "3stack",
  2380. [AD1988_3STACK_DIG] = "3stack-dig",
  2381. [AD1988_LAPTOP] = "laptop",
  2382. [AD1988_LAPTOP_DIG] = "laptop-dig",
  2383. [AD1988_AUTO] = "auto",
  2384. };
  2385. static struct snd_pci_quirk ad1988_cfg_tbl[] = {
  2386. SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
  2387. SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
  2388. {}
  2389. };
  2390. static int patch_ad1988(struct hda_codec *codec)
  2391. {
  2392. struct ad198x_spec *spec;
  2393. int board_config;
  2394. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2395. if (spec == NULL)
  2396. return -ENOMEM;
  2397. mutex_init(&spec->amp_mutex);
  2398. codec->spec = spec;
  2399. if (is_rev2(codec))
  2400. snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
  2401. board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
  2402. ad1988_models, ad1988_cfg_tbl);
  2403. if (board_config < 0) {
  2404. printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
  2405. board_config = AD1988_AUTO;
  2406. }
  2407. if (board_config == AD1988_AUTO) {
  2408. /* automatic parse from the BIOS config */
  2409. int err = ad1988_parse_auto_config(codec);
  2410. if (err < 0) {
  2411. ad198x_free(codec);
  2412. return err;
  2413. } else if (! err) {
  2414. printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
  2415. board_config = AD1988_6STACK;
  2416. }
  2417. }
  2418. switch (board_config) {
  2419. case AD1988_6STACK:
  2420. case AD1988_6STACK_DIG:
  2421. spec->multiout.max_channels = 8;
  2422. spec->multiout.num_dacs = 4;
  2423. if (is_rev2(codec))
  2424. spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
  2425. else
  2426. spec->multiout.dac_nids = ad1988_6stack_dac_nids;
  2427. spec->input_mux = &ad1988_6stack_capture_source;
  2428. spec->num_mixers = 2;
  2429. if (is_rev2(codec))
  2430. spec->mixers[0] = ad1988_6stack_mixers1_rev2;
  2431. else
  2432. spec->mixers[0] = ad1988_6stack_mixers1;
  2433. spec->mixers[1] = ad1988_6stack_mixers2;
  2434. spec->num_init_verbs = 1;
  2435. spec->init_verbs[0] = ad1988_6stack_init_verbs;
  2436. if (board_config == AD1988_6STACK_DIG) {
  2437. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2438. spec->dig_in_nid = AD1988_SPDIF_IN;
  2439. }
  2440. break;
  2441. case AD1988_3STACK:
  2442. case AD1988_3STACK_DIG:
  2443. spec->multiout.max_channels = 6;
  2444. spec->multiout.num_dacs = 3;
  2445. if (is_rev2(codec))
  2446. spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
  2447. else
  2448. spec->multiout.dac_nids = ad1988_3stack_dac_nids;
  2449. spec->input_mux = &ad1988_6stack_capture_source;
  2450. spec->channel_mode = ad1988_3stack_modes;
  2451. spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
  2452. spec->num_mixers = 2;
  2453. if (is_rev2(codec))
  2454. spec->mixers[0] = ad1988_3stack_mixers1_rev2;
  2455. else
  2456. spec->mixers[0] = ad1988_3stack_mixers1;
  2457. spec->mixers[1] = ad1988_3stack_mixers2;
  2458. spec->num_init_verbs = 1;
  2459. spec->init_verbs[0] = ad1988_3stack_init_verbs;
  2460. if (board_config == AD1988_3STACK_DIG)
  2461. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2462. break;
  2463. case AD1988_LAPTOP:
  2464. case AD1988_LAPTOP_DIG:
  2465. spec->multiout.max_channels = 2;
  2466. spec->multiout.num_dacs = 1;
  2467. spec->multiout.dac_nids = ad1988_3stack_dac_nids;
  2468. spec->input_mux = &ad1988_laptop_capture_source;
  2469. spec->num_mixers = 1;
  2470. spec->mixers[0] = ad1988_laptop_mixers;
  2471. spec->num_init_verbs = 1;
  2472. spec->init_verbs[0] = ad1988_laptop_init_verbs;
  2473. if (board_config == AD1988_LAPTOP_DIG)
  2474. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2475. break;
  2476. }
  2477. spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
  2478. spec->adc_nids = ad1988_adc_nids;
  2479. spec->capsrc_nids = ad1988_capsrc_nids;
  2480. spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
  2481. spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
  2482. if (spec->multiout.dig_out_nid) {
  2483. spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
  2484. spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
  2485. }
  2486. if (spec->dig_in_nid)
  2487. spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
  2488. codec->patch_ops = ad198x_patch_ops;
  2489. switch (board_config) {
  2490. case AD1988_AUTO:
  2491. codec->patch_ops.init = ad1988_auto_init;
  2492. break;
  2493. case AD1988_LAPTOP:
  2494. case AD1988_LAPTOP_DIG:
  2495. codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
  2496. break;
  2497. }
  2498. return 0;
  2499. }
  2500. /*
  2501. * patch entries
  2502. */
  2503. struct hda_codec_preset snd_hda_preset_analog[] = {
  2504. { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
  2505. { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
  2506. { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
  2507. { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
  2508. { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
  2509. {} /* terminator */
  2510. };