patch_analog.c 84 KB

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