patch_analog.c 84 KB

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