patch_analog.c 84 KB

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