patch_analog.c 82 KB

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