patch_analog.c 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621
  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. { .modelname = "laptop", .config = AD1986A_LAPTOP },
  709. { .pci_subvendor = 0x144d, .pci_subdevice = 0xc01e,
  710. .config = AD1986A_LAPTOP }, /* FSC V2060 */
  711. { .pci_subvendor = 0x17c0, .pci_subdevice = 0x2017,
  712. .config = AD1986A_LAPTOP }, /* Samsung M50 */
  713. { .pci_subvendor = 0x1043, .pci_subdevice = 0x818f,
  714. .config = AD1986A_LAPTOP }, /* ASUS P5GV-MX */
  715. { .modelname = "laptop-eapd", .config = AD1986A_LAPTOP_EAPD },
  716. { .pci_subvendor = 0x144d, .pci_subdevice = 0xc024,
  717. .config = AD1986A_LAPTOP_EAPD }, /* Samsung R65-T2300 Charis */
  718. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1213,
  719. .config = AD1986A_LAPTOP_EAPD }, /* ASUS A6J */
  720. {}
  721. };
  722. static int patch_ad1986a(struct hda_codec *codec)
  723. {
  724. struct ad198x_spec *spec;
  725. int board_config;
  726. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  727. if (spec == NULL)
  728. return -ENOMEM;
  729. mutex_init(&spec->amp_mutex);
  730. codec->spec = spec;
  731. spec->multiout.max_channels = 6;
  732. spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
  733. spec->multiout.dac_nids = ad1986a_dac_nids;
  734. spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
  735. spec->num_adc_nids = 1;
  736. spec->adc_nids = ad1986a_adc_nids;
  737. spec->capsrc_nids = ad1986a_capsrc_nids;
  738. spec->input_mux = &ad1986a_capture_source;
  739. spec->num_mixers = 1;
  740. spec->mixers[0] = ad1986a_mixers;
  741. spec->num_init_verbs = 1;
  742. spec->init_verbs[0] = ad1986a_init_verbs;
  743. codec->patch_ops = ad198x_patch_ops;
  744. /* override some parameters */
  745. board_config = snd_hda_check_board_config(codec, ad1986a_cfg_tbl);
  746. switch (board_config) {
  747. case AD1986A_3STACK:
  748. spec->num_mixers = 2;
  749. spec->mixers[1] = ad1986a_3st_mixers;
  750. spec->num_init_verbs = 3;
  751. spec->init_verbs[1] = ad1986a_3st_init_verbs;
  752. spec->init_verbs[2] = ad1986a_ch2_init;
  753. spec->channel_mode = ad1986a_modes;
  754. spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
  755. spec->need_dac_fix = 1;
  756. spec->multiout.max_channels = 2;
  757. spec->multiout.num_dacs = 1;
  758. break;
  759. case AD1986A_LAPTOP:
  760. spec->mixers[0] = ad1986a_laptop_mixers;
  761. spec->multiout.max_channels = 2;
  762. spec->multiout.num_dacs = 1;
  763. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  764. break;
  765. case AD1986A_LAPTOP_EAPD:
  766. spec->mixers[0] = ad1986a_laptop_eapd_mixers;
  767. spec->num_init_verbs = 2;
  768. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  769. spec->multiout.max_channels = 2;
  770. spec->multiout.num_dacs = 1;
  771. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  772. spec->multiout.dig_out_nid = 0;
  773. spec->input_mux = &ad1986a_laptop_eapd_capture_source;
  774. break;
  775. }
  776. return 0;
  777. }
  778. /*
  779. * AD1983 specific
  780. */
  781. #define AD1983_SPDIF_OUT 0x02
  782. #define AD1983_DAC 0x03
  783. #define AD1983_ADC 0x04
  784. static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
  785. static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
  786. static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
  787. static struct hda_input_mux ad1983_capture_source = {
  788. .num_items = 4,
  789. .items = {
  790. { "Mic", 0x0 },
  791. { "Line", 0x1 },
  792. { "Mix", 0x2 },
  793. { "Mix Mono", 0x3 },
  794. },
  795. };
  796. /*
  797. * SPDIF playback route
  798. */
  799. static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  800. {
  801. static char *texts[] = { "PCM", "ADC" };
  802. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  803. uinfo->count = 1;
  804. uinfo->value.enumerated.items = 2;
  805. if (uinfo->value.enumerated.item > 1)
  806. uinfo->value.enumerated.item = 1;
  807. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  808. return 0;
  809. }
  810. static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  811. {
  812. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  813. struct ad198x_spec *spec = codec->spec;
  814. ucontrol->value.enumerated.item[0] = spec->spdif_route;
  815. return 0;
  816. }
  817. static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  818. {
  819. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  820. struct ad198x_spec *spec = codec->spec;
  821. if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
  822. spec->spdif_route = ucontrol->value.enumerated.item[0];
  823. snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
  824. AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
  825. return 1;
  826. }
  827. return 0;
  828. }
  829. static struct snd_kcontrol_new ad1983_mixers[] = {
  830. HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  831. HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  832. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  833. HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  834. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
  835. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
  836. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  837. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  838. HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  839. HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  840. HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  841. HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  842. HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
  843. HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
  844. HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
  845. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  846. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  847. {
  848. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  849. .name = "Capture Source",
  850. .info = ad198x_mux_enum_info,
  851. .get = ad198x_mux_enum_get,
  852. .put = ad198x_mux_enum_put,
  853. },
  854. {
  855. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  856. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
  857. .info = ad1983_spdif_route_info,
  858. .get = ad1983_spdif_route_get,
  859. .put = ad1983_spdif_route_put,
  860. },
  861. { } /* end */
  862. };
  863. static struct hda_verb ad1983_init_verbs[] = {
  864. /* Front, HP, Mono; mute as default */
  865. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  866. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  867. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  868. /* Beep, PCM, Mic, Line-In: mute */
  869. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  870. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  871. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  872. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  873. /* Front, HP selectors; from Mix */
  874. {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
  875. {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
  876. /* Mono selector; from Mix */
  877. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
  878. /* Mic selector; Mic */
  879. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  880. /* Line-in selector: Line-in */
  881. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  882. /* Mic boost: 0dB */
  883. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  884. /* Record selector: mic */
  885. {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
  886. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  887. /* SPDIF route: PCM */
  888. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
  889. /* Front Pin */
  890. {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  891. /* HP Pin */
  892. {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  893. /* Mono Pin */
  894. {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  895. /* Mic Pin */
  896. {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  897. /* Line Pin */
  898. {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  899. { } /* end */
  900. };
  901. static int patch_ad1983(struct hda_codec *codec)
  902. {
  903. struct ad198x_spec *spec;
  904. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  905. if (spec == NULL)
  906. return -ENOMEM;
  907. mutex_init(&spec->amp_mutex);
  908. codec->spec = spec;
  909. spec->multiout.max_channels = 2;
  910. spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
  911. spec->multiout.dac_nids = ad1983_dac_nids;
  912. spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
  913. spec->num_adc_nids = 1;
  914. spec->adc_nids = ad1983_adc_nids;
  915. spec->capsrc_nids = ad1983_capsrc_nids;
  916. spec->input_mux = &ad1983_capture_source;
  917. spec->num_mixers = 1;
  918. spec->mixers[0] = ad1983_mixers;
  919. spec->num_init_verbs = 1;
  920. spec->init_verbs[0] = ad1983_init_verbs;
  921. spec->spdif_route = 0;
  922. codec->patch_ops = ad198x_patch_ops;
  923. return 0;
  924. }
  925. /*
  926. * AD1981 HD specific
  927. */
  928. #define AD1981_SPDIF_OUT 0x02
  929. #define AD1981_DAC 0x03
  930. #define AD1981_ADC 0x04
  931. static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
  932. static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
  933. static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
  934. /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
  935. static struct hda_input_mux ad1981_capture_source = {
  936. .num_items = 7,
  937. .items = {
  938. { "Front Mic", 0x0 },
  939. { "Line", 0x1 },
  940. { "Mix", 0x2 },
  941. { "Mix Mono", 0x3 },
  942. { "CD", 0x4 },
  943. { "Mic", 0x6 },
  944. { "Aux", 0x7 },
  945. },
  946. };
  947. static struct snd_kcontrol_new ad1981_mixers[] = {
  948. HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  949. HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  950. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  951. HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  952. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
  953. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
  954. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  955. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  956. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  957. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  958. HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  959. HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  960. HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  961. HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  962. HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  963. HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  964. HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  965. HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  966. HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
  967. HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
  968. HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
  969. HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
  970. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  971. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  972. {
  973. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  974. .name = "Capture Source",
  975. .info = ad198x_mux_enum_info,
  976. .get = ad198x_mux_enum_get,
  977. .put = ad198x_mux_enum_put,
  978. },
  979. /* identical with AD1983 */
  980. {
  981. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  982. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
  983. .info = ad1983_spdif_route_info,
  984. .get = ad1983_spdif_route_get,
  985. .put = ad1983_spdif_route_put,
  986. },
  987. { } /* end */
  988. };
  989. static struct hda_verb ad1981_init_verbs[] = {
  990. /* Front, HP, Mono; mute as default */
  991. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  992. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  993. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  994. /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
  995. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  996. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  997. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  998. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  999. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1000. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1001. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1002. /* Front, HP selectors; from Mix */
  1003. {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
  1004. {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
  1005. /* Mono selector; from Mix */
  1006. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
  1007. /* Mic Mixer; select Front Mic */
  1008. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1009. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1010. /* Mic boost: 0dB */
  1011. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1012. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1013. /* Record selector: Front mic */
  1014. {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
  1015. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1016. /* SPDIF route: PCM */
  1017. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
  1018. /* Front Pin */
  1019. {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  1020. /* HP Pin */
  1021. {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  1022. /* Mono Pin */
  1023. {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  1024. /* Front & Rear Mic Pins */
  1025. {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  1026. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  1027. /* Line Pin */
  1028. {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  1029. /* Digital Beep */
  1030. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
  1031. /* Line-Out as Input: disabled */
  1032. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1033. { } /* end */
  1034. };
  1035. /*
  1036. * Patch for HP nx6320
  1037. *
  1038. * nx6320 uses EAPD in the reserve way - EAPD-on means the internal
  1039. * speaker output enabled _and_ mute-LED off.
  1040. */
  1041. #define AD1981_HP_EVENT 0x37
  1042. #define AD1981_MIC_EVENT 0x38
  1043. static struct hda_verb ad1981_hp_init_verbs[] = {
  1044. {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
  1045. /* pin sensing on HP and Mic jacks */
  1046. {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
  1047. {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
  1048. {}
  1049. };
  1050. /* turn on/off EAPD (+ mute HP) as a master switch */
  1051. static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1052. struct snd_ctl_elem_value *ucontrol)
  1053. {
  1054. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1055. struct ad198x_spec *spec = codec->spec;
  1056. if (! ad198x_eapd_put(kcontrol, ucontrol))
  1057. return 0;
  1058. /* toggle HP mute appropriately */
  1059. snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
  1060. 0x80, spec->cur_eapd ? 0 : 0x80);
  1061. snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
  1062. 0x80, spec->cur_eapd ? 0 : 0x80);
  1063. return 1;
  1064. }
  1065. /* bind volumes of both NID 0x05 and 0x06 */
  1066. static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
  1067. struct snd_ctl_elem_value *ucontrol)
  1068. {
  1069. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1070. long *valp = ucontrol->value.integer.value;
  1071. int change;
  1072. change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
  1073. 0x7f, valp[0] & 0x7f);
  1074. change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
  1075. 0x7f, valp[1] & 0x7f);
  1076. snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
  1077. 0x7f, valp[0] & 0x7f);
  1078. snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
  1079. 0x7f, valp[1] & 0x7f);
  1080. return change;
  1081. }
  1082. /* mute internal speaker if HP is plugged */
  1083. static void ad1981_hp_automute(struct hda_codec *codec)
  1084. {
  1085. unsigned int present;
  1086. present = snd_hda_codec_read(codec, 0x06, 0,
  1087. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1088. snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
  1089. 0x80, present ? 0x80 : 0);
  1090. snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
  1091. 0x80, present ? 0x80 : 0);
  1092. }
  1093. /* toggle input of built-in and mic jack appropriately */
  1094. static void ad1981_hp_automic(struct hda_codec *codec)
  1095. {
  1096. static struct hda_verb mic_jack_on[] = {
  1097. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1098. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1099. {}
  1100. };
  1101. static struct hda_verb mic_jack_off[] = {
  1102. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1103. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1104. {}
  1105. };
  1106. unsigned int present;
  1107. present = snd_hda_codec_read(codec, 0x08, 0,
  1108. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1109. if (present)
  1110. snd_hda_sequence_write(codec, mic_jack_on);
  1111. else
  1112. snd_hda_sequence_write(codec, mic_jack_off);
  1113. }
  1114. /* unsolicited event for HP jack sensing */
  1115. static void ad1981_hp_unsol_event(struct hda_codec *codec,
  1116. unsigned int res)
  1117. {
  1118. res >>= 26;
  1119. switch (res) {
  1120. case AD1981_HP_EVENT:
  1121. ad1981_hp_automute(codec);
  1122. break;
  1123. case AD1981_MIC_EVENT:
  1124. ad1981_hp_automic(codec);
  1125. break;
  1126. }
  1127. }
  1128. static struct hda_input_mux ad1981_hp_capture_source = {
  1129. .num_items = 3,
  1130. .items = {
  1131. { "Mic", 0x0 },
  1132. { "Docking-Station", 0x1 },
  1133. { "Mix", 0x2 },
  1134. },
  1135. };
  1136. static struct snd_kcontrol_new ad1981_hp_mixers[] = {
  1137. {
  1138. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1139. .name = "Master Playback Volume",
  1140. .info = snd_hda_mixer_amp_volume_info,
  1141. .get = snd_hda_mixer_amp_volume_get,
  1142. .put = ad1981_hp_master_vol_put,
  1143. .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  1144. },
  1145. {
  1146. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1147. .name = "Master Playback Switch",
  1148. .info = ad198x_eapd_info,
  1149. .get = ad198x_eapd_get,
  1150. .put = ad1981_hp_master_sw_put,
  1151. .private_value = 0x05,
  1152. },
  1153. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  1154. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  1155. #if 0
  1156. /* FIXME: analog mic/line loopback doesn't work with my tests...
  1157. * (although recording is OK)
  1158. */
  1159. HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  1160. HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  1161. HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1162. HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1163. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  1164. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  1165. /* FIXME: does this laptop have analog CD connection? */
  1166. HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1167. HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1168. #endif
  1169. HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
  1170. HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
  1171. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  1172. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  1173. {
  1174. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1175. .name = "Capture Source",
  1176. .info = ad198x_mux_enum_info,
  1177. .get = ad198x_mux_enum_get,
  1178. .put = ad198x_mux_enum_put,
  1179. },
  1180. { } /* end */
  1181. };
  1182. /* initialize jack-sensing, too */
  1183. static int ad1981_hp_init(struct hda_codec *codec)
  1184. {
  1185. ad198x_init(codec);
  1186. ad1981_hp_automute(codec);
  1187. ad1981_hp_automic(codec);
  1188. return 0;
  1189. }
  1190. /* models */
  1191. enum { AD1981_BASIC, AD1981_HP };
  1192. static struct hda_board_config ad1981_cfg_tbl[] = {
  1193. { .modelname = "hp", .config = AD1981_HP },
  1194. { .pci_subvendor = 0x103c, .pci_subdevice = 0x30aa,
  1195. .config = AD1981_HP }, /* HP nx6320 */
  1196. { .pci_subvendor = 0x103c, .pci_subdevice = 0x309f,
  1197. .config = AD1981_HP }, /* HP nx9420 AngelFire */
  1198. { .modelname = "basic", .config = AD1981_BASIC },
  1199. {}
  1200. };
  1201. static int patch_ad1981(struct hda_codec *codec)
  1202. {
  1203. struct ad198x_spec *spec;
  1204. int board_config;
  1205. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1206. if (spec == NULL)
  1207. return -ENOMEM;
  1208. mutex_init(&spec->amp_mutex);
  1209. codec->spec = spec;
  1210. spec->multiout.max_channels = 2;
  1211. spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
  1212. spec->multiout.dac_nids = ad1981_dac_nids;
  1213. spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
  1214. spec->num_adc_nids = 1;
  1215. spec->adc_nids = ad1981_adc_nids;
  1216. spec->capsrc_nids = ad1981_capsrc_nids;
  1217. spec->input_mux = &ad1981_capture_source;
  1218. spec->num_mixers = 1;
  1219. spec->mixers[0] = ad1981_mixers;
  1220. spec->num_init_verbs = 1;
  1221. spec->init_verbs[0] = ad1981_init_verbs;
  1222. spec->spdif_route = 0;
  1223. codec->patch_ops = ad198x_patch_ops;
  1224. /* override some parameters */
  1225. board_config = snd_hda_check_board_config(codec, ad1981_cfg_tbl);
  1226. switch (board_config) {
  1227. case AD1981_HP:
  1228. spec->mixers[0] = ad1981_hp_mixers;
  1229. spec->num_init_verbs = 2;
  1230. spec->init_verbs[1] = ad1981_hp_init_verbs;
  1231. spec->multiout.dig_out_nid = 0;
  1232. spec->input_mux = &ad1981_hp_capture_source;
  1233. codec->patch_ops.init = ad1981_hp_init;
  1234. codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
  1235. break;
  1236. }
  1237. return 0;
  1238. }
  1239. /*
  1240. * AD1988
  1241. *
  1242. * Output pins and routes
  1243. *
  1244. * Pin Mix Sel DAC (*)
  1245. * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
  1246. * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
  1247. * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
  1248. * port-D 0x12 (mute/hp) <- 0x29 <- 04
  1249. * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
  1250. * port-F 0x16 (mute) <- 0x2a <- 06
  1251. * port-G 0x24 (mute) <- 0x27 <- 05
  1252. * port-H 0x25 (mute) <- 0x28 <- 0a
  1253. * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
  1254. *
  1255. * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
  1256. * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
  1257. *
  1258. * Input pins and routes
  1259. *
  1260. * pin boost mix input # / adc input #
  1261. * port-A 0x11 -> 0x38 -> mix 2, ADC 0
  1262. * port-B 0x14 -> 0x39 -> mix 0, ADC 1
  1263. * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
  1264. * port-D 0x12 -> 0x3d -> mix 3, ADC 8
  1265. * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
  1266. * port-F 0x16 -> 0x3b -> mix 5, ADC 3
  1267. * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
  1268. * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
  1269. *
  1270. *
  1271. * DAC assignment
  1272. * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
  1273. * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
  1274. *
  1275. * Inputs of Analog Mix (0x20)
  1276. * 0:Port-B (front mic)
  1277. * 1:Port-C/G/H (line-in)
  1278. * 2:Port-A
  1279. * 3:Port-D (line-in/2)
  1280. * 4:Port-E/G/H (mic-in)
  1281. * 5:Port-F (mic2-in)
  1282. * 6:CD
  1283. * 7:Beep
  1284. *
  1285. * ADC selection
  1286. * 0:Port-A
  1287. * 1:Port-B (front mic-in)
  1288. * 2:Port-C (line-in)
  1289. * 3:Port-F (mic2-in)
  1290. * 4:Port-E (mic-in)
  1291. * 5:CD
  1292. * 6:Port-G
  1293. * 7:Port-H
  1294. * 8:Port-D (line-in/2)
  1295. * 9:Mix
  1296. *
  1297. * Proposed pin assignments by the datasheet
  1298. *
  1299. * 6-stack
  1300. * Port-A front headphone
  1301. * B front mic-in
  1302. * C rear line-in
  1303. * D rear front-out
  1304. * E rear mic-in
  1305. * F rear surround
  1306. * G rear CLFE
  1307. * H rear side
  1308. *
  1309. * 3-stack
  1310. * Port-A front headphone
  1311. * B front mic
  1312. * C rear line-in/surround
  1313. * D rear front-out
  1314. * E rear mic-in/CLFE
  1315. *
  1316. * laptop
  1317. * Port-A headphone
  1318. * B mic-in
  1319. * C docking station
  1320. * D internal speaker (with EAPD)
  1321. * E/F quad mic array
  1322. */
  1323. /* models */
  1324. enum {
  1325. AD1988_6STACK,
  1326. AD1988_6STACK_DIG,
  1327. AD1988_3STACK,
  1328. AD1988_3STACK_DIG,
  1329. AD1988_LAPTOP,
  1330. AD1988_LAPTOP_DIG,
  1331. AD1988_AUTO,
  1332. AD1988_MODEL_LAST,
  1333. };
  1334. /* reivision id to check workarounds */
  1335. #define AD1988A_REV2 0x100200
  1336. /*
  1337. * mixers
  1338. */
  1339. static hda_nid_t ad1988_6stack_dac_nids[4] = {
  1340. 0x04, 0x06, 0x05, 0x0a
  1341. };
  1342. static hda_nid_t ad1988_3stack_dac_nids[3] = {
  1343. 0x04, 0x05, 0x0a
  1344. };
  1345. /* for AD1988A revision-2, DAC2-4 are swapped */
  1346. static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
  1347. 0x04, 0x05, 0x0a, 0x06
  1348. };
  1349. static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
  1350. 0x04, 0x0a, 0x06
  1351. };
  1352. static hda_nid_t ad1988_adc_nids[3] = {
  1353. 0x08, 0x09, 0x0f
  1354. };
  1355. static hda_nid_t ad1988_capsrc_nids[3] = {
  1356. 0x0c, 0x0d, 0x0e
  1357. };
  1358. #define AD1988_SPDIF_OUT 0x02
  1359. #define AD1988_SPDIF_IN 0x07
  1360. static struct hda_input_mux ad1988_6stack_capture_source = {
  1361. .num_items = 5,
  1362. .items = {
  1363. { "Front Mic", 0x0 },
  1364. { "Line", 0x1 },
  1365. { "Mic", 0x4 },
  1366. { "CD", 0x5 },
  1367. { "Mix", 0x9 },
  1368. },
  1369. };
  1370. static struct hda_input_mux ad1988_laptop_capture_source = {
  1371. .num_items = 3,
  1372. .items = {
  1373. { "Mic/Line", 0x0 },
  1374. { "CD", 0x5 },
  1375. { "Mix", 0x9 },
  1376. },
  1377. };
  1378. /*
  1379. */
  1380. static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
  1381. struct snd_ctl_elem_info *uinfo)
  1382. {
  1383. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1384. struct ad198x_spec *spec = codec->spec;
  1385. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  1386. spec->num_channel_mode);
  1387. }
  1388. static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
  1389. struct snd_ctl_elem_value *ucontrol)
  1390. {
  1391. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1392. struct ad198x_spec *spec = codec->spec;
  1393. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  1394. spec->num_channel_mode, spec->multiout.max_channels);
  1395. }
  1396. static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
  1397. struct snd_ctl_elem_value *ucontrol)
  1398. {
  1399. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1400. struct ad198x_spec *spec = codec->spec;
  1401. if (spec->need_dac_fix)
  1402. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  1403. return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  1404. spec->num_channel_mode, &spec->multiout.max_channels);
  1405. }
  1406. /* 6-stack mode */
  1407. static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
  1408. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1409. HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  1410. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  1411. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  1412. HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  1413. };
  1414. static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
  1415. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1416. HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  1417. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
  1418. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
  1419. HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  1420. };
  1421. static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
  1422. HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
  1423. HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
  1424. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
  1425. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
  1426. HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
  1427. HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
  1428. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  1429. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  1430. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  1431. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  1432. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  1433. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  1434. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  1435. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
  1436. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
  1437. HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  1438. HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  1439. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  1440. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  1441. HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
  1442. HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
  1443. { } /* end */
  1444. };
  1445. /* 3-stack mode */
  1446. static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
  1447. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1448. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  1449. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  1450. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  1451. };
  1452. static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
  1453. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1454. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  1455. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
  1456. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
  1457. };
  1458. static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
  1459. HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
  1460. HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
  1461. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
  1462. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
  1463. HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
  1464. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  1465. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  1466. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  1467. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  1468. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  1469. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  1470. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  1471. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
  1472. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
  1473. HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  1474. HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  1475. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  1476. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  1477. HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
  1478. HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
  1479. {
  1480. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1481. .name = "Channel Mode",
  1482. .info = ad198x_ch_mode_info,
  1483. .get = ad198x_ch_mode_get,
  1484. .put = ad198x_ch_mode_put,
  1485. },
  1486. { } /* end */
  1487. };
  1488. /* laptop mode */
  1489. static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
  1490. HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  1491. HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
  1492. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  1493. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  1494. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  1495. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  1496. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  1497. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  1498. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  1499. HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  1500. HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  1501. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  1502. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  1503. HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
  1504. {
  1505. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1506. .name = "External Amplifier",
  1507. .info = ad198x_eapd_info,
  1508. .get = ad198x_eapd_get,
  1509. .put = ad198x_eapd_put,
  1510. .private_value = 0x12 | (1 << 8), /* port-D, inversed */
  1511. },
  1512. { } /* end */
  1513. };
  1514. /* capture */
  1515. static struct snd_kcontrol_new ad1988_capture_mixers[] = {
  1516. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  1517. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  1518. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  1519. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  1520. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
  1521. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
  1522. {
  1523. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1524. /* The multiple "Capture Source" controls confuse alsamixer
  1525. * So call somewhat different..
  1526. * FIXME: the controls appear in the "playback" view!
  1527. */
  1528. /* .name = "Capture Source", */
  1529. .name = "Input Source",
  1530. .count = 3,
  1531. .info = ad198x_mux_enum_info,
  1532. .get = ad198x_mux_enum_get,
  1533. .put = ad198x_mux_enum_put,
  1534. },
  1535. { } /* end */
  1536. };
  1537. static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
  1538. struct snd_ctl_elem_info *uinfo)
  1539. {
  1540. static char *texts[] = {
  1541. "PCM", "ADC1", "ADC2", "ADC3"
  1542. };
  1543. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1544. uinfo->count = 1;
  1545. uinfo->value.enumerated.items = 4;
  1546. if (uinfo->value.enumerated.item >= 4)
  1547. uinfo->value.enumerated.item = 3;
  1548. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1549. return 0;
  1550. }
  1551. static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
  1552. struct snd_ctl_elem_value *ucontrol)
  1553. {
  1554. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1555. unsigned int sel;
  1556. sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
  1557. if (sel > 0) {
  1558. sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0);
  1559. if (sel <= 3)
  1560. sel++;
  1561. else
  1562. sel = 0;
  1563. }
  1564. ucontrol->value.enumerated.item[0] = sel;
  1565. return 0;
  1566. }
  1567. static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
  1568. struct snd_ctl_elem_value *ucontrol)
  1569. {
  1570. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1571. unsigned int sel;
  1572. int change;
  1573. sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
  1574. if (! ucontrol->value.enumerated.item[0]) {
  1575. change = sel != 0;
  1576. if (change)
  1577. snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 0);
  1578. } else {
  1579. change = sel == 0;
  1580. if (change)
  1581. snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 1);
  1582. sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0) + 1;
  1583. change |= sel == ucontrol->value.enumerated.item[0];
  1584. if (change)
  1585. snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL,
  1586. ucontrol->value.enumerated.item[0] - 1);
  1587. }
  1588. return change;
  1589. }
  1590. static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
  1591. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  1592. {
  1593. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1594. .name = "IEC958 Playback Source",
  1595. .info = ad1988_spdif_playback_source_info,
  1596. .get = ad1988_spdif_playback_source_get,
  1597. .put = ad1988_spdif_playback_source_put,
  1598. },
  1599. { } /* end */
  1600. };
  1601. static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
  1602. HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
  1603. { } /* end */
  1604. };
  1605. /*
  1606. * initialization verbs
  1607. */
  1608. /*
  1609. * for 6-stack (+dig)
  1610. */
  1611. static struct hda_verb ad1988_6stack_init_verbs[] = {
  1612. /* Front, Surround, CLFE, side DAC; unmute as default */
  1613. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1614. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1615. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1616. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1617. /* Port-A front headphon path */
  1618. {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
  1619. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1620. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1621. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1622. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1623. /* Port-D line-out path */
  1624. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1625. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1626. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1627. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1628. /* Port-F surround path */
  1629. {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1630. {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1631. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1632. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1633. /* Port-G CLFE path */
  1634. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1635. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1636. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1637. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1638. /* Port-H side path */
  1639. {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1640. {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1641. {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1642. {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1643. /* Mono out path */
  1644. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  1645. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1646. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1647. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1648. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  1649. /* Port-B front mic-in path */
  1650. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1651. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1652. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1653. /* Port-C line-in path */
  1654. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1655. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1656. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1657. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  1658. /* Port-E mic-in path */
  1659. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1660. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1661. {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1662. {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
  1663. { }
  1664. };
  1665. static struct hda_verb ad1988_capture_init_verbs[] = {
  1666. /* mute analog mix */
  1667. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1668. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1669. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  1670. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1671. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  1672. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  1673. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  1674. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  1675. /* select ADCs - front-mic */
  1676. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  1677. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  1678. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  1679. /* ADCs; muted */
  1680. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1681. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1682. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1683. { }
  1684. };
  1685. static struct hda_verb ad1988_spdif_init_verbs[] = {
  1686. /* SPDIF out sel */
  1687. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
  1688. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
  1689. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1690. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1691. /* SPDIF out pin */
  1692. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  1693. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x17}, /* 0dB */
  1694. { }
  1695. };
  1696. /*
  1697. * verbs for 3stack (+dig)
  1698. */
  1699. static struct hda_verb ad1988_3stack_ch2_init[] = {
  1700. /* set port-C to line-in */
  1701. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  1702. { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1703. /* set port-E to mic-in */
  1704. { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  1705. { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  1706. { } /* end */
  1707. };
  1708. static struct hda_verb ad1988_3stack_ch6_init[] = {
  1709. /* set port-C to surround out */
  1710. { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  1711. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  1712. /* set port-E to CLFE out */
  1713. { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  1714. { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  1715. { } /* end */
  1716. };
  1717. static struct hda_channel_mode ad1988_3stack_modes[2] = {
  1718. { 2, ad1988_3stack_ch2_init },
  1719. { 6, ad1988_3stack_ch6_init },
  1720. };
  1721. static struct hda_verb ad1988_3stack_init_verbs[] = {
  1722. /* Front, Surround, CLFE, side DAC; unmute as default */
  1723. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1724. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1725. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1726. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1727. /* Port-A front headphon path */
  1728. {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
  1729. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1730. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1731. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1732. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1733. /* Port-D line-out path */
  1734. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1735. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1736. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1737. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1738. /* Mono out path */
  1739. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  1740. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1741. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1742. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1743. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  1744. /* Port-B front mic-in path */
  1745. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1746. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1747. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1748. /* Port-C line-in/surround path - 6ch mode as default */
  1749. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1750. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1751. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1752. {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
  1753. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  1754. /* Port-E mic-in/CLFE path - 6ch mode as default */
  1755. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1756. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1757. {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1758. {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
  1759. {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
  1760. /* mute analog mix */
  1761. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1762. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1763. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  1764. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1765. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  1766. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  1767. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  1768. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  1769. /* select ADCs - front-mic */
  1770. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  1771. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  1772. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  1773. /* ADCs; muted */
  1774. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1775. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1776. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1777. { }
  1778. };
  1779. /*
  1780. * verbs for laptop mode (+dig)
  1781. */
  1782. static struct hda_verb ad1988_laptop_hp_on[] = {
  1783. /* unmute port-A and mute port-D */
  1784. { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  1785. { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  1786. { } /* end */
  1787. };
  1788. static struct hda_verb ad1988_laptop_hp_off[] = {
  1789. /* mute port-A and unmute port-D */
  1790. { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  1791. { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  1792. { } /* end */
  1793. };
  1794. #define AD1988_HP_EVENT 0x01
  1795. static struct hda_verb ad1988_laptop_init_verbs[] = {
  1796. /* Front, Surround, CLFE, side DAC; unmute as default */
  1797. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1798. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1799. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1800. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1801. /* Port-A front headphon path */
  1802. {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
  1803. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1804. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1805. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1806. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1807. /* unsolicited event for pin-sense */
  1808. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
  1809. /* Port-D line-out path + EAPD */
  1810. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1811. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1812. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1813. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1814. {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
  1815. /* Mono out path */
  1816. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  1817. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1818. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1819. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1820. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  1821. /* Port-B mic-in path */
  1822. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1823. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1824. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1825. /* Port-C docking station - try to output */
  1826. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1827. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1828. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1829. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  1830. /* mute analog mix */
  1831. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1832. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1833. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  1834. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1835. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  1836. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  1837. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  1838. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  1839. /* select ADCs - mic */
  1840. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  1841. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  1842. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  1843. /* ADCs; muted */
  1844. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1845. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1846. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1847. { }
  1848. };
  1849. static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
  1850. {
  1851. if ((res >> 26) != AD1988_HP_EVENT)
  1852. return;
  1853. if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
  1854. snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
  1855. else
  1856. snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
  1857. }
  1858. /*
  1859. * Automatic parse of I/O pins from the BIOS configuration
  1860. */
  1861. #define NUM_CONTROL_ALLOC 32
  1862. #define NUM_VERB_ALLOC 32
  1863. enum {
  1864. AD_CTL_WIDGET_VOL,
  1865. AD_CTL_WIDGET_MUTE,
  1866. AD_CTL_BIND_MUTE,
  1867. };
  1868. static struct snd_kcontrol_new ad1988_control_templates[] = {
  1869. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  1870. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  1871. HDA_BIND_MUTE(NULL, 0, 0, 0),
  1872. };
  1873. /* add dynamic controls */
  1874. static int add_control(struct ad198x_spec *spec, int type, const char *name,
  1875. unsigned long val)
  1876. {
  1877. struct snd_kcontrol_new *knew;
  1878. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  1879. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  1880. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
  1881. if (! knew)
  1882. return -ENOMEM;
  1883. if (spec->kctl_alloc) {
  1884. memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
  1885. kfree(spec->kctl_alloc);
  1886. }
  1887. spec->kctl_alloc = knew;
  1888. spec->num_kctl_alloc = num;
  1889. }
  1890. knew = &spec->kctl_alloc[spec->num_kctl_used];
  1891. *knew = ad1988_control_templates[type];
  1892. knew->name = kstrdup(name, GFP_KERNEL);
  1893. if (! knew->name)
  1894. return -ENOMEM;
  1895. knew->private_value = val;
  1896. spec->num_kctl_used++;
  1897. return 0;
  1898. }
  1899. #define AD1988_PIN_CD_NID 0x18
  1900. #define AD1988_PIN_BEEP_NID 0x10
  1901. static hda_nid_t ad1988_mixer_nids[8] = {
  1902. /* A B C D E F G H */
  1903. 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
  1904. };
  1905. static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
  1906. {
  1907. static hda_nid_t idx_to_dac[8] = {
  1908. /* A B C D E F G H */
  1909. 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
  1910. };
  1911. static hda_nid_t idx_to_dac_rev2[8] = {
  1912. /* A B C D E F G H */
  1913. 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
  1914. };
  1915. if (codec->revision_id == AD1988A_REV2)
  1916. return idx_to_dac_rev2[idx];
  1917. else
  1918. return idx_to_dac[idx];
  1919. }
  1920. static hda_nid_t ad1988_boost_nids[8] = {
  1921. 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
  1922. };
  1923. static int ad1988_pin_idx(hda_nid_t nid)
  1924. {
  1925. static hda_nid_t ad1988_io_pins[8] = {
  1926. 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
  1927. };
  1928. int i;
  1929. for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
  1930. if (ad1988_io_pins[i] == nid)
  1931. return i;
  1932. return 0; /* should be -1 */
  1933. }
  1934. static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
  1935. {
  1936. static int loopback_idx[8] = {
  1937. 2, 0, 1, 3, 4, 5, 1, 4
  1938. };
  1939. switch (nid) {
  1940. case AD1988_PIN_CD_NID:
  1941. return 6;
  1942. default:
  1943. return loopback_idx[ad1988_pin_idx(nid)];
  1944. }
  1945. }
  1946. static int ad1988_pin_to_adc_idx(hda_nid_t nid)
  1947. {
  1948. static int adc_idx[8] = {
  1949. 0, 1, 2, 8, 4, 3, 6, 7
  1950. };
  1951. switch (nid) {
  1952. case AD1988_PIN_CD_NID:
  1953. return 5;
  1954. default:
  1955. return adc_idx[ad1988_pin_idx(nid)];
  1956. }
  1957. }
  1958. /* fill in the dac_nids table from the parsed pin configuration */
  1959. static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
  1960. const struct auto_pin_cfg *cfg)
  1961. {
  1962. struct ad198x_spec *spec = codec->spec;
  1963. int i, idx;
  1964. spec->multiout.dac_nids = spec->private_dac_nids;
  1965. /* check the pins hardwired to audio widget */
  1966. for (i = 0; i < cfg->line_outs; i++) {
  1967. idx = ad1988_pin_idx(cfg->line_out_pins[i]);
  1968. spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
  1969. }
  1970. spec->multiout.num_dacs = cfg->line_outs;
  1971. return 0;
  1972. }
  1973. /* add playback controls from the parsed DAC table */
  1974. static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
  1975. const struct auto_pin_cfg *cfg)
  1976. {
  1977. char name[32];
  1978. static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
  1979. hda_nid_t nid;
  1980. int i, err;
  1981. for (i = 0; i < cfg->line_outs; i++) {
  1982. hda_nid_t dac = spec->multiout.dac_nids[i];
  1983. if (! dac)
  1984. continue;
  1985. nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
  1986. if (i == 2) {
  1987. /* Center/LFE */
  1988. err = add_control(spec, AD_CTL_WIDGET_VOL,
  1989. "Center Playback Volume",
  1990. HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
  1991. if (err < 0)
  1992. return err;
  1993. err = add_control(spec, AD_CTL_WIDGET_VOL,
  1994. "LFE Playback Volume",
  1995. HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
  1996. if (err < 0)
  1997. return err;
  1998. err = add_control(spec, AD_CTL_BIND_MUTE,
  1999. "Center Playback Switch",
  2000. HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
  2001. if (err < 0)
  2002. return err;
  2003. err = add_control(spec, AD_CTL_BIND_MUTE,
  2004. "LFE Playback Switch",
  2005. HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
  2006. if (err < 0)
  2007. return err;
  2008. } else {
  2009. sprintf(name, "%s Playback Volume", chname[i]);
  2010. err = add_control(spec, AD_CTL_WIDGET_VOL, name,
  2011. HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
  2012. if (err < 0)
  2013. return err;
  2014. sprintf(name, "%s Playback Switch", chname[i]);
  2015. err = add_control(spec, AD_CTL_BIND_MUTE, name,
  2016. HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
  2017. if (err < 0)
  2018. return err;
  2019. }
  2020. }
  2021. return 0;
  2022. }
  2023. /* add playback controls for speaker and HP outputs */
  2024. static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
  2025. const char *pfx)
  2026. {
  2027. struct ad198x_spec *spec = codec->spec;
  2028. hda_nid_t nid;
  2029. int idx, err;
  2030. char name[32];
  2031. if (! pin)
  2032. return 0;
  2033. idx = ad1988_pin_idx(pin);
  2034. nid = ad1988_idx_to_dac(codec, idx);
  2035. /* specify the DAC as the extra output */
  2036. if (! spec->multiout.hp_nid)
  2037. spec->multiout.hp_nid = nid;
  2038. else
  2039. spec->multiout.extra_out_nid[0] = nid;
  2040. /* control HP volume/switch on the output mixer amp */
  2041. sprintf(name, "%s Playback Volume", pfx);
  2042. if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
  2043. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  2044. return err;
  2045. nid = ad1988_mixer_nids[idx];
  2046. sprintf(name, "%s Playback Switch", pfx);
  2047. if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
  2048. HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
  2049. return err;
  2050. return 0;
  2051. }
  2052. /* create input playback/capture controls for the given pin */
  2053. static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
  2054. const char *ctlname, int boost)
  2055. {
  2056. char name[32];
  2057. int err, idx;
  2058. sprintf(name, "%s Playback Volume", ctlname);
  2059. idx = ad1988_pin_to_loopback_idx(pin);
  2060. if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
  2061. HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
  2062. return err;
  2063. sprintf(name, "%s Playback Switch", ctlname);
  2064. if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
  2065. HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
  2066. return err;
  2067. if (boost) {
  2068. hda_nid_t bnid;
  2069. idx = ad1988_pin_idx(pin);
  2070. bnid = ad1988_boost_nids[idx];
  2071. if (bnid) {
  2072. sprintf(name, "%s Boost", ctlname);
  2073. return add_control(spec, AD_CTL_WIDGET_VOL, name,
  2074. HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
  2075. }
  2076. }
  2077. return 0;
  2078. }
  2079. /* create playback/capture controls for input pins */
  2080. static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
  2081. const struct auto_pin_cfg *cfg)
  2082. {
  2083. struct hda_input_mux *imux = &spec->private_imux;
  2084. int i, err;
  2085. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2086. err = new_analog_input(spec, cfg->input_pins[i],
  2087. auto_pin_cfg_labels[i],
  2088. i <= AUTO_PIN_FRONT_MIC);
  2089. if (err < 0)
  2090. return err;
  2091. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  2092. imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
  2093. imux->num_items++;
  2094. }
  2095. imux->items[imux->num_items].label = "Mix";
  2096. imux->items[imux->num_items].index = 9;
  2097. imux->num_items++;
  2098. if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
  2099. "Analog Mix Playback Volume",
  2100. HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
  2101. return err;
  2102. if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
  2103. "Analog Mix Playback Switch",
  2104. HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
  2105. return err;
  2106. return 0;
  2107. }
  2108. static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
  2109. hda_nid_t nid, int pin_type,
  2110. int dac_idx)
  2111. {
  2112. /* set as output */
  2113. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  2114. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  2115. switch (nid) {
  2116. case 0x11: /* port-A - DAC 04 */
  2117. snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
  2118. break;
  2119. case 0x14: /* port-B - DAC 06 */
  2120. snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
  2121. break;
  2122. case 0x15: /* port-C - DAC 05 */
  2123. snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
  2124. break;
  2125. case 0x17: /* port-E - DAC 0a */
  2126. snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
  2127. break;
  2128. case 0x13: /* mono - DAC 04 */
  2129. snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
  2130. break;
  2131. }
  2132. }
  2133. static void ad1988_auto_init_multi_out(struct hda_codec *codec)
  2134. {
  2135. struct ad198x_spec *spec = codec->spec;
  2136. int i;
  2137. for (i = 0; i < spec->autocfg.line_outs; i++) {
  2138. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  2139. ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
  2140. }
  2141. }
  2142. static void ad1988_auto_init_extra_out(struct hda_codec *codec)
  2143. {
  2144. struct ad198x_spec *spec = codec->spec;
  2145. hda_nid_t pin;
  2146. pin = spec->autocfg.speaker_pins[0];
  2147. if (pin) /* connect to front */
  2148. ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
  2149. pin = spec->autocfg.hp_pin;
  2150. if (pin) /* connect to front */
  2151. ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
  2152. }
  2153. static void ad1988_auto_init_analog_input(struct hda_codec *codec)
  2154. {
  2155. struct ad198x_spec *spec = codec->spec;
  2156. int i, idx;
  2157. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2158. hda_nid_t nid = spec->autocfg.input_pins[i];
  2159. if (! nid)
  2160. continue;
  2161. switch (nid) {
  2162. case 0x15: /* port-C */
  2163. snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
  2164. break;
  2165. case 0x17: /* port-E */
  2166. snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
  2167. break;
  2168. }
  2169. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  2170. i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
  2171. if (nid != AD1988_PIN_CD_NID)
  2172. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2173. AMP_OUT_MUTE);
  2174. idx = ad1988_pin_idx(nid);
  2175. if (ad1988_boost_nids[idx])
  2176. snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
  2177. AC_VERB_SET_AMP_GAIN_MUTE,
  2178. AMP_OUT_ZERO);
  2179. }
  2180. }
  2181. /* parse the BIOS configuration and set up the alc_spec */
  2182. /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
  2183. static int ad1988_parse_auto_config(struct hda_codec *codec)
  2184. {
  2185. struct ad198x_spec *spec = codec->spec;
  2186. int err;
  2187. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  2188. return err;
  2189. if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  2190. return err;
  2191. if (! spec->autocfg.line_outs)
  2192. return 0; /* can't find valid BIOS pin config */
  2193. if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
  2194. (err = ad1988_auto_create_extra_out(codec,
  2195. spec->autocfg.speaker_pins[0],
  2196. "Speaker")) < 0 ||
  2197. (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pin,
  2198. "Headphone")) < 0 ||
  2199. (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
  2200. return err;
  2201. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2202. if (spec->autocfg.dig_out_pin)
  2203. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2204. if (spec->autocfg.dig_in_pin)
  2205. spec->dig_in_nid = AD1988_SPDIF_IN;
  2206. if (spec->kctl_alloc)
  2207. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  2208. spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
  2209. spec->input_mux = &spec->private_imux;
  2210. return 1;
  2211. }
  2212. /* init callback for auto-configuration model -- overriding the default init */
  2213. static int ad1988_auto_init(struct hda_codec *codec)
  2214. {
  2215. ad198x_init(codec);
  2216. ad1988_auto_init_multi_out(codec);
  2217. ad1988_auto_init_extra_out(codec);
  2218. ad1988_auto_init_analog_input(codec);
  2219. return 0;
  2220. }
  2221. /*
  2222. */
  2223. static struct hda_board_config ad1988_cfg_tbl[] = {
  2224. { .modelname = "6stack", .config = AD1988_6STACK },
  2225. { .modelname = "6stack-dig", .config = AD1988_6STACK_DIG },
  2226. { .modelname = "3stack", .config = AD1988_3STACK },
  2227. { .modelname = "3stack-dig", .config = AD1988_3STACK_DIG },
  2228. { .modelname = "laptop", .config = AD1988_LAPTOP },
  2229. { .modelname = "laptop-dig", .config = AD1988_LAPTOP_DIG },
  2230. { .modelname = "auto", .config = AD1988_AUTO },
  2231. {}
  2232. };
  2233. static int patch_ad1988(struct hda_codec *codec)
  2234. {
  2235. struct ad198x_spec *spec;
  2236. int board_config;
  2237. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2238. if (spec == NULL)
  2239. return -ENOMEM;
  2240. mutex_init(&spec->amp_mutex);
  2241. codec->spec = spec;
  2242. if (codec->revision_id == AD1988A_REV2)
  2243. snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
  2244. board_config = snd_hda_check_board_config(codec, ad1988_cfg_tbl);
  2245. if (board_config < 0 || board_config >= AD1988_MODEL_LAST) {
  2246. printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
  2247. board_config = AD1988_AUTO;
  2248. }
  2249. if (board_config == AD1988_AUTO) {
  2250. /* automatic parse from the BIOS config */
  2251. int err = ad1988_parse_auto_config(codec);
  2252. if (err < 0) {
  2253. ad198x_free(codec);
  2254. return err;
  2255. } else if (! err) {
  2256. printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
  2257. board_config = AD1988_6STACK;
  2258. }
  2259. }
  2260. switch (board_config) {
  2261. case AD1988_6STACK:
  2262. case AD1988_6STACK_DIG:
  2263. spec->multiout.max_channels = 8;
  2264. spec->multiout.num_dacs = 4;
  2265. if (codec->revision_id == AD1988A_REV2)
  2266. spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
  2267. else
  2268. spec->multiout.dac_nids = ad1988_6stack_dac_nids;
  2269. spec->input_mux = &ad1988_6stack_capture_source;
  2270. spec->num_mixers = 2;
  2271. if (codec->revision_id == AD1988A_REV2)
  2272. spec->mixers[0] = ad1988_6stack_mixers1_rev2;
  2273. else
  2274. spec->mixers[0] = ad1988_6stack_mixers1;
  2275. spec->mixers[1] = ad1988_6stack_mixers2;
  2276. spec->num_init_verbs = 1;
  2277. spec->init_verbs[0] = ad1988_6stack_init_verbs;
  2278. if (board_config == AD1988_6STACK_DIG) {
  2279. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2280. spec->dig_in_nid = AD1988_SPDIF_IN;
  2281. }
  2282. break;
  2283. case AD1988_3STACK:
  2284. case AD1988_3STACK_DIG:
  2285. spec->multiout.max_channels = 6;
  2286. spec->multiout.num_dacs = 3;
  2287. if (codec->revision_id == AD1988A_REV2)
  2288. spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
  2289. else
  2290. spec->multiout.dac_nids = ad1988_3stack_dac_nids;
  2291. spec->input_mux = &ad1988_6stack_capture_source;
  2292. spec->channel_mode = ad1988_3stack_modes;
  2293. spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
  2294. spec->num_mixers = 2;
  2295. if (codec->revision_id == AD1988A_REV2)
  2296. spec->mixers[0] = ad1988_3stack_mixers1_rev2;
  2297. else
  2298. spec->mixers[0] = ad1988_3stack_mixers1;
  2299. spec->mixers[1] = ad1988_3stack_mixers2;
  2300. spec->num_init_verbs = 1;
  2301. spec->init_verbs[0] = ad1988_3stack_init_verbs;
  2302. if (board_config == AD1988_3STACK_DIG)
  2303. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2304. break;
  2305. case AD1988_LAPTOP:
  2306. case AD1988_LAPTOP_DIG:
  2307. spec->multiout.max_channels = 2;
  2308. spec->multiout.num_dacs = 1;
  2309. spec->multiout.dac_nids = ad1988_3stack_dac_nids;
  2310. spec->input_mux = &ad1988_laptop_capture_source;
  2311. spec->num_mixers = 1;
  2312. spec->mixers[0] = ad1988_laptop_mixers;
  2313. spec->num_init_verbs = 1;
  2314. spec->init_verbs[0] = ad1988_laptop_init_verbs;
  2315. if (board_config == AD1988_LAPTOP_DIG)
  2316. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2317. break;
  2318. }
  2319. spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
  2320. spec->adc_nids = ad1988_adc_nids;
  2321. spec->capsrc_nids = ad1988_capsrc_nids;
  2322. spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
  2323. spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
  2324. if (spec->multiout.dig_out_nid) {
  2325. spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
  2326. spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
  2327. }
  2328. if (spec->dig_in_nid)
  2329. spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
  2330. codec->patch_ops = ad198x_patch_ops;
  2331. switch (board_config) {
  2332. case AD1988_AUTO:
  2333. codec->patch_ops.init = ad1988_auto_init;
  2334. break;
  2335. case AD1988_LAPTOP:
  2336. case AD1988_LAPTOP_DIG:
  2337. codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
  2338. break;
  2339. }
  2340. return 0;
  2341. }
  2342. /*
  2343. * patch entries
  2344. */
  2345. struct hda_codec_preset snd_hda_preset_analog[] = {
  2346. { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
  2347. { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
  2348. { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
  2349. { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
  2350. {} /* terminator */
  2351. };