patch_analog.c 84 KB

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