patch_analog.c 87 KB

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