patch_analog.c 148 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771
  1. /*
  2. * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
  3. * AD1986A, AD1988
  4. *
  5. * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
  6. *
  7. * This driver is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This driver is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/init.h>
  22. #include <linux/delay.h>
  23. #include <linux/slab.h>
  24. #include <linux/pci.h>
  25. #include <linux/module.h>
  26. #include <sound/core.h>
  27. #include "hda_codec.h"
  28. #include "hda_local.h"
  29. #include "hda_auto_parser.h"
  30. #include "hda_beep.h"
  31. #include "hda_jack.h"
  32. #include "hda_generic.h"
  33. struct ad198x_spec {
  34. struct hda_gen_spec gen;
  35. const struct snd_kcontrol_new *mixers[6];
  36. int num_mixers;
  37. unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
  38. hda_nid_t beep_dev_nid;
  39. const struct hda_verb *init_verbs[6]; /* initialization verbs
  40. * don't forget NULL termination!
  41. */
  42. unsigned int num_init_verbs;
  43. /* playback */
  44. struct hda_multi_out multiout; /* playback set-up
  45. * max_channels, dacs must be set
  46. * dig_out_nid and hp_nid are optional
  47. */
  48. unsigned int cur_eapd;
  49. unsigned int need_dac_fix;
  50. /* capture */
  51. unsigned int num_adc_nids;
  52. const hda_nid_t *adc_nids;
  53. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  54. /* capture source */
  55. const struct hda_input_mux *input_mux;
  56. const hda_nid_t *capsrc_nids;
  57. unsigned int cur_mux[3];
  58. /* channel model */
  59. const struct hda_channel_mode *channel_mode;
  60. int num_channel_mode;
  61. /* PCM information */
  62. struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
  63. unsigned int spdif_route;
  64. unsigned int jack_present: 1;
  65. unsigned int inv_jack_detect: 1;/* inverted jack-detection */
  66. unsigned int analog_beep: 1; /* analog beep input present */
  67. unsigned int avoid_init_slave_vol:1;
  68. #ifdef CONFIG_PM
  69. struct hda_loopback_check loopback;
  70. #endif
  71. /* for virtual master */
  72. hda_nid_t vmaster_nid;
  73. const char * const *slave_vols;
  74. const char * const *slave_sws;
  75. };
  76. /*
  77. * input MUX handling (common part)
  78. */
  79. static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  80. {
  81. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  82. struct ad198x_spec *spec = codec->spec;
  83. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  84. }
  85. static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  86. {
  87. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  88. struct ad198x_spec *spec = codec->spec;
  89. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  90. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  91. return 0;
  92. }
  93. static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  94. {
  95. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  96. struct ad198x_spec *spec = codec->spec;
  97. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  98. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  99. spec->capsrc_nids[adc_idx],
  100. &spec->cur_mux[adc_idx]);
  101. }
  102. /*
  103. * initialization (common callbacks)
  104. */
  105. static int ad198x_init(struct hda_codec *codec)
  106. {
  107. struct ad198x_spec *spec = codec->spec;
  108. int i;
  109. for (i = 0; i < spec->num_init_verbs; i++)
  110. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  111. return 0;
  112. }
  113. static const char * const ad_slave_pfxs[] = {
  114. "Front", "Surround", "Center", "LFE", "Side",
  115. "Headphone", "Mono", "Speaker", "IEC958",
  116. NULL
  117. };
  118. static const char * const ad1988_6stack_fp_slave_pfxs[] = {
  119. "Front", "Surround", "Center", "LFE", "Side", "IEC958",
  120. NULL
  121. };
  122. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  123. /* additional beep mixers; the actual parameters are overwritten at build */
  124. static const struct snd_kcontrol_new ad_beep_mixer[] = {
  125. HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
  126. HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
  127. { } /* end */
  128. };
  129. static const struct snd_kcontrol_new ad_beep2_mixer[] = {
  130. HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0, 0, HDA_OUTPUT),
  131. HDA_CODEC_MUTE_BEEP("Digital Beep Playback Switch", 0, 0, HDA_OUTPUT),
  132. { } /* end */
  133. };
  134. #define set_beep_amp(spec, nid, idx, dir) \
  135. ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
  136. #else
  137. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  138. #endif
  139. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  140. static int create_beep_ctls(struct hda_codec *codec)
  141. {
  142. struct ad198x_spec *spec = codec->spec;
  143. const struct snd_kcontrol_new *knew;
  144. if (!spec->beep_amp)
  145. return 0;
  146. knew = spec->analog_beep ? ad_beep2_mixer : ad_beep_mixer;
  147. for ( ; knew->name; knew++) {
  148. int err;
  149. struct snd_kcontrol *kctl;
  150. kctl = snd_ctl_new1(knew, codec);
  151. if (!kctl)
  152. return -ENOMEM;
  153. kctl->private_value = spec->beep_amp;
  154. err = snd_hda_ctl_add(codec, 0, kctl);
  155. if (err < 0)
  156. return err;
  157. }
  158. return 0;
  159. }
  160. #else
  161. #define create_beep_ctls(codec) 0
  162. #endif
  163. static int ad198x_build_controls(struct hda_codec *codec)
  164. {
  165. struct ad198x_spec *spec = codec->spec;
  166. struct snd_kcontrol *kctl;
  167. unsigned int i;
  168. int err;
  169. for (i = 0; i < spec->num_mixers; i++) {
  170. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  171. if (err < 0)
  172. return err;
  173. }
  174. if (spec->multiout.dig_out_nid) {
  175. err = snd_hda_create_spdif_out_ctls(codec,
  176. spec->multiout.dig_out_nid,
  177. spec->multiout.dig_out_nid);
  178. if (err < 0)
  179. return err;
  180. err = snd_hda_create_spdif_share_sw(codec,
  181. &spec->multiout);
  182. if (err < 0)
  183. return err;
  184. spec->multiout.share_spdif = 1;
  185. }
  186. if (spec->dig_in_nid) {
  187. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  188. if (err < 0)
  189. return err;
  190. }
  191. /* create beep controls if needed */
  192. err = create_beep_ctls(codec);
  193. if (err < 0)
  194. return err;
  195. /* if we have no master control, let's create it */
  196. if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  197. unsigned int vmaster_tlv[4];
  198. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  199. HDA_OUTPUT, vmaster_tlv);
  200. err = __snd_hda_add_vmaster(codec, "Master Playback Volume",
  201. vmaster_tlv,
  202. (spec->slave_vols ?
  203. spec->slave_vols : ad_slave_pfxs),
  204. "Playback Volume",
  205. !spec->avoid_init_slave_vol, NULL);
  206. if (err < 0)
  207. return err;
  208. }
  209. if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  210. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  211. NULL,
  212. (spec->slave_sws ?
  213. spec->slave_sws : ad_slave_pfxs),
  214. "Playback Switch");
  215. if (err < 0)
  216. return err;
  217. }
  218. /* assign Capture Source enums to NID */
  219. kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
  220. if (!kctl)
  221. kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
  222. for (i = 0; kctl && i < kctl->count; i++) {
  223. err = snd_hda_add_nid(codec, kctl, i, spec->capsrc_nids[i]);
  224. if (err < 0)
  225. return err;
  226. }
  227. /* assign IEC958 enums to NID */
  228. kctl = snd_hda_find_mixer_ctl(codec,
  229. SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source");
  230. if (kctl) {
  231. err = snd_hda_add_nid(codec, kctl, 0,
  232. spec->multiout.dig_out_nid);
  233. if (err < 0)
  234. return err;
  235. }
  236. return 0;
  237. }
  238. #ifdef CONFIG_PM
  239. static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  240. {
  241. struct ad198x_spec *spec = codec->spec;
  242. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  243. }
  244. #endif
  245. /*
  246. * Analog playback callbacks
  247. */
  248. static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
  249. struct hda_codec *codec,
  250. struct snd_pcm_substream *substream)
  251. {
  252. struct ad198x_spec *spec = codec->spec;
  253. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  254. hinfo);
  255. }
  256. static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  257. struct hda_codec *codec,
  258. unsigned int stream_tag,
  259. unsigned int format,
  260. struct snd_pcm_substream *substream)
  261. {
  262. struct ad198x_spec *spec = codec->spec;
  263. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
  264. format, substream);
  265. }
  266. static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  267. struct hda_codec *codec,
  268. struct snd_pcm_substream *substream)
  269. {
  270. struct ad198x_spec *spec = codec->spec;
  271. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  272. }
  273. /*
  274. * Digital out
  275. */
  276. static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  277. struct hda_codec *codec,
  278. struct snd_pcm_substream *substream)
  279. {
  280. struct ad198x_spec *spec = codec->spec;
  281. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  282. }
  283. static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  284. struct hda_codec *codec,
  285. struct snd_pcm_substream *substream)
  286. {
  287. struct ad198x_spec *spec = codec->spec;
  288. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  289. }
  290. static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  291. struct hda_codec *codec,
  292. unsigned int stream_tag,
  293. unsigned int format,
  294. struct snd_pcm_substream *substream)
  295. {
  296. struct ad198x_spec *spec = codec->spec;
  297. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
  298. format, substream);
  299. }
  300. static int ad198x_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  301. struct hda_codec *codec,
  302. struct snd_pcm_substream *substream)
  303. {
  304. struct ad198x_spec *spec = codec->spec;
  305. return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  306. }
  307. /*
  308. * Analog capture
  309. */
  310. static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  311. struct hda_codec *codec,
  312. unsigned int stream_tag,
  313. unsigned int format,
  314. struct snd_pcm_substream *substream)
  315. {
  316. struct ad198x_spec *spec = codec->spec;
  317. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  318. stream_tag, 0, format);
  319. return 0;
  320. }
  321. static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  322. struct hda_codec *codec,
  323. struct snd_pcm_substream *substream)
  324. {
  325. struct ad198x_spec *spec = codec->spec;
  326. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  327. return 0;
  328. }
  329. /*
  330. */
  331. static const struct hda_pcm_stream ad198x_pcm_analog_playback = {
  332. .substreams = 1,
  333. .channels_min = 2,
  334. .channels_max = 6, /* changed later */
  335. .nid = 0, /* fill later */
  336. .ops = {
  337. .open = ad198x_playback_pcm_open,
  338. .prepare = ad198x_playback_pcm_prepare,
  339. .cleanup = ad198x_playback_pcm_cleanup,
  340. },
  341. };
  342. static const struct hda_pcm_stream ad198x_pcm_analog_capture = {
  343. .substreams = 1,
  344. .channels_min = 2,
  345. .channels_max = 2,
  346. .nid = 0, /* fill later */
  347. .ops = {
  348. .prepare = ad198x_capture_pcm_prepare,
  349. .cleanup = ad198x_capture_pcm_cleanup
  350. },
  351. };
  352. static const struct hda_pcm_stream ad198x_pcm_digital_playback = {
  353. .substreams = 1,
  354. .channels_min = 2,
  355. .channels_max = 2,
  356. .nid = 0, /* fill later */
  357. .ops = {
  358. .open = ad198x_dig_playback_pcm_open,
  359. .close = ad198x_dig_playback_pcm_close,
  360. .prepare = ad198x_dig_playback_pcm_prepare,
  361. .cleanup = ad198x_dig_playback_pcm_cleanup
  362. },
  363. };
  364. static const struct hda_pcm_stream ad198x_pcm_digital_capture = {
  365. .substreams = 1,
  366. .channels_min = 2,
  367. .channels_max = 2,
  368. /* NID is set in alc_build_pcms */
  369. };
  370. static int ad198x_build_pcms(struct hda_codec *codec)
  371. {
  372. struct ad198x_spec *spec = codec->spec;
  373. struct hda_pcm *info = spec->pcm_rec;
  374. codec->num_pcms = 1;
  375. codec->pcm_info = info;
  376. info->name = "AD198x Analog";
  377. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
  378. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
  379. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  380. info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
  381. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  382. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  383. if (spec->multiout.dig_out_nid) {
  384. info++;
  385. codec->num_pcms++;
  386. codec->spdif_status_reset = 1;
  387. info->name = "AD198x Digital";
  388. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  389. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
  390. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  391. if (spec->dig_in_nid) {
  392. info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
  393. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  394. }
  395. }
  396. return 0;
  397. }
  398. static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
  399. hda_nid_t hp)
  400. {
  401. if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
  402. snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
  403. !codec->inv_eapd ? 0x00 : 0x02);
  404. if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
  405. snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
  406. !codec->inv_eapd ? 0x00 : 0x02);
  407. }
  408. static void ad198x_power_eapd(struct hda_codec *codec)
  409. {
  410. /* We currently only handle front, HP */
  411. switch (codec->vendor_id) {
  412. case 0x11d41882:
  413. case 0x11d4882a:
  414. case 0x11d41884:
  415. case 0x11d41984:
  416. case 0x11d41883:
  417. case 0x11d4184a:
  418. case 0x11d4194a:
  419. case 0x11d4194b:
  420. case 0x11d41988:
  421. case 0x11d4198b:
  422. case 0x11d4989a:
  423. case 0x11d4989b:
  424. ad198x_power_eapd_write(codec, 0x12, 0x11);
  425. break;
  426. case 0x11d41981:
  427. case 0x11d41983:
  428. ad198x_power_eapd_write(codec, 0x05, 0x06);
  429. break;
  430. case 0x11d41986:
  431. ad198x_power_eapd_write(codec, 0x1b, 0x1a);
  432. break;
  433. }
  434. }
  435. static void ad198x_shutup(struct hda_codec *codec)
  436. {
  437. snd_hda_shutup_pins(codec);
  438. ad198x_power_eapd(codec);
  439. }
  440. static void ad198x_free(struct hda_codec *codec)
  441. {
  442. struct ad198x_spec *spec = codec->spec;
  443. if (!spec)
  444. return;
  445. snd_hda_gen_spec_free(&spec->gen);
  446. kfree(spec);
  447. snd_hda_detach_beep_device(codec);
  448. }
  449. #ifdef CONFIG_PM
  450. static int ad198x_suspend(struct hda_codec *codec)
  451. {
  452. ad198x_shutup(codec);
  453. return 0;
  454. }
  455. #endif
  456. static const struct hda_codec_ops ad198x_patch_ops = {
  457. .build_controls = ad198x_build_controls,
  458. .build_pcms = ad198x_build_pcms,
  459. .init = ad198x_init,
  460. .free = ad198x_free,
  461. #ifdef CONFIG_PM
  462. .check_power_status = ad198x_check_power_status,
  463. .suspend = ad198x_suspend,
  464. #endif
  465. .reboot_notify = ad198x_shutup,
  466. };
  467. /*
  468. * EAPD control
  469. * the private value = nid
  470. */
  471. #define ad198x_eapd_info snd_ctl_boolean_mono_info
  472. static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
  473. struct snd_ctl_elem_value *ucontrol)
  474. {
  475. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  476. struct ad198x_spec *spec = codec->spec;
  477. if (codec->inv_eapd)
  478. ucontrol->value.integer.value[0] = ! spec->cur_eapd;
  479. else
  480. ucontrol->value.integer.value[0] = spec->cur_eapd;
  481. return 0;
  482. }
  483. static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
  484. struct snd_ctl_elem_value *ucontrol)
  485. {
  486. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  487. struct ad198x_spec *spec = codec->spec;
  488. hda_nid_t nid = kcontrol->private_value & 0xff;
  489. unsigned int eapd;
  490. eapd = !!ucontrol->value.integer.value[0];
  491. if (codec->inv_eapd)
  492. eapd = !eapd;
  493. if (eapd == spec->cur_eapd)
  494. return 0;
  495. spec->cur_eapd = eapd;
  496. snd_hda_codec_write_cache(codec, nid,
  497. 0, AC_VERB_SET_EAPD_BTLENABLE,
  498. eapd ? 0x02 : 0x00);
  499. return 1;
  500. }
  501. static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
  502. struct snd_ctl_elem_info *uinfo);
  503. static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
  504. struct snd_ctl_elem_value *ucontrol);
  505. static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
  506. struct snd_ctl_elem_value *ucontrol);
  507. /*
  508. * Automatic parse of I/O pins from the BIOS configuration
  509. */
  510. static int ad198x_auto_build_controls(struct hda_codec *codec)
  511. {
  512. int err;
  513. err = snd_hda_gen_build_controls(codec);
  514. if (err < 0)
  515. return err;
  516. err = create_beep_ctls(codec);
  517. if (err < 0)
  518. return err;
  519. return 0;
  520. }
  521. static const struct hda_codec_ops ad198x_auto_patch_ops = {
  522. .build_controls = ad198x_auto_build_controls,
  523. .build_pcms = snd_hda_gen_build_pcms,
  524. .init = snd_hda_gen_init,
  525. .free = ad198x_free,
  526. .unsol_event = snd_hda_jack_unsol_event,
  527. #ifdef CONFIG_PM
  528. .check_power_status = snd_hda_gen_check_power_status,
  529. .suspend = ad198x_suspend,
  530. #endif
  531. .reboot_notify = ad198x_shutup,
  532. };
  533. static int ad198x_parse_auto_config(struct hda_codec *codec)
  534. {
  535. struct ad198x_spec *spec = codec->spec;
  536. struct auto_pin_cfg *cfg = &spec->gen.autocfg;
  537. int err;
  538. codec->spdif_status_reset = 1;
  539. codec->no_trigger_sense = 1;
  540. codec->no_sticky_stream = 1;
  541. spec->gen.indep_hp = 1;
  542. err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
  543. if (err < 0)
  544. return err;
  545. err = snd_hda_gen_parse_auto_config(codec, cfg);
  546. if (err < 0)
  547. return err;
  548. if (spec->beep_dev_nid) {
  549. err = snd_hda_attach_beep_device(codec, spec->beep_dev_nid);
  550. if (err < 0)
  551. return err;
  552. }
  553. codec->patch_ops = ad198x_auto_patch_ops;
  554. return 0;
  555. }
  556. /*
  557. * AD1986A specific
  558. */
  559. #define AD1986A_SPDIF_OUT 0x02
  560. #define AD1986A_FRONT_DAC 0x03
  561. #define AD1986A_SURR_DAC 0x04
  562. #define AD1986A_CLFE_DAC 0x05
  563. #define AD1986A_ADC 0x06
  564. static const hda_nid_t ad1986a_dac_nids[3] = {
  565. AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
  566. };
  567. static const hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
  568. static const hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
  569. static const struct hda_input_mux ad1986a_capture_source = {
  570. .num_items = 7,
  571. .items = {
  572. { "Mic", 0x0 },
  573. { "CD", 0x1 },
  574. { "Aux", 0x3 },
  575. { "Line", 0x4 },
  576. { "Mix", 0x5 },
  577. { "Mono", 0x6 },
  578. { "Phone", 0x7 },
  579. },
  580. };
  581. static const struct hda_bind_ctls ad1986a_bind_pcm_vol = {
  582. .ops = &snd_hda_bind_vol,
  583. .values = {
  584. HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
  585. HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
  586. HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
  587. 0
  588. },
  589. };
  590. static const struct hda_bind_ctls ad1986a_bind_pcm_sw = {
  591. .ops = &snd_hda_bind_sw,
  592. .values = {
  593. HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
  594. HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
  595. HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
  596. 0
  597. },
  598. };
  599. /*
  600. * mixers
  601. */
  602. static const struct snd_kcontrol_new ad1986a_mixers[] = {
  603. /*
  604. * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
  605. */
  606. HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
  607. HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
  608. HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  609. HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  610. HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  611. HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  612. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
  613. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
  614. HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
  615. HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
  616. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
  617. HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
  618. HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  619. HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  620. HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
  621. HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
  622. HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
  623. HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  624. HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  625. HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  626. HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
  627. HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
  628. HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
  629. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  630. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  631. {
  632. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  633. .name = "Capture Source",
  634. .info = ad198x_mux_enum_info,
  635. .get = ad198x_mux_enum_get,
  636. .put = ad198x_mux_enum_put,
  637. },
  638. HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
  639. { } /* end */
  640. };
  641. /* additional mixers for 3stack mode */
  642. static const struct snd_kcontrol_new ad1986a_3st_mixers[] = {
  643. {
  644. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  645. .name = "Channel Mode",
  646. .info = ad198x_ch_mode_info,
  647. .get = ad198x_ch_mode_get,
  648. .put = ad198x_ch_mode_put,
  649. },
  650. { } /* end */
  651. };
  652. /* laptop model - 2ch only */
  653. static const hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
  654. /* master controls both pins 0x1a and 0x1b */
  655. static const struct hda_bind_ctls ad1986a_laptop_master_vol = {
  656. .ops = &snd_hda_bind_vol,
  657. .values = {
  658. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  659. HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
  660. 0,
  661. },
  662. };
  663. static const struct hda_bind_ctls ad1986a_laptop_master_sw = {
  664. .ops = &snd_hda_bind_sw,
  665. .values = {
  666. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  667. HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
  668. 0,
  669. },
  670. };
  671. static const struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
  672. HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  673. HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
  674. HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
  675. HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
  676. HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  677. HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  678. HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
  679. HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
  680. HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
  681. HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  682. HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  683. HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  684. HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
  685. /*
  686. HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
  687. HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
  688. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  689. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  690. {
  691. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  692. .name = "Capture Source",
  693. .info = ad198x_mux_enum_info,
  694. .get = ad198x_mux_enum_get,
  695. .put = ad198x_mux_enum_put,
  696. },
  697. { } /* end */
  698. };
  699. /* laptop-eapd model - 2ch only */
  700. static const struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
  701. .num_items = 3,
  702. .items = {
  703. { "Mic", 0x0 },
  704. { "Internal Mic", 0x4 },
  705. { "Mix", 0x5 },
  706. },
  707. };
  708. static const struct hda_input_mux ad1986a_automic_capture_source = {
  709. .num_items = 2,
  710. .items = {
  711. { "Mic", 0x0 },
  712. { "Mix", 0x5 },
  713. },
  714. };
  715. static const struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
  716. HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
  717. HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
  718. { } /* end */
  719. };
  720. static const struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
  721. HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  722. HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
  723. HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  724. HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  725. HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
  726. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  727. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  728. {
  729. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  730. .name = "Capture Source",
  731. .info = ad198x_mux_enum_info,
  732. .get = ad198x_mux_enum_get,
  733. .put = ad198x_mux_enum_put,
  734. },
  735. {
  736. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  737. .name = "External Amplifier",
  738. .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
  739. .info = ad198x_eapd_info,
  740. .get = ad198x_eapd_get,
  741. .put = ad198x_eapd_put,
  742. .private_value = 0x1b, /* port-D */
  743. },
  744. { } /* end */
  745. };
  746. static const struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
  747. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
  748. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
  749. { } /* end */
  750. };
  751. /* re-connect the mic boost input according to the jack sensing */
  752. static void ad1986a_automic(struct hda_codec *codec)
  753. {
  754. unsigned int present;
  755. present = snd_hda_jack_detect(codec, 0x1f);
  756. /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
  757. snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
  758. present ? 0 : 2);
  759. }
  760. #define AD1986A_MIC_EVENT 0x36
  761. static void ad1986a_automic_unsol_event(struct hda_codec *codec,
  762. unsigned int res)
  763. {
  764. if ((res >> 26) != AD1986A_MIC_EVENT)
  765. return;
  766. ad1986a_automic(codec);
  767. }
  768. static int ad1986a_automic_init(struct hda_codec *codec)
  769. {
  770. ad198x_init(codec);
  771. ad1986a_automic(codec);
  772. return 0;
  773. }
  774. /* laptop-automute - 2ch only */
  775. static void ad1986a_update_hp(struct hda_codec *codec)
  776. {
  777. struct ad198x_spec *spec = codec->spec;
  778. unsigned int mute;
  779. if (spec->jack_present)
  780. mute = HDA_AMP_MUTE; /* mute internal speaker */
  781. else
  782. /* unmute internal speaker if necessary */
  783. mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
  784. snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
  785. HDA_AMP_MUTE, mute);
  786. }
  787. static void ad1986a_hp_automute(struct hda_codec *codec)
  788. {
  789. struct ad198x_spec *spec = codec->spec;
  790. spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
  791. if (spec->inv_jack_detect)
  792. spec->jack_present = !spec->jack_present;
  793. ad1986a_update_hp(codec);
  794. }
  795. #define AD1986A_HP_EVENT 0x37
  796. static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
  797. {
  798. if ((res >> 26) != AD1986A_HP_EVENT)
  799. return;
  800. ad1986a_hp_automute(codec);
  801. }
  802. static int ad1986a_hp_init(struct hda_codec *codec)
  803. {
  804. ad198x_init(codec);
  805. ad1986a_hp_automute(codec);
  806. return 0;
  807. }
  808. /* bind hp and internal speaker mute (with plug check) */
  809. static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  810. struct snd_ctl_elem_value *ucontrol)
  811. {
  812. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  813. int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
  814. if (change)
  815. ad1986a_update_hp(codec);
  816. return change;
  817. }
  818. static const struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
  819. HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
  820. {
  821. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  822. .name = "Master Playback Switch",
  823. .subdevice = HDA_SUBDEV_AMP_FLAG,
  824. .info = snd_hda_mixer_amp_switch_info,
  825. .get = snd_hda_mixer_amp_switch_get,
  826. .put = ad1986a_hp_master_sw_put,
  827. .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  828. },
  829. { } /* end */
  830. };
  831. /*
  832. * initialization verbs
  833. */
  834. static const struct hda_verb ad1986a_init_verbs[] = {
  835. /* Front, Surround, CLFE DAC; mute as default */
  836. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  837. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  838. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  839. /* Downmix - off */
  840. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  841. /* HP, Line-Out, Surround, CLFE selectors */
  842. {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
  843. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
  844. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  845. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  846. /* Mono selector */
  847. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
  848. /* Mic selector: Mic 1/2 pin */
  849. {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
  850. /* Line-in selector: Line-in */
  851. {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
  852. /* Mic 1/2 swap */
  853. {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
  854. /* Record selector: mic */
  855. {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
  856. /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
  857. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  858. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  859. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  860. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  861. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  862. /* PC beep */
  863. {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
  864. /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
  865. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  866. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  867. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  868. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  869. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  870. /* HP Pin */
  871. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  872. /* Front, Surround, CLFE Pins */
  873. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  874. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  875. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  876. /* Mono Pin */
  877. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  878. /* Mic Pin */
  879. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  880. /* Line, Aux, CD, Beep-In Pin */
  881. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  882. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  883. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  884. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  885. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  886. { } /* end */
  887. };
  888. static const struct hda_verb ad1986a_ch2_init[] = {
  889. /* Surround out -> Line In */
  890. { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  891. /* Line-in selectors */
  892. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
  893. /* CLFE -> Mic in */
  894. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  895. /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
  896. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
  897. { } /* end */
  898. };
  899. static const struct hda_verb ad1986a_ch4_init[] = {
  900. /* Surround out -> Surround */
  901. { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  902. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  903. /* CLFE -> Mic in */
  904. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  905. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
  906. { } /* end */
  907. };
  908. static const struct hda_verb ad1986a_ch6_init[] = {
  909. /* Surround out -> Surround out */
  910. { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  911. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  912. /* CLFE -> CLFE */
  913. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  914. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
  915. { } /* end */
  916. };
  917. static const struct hda_channel_mode ad1986a_modes[3] = {
  918. { 2, ad1986a_ch2_init },
  919. { 4, ad1986a_ch4_init },
  920. { 6, ad1986a_ch6_init },
  921. };
  922. /* eapd initialization */
  923. static const struct hda_verb ad1986a_eapd_init_verbs[] = {
  924. {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
  925. {}
  926. };
  927. static const struct hda_verb ad1986a_automic_verbs[] = {
  928. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  929. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  930. /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
  931. {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
  932. {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
  933. {}
  934. };
  935. /* Ultra initialization */
  936. static const struct hda_verb ad1986a_ultra_init[] = {
  937. /* eapd initialization */
  938. { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
  939. /* CLFE -> Mic in */
  940. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
  941. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  942. { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
  943. { } /* end */
  944. };
  945. /* pin sensing on HP jack */
  946. static const struct hda_verb ad1986a_hp_init_verbs[] = {
  947. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
  948. {}
  949. };
  950. static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
  951. unsigned int res)
  952. {
  953. switch (res >> 26) {
  954. case AD1986A_HP_EVENT:
  955. ad1986a_hp_automute(codec);
  956. break;
  957. case AD1986A_MIC_EVENT:
  958. ad1986a_automic(codec);
  959. break;
  960. }
  961. }
  962. static int ad1986a_samsung_p50_init(struct hda_codec *codec)
  963. {
  964. ad198x_init(codec);
  965. ad1986a_hp_automute(codec);
  966. ad1986a_automic(codec);
  967. return 0;
  968. }
  969. /* models */
  970. enum {
  971. AD1986A_AUTO,
  972. AD1986A_6STACK,
  973. AD1986A_3STACK,
  974. AD1986A_LAPTOP,
  975. AD1986A_LAPTOP_EAPD,
  976. AD1986A_LAPTOP_AUTOMUTE,
  977. AD1986A_ULTRA,
  978. AD1986A_SAMSUNG,
  979. AD1986A_SAMSUNG_P50,
  980. AD1986A_MODELS
  981. };
  982. static const char * const ad1986a_models[AD1986A_MODELS] = {
  983. [AD1986A_AUTO] = "auto",
  984. [AD1986A_6STACK] = "6stack",
  985. [AD1986A_3STACK] = "3stack",
  986. [AD1986A_LAPTOP] = "laptop",
  987. [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
  988. [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
  989. [AD1986A_ULTRA] = "ultra",
  990. [AD1986A_SAMSUNG] = "samsung",
  991. [AD1986A_SAMSUNG_P50] = "samsung-p50",
  992. };
  993. static const struct snd_pci_quirk ad1986a_cfg_tbl[] = {
  994. SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
  995. SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
  996. SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
  997. SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
  998. SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
  999. SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
  1000. SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
  1001. SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
  1002. SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
  1003. SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
  1004. SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
  1005. SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
  1006. SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
  1007. SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
  1008. SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
  1009. SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
  1010. SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40-10Q", AD1986A_3STACK),
  1011. SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
  1012. SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
  1013. SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
  1014. SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
  1015. SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
  1016. SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
  1017. SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
  1018. SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
  1019. SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
  1020. SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
  1021. {}
  1022. };
  1023. #ifdef CONFIG_PM
  1024. static const struct hda_amp_list ad1986a_loopbacks[] = {
  1025. { 0x13, HDA_OUTPUT, 0 }, /* Mic */
  1026. { 0x14, HDA_OUTPUT, 0 }, /* Phone */
  1027. { 0x15, HDA_OUTPUT, 0 }, /* CD */
  1028. { 0x16, HDA_OUTPUT, 0 }, /* Aux */
  1029. { 0x17, HDA_OUTPUT, 0 }, /* Line */
  1030. { } /* end */
  1031. };
  1032. #endif
  1033. static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
  1034. {
  1035. unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
  1036. return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
  1037. }
  1038. static int alloc_ad_spec(struct hda_codec *codec)
  1039. {
  1040. struct ad198x_spec *spec;
  1041. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1042. if (!spec)
  1043. return -ENOMEM;
  1044. codec->spec = spec;
  1045. snd_hda_gen_spec_init(&spec->gen);
  1046. return 0;
  1047. }
  1048. /*
  1049. */
  1050. static int ad1986a_parse_auto_config(struct hda_codec *codec)
  1051. {
  1052. struct ad198x_spec *spec = codec->spec;
  1053. /* AD1986A has the inverted EAPD implementation */
  1054. codec->inv_eapd = 1;
  1055. spec->beep_dev_nid = 0x19;
  1056. set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
  1057. /* AD1986A has a hardware problem that it can't share a stream
  1058. * with multiple output pins. The copy of front to surrounds
  1059. * causes noisy or silent outputs at a certain timing, e.g.
  1060. * changing the volume.
  1061. * So, let's disable the shared stream.
  1062. */
  1063. spec->gen.multiout.no_share_stream = 1;
  1064. return ad198x_parse_auto_config(codec);
  1065. }
  1066. static int patch_ad1986a(struct hda_codec *codec)
  1067. {
  1068. struct ad198x_spec *spec;
  1069. int err, board_config;
  1070. err = alloc_ad_spec(codec);
  1071. if (err < 0)
  1072. return err;
  1073. spec = codec->spec;
  1074. board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
  1075. ad1986a_models,
  1076. ad1986a_cfg_tbl);
  1077. if (board_config == AD1986A_AUTO) {
  1078. err = ad1986a_parse_auto_config(codec);
  1079. if (err < 0) {
  1080. ad198x_free(codec);
  1081. return err;
  1082. }
  1083. return 0;
  1084. }
  1085. err = snd_hda_attach_beep_device(codec, 0x19);
  1086. if (err < 0) {
  1087. ad198x_free(codec);
  1088. return err;
  1089. }
  1090. set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
  1091. spec->multiout.max_channels = 6;
  1092. spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
  1093. spec->multiout.dac_nids = ad1986a_dac_nids;
  1094. spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
  1095. spec->num_adc_nids = 1;
  1096. spec->adc_nids = ad1986a_adc_nids;
  1097. spec->capsrc_nids = ad1986a_capsrc_nids;
  1098. spec->input_mux = &ad1986a_capture_source;
  1099. spec->num_mixers = 1;
  1100. spec->mixers[0] = ad1986a_mixers;
  1101. spec->num_init_verbs = 1;
  1102. spec->init_verbs[0] = ad1986a_init_verbs;
  1103. #ifdef CONFIG_PM
  1104. spec->loopback.amplist = ad1986a_loopbacks;
  1105. #endif
  1106. spec->vmaster_nid = 0x1b;
  1107. codec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
  1108. codec->patch_ops = ad198x_patch_ops;
  1109. /* override some parameters */
  1110. switch (board_config) {
  1111. case AD1986A_3STACK:
  1112. spec->num_mixers = 2;
  1113. spec->mixers[1] = ad1986a_3st_mixers;
  1114. spec->num_init_verbs = 2;
  1115. spec->init_verbs[1] = ad1986a_ch2_init;
  1116. spec->channel_mode = ad1986a_modes;
  1117. spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
  1118. spec->need_dac_fix = 1;
  1119. spec->multiout.max_channels = 2;
  1120. spec->multiout.num_dacs = 1;
  1121. break;
  1122. case AD1986A_LAPTOP:
  1123. spec->mixers[0] = ad1986a_laptop_mixers;
  1124. spec->multiout.max_channels = 2;
  1125. spec->multiout.num_dacs = 1;
  1126. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1127. break;
  1128. case AD1986A_LAPTOP_EAPD:
  1129. spec->num_mixers = 3;
  1130. spec->mixers[0] = ad1986a_laptop_master_mixers;
  1131. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1132. spec->mixers[2] = ad1986a_laptop_intmic_mixers;
  1133. spec->num_init_verbs = 2;
  1134. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1135. spec->multiout.max_channels = 2;
  1136. spec->multiout.num_dacs = 1;
  1137. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1138. if (!is_jack_available(codec, 0x25))
  1139. spec->multiout.dig_out_nid = 0;
  1140. spec->input_mux = &ad1986a_laptop_eapd_capture_source;
  1141. break;
  1142. case AD1986A_SAMSUNG:
  1143. spec->num_mixers = 2;
  1144. spec->mixers[0] = ad1986a_laptop_master_mixers;
  1145. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1146. spec->num_init_verbs = 3;
  1147. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1148. spec->init_verbs[2] = ad1986a_automic_verbs;
  1149. spec->multiout.max_channels = 2;
  1150. spec->multiout.num_dacs = 1;
  1151. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1152. if (!is_jack_available(codec, 0x25))
  1153. spec->multiout.dig_out_nid = 0;
  1154. spec->input_mux = &ad1986a_automic_capture_source;
  1155. codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
  1156. codec->patch_ops.init = ad1986a_automic_init;
  1157. break;
  1158. case AD1986A_SAMSUNG_P50:
  1159. spec->num_mixers = 2;
  1160. spec->mixers[0] = ad1986a_automute_master_mixers;
  1161. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1162. spec->num_init_verbs = 4;
  1163. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1164. spec->init_verbs[2] = ad1986a_automic_verbs;
  1165. spec->init_verbs[3] = ad1986a_hp_init_verbs;
  1166. spec->multiout.max_channels = 2;
  1167. spec->multiout.num_dacs = 1;
  1168. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1169. if (!is_jack_available(codec, 0x25))
  1170. spec->multiout.dig_out_nid = 0;
  1171. spec->input_mux = &ad1986a_automic_capture_source;
  1172. codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
  1173. codec->patch_ops.init = ad1986a_samsung_p50_init;
  1174. break;
  1175. case AD1986A_LAPTOP_AUTOMUTE:
  1176. spec->num_mixers = 3;
  1177. spec->mixers[0] = ad1986a_automute_master_mixers;
  1178. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1179. spec->mixers[2] = ad1986a_laptop_intmic_mixers;
  1180. spec->num_init_verbs = 3;
  1181. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1182. spec->init_verbs[2] = ad1986a_hp_init_verbs;
  1183. spec->multiout.max_channels = 2;
  1184. spec->multiout.num_dacs = 1;
  1185. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1186. if (!is_jack_available(codec, 0x25))
  1187. spec->multiout.dig_out_nid = 0;
  1188. spec->input_mux = &ad1986a_laptop_eapd_capture_source;
  1189. codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
  1190. codec->patch_ops.init = ad1986a_hp_init;
  1191. /* Lenovo N100 seems to report the reversed bit
  1192. * for HP jack-sensing
  1193. */
  1194. spec->inv_jack_detect = 1;
  1195. break;
  1196. case AD1986A_ULTRA:
  1197. spec->mixers[0] = ad1986a_laptop_eapd_mixers;
  1198. spec->num_init_verbs = 2;
  1199. spec->init_verbs[1] = ad1986a_ultra_init;
  1200. spec->multiout.max_channels = 2;
  1201. spec->multiout.num_dacs = 1;
  1202. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1203. spec->multiout.dig_out_nid = 0;
  1204. break;
  1205. }
  1206. /* AD1986A has a hardware problem that it can't share a stream
  1207. * with multiple output pins. The copy of front to surrounds
  1208. * causes noisy or silent outputs at a certain timing, e.g.
  1209. * changing the volume.
  1210. * So, let's disable the shared stream.
  1211. */
  1212. spec->multiout.no_share_stream = 1;
  1213. codec->no_trigger_sense = 1;
  1214. codec->no_sticky_stream = 1;
  1215. return 0;
  1216. }
  1217. /*
  1218. * AD1983 specific
  1219. */
  1220. #define AD1983_SPDIF_OUT 0x02
  1221. #define AD1983_DAC 0x03
  1222. #define AD1983_ADC 0x04
  1223. static const hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
  1224. static const hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
  1225. static const hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
  1226. static const struct hda_input_mux ad1983_capture_source = {
  1227. .num_items = 4,
  1228. .items = {
  1229. { "Mic", 0x0 },
  1230. { "Line", 0x1 },
  1231. { "Mix", 0x2 },
  1232. { "Mix Mono", 0x3 },
  1233. },
  1234. };
  1235. /*
  1236. * SPDIF playback route
  1237. */
  1238. static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1239. {
  1240. static const char * const texts[] = { "PCM", "ADC" };
  1241. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1242. uinfo->count = 1;
  1243. uinfo->value.enumerated.items = 2;
  1244. if (uinfo->value.enumerated.item > 1)
  1245. uinfo->value.enumerated.item = 1;
  1246. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1247. return 0;
  1248. }
  1249. static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1250. {
  1251. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1252. struct ad198x_spec *spec = codec->spec;
  1253. ucontrol->value.enumerated.item[0] = spec->spdif_route;
  1254. return 0;
  1255. }
  1256. static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1257. {
  1258. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1259. struct ad198x_spec *spec = codec->spec;
  1260. if (ucontrol->value.enumerated.item[0] > 1)
  1261. return -EINVAL;
  1262. if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
  1263. spec->spdif_route = ucontrol->value.enumerated.item[0];
  1264. snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
  1265. AC_VERB_SET_CONNECT_SEL,
  1266. spec->spdif_route);
  1267. return 1;
  1268. }
  1269. return 0;
  1270. }
  1271. static const struct snd_kcontrol_new ad1983_mixers[] = {
  1272. HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  1273. HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  1274. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  1275. HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  1276. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
  1277. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
  1278. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  1279. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  1280. HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  1281. HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  1282. HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1283. HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1284. HDA_CODEC_VOLUME("Mic Boost Volume", 0x0c, 0x0, HDA_OUTPUT),
  1285. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  1286. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  1287. {
  1288. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1289. .name = "Capture Source",
  1290. .info = ad198x_mux_enum_info,
  1291. .get = ad198x_mux_enum_get,
  1292. .put = ad198x_mux_enum_put,
  1293. },
  1294. {
  1295. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1296. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  1297. .info = ad1983_spdif_route_info,
  1298. .get = ad1983_spdif_route_get,
  1299. .put = ad1983_spdif_route_put,
  1300. },
  1301. { } /* end */
  1302. };
  1303. static const struct hda_verb ad1983_init_verbs[] = {
  1304. /* Front, HP, Mono; mute as default */
  1305. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1306. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1307. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1308. /* Beep, PCM, Mic, Line-In: mute */
  1309. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1310. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1311. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1312. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1313. /* Front, HP selectors; from Mix */
  1314. {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
  1315. {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
  1316. /* Mono selector; from Mix */
  1317. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
  1318. /* Mic selector; Mic */
  1319. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1320. /* Line-in selector: Line-in */
  1321. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  1322. /* Mic boost: 0dB */
  1323. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1324. /* Record selector: mic */
  1325. {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
  1326. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1327. /* SPDIF route: PCM */
  1328. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
  1329. /* Front Pin */
  1330. {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  1331. /* HP Pin */
  1332. {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  1333. /* Mono Pin */
  1334. {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  1335. /* Mic Pin */
  1336. {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  1337. /* Line Pin */
  1338. {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  1339. { } /* end */
  1340. };
  1341. #ifdef CONFIG_PM
  1342. static const struct hda_amp_list ad1983_loopbacks[] = {
  1343. { 0x12, HDA_OUTPUT, 0 }, /* Mic */
  1344. { 0x13, HDA_OUTPUT, 0 }, /* Line */
  1345. { } /* end */
  1346. };
  1347. #endif
  1348. /* models */
  1349. enum {
  1350. AD1983_AUTO,
  1351. AD1983_BASIC,
  1352. AD1983_MODELS
  1353. };
  1354. static const char * const ad1983_models[AD1983_MODELS] = {
  1355. [AD1983_AUTO] = "auto",
  1356. [AD1983_BASIC] = "basic",
  1357. };
  1358. static int ad1983_parse_auto_config(struct hda_codec *codec)
  1359. {
  1360. struct ad198x_spec *spec = codec->spec;
  1361. spec->beep_dev_nid = 0x10;
  1362. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  1363. return ad198x_parse_auto_config(codec);
  1364. }
  1365. static int patch_ad1983(struct hda_codec *codec)
  1366. {
  1367. struct ad198x_spec *spec;
  1368. int board_config;
  1369. int err;
  1370. err = alloc_ad_spec(codec);
  1371. if (err < 0)
  1372. return err;
  1373. spec = codec->spec;
  1374. board_config = snd_hda_check_board_config(codec, AD1983_MODELS,
  1375. ad1983_models, NULL);
  1376. if (board_config == AD1983_AUTO) {
  1377. err = ad1983_parse_auto_config(codec);
  1378. if (err < 0) {
  1379. ad198x_free(codec);
  1380. return err;
  1381. }
  1382. return 0;
  1383. }
  1384. err = snd_hda_attach_beep_device(codec, 0x10);
  1385. if (err < 0) {
  1386. ad198x_free(codec);
  1387. return err;
  1388. }
  1389. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  1390. spec->multiout.max_channels = 2;
  1391. spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
  1392. spec->multiout.dac_nids = ad1983_dac_nids;
  1393. spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
  1394. spec->num_adc_nids = 1;
  1395. spec->adc_nids = ad1983_adc_nids;
  1396. spec->capsrc_nids = ad1983_capsrc_nids;
  1397. spec->input_mux = &ad1983_capture_source;
  1398. spec->num_mixers = 1;
  1399. spec->mixers[0] = ad1983_mixers;
  1400. spec->num_init_verbs = 1;
  1401. spec->init_verbs[0] = ad1983_init_verbs;
  1402. spec->spdif_route = 0;
  1403. #ifdef CONFIG_PM
  1404. spec->loopback.amplist = ad1983_loopbacks;
  1405. #endif
  1406. spec->vmaster_nid = 0x05;
  1407. codec->patch_ops = ad198x_patch_ops;
  1408. codec->no_trigger_sense = 1;
  1409. codec->no_sticky_stream = 1;
  1410. return 0;
  1411. }
  1412. /*
  1413. * AD1981 HD specific
  1414. */
  1415. #define AD1981_SPDIF_OUT 0x02
  1416. #define AD1981_DAC 0x03
  1417. #define AD1981_ADC 0x04
  1418. static const hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
  1419. static const hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
  1420. static const hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
  1421. /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
  1422. static const struct hda_input_mux ad1981_capture_source = {
  1423. .num_items = 7,
  1424. .items = {
  1425. { "Front Mic", 0x0 },
  1426. { "Line", 0x1 },
  1427. { "Mix", 0x2 },
  1428. { "Mix Mono", 0x3 },
  1429. { "CD", 0x4 },
  1430. { "Mic", 0x6 },
  1431. { "Aux", 0x7 },
  1432. },
  1433. };
  1434. static const struct snd_kcontrol_new ad1981_mixers[] = {
  1435. HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  1436. HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  1437. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  1438. HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  1439. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
  1440. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
  1441. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  1442. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  1443. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  1444. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  1445. HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1446. HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1447. HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  1448. HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  1449. HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  1450. HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  1451. HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1452. HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1453. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
  1454. HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0x0, HDA_INPUT),
  1455. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  1456. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  1457. {
  1458. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1459. .name = "Capture Source",
  1460. .info = ad198x_mux_enum_info,
  1461. .get = ad198x_mux_enum_get,
  1462. .put = ad198x_mux_enum_put,
  1463. },
  1464. /* identical with AD1983 */
  1465. {
  1466. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1467. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  1468. .info = ad1983_spdif_route_info,
  1469. .get = ad1983_spdif_route_get,
  1470. .put = ad1983_spdif_route_put,
  1471. },
  1472. { } /* end */
  1473. };
  1474. static const struct hda_verb ad1981_init_verbs[] = {
  1475. /* Front, HP, Mono; mute as default */
  1476. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1477. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1478. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1479. /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
  1480. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1481. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1482. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1483. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1484. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1485. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1486. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1487. /* Front, HP selectors; from Mix */
  1488. {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
  1489. {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
  1490. /* Mono selector; from Mix */
  1491. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
  1492. /* Mic Mixer; select Front Mic */
  1493. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1494. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1495. /* Mic boost: 0dB */
  1496. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1497. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1498. /* Record selector: Front mic */
  1499. {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
  1500. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1501. /* SPDIF route: PCM */
  1502. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
  1503. /* Front Pin */
  1504. {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  1505. /* HP Pin */
  1506. {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  1507. /* Mono Pin */
  1508. {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  1509. /* Front & Rear Mic Pins */
  1510. {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  1511. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  1512. /* Line Pin */
  1513. {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  1514. /* Digital Beep */
  1515. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
  1516. /* Line-Out as Input: disabled */
  1517. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1518. { } /* end */
  1519. };
  1520. #ifdef CONFIG_PM
  1521. static const struct hda_amp_list ad1981_loopbacks[] = {
  1522. { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
  1523. { 0x13, HDA_OUTPUT, 0 }, /* Line */
  1524. { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
  1525. { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
  1526. { 0x1d, HDA_OUTPUT, 0 }, /* CD */
  1527. { } /* end */
  1528. };
  1529. #endif
  1530. /*
  1531. * Patch for HP nx6320
  1532. *
  1533. * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
  1534. * speaker output enabled _and_ mute-LED off.
  1535. */
  1536. #define AD1981_HP_EVENT 0x37
  1537. #define AD1981_MIC_EVENT 0x38
  1538. static const struct hda_verb ad1981_hp_init_verbs[] = {
  1539. {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
  1540. /* pin sensing on HP and Mic jacks */
  1541. {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
  1542. {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
  1543. {}
  1544. };
  1545. /* turn on/off EAPD (+ mute HP) as a master switch */
  1546. static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1547. struct snd_ctl_elem_value *ucontrol)
  1548. {
  1549. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1550. struct ad198x_spec *spec = codec->spec;
  1551. if (! ad198x_eapd_put(kcontrol, ucontrol))
  1552. return 0;
  1553. /* change speaker pin appropriately */
  1554. snd_hda_set_pin_ctl(codec, 0x05, spec->cur_eapd ? PIN_OUT : 0);
  1555. /* toggle HP mute appropriately */
  1556. snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
  1557. HDA_AMP_MUTE,
  1558. spec->cur_eapd ? 0 : HDA_AMP_MUTE);
  1559. return 1;
  1560. }
  1561. /* bind volumes of both NID 0x05 and 0x06 */
  1562. static const struct hda_bind_ctls ad1981_hp_bind_master_vol = {
  1563. .ops = &snd_hda_bind_vol,
  1564. .values = {
  1565. HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  1566. HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
  1567. 0
  1568. },
  1569. };
  1570. /* mute internal speaker if HP is plugged */
  1571. static void ad1981_hp_automute(struct hda_codec *codec)
  1572. {
  1573. unsigned int present;
  1574. present = snd_hda_jack_detect(codec, 0x06);
  1575. snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
  1576. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  1577. }
  1578. /* toggle input of built-in and mic jack appropriately */
  1579. static void ad1981_hp_automic(struct hda_codec *codec)
  1580. {
  1581. static const struct hda_verb mic_jack_on[] = {
  1582. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1583. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1584. {}
  1585. };
  1586. static const struct hda_verb mic_jack_off[] = {
  1587. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1588. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1589. {}
  1590. };
  1591. unsigned int present;
  1592. present = snd_hda_jack_detect(codec, 0x08);
  1593. if (present)
  1594. snd_hda_sequence_write(codec, mic_jack_on);
  1595. else
  1596. snd_hda_sequence_write(codec, mic_jack_off);
  1597. }
  1598. /* unsolicited event for HP jack sensing */
  1599. static void ad1981_hp_unsol_event(struct hda_codec *codec,
  1600. unsigned int res)
  1601. {
  1602. res >>= 26;
  1603. switch (res) {
  1604. case AD1981_HP_EVENT:
  1605. ad1981_hp_automute(codec);
  1606. break;
  1607. case AD1981_MIC_EVENT:
  1608. ad1981_hp_automic(codec);
  1609. break;
  1610. }
  1611. }
  1612. static const struct hda_input_mux ad1981_hp_capture_source = {
  1613. .num_items = 3,
  1614. .items = {
  1615. { "Mic", 0x0 },
  1616. { "Dock Mic", 0x1 },
  1617. { "Mix", 0x2 },
  1618. },
  1619. };
  1620. static const struct snd_kcontrol_new ad1981_hp_mixers[] = {
  1621. HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
  1622. {
  1623. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1624. .subdevice = HDA_SUBDEV_NID_FLAG | 0x05,
  1625. .name = "Master Playback Switch",
  1626. .info = ad198x_eapd_info,
  1627. .get = ad198x_eapd_get,
  1628. .put = ad1981_hp_master_sw_put,
  1629. .private_value = 0x05,
  1630. },
  1631. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  1632. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  1633. #if 0
  1634. /* FIXME: analog mic/line loopback doesn't work with my tests...
  1635. * (although recording is OK)
  1636. */
  1637. HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  1638. HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  1639. HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1640. HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1641. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  1642. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  1643. /* FIXME: does this laptop have analog CD connection? */
  1644. HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1645. HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1646. #endif
  1647. HDA_CODEC_VOLUME("Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
  1648. HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x18, 0x0, HDA_INPUT),
  1649. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  1650. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  1651. {
  1652. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1653. .name = "Capture Source",
  1654. .info = ad198x_mux_enum_info,
  1655. .get = ad198x_mux_enum_get,
  1656. .put = ad198x_mux_enum_put,
  1657. },
  1658. { } /* end */
  1659. };
  1660. /* initialize jack-sensing, too */
  1661. static int ad1981_hp_init(struct hda_codec *codec)
  1662. {
  1663. ad198x_init(codec);
  1664. ad1981_hp_automute(codec);
  1665. ad1981_hp_automic(codec);
  1666. return 0;
  1667. }
  1668. /* configuration for Toshiba Laptops */
  1669. static const struct hda_verb ad1981_toshiba_init_verbs[] = {
  1670. {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
  1671. /* pin sensing on HP and Mic jacks */
  1672. {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
  1673. {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
  1674. {}
  1675. };
  1676. static const struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
  1677. HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
  1678. HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
  1679. { }
  1680. };
  1681. /* configuration for Lenovo Thinkpad T60 */
  1682. static const struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
  1683. HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  1684. HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  1685. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  1686. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  1687. HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  1688. HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  1689. HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1690. HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1691. HDA_CODEC_VOLUME("Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
  1692. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  1693. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  1694. {
  1695. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1696. .name = "Capture Source",
  1697. .info = ad198x_mux_enum_info,
  1698. .get = ad198x_mux_enum_get,
  1699. .put = ad198x_mux_enum_put,
  1700. },
  1701. /* identical with AD1983 */
  1702. {
  1703. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1704. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  1705. .info = ad1983_spdif_route_info,
  1706. .get = ad1983_spdif_route_get,
  1707. .put = ad1983_spdif_route_put,
  1708. },
  1709. { } /* end */
  1710. };
  1711. static const struct hda_input_mux ad1981_thinkpad_capture_source = {
  1712. .num_items = 3,
  1713. .items = {
  1714. { "Mic", 0x0 },
  1715. { "Mix", 0x2 },
  1716. { "CD", 0x4 },
  1717. },
  1718. };
  1719. /* models */
  1720. enum {
  1721. AD1981_AUTO,
  1722. AD1981_BASIC,
  1723. AD1981_HP,
  1724. AD1981_THINKPAD,
  1725. AD1981_TOSHIBA,
  1726. AD1981_MODELS
  1727. };
  1728. static const char * const ad1981_models[AD1981_MODELS] = {
  1729. [AD1981_AUTO] = "auto",
  1730. [AD1981_HP] = "hp",
  1731. [AD1981_THINKPAD] = "thinkpad",
  1732. [AD1981_BASIC] = "basic",
  1733. [AD1981_TOSHIBA] = "toshiba"
  1734. };
  1735. static const struct snd_pci_quirk ad1981_cfg_tbl[] = {
  1736. SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
  1737. SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
  1738. /* All HP models */
  1739. SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
  1740. SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
  1741. /* Lenovo Thinkpad T60/X60/Z6xx */
  1742. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
  1743. /* HP nx6320 (reversed SSID, H/W bug) */
  1744. SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
  1745. {}
  1746. };
  1747. static int ad1981_parse_auto_config(struct hda_codec *codec)
  1748. {
  1749. struct ad198x_spec *spec = codec->spec;
  1750. spec->beep_dev_nid = 0x10;
  1751. set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
  1752. return ad198x_parse_auto_config(codec);
  1753. }
  1754. static int patch_ad1981(struct hda_codec *codec)
  1755. {
  1756. struct ad198x_spec *spec;
  1757. int err, board_config;
  1758. err = alloc_ad_spec(codec);
  1759. if (err < 0)
  1760. return -ENOMEM;
  1761. spec = codec->spec;
  1762. board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
  1763. ad1981_models,
  1764. ad1981_cfg_tbl);
  1765. if (board_config == AD1981_AUTO) {
  1766. err = ad1981_parse_auto_config(codec);
  1767. if (err < 0) {
  1768. ad198x_free(codec);
  1769. return err;
  1770. }
  1771. return 0;
  1772. }
  1773. err = snd_hda_attach_beep_device(codec, 0x10);
  1774. if (err < 0) {
  1775. ad198x_free(codec);
  1776. return err;
  1777. }
  1778. set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
  1779. spec->multiout.max_channels = 2;
  1780. spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
  1781. spec->multiout.dac_nids = ad1981_dac_nids;
  1782. spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
  1783. spec->num_adc_nids = 1;
  1784. spec->adc_nids = ad1981_adc_nids;
  1785. spec->capsrc_nids = ad1981_capsrc_nids;
  1786. spec->input_mux = &ad1981_capture_source;
  1787. spec->num_mixers = 1;
  1788. spec->mixers[0] = ad1981_mixers;
  1789. spec->num_init_verbs = 1;
  1790. spec->init_verbs[0] = ad1981_init_verbs;
  1791. spec->spdif_route = 0;
  1792. #ifdef CONFIG_PM
  1793. spec->loopback.amplist = ad1981_loopbacks;
  1794. #endif
  1795. spec->vmaster_nid = 0x05;
  1796. codec->patch_ops = ad198x_patch_ops;
  1797. /* override some parameters */
  1798. switch (board_config) {
  1799. case AD1981_HP:
  1800. spec->mixers[0] = ad1981_hp_mixers;
  1801. spec->num_init_verbs = 2;
  1802. spec->init_verbs[1] = ad1981_hp_init_verbs;
  1803. if (!is_jack_available(codec, 0x0a))
  1804. spec->multiout.dig_out_nid = 0;
  1805. spec->input_mux = &ad1981_hp_capture_source;
  1806. codec->patch_ops.init = ad1981_hp_init;
  1807. codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
  1808. /* set the upper-limit for mixer amp to 0dB for avoiding the
  1809. * possible damage by overloading
  1810. */
  1811. snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
  1812. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1813. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1814. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1815. (1 << AC_AMPCAP_MUTE_SHIFT));
  1816. break;
  1817. case AD1981_THINKPAD:
  1818. spec->mixers[0] = ad1981_thinkpad_mixers;
  1819. spec->input_mux = &ad1981_thinkpad_capture_source;
  1820. /* set the upper-limit for mixer amp to 0dB for avoiding the
  1821. * possible damage by overloading
  1822. */
  1823. snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
  1824. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1825. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1826. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1827. (1 << AC_AMPCAP_MUTE_SHIFT));
  1828. break;
  1829. case AD1981_TOSHIBA:
  1830. spec->mixers[0] = ad1981_hp_mixers;
  1831. spec->mixers[1] = ad1981_toshiba_mixers;
  1832. spec->num_init_verbs = 2;
  1833. spec->init_verbs[1] = ad1981_toshiba_init_verbs;
  1834. spec->multiout.dig_out_nid = 0;
  1835. spec->input_mux = &ad1981_hp_capture_source;
  1836. codec->patch_ops.init = ad1981_hp_init;
  1837. codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
  1838. break;
  1839. }
  1840. codec->no_trigger_sense = 1;
  1841. codec->no_sticky_stream = 1;
  1842. return 0;
  1843. }
  1844. /*
  1845. * AD1988
  1846. *
  1847. * Output pins and routes
  1848. *
  1849. * Pin Mix Sel DAC (*)
  1850. * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
  1851. * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
  1852. * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
  1853. * port-D 0x12 (mute/hp) <- 0x29 <- 04
  1854. * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
  1855. * port-F 0x16 (mute) <- 0x2a <- 06
  1856. * port-G 0x24 (mute) <- 0x27 <- 05
  1857. * port-H 0x25 (mute) <- 0x28 <- 0a
  1858. * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
  1859. *
  1860. * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
  1861. * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
  1862. *
  1863. * Input pins and routes
  1864. *
  1865. * pin boost mix input # / adc input #
  1866. * port-A 0x11 -> 0x38 -> mix 2, ADC 0
  1867. * port-B 0x14 -> 0x39 -> mix 0, ADC 1
  1868. * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
  1869. * port-D 0x12 -> 0x3d -> mix 3, ADC 8
  1870. * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
  1871. * port-F 0x16 -> 0x3b -> mix 5, ADC 3
  1872. * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
  1873. * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
  1874. *
  1875. *
  1876. * DAC assignment
  1877. * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
  1878. * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
  1879. *
  1880. * Inputs of Analog Mix (0x20)
  1881. * 0:Port-B (front mic)
  1882. * 1:Port-C/G/H (line-in)
  1883. * 2:Port-A
  1884. * 3:Port-D (line-in/2)
  1885. * 4:Port-E/G/H (mic-in)
  1886. * 5:Port-F (mic2-in)
  1887. * 6:CD
  1888. * 7:Beep
  1889. *
  1890. * ADC selection
  1891. * 0:Port-A
  1892. * 1:Port-B (front mic-in)
  1893. * 2:Port-C (line-in)
  1894. * 3:Port-F (mic2-in)
  1895. * 4:Port-E (mic-in)
  1896. * 5:CD
  1897. * 6:Port-G
  1898. * 7:Port-H
  1899. * 8:Port-D (line-in/2)
  1900. * 9:Mix
  1901. *
  1902. * Proposed pin assignments by the datasheet
  1903. *
  1904. * 6-stack
  1905. * Port-A front headphone
  1906. * B front mic-in
  1907. * C rear line-in
  1908. * D rear front-out
  1909. * E rear mic-in
  1910. * F rear surround
  1911. * G rear CLFE
  1912. * H rear side
  1913. *
  1914. * 3-stack
  1915. * Port-A front headphone
  1916. * B front mic
  1917. * C rear line-in/surround
  1918. * D rear front-out
  1919. * E rear mic-in/CLFE
  1920. *
  1921. * laptop
  1922. * Port-A headphone
  1923. * B mic-in
  1924. * C docking station
  1925. * D internal speaker (with EAPD)
  1926. * E/F quad mic array
  1927. */
  1928. /* models */
  1929. enum {
  1930. AD1988_AUTO,
  1931. AD1988_6STACK,
  1932. AD1988_6STACK_DIG,
  1933. AD1988_3STACK,
  1934. AD1988_3STACK_DIG,
  1935. AD1988_LAPTOP,
  1936. AD1988_LAPTOP_DIG,
  1937. AD1988_MODEL_LAST,
  1938. };
  1939. /* reivision id to check workarounds */
  1940. #define AD1988A_REV2 0x100200
  1941. #define is_rev2(codec) \
  1942. ((codec)->vendor_id == 0x11d41988 && \
  1943. (codec)->revision_id == AD1988A_REV2)
  1944. /*
  1945. * mixers
  1946. */
  1947. static const hda_nid_t ad1988_6stack_dac_nids[4] = {
  1948. 0x04, 0x06, 0x05, 0x0a
  1949. };
  1950. static const hda_nid_t ad1988_3stack_dac_nids[3] = {
  1951. 0x04, 0x05, 0x0a
  1952. };
  1953. /* for AD1988A revision-2, DAC2-4 are swapped */
  1954. static const hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
  1955. 0x04, 0x05, 0x0a, 0x06
  1956. };
  1957. static const hda_nid_t ad1988_alt_dac_nid[1] = {
  1958. 0x03
  1959. };
  1960. static const hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
  1961. 0x04, 0x0a, 0x06
  1962. };
  1963. static const hda_nid_t ad1988_adc_nids[3] = {
  1964. 0x08, 0x09, 0x0f
  1965. };
  1966. static const hda_nid_t ad1988_capsrc_nids[3] = {
  1967. 0x0c, 0x0d, 0x0e
  1968. };
  1969. #define AD1988_SPDIF_OUT 0x02
  1970. #define AD1988_SPDIF_OUT_HDMI 0x0b
  1971. #define AD1988_SPDIF_IN 0x07
  1972. static const hda_nid_t ad1989b_slave_dig_outs[] = {
  1973. AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
  1974. };
  1975. static const struct hda_input_mux ad1988_6stack_capture_source = {
  1976. .num_items = 5,
  1977. .items = {
  1978. { "Front Mic", 0x1 }, /* port-B */
  1979. { "Line", 0x2 }, /* port-C */
  1980. { "Mic", 0x4 }, /* port-E */
  1981. { "CD", 0x5 },
  1982. { "Mix", 0x9 },
  1983. },
  1984. };
  1985. static const struct hda_input_mux ad1988_laptop_capture_source = {
  1986. .num_items = 3,
  1987. .items = {
  1988. { "Mic/Line", 0x1 }, /* port-B */
  1989. { "CD", 0x5 },
  1990. { "Mix", 0x9 },
  1991. },
  1992. };
  1993. /*
  1994. */
  1995. static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
  1996. struct snd_ctl_elem_info *uinfo)
  1997. {
  1998. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1999. struct ad198x_spec *spec = codec->spec;
  2000. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  2001. spec->num_channel_mode);
  2002. }
  2003. static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
  2004. struct snd_ctl_elem_value *ucontrol)
  2005. {
  2006. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2007. struct ad198x_spec *spec = codec->spec;
  2008. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  2009. spec->num_channel_mode, spec->multiout.max_channels);
  2010. }
  2011. static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
  2012. struct snd_ctl_elem_value *ucontrol)
  2013. {
  2014. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2015. struct ad198x_spec *spec = codec->spec;
  2016. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  2017. spec->num_channel_mode,
  2018. &spec->multiout.max_channels);
  2019. if (err >= 0 && spec->need_dac_fix)
  2020. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  2021. return err;
  2022. }
  2023. /* 6-stack mode */
  2024. static const struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
  2025. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  2026. HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  2027. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  2028. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  2029. HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  2030. { } /* end */
  2031. };
  2032. static const struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
  2033. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  2034. HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  2035. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
  2036. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
  2037. HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  2038. { } /* end */
  2039. };
  2040. static const struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
  2041. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  2042. HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
  2043. HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
  2044. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
  2045. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
  2046. HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
  2047. HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
  2048. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  2049. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  2050. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  2051. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  2052. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  2053. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  2054. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  2055. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
  2056. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
  2057. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  2058. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  2059. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  2060. HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
  2061. { } /* end */
  2062. };
  2063. /* 3-stack mode */
  2064. static const struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
  2065. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  2066. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  2067. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  2068. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  2069. { } /* end */
  2070. };
  2071. static const struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
  2072. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  2073. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  2074. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
  2075. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
  2076. { } /* end */
  2077. };
  2078. static const struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
  2079. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  2080. HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
  2081. HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
  2082. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
  2083. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
  2084. HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
  2085. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  2086. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  2087. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  2088. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  2089. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  2090. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  2091. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  2092. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
  2093. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
  2094. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  2095. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  2096. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  2097. HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
  2098. {
  2099. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2100. .name = "Channel Mode",
  2101. .info = ad198x_ch_mode_info,
  2102. .get = ad198x_ch_mode_get,
  2103. .put = ad198x_ch_mode_put,
  2104. },
  2105. { } /* end */
  2106. };
  2107. /* laptop mode */
  2108. static const struct snd_kcontrol_new ad1988_laptop_mixers[] = {
  2109. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  2110. HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  2111. HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
  2112. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  2113. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  2114. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  2115. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  2116. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  2117. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  2118. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  2119. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  2120. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  2121. HDA_CODEC_VOLUME("Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  2122. {
  2123. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2124. .name = "External Amplifier",
  2125. .subdevice = HDA_SUBDEV_NID_FLAG | 0x12,
  2126. .info = ad198x_eapd_info,
  2127. .get = ad198x_eapd_get,
  2128. .put = ad198x_eapd_put,
  2129. .private_value = 0x12, /* port-D */
  2130. },
  2131. { } /* end */
  2132. };
  2133. /* capture */
  2134. static const struct snd_kcontrol_new ad1988_capture_mixers[] = {
  2135. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  2136. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  2137. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  2138. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  2139. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
  2140. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
  2141. {
  2142. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2143. /* The multiple "Capture Source" controls confuse alsamixer
  2144. * So call somewhat different..
  2145. */
  2146. /* .name = "Capture Source", */
  2147. .name = "Input Source",
  2148. .count = 3,
  2149. .info = ad198x_mux_enum_info,
  2150. .get = ad198x_mux_enum_get,
  2151. .put = ad198x_mux_enum_put,
  2152. },
  2153. { } /* end */
  2154. };
  2155. static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
  2156. struct snd_ctl_elem_info *uinfo)
  2157. {
  2158. static const char * const texts[] = {
  2159. "PCM", "ADC1", "ADC2", "ADC3"
  2160. };
  2161. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2162. uinfo->count = 1;
  2163. uinfo->value.enumerated.items = 4;
  2164. if (uinfo->value.enumerated.item >= 4)
  2165. uinfo->value.enumerated.item = 3;
  2166. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  2167. return 0;
  2168. }
  2169. static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
  2170. struct snd_ctl_elem_value *ucontrol)
  2171. {
  2172. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2173. unsigned int sel;
  2174. sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
  2175. AC_AMP_GET_INPUT);
  2176. if (!(sel & 0x80))
  2177. ucontrol->value.enumerated.item[0] = 0;
  2178. else {
  2179. sel = snd_hda_codec_read(codec, 0x0b, 0,
  2180. AC_VERB_GET_CONNECT_SEL, 0);
  2181. if (sel < 3)
  2182. sel++;
  2183. else
  2184. sel = 0;
  2185. ucontrol->value.enumerated.item[0] = sel;
  2186. }
  2187. return 0;
  2188. }
  2189. static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
  2190. struct snd_ctl_elem_value *ucontrol)
  2191. {
  2192. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2193. unsigned int val, sel;
  2194. int change;
  2195. val = ucontrol->value.enumerated.item[0];
  2196. if (val > 3)
  2197. return -EINVAL;
  2198. if (!val) {
  2199. sel = snd_hda_codec_read(codec, 0x1d, 0,
  2200. AC_VERB_GET_AMP_GAIN_MUTE,
  2201. AC_AMP_GET_INPUT);
  2202. change = sel & 0x80;
  2203. if (change) {
  2204. snd_hda_codec_write_cache(codec, 0x1d, 0,
  2205. AC_VERB_SET_AMP_GAIN_MUTE,
  2206. AMP_IN_UNMUTE(0));
  2207. snd_hda_codec_write_cache(codec, 0x1d, 0,
  2208. AC_VERB_SET_AMP_GAIN_MUTE,
  2209. AMP_IN_MUTE(1));
  2210. }
  2211. } else {
  2212. sel = snd_hda_codec_read(codec, 0x1d, 0,
  2213. AC_VERB_GET_AMP_GAIN_MUTE,
  2214. AC_AMP_GET_INPUT | 0x01);
  2215. change = sel & 0x80;
  2216. if (change) {
  2217. snd_hda_codec_write_cache(codec, 0x1d, 0,
  2218. AC_VERB_SET_AMP_GAIN_MUTE,
  2219. AMP_IN_MUTE(0));
  2220. snd_hda_codec_write_cache(codec, 0x1d, 0,
  2221. AC_VERB_SET_AMP_GAIN_MUTE,
  2222. AMP_IN_UNMUTE(1));
  2223. }
  2224. sel = snd_hda_codec_read(codec, 0x0b, 0,
  2225. AC_VERB_GET_CONNECT_SEL, 0) + 1;
  2226. change |= sel != val;
  2227. if (change)
  2228. snd_hda_codec_write_cache(codec, 0x0b, 0,
  2229. AC_VERB_SET_CONNECT_SEL,
  2230. val - 1);
  2231. }
  2232. return change;
  2233. }
  2234. static const struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
  2235. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  2236. {
  2237. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2238. .name = "IEC958 Playback Source",
  2239. .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
  2240. .info = ad1988_spdif_playback_source_info,
  2241. .get = ad1988_spdif_playback_source_get,
  2242. .put = ad1988_spdif_playback_source_put,
  2243. },
  2244. { } /* end */
  2245. };
  2246. static const struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
  2247. HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
  2248. { } /* end */
  2249. };
  2250. static const struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
  2251. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  2252. HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  2253. { } /* end */
  2254. };
  2255. /*
  2256. * initialization verbs
  2257. */
  2258. /*
  2259. * for 6-stack (+dig)
  2260. */
  2261. static const struct hda_verb ad1988_6stack_init_verbs[] = {
  2262. /* Front, Surround, CLFE, side DAC; unmute as default */
  2263. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2264. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2265. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2266. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2267. /* Port-A front headphon path */
  2268. {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  2269. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2270. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2271. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2272. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2273. /* Port-D line-out path */
  2274. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2275. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2276. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2277. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2278. /* Port-F surround path */
  2279. {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2280. {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2281. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2282. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2283. /* Port-G CLFE path */
  2284. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2285. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2286. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2287. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2288. /* Port-H side path */
  2289. {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2290. {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2291. {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2292. {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2293. /* Mono out path */
  2294. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  2295. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2296. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2297. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2298. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  2299. /* Port-B front mic-in path */
  2300. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2301. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2302. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2303. /* Port-C line-in path */
  2304. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2305. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2306. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2307. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  2308. /* Port-E mic-in path */
  2309. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2310. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2311. {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2312. {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
  2313. /* Analog CD Input */
  2314. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2315. /* Analog Mix output amp */
  2316. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  2317. { }
  2318. };
  2319. static const struct hda_verb ad1988_6stack_fp_init_verbs[] = {
  2320. /* Headphone; unmute as default */
  2321. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2322. /* Port-A front headphon path */
  2323. {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  2324. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2325. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2326. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2327. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2328. { }
  2329. };
  2330. static const struct hda_verb ad1988_capture_init_verbs[] = {
  2331. /* mute analog mix */
  2332. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2333. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2334. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2335. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2336. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2337. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  2338. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  2339. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  2340. /* select ADCs - front-mic */
  2341. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  2342. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  2343. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  2344. { }
  2345. };
  2346. static const struct hda_verb ad1988_spdif_init_verbs[] = {
  2347. /* SPDIF out sel */
  2348. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
  2349. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
  2350. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2351. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2352. /* SPDIF out pin */
  2353. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  2354. { }
  2355. };
  2356. static const struct hda_verb ad1988_spdif_in_init_verbs[] = {
  2357. /* unmute SPDIF input pin */
  2358. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2359. { }
  2360. };
  2361. /* AD1989 has no ADC -> SPDIF route */
  2362. static const struct hda_verb ad1989_spdif_init_verbs[] = {
  2363. /* SPDIF-1 out pin */
  2364. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  2365. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  2366. /* SPDIF-2/HDMI out pin */
  2367. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  2368. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  2369. { }
  2370. };
  2371. /*
  2372. * verbs for 3stack (+dig)
  2373. */
  2374. static const struct hda_verb ad1988_3stack_ch2_init[] = {
  2375. /* set port-C to line-in */
  2376. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2377. { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  2378. /* set port-E to mic-in */
  2379. { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2380. { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  2381. { } /* end */
  2382. };
  2383. static const struct hda_verb ad1988_3stack_ch6_init[] = {
  2384. /* set port-C to surround out */
  2385. { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  2386. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  2387. /* set port-E to CLFE out */
  2388. { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  2389. { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  2390. { } /* end */
  2391. };
  2392. static const struct hda_channel_mode ad1988_3stack_modes[2] = {
  2393. { 2, ad1988_3stack_ch2_init },
  2394. { 6, ad1988_3stack_ch6_init },
  2395. };
  2396. static const struct hda_verb ad1988_3stack_init_verbs[] = {
  2397. /* Front, Surround, CLFE, side DAC; unmute as default */
  2398. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2399. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2400. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2401. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2402. /* Port-A front headphon path */
  2403. {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  2404. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2405. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2406. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2407. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2408. /* Port-D line-out path */
  2409. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2410. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2411. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2412. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2413. /* Mono out path */
  2414. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  2415. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2416. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2417. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2418. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  2419. /* Port-B front mic-in path */
  2420. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2421. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2422. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2423. /* Port-C line-in/surround path - 6ch mode as default */
  2424. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2425. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2426. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2427. {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
  2428. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  2429. /* Port-E mic-in/CLFE path - 6ch mode as default */
  2430. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2431. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2432. {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2433. {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
  2434. {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
  2435. /* mute analog mix */
  2436. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2437. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2438. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2439. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2440. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2441. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  2442. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  2443. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  2444. /* select ADCs - front-mic */
  2445. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  2446. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  2447. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  2448. /* Analog Mix output amp */
  2449. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  2450. { }
  2451. };
  2452. /*
  2453. * verbs for laptop mode (+dig)
  2454. */
  2455. static const struct hda_verb ad1988_laptop_hp_on[] = {
  2456. /* unmute port-A and mute port-D */
  2457. { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  2458. { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2459. { } /* end */
  2460. };
  2461. static const struct hda_verb ad1988_laptop_hp_off[] = {
  2462. /* mute port-A and unmute port-D */
  2463. { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2464. { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  2465. { } /* end */
  2466. };
  2467. #define AD1988_HP_EVENT 0x01
  2468. static const struct hda_verb ad1988_laptop_init_verbs[] = {
  2469. /* Front, Surround, CLFE, side DAC; unmute as default */
  2470. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2471. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2472. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2473. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2474. /* Port-A front headphon path */
  2475. {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  2476. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2477. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2478. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2479. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2480. /* unsolicited event for pin-sense */
  2481. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
  2482. /* Port-D line-out path + EAPD */
  2483. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2484. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2485. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2486. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2487. {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
  2488. /* Mono out path */
  2489. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  2490. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2491. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2492. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2493. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  2494. /* Port-B mic-in path */
  2495. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2496. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2497. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2498. /* Port-C docking station - try to output */
  2499. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2500. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2501. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2502. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  2503. /* mute analog mix */
  2504. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2505. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2506. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2507. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2508. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2509. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  2510. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  2511. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  2512. /* select ADCs - mic */
  2513. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  2514. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  2515. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  2516. /* Analog Mix output amp */
  2517. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  2518. { }
  2519. };
  2520. static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
  2521. {
  2522. if ((res >> 26) != AD1988_HP_EVENT)
  2523. return;
  2524. if (snd_hda_jack_detect(codec, 0x11))
  2525. snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
  2526. else
  2527. snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
  2528. }
  2529. #ifdef CONFIG_PM
  2530. static const struct hda_amp_list ad1988_loopbacks[] = {
  2531. { 0x20, HDA_INPUT, 0 }, /* Front Mic */
  2532. { 0x20, HDA_INPUT, 1 }, /* Line */
  2533. { 0x20, HDA_INPUT, 4 }, /* Mic */
  2534. { 0x20, HDA_INPUT, 6 }, /* CD */
  2535. { } /* end */
  2536. };
  2537. #endif
  2538. /*
  2539. */
  2540. static int ad1988_parse_auto_config(struct hda_codec *codec)
  2541. {
  2542. struct ad198x_spec *spec = codec->spec;
  2543. spec->beep_dev_nid = 0x10;
  2544. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  2545. return ad198x_parse_auto_config(codec);
  2546. }
  2547. /*
  2548. */
  2549. static const char * const ad1988_models[AD1988_MODEL_LAST] = {
  2550. [AD1988_6STACK] = "6stack",
  2551. [AD1988_6STACK_DIG] = "6stack-dig",
  2552. [AD1988_3STACK] = "3stack",
  2553. [AD1988_3STACK_DIG] = "3stack-dig",
  2554. [AD1988_LAPTOP] = "laptop",
  2555. [AD1988_LAPTOP_DIG] = "laptop-dig",
  2556. [AD1988_AUTO] = "auto",
  2557. };
  2558. static const struct snd_pci_quirk ad1988_cfg_tbl[] = {
  2559. SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
  2560. SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
  2561. SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
  2562. SND_PCI_QUIRK(0x1043, 0x82c0, "Asus M3N-HT Deluxe", AD1988_6STACK_DIG),
  2563. SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
  2564. {}
  2565. };
  2566. static int patch_ad1988(struct hda_codec *codec)
  2567. {
  2568. struct ad198x_spec *spec;
  2569. int err, board_config;
  2570. err = alloc_ad_spec(codec);
  2571. if (err < 0)
  2572. return err;
  2573. spec = codec->spec;
  2574. board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
  2575. ad1988_models, ad1988_cfg_tbl);
  2576. if (board_config < 0) {
  2577. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  2578. codec->chip_name);
  2579. board_config = AD1988_AUTO;
  2580. }
  2581. if (board_config == AD1988_AUTO) {
  2582. /* automatic parse from the BIOS config */
  2583. err = ad1988_parse_auto_config(codec);
  2584. if (err < 0) {
  2585. ad198x_free(codec);
  2586. return err;
  2587. }
  2588. return 0;
  2589. }
  2590. if (is_rev2(codec))
  2591. snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
  2592. err = snd_hda_attach_beep_device(codec, 0x10);
  2593. if (err < 0) {
  2594. ad198x_free(codec);
  2595. return err;
  2596. }
  2597. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  2598. if (!spec->multiout.hp_nid)
  2599. spec->multiout.hp_nid = ad1988_alt_dac_nid[0];
  2600. switch (board_config) {
  2601. case AD1988_6STACK:
  2602. case AD1988_6STACK_DIG:
  2603. spec->multiout.max_channels = 8;
  2604. spec->multiout.num_dacs = 4;
  2605. if (is_rev2(codec))
  2606. spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
  2607. else
  2608. spec->multiout.dac_nids = ad1988_6stack_dac_nids;
  2609. spec->input_mux = &ad1988_6stack_capture_source;
  2610. spec->num_mixers = 2;
  2611. if (is_rev2(codec))
  2612. spec->mixers[0] = ad1988_6stack_mixers1_rev2;
  2613. else
  2614. spec->mixers[0] = ad1988_6stack_mixers1;
  2615. spec->mixers[1] = ad1988_6stack_mixers2;
  2616. spec->num_init_verbs = 1;
  2617. spec->init_verbs[0] = ad1988_6stack_init_verbs;
  2618. if (board_config == AD1988_6STACK_DIG) {
  2619. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2620. spec->dig_in_nid = AD1988_SPDIF_IN;
  2621. }
  2622. break;
  2623. case AD1988_3STACK:
  2624. case AD1988_3STACK_DIG:
  2625. spec->multiout.max_channels = 6;
  2626. spec->multiout.num_dacs = 3;
  2627. if (is_rev2(codec))
  2628. spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
  2629. else
  2630. spec->multiout.dac_nids = ad1988_3stack_dac_nids;
  2631. spec->input_mux = &ad1988_6stack_capture_source;
  2632. spec->channel_mode = ad1988_3stack_modes;
  2633. spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
  2634. spec->num_mixers = 2;
  2635. if (is_rev2(codec))
  2636. spec->mixers[0] = ad1988_3stack_mixers1_rev2;
  2637. else
  2638. spec->mixers[0] = ad1988_3stack_mixers1;
  2639. spec->mixers[1] = ad1988_3stack_mixers2;
  2640. spec->num_init_verbs = 1;
  2641. spec->init_verbs[0] = ad1988_3stack_init_verbs;
  2642. if (board_config == AD1988_3STACK_DIG)
  2643. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2644. break;
  2645. case AD1988_LAPTOP:
  2646. case AD1988_LAPTOP_DIG:
  2647. spec->multiout.max_channels = 2;
  2648. spec->multiout.num_dacs = 1;
  2649. spec->multiout.dac_nids = ad1988_3stack_dac_nids;
  2650. spec->input_mux = &ad1988_laptop_capture_source;
  2651. spec->num_mixers = 1;
  2652. spec->mixers[0] = ad1988_laptop_mixers;
  2653. codec->inv_eapd = 1; /* inverted EAPD */
  2654. spec->num_init_verbs = 1;
  2655. spec->init_verbs[0] = ad1988_laptop_init_verbs;
  2656. if (board_config == AD1988_LAPTOP_DIG)
  2657. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2658. break;
  2659. }
  2660. spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
  2661. spec->adc_nids = ad1988_adc_nids;
  2662. spec->capsrc_nids = ad1988_capsrc_nids;
  2663. spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
  2664. spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
  2665. if (spec->multiout.dig_out_nid) {
  2666. if (codec->vendor_id >= 0x11d4989a) {
  2667. spec->mixers[spec->num_mixers++] =
  2668. ad1989_spdif_out_mixers;
  2669. spec->init_verbs[spec->num_init_verbs++] =
  2670. ad1989_spdif_init_verbs;
  2671. codec->slave_dig_outs = ad1989b_slave_dig_outs;
  2672. } else {
  2673. spec->mixers[spec->num_mixers++] =
  2674. ad1988_spdif_out_mixers;
  2675. spec->init_verbs[spec->num_init_verbs++] =
  2676. ad1988_spdif_init_verbs;
  2677. }
  2678. }
  2679. if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a) {
  2680. spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
  2681. spec->init_verbs[spec->num_init_verbs++] =
  2682. ad1988_spdif_in_init_verbs;
  2683. }
  2684. codec->patch_ops = ad198x_patch_ops;
  2685. switch (board_config) {
  2686. case AD1988_LAPTOP:
  2687. case AD1988_LAPTOP_DIG:
  2688. codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
  2689. break;
  2690. }
  2691. #ifdef CONFIG_PM
  2692. spec->loopback.amplist = ad1988_loopbacks;
  2693. #endif
  2694. spec->vmaster_nid = 0x04;
  2695. codec->no_trigger_sense = 1;
  2696. codec->no_sticky_stream = 1;
  2697. return 0;
  2698. }
  2699. /*
  2700. * AD1884 / AD1984
  2701. *
  2702. * port-B - front line/mic-in
  2703. * port-E - aux in/out
  2704. * port-F - aux in/out
  2705. * port-C - rear line/mic-in
  2706. * port-D - rear line/hp-out
  2707. * port-A - front line/hp-out
  2708. *
  2709. * AD1984 = AD1884 + two digital mic-ins
  2710. *
  2711. * FIXME:
  2712. * For simplicity, we share the single DAC for both HP and line-outs
  2713. * right now. The inidividual playbacks could be easily implemented,
  2714. * but no build-up framework is given, so far.
  2715. */
  2716. static const hda_nid_t ad1884_dac_nids[1] = {
  2717. 0x04,
  2718. };
  2719. static const hda_nid_t ad1884_adc_nids[2] = {
  2720. 0x08, 0x09,
  2721. };
  2722. static const hda_nid_t ad1884_capsrc_nids[2] = {
  2723. 0x0c, 0x0d,
  2724. };
  2725. #define AD1884_SPDIF_OUT 0x02
  2726. static const struct hda_input_mux ad1884_capture_source = {
  2727. .num_items = 4,
  2728. .items = {
  2729. { "Front Mic", 0x0 },
  2730. { "Mic", 0x1 },
  2731. { "CD", 0x2 },
  2732. { "Mix", 0x3 },
  2733. },
  2734. };
  2735. static const struct snd_kcontrol_new ad1884_base_mixers[] = {
  2736. HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  2737. /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
  2738. HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  2739. HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  2740. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  2741. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
  2742. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  2743. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  2744. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  2745. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  2746. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
  2747. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
  2748. HDA_CODEC_VOLUME("Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
  2749. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  2750. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  2751. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  2752. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  2753. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  2754. {
  2755. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2756. /* The multiple "Capture Source" controls confuse alsamixer
  2757. * So call somewhat different..
  2758. */
  2759. /* .name = "Capture Source", */
  2760. .name = "Input Source",
  2761. .count = 2,
  2762. .info = ad198x_mux_enum_info,
  2763. .get = ad198x_mux_enum_get,
  2764. .put = ad198x_mux_enum_put,
  2765. },
  2766. /* SPDIF controls */
  2767. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  2768. {
  2769. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2770. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  2771. /* identical with ad1983 */
  2772. .info = ad1983_spdif_route_info,
  2773. .get = ad1983_spdif_route_get,
  2774. .put = ad1983_spdif_route_put,
  2775. },
  2776. { } /* end */
  2777. };
  2778. static const struct snd_kcontrol_new ad1984_dmic_mixers[] = {
  2779. HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
  2780. HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
  2781. HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
  2782. HDA_INPUT),
  2783. HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
  2784. HDA_INPUT),
  2785. { } /* end */
  2786. };
  2787. /*
  2788. * initialization verbs
  2789. */
  2790. static const struct hda_verb ad1884_init_verbs[] = {
  2791. /* DACs; mute as default */
  2792. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2793. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2794. /* Port-A (HP) mixer */
  2795. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2796. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2797. /* Port-A pin */
  2798. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2799. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2800. /* HP selector - select DAC2 */
  2801. {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
  2802. /* Port-D (Line-out) mixer */
  2803. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2804. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2805. /* Port-D pin */
  2806. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2807. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2808. /* Mono-out mixer */
  2809. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2810. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2811. /* Mono-out pin */
  2812. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2813. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2814. /* Mono selector */
  2815. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  2816. /* Port-B (front mic) pin */
  2817. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2818. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2819. /* Port-C (rear mic) pin */
  2820. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2821. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2822. /* Analog mixer; mute as default */
  2823. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2824. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2825. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2826. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2827. /* Analog Mix output amp */
  2828. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  2829. /* SPDIF output selector */
  2830. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
  2831. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  2832. { } /* end */
  2833. };
  2834. #ifdef CONFIG_PM
  2835. static const struct hda_amp_list ad1884_loopbacks[] = {
  2836. { 0x20, HDA_INPUT, 0 }, /* Front Mic */
  2837. { 0x20, HDA_INPUT, 1 }, /* Mic */
  2838. { 0x20, HDA_INPUT, 2 }, /* CD */
  2839. { 0x20, HDA_INPUT, 4 }, /* Docking */
  2840. { } /* end */
  2841. };
  2842. #endif
  2843. static const char * const ad1884_slave_vols[] = {
  2844. "PCM", "Mic", "Mono", "Front Mic", "Mic", "CD",
  2845. "Internal Mic", "Dock Mic", /* "Beep", */ "IEC958",
  2846. NULL
  2847. };
  2848. enum {
  2849. AD1884_AUTO,
  2850. AD1884_BASIC,
  2851. AD1884_MODELS
  2852. };
  2853. static const char * const ad1884_models[AD1884_MODELS] = {
  2854. [AD1884_AUTO] = "auto",
  2855. [AD1884_BASIC] = "basic",
  2856. };
  2857. static int ad1884_parse_auto_config(struct hda_codec *codec)
  2858. {
  2859. struct ad198x_spec *spec = codec->spec;
  2860. spec->beep_dev_nid = 0x10;
  2861. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  2862. return ad198x_parse_auto_config(codec);
  2863. }
  2864. static int patch_ad1884_auto(struct hda_codec *codec)
  2865. {
  2866. int err;
  2867. err = alloc_ad_spec(codec);
  2868. if (err < 0)
  2869. return err;
  2870. err = ad1884_parse_auto_config(codec);
  2871. if (err < 0) {
  2872. ad198x_free(codec);
  2873. return err;
  2874. }
  2875. return 0;
  2876. }
  2877. static int patch_ad1884_basic(struct hda_codec *codec)
  2878. {
  2879. struct ad198x_spec *spec;
  2880. int err;
  2881. err = alloc_ad_spec(codec);
  2882. if (err < 0)
  2883. return err;
  2884. spec = codec->spec;
  2885. err = snd_hda_attach_beep_device(codec, 0x10);
  2886. if (err < 0) {
  2887. ad198x_free(codec);
  2888. return err;
  2889. }
  2890. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  2891. spec->multiout.max_channels = 2;
  2892. spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
  2893. spec->multiout.dac_nids = ad1884_dac_nids;
  2894. spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
  2895. spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
  2896. spec->adc_nids = ad1884_adc_nids;
  2897. spec->capsrc_nids = ad1884_capsrc_nids;
  2898. spec->input_mux = &ad1884_capture_source;
  2899. spec->num_mixers = 1;
  2900. spec->mixers[0] = ad1884_base_mixers;
  2901. spec->num_init_verbs = 1;
  2902. spec->init_verbs[0] = ad1884_init_verbs;
  2903. spec->spdif_route = 0;
  2904. #ifdef CONFIG_PM
  2905. spec->loopback.amplist = ad1884_loopbacks;
  2906. #endif
  2907. spec->vmaster_nid = 0x04;
  2908. /* we need to cover all playback volumes */
  2909. spec->slave_vols = ad1884_slave_vols;
  2910. /* slaves may contain input volumes, so we can't raise to 0dB blindly */
  2911. spec->avoid_init_slave_vol = 1;
  2912. codec->patch_ops = ad198x_patch_ops;
  2913. codec->no_trigger_sense = 1;
  2914. codec->no_sticky_stream = 1;
  2915. return 0;
  2916. }
  2917. static int patch_ad1884(struct hda_codec *codec)
  2918. {
  2919. int board_config;
  2920. board_config = snd_hda_check_board_config(codec, AD1884_MODELS,
  2921. ad1884_models, NULL);
  2922. if (board_config == AD1884_AUTO)
  2923. return patch_ad1884_auto(codec);
  2924. else
  2925. return patch_ad1884_basic(codec);
  2926. }
  2927. /*
  2928. * Lenovo Thinkpad T61/X61
  2929. */
  2930. static const struct hda_input_mux ad1984_thinkpad_capture_source = {
  2931. .num_items = 4,
  2932. .items = {
  2933. { "Mic", 0x0 },
  2934. { "Internal Mic", 0x1 },
  2935. { "Mix", 0x3 },
  2936. { "Dock Mic", 0x4 },
  2937. },
  2938. };
  2939. /*
  2940. * Dell Precision T3400
  2941. */
  2942. static const struct hda_input_mux ad1984_dell_desktop_capture_source = {
  2943. .num_items = 3,
  2944. .items = {
  2945. { "Front Mic", 0x0 },
  2946. { "Line-In", 0x1 },
  2947. { "Mix", 0x3 },
  2948. },
  2949. };
  2950. static const struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
  2951. HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  2952. /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
  2953. HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  2954. HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  2955. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  2956. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  2957. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  2958. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  2959. HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
  2960. HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
  2961. HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
  2962. HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
  2963. HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  2964. HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
  2965. HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
  2966. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  2967. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  2968. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  2969. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  2970. {
  2971. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2972. /* The multiple "Capture Source" controls confuse alsamixer
  2973. * So call somewhat different..
  2974. */
  2975. /* .name = "Capture Source", */
  2976. .name = "Input Source",
  2977. .count = 2,
  2978. .info = ad198x_mux_enum_info,
  2979. .get = ad198x_mux_enum_get,
  2980. .put = ad198x_mux_enum_put,
  2981. },
  2982. /* SPDIF controls */
  2983. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  2984. {
  2985. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2986. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  2987. /* identical with ad1983 */
  2988. .info = ad1983_spdif_route_info,
  2989. .get = ad1983_spdif_route_get,
  2990. .put = ad1983_spdif_route_put,
  2991. },
  2992. { } /* end */
  2993. };
  2994. /* additional verbs */
  2995. static const struct hda_verb ad1984_thinkpad_init_verbs[] = {
  2996. /* Port-E (docking station mic) pin */
  2997. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2998. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2999. /* docking mic boost */
  3000. {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3001. /* Analog PC Beeper - allow firmware/ACPI beeps */
  3002. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3) | 0x1a},
  3003. /* Analog mixer - docking mic; mute as default */
  3004. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3005. /* enable EAPD bit */
  3006. {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  3007. { } /* end */
  3008. };
  3009. /*
  3010. * Dell Precision T3400
  3011. */
  3012. static const struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
  3013. HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  3014. HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  3015. HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  3016. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  3017. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
  3018. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  3019. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  3020. HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
  3021. HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
  3022. HDA_CODEC_VOLUME("Line-In Boost Volume", 0x15, 0x0, HDA_INPUT),
  3023. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  3024. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3025. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3026. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  3027. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  3028. {
  3029. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3030. /* The multiple "Capture Source" controls confuse alsamixer
  3031. * So call somewhat different..
  3032. */
  3033. /* .name = "Capture Source", */
  3034. .name = "Input Source",
  3035. .count = 2,
  3036. .info = ad198x_mux_enum_info,
  3037. .get = ad198x_mux_enum_get,
  3038. .put = ad198x_mux_enum_put,
  3039. },
  3040. { } /* end */
  3041. };
  3042. /* Digial MIC ADC NID 0x05 + 0x06 */
  3043. static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
  3044. struct hda_codec *codec,
  3045. unsigned int stream_tag,
  3046. unsigned int format,
  3047. struct snd_pcm_substream *substream)
  3048. {
  3049. snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
  3050. stream_tag, 0, format);
  3051. return 0;
  3052. }
  3053. static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
  3054. struct hda_codec *codec,
  3055. struct snd_pcm_substream *substream)
  3056. {
  3057. snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
  3058. return 0;
  3059. }
  3060. static const struct hda_pcm_stream ad1984_pcm_dmic_capture = {
  3061. .substreams = 2,
  3062. .channels_min = 2,
  3063. .channels_max = 2,
  3064. .nid = 0x05,
  3065. .ops = {
  3066. .prepare = ad1984_pcm_dmic_prepare,
  3067. .cleanup = ad1984_pcm_dmic_cleanup
  3068. },
  3069. };
  3070. static int ad1984_build_pcms(struct hda_codec *codec)
  3071. {
  3072. struct ad198x_spec *spec = codec->spec;
  3073. struct hda_pcm *info;
  3074. int err;
  3075. err = ad198x_build_pcms(codec);
  3076. if (err < 0)
  3077. return err;
  3078. info = spec->pcm_rec + codec->num_pcms;
  3079. codec->num_pcms++;
  3080. info->name = "AD1984 Digital Mic";
  3081. info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
  3082. return 0;
  3083. }
  3084. /* models */
  3085. enum {
  3086. AD1984_AUTO,
  3087. AD1984_BASIC,
  3088. AD1984_THINKPAD,
  3089. AD1984_DELL_DESKTOP,
  3090. AD1984_MODELS
  3091. };
  3092. static const char * const ad1984_models[AD1984_MODELS] = {
  3093. [AD1984_AUTO] = "auto",
  3094. [AD1984_BASIC] = "basic",
  3095. [AD1984_THINKPAD] = "thinkpad",
  3096. [AD1984_DELL_DESKTOP] = "dell_desktop",
  3097. };
  3098. static const struct snd_pci_quirk ad1984_cfg_tbl[] = {
  3099. /* Lenovo Thinkpad T61/X61 */
  3100. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
  3101. SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
  3102. SND_PCI_QUIRK(0x1028, 0x0233, "Dell Latitude E6400", AD1984_DELL_DESKTOP),
  3103. {}
  3104. };
  3105. static int patch_ad1984(struct hda_codec *codec)
  3106. {
  3107. struct ad198x_spec *spec;
  3108. int board_config, err;
  3109. board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
  3110. ad1984_models, ad1984_cfg_tbl);
  3111. if (board_config == AD1984_AUTO)
  3112. return patch_ad1884_auto(codec);
  3113. err = patch_ad1884_basic(codec);
  3114. if (err < 0)
  3115. return err;
  3116. spec = codec->spec;
  3117. switch (board_config) {
  3118. case AD1984_BASIC:
  3119. /* additional digital mics */
  3120. spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
  3121. codec->patch_ops.build_pcms = ad1984_build_pcms;
  3122. break;
  3123. case AD1984_THINKPAD:
  3124. if (codec->subsystem_id == 0x17aa20fb) {
  3125. /* Thinpad X300 does not have the ability to do SPDIF,
  3126. or attach to docking station to use SPDIF */
  3127. spec->multiout.dig_out_nid = 0;
  3128. } else
  3129. spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
  3130. spec->input_mux = &ad1984_thinkpad_capture_source;
  3131. spec->mixers[0] = ad1984_thinkpad_mixers;
  3132. spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
  3133. spec->analog_beep = 1;
  3134. break;
  3135. case AD1984_DELL_DESKTOP:
  3136. spec->multiout.dig_out_nid = 0;
  3137. spec->input_mux = &ad1984_dell_desktop_capture_source;
  3138. spec->mixers[0] = ad1984_dell_desktop_mixers;
  3139. break;
  3140. }
  3141. return 0;
  3142. }
  3143. /*
  3144. * AD1883 / AD1884A / AD1984A / AD1984B
  3145. *
  3146. * port-B (0x14) - front mic-in
  3147. * port-E (0x1c) - rear mic-in
  3148. * port-F (0x16) - CD / ext out
  3149. * port-C (0x15) - rear line-in
  3150. * port-D (0x12) - rear line-out
  3151. * port-A (0x11) - front hp-out
  3152. *
  3153. * AD1984A = AD1884A + digital-mic
  3154. * AD1883 = equivalent with AD1984A
  3155. * AD1984B = AD1984A + extra SPDIF-out
  3156. *
  3157. * FIXME:
  3158. * We share the single DAC for both HP and line-outs (see AD1884/1984).
  3159. */
  3160. static const hda_nid_t ad1884a_dac_nids[1] = {
  3161. 0x03,
  3162. };
  3163. #define ad1884a_adc_nids ad1884_adc_nids
  3164. #define ad1884a_capsrc_nids ad1884_capsrc_nids
  3165. #define AD1884A_SPDIF_OUT 0x02
  3166. static const struct hda_input_mux ad1884a_capture_source = {
  3167. .num_items = 5,
  3168. .items = {
  3169. { "Front Mic", 0x0 },
  3170. { "Mic", 0x4 },
  3171. { "Line", 0x1 },
  3172. { "CD", 0x2 },
  3173. { "Mix", 0x3 },
  3174. },
  3175. };
  3176. static const struct snd_kcontrol_new ad1884a_base_mixers[] = {
  3177. HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  3178. HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  3179. HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  3180. HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  3181. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  3182. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
  3183. HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  3184. HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  3185. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  3186. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  3187. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
  3188. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
  3189. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
  3190. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
  3191. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
  3192. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
  3193. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  3194. HDA_CODEC_VOLUME("Line Boost Volume", 0x15, 0x0, HDA_INPUT),
  3195. HDA_CODEC_VOLUME("Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
  3196. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3197. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3198. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  3199. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  3200. {
  3201. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3202. /* The multiple "Capture Source" controls confuse alsamixer
  3203. * So call somewhat different..
  3204. */
  3205. /* .name = "Capture Source", */
  3206. .name = "Input Source",
  3207. .count = 2,
  3208. .info = ad198x_mux_enum_info,
  3209. .get = ad198x_mux_enum_get,
  3210. .put = ad198x_mux_enum_put,
  3211. },
  3212. /* SPDIF controls */
  3213. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  3214. {
  3215. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3216. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  3217. /* identical with ad1983 */
  3218. .info = ad1983_spdif_route_info,
  3219. .get = ad1983_spdif_route_get,
  3220. .put = ad1983_spdif_route_put,
  3221. },
  3222. { } /* end */
  3223. };
  3224. /*
  3225. * initialization verbs
  3226. */
  3227. static const struct hda_verb ad1884a_init_verbs[] = {
  3228. /* DACs; unmute as default */
  3229. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  3230. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  3231. /* Port-A (HP) mixer - route only from analog mixer */
  3232. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3233. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3234. /* Port-A pin */
  3235. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3236. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3237. /* Port-D (Line-out) mixer - route only from analog mixer */
  3238. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3239. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3240. /* Port-D pin */
  3241. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3242. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3243. /* Mono-out mixer - route only from analog mixer */
  3244. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3245. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3246. /* Mono-out pin */
  3247. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3248. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3249. /* Port-B (front mic) pin */
  3250. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3251. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3252. /* Port-C (rear line-in) pin */
  3253. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  3254. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3255. /* Port-E (rear mic) pin */
  3256. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3257. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3258. {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
  3259. /* Port-F (CD) pin */
  3260. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  3261. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3262. /* Analog mixer; mute as default */
  3263. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3264. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3265. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3266. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3267. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
  3268. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  3269. /* Analog Mix output amp */
  3270. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3271. /* capture sources */
  3272. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  3273. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3274. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  3275. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3276. /* SPDIF output amp */
  3277. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  3278. { } /* end */
  3279. };
  3280. #ifdef CONFIG_PM
  3281. static const struct hda_amp_list ad1884a_loopbacks[] = {
  3282. { 0x20, HDA_INPUT, 0 }, /* Front Mic */
  3283. { 0x20, HDA_INPUT, 1 }, /* Mic */
  3284. { 0x20, HDA_INPUT, 2 }, /* CD */
  3285. { 0x20, HDA_INPUT, 4 }, /* Docking */
  3286. { } /* end */
  3287. };
  3288. #endif
  3289. /*
  3290. * Laptop model
  3291. *
  3292. * Port A: Headphone jack
  3293. * Port B: MIC jack
  3294. * Port C: Internal MIC
  3295. * Port D: Dock Line Out (if enabled)
  3296. * Port E: Dock Line In (if enabled)
  3297. * Port F: Internal speakers
  3298. */
  3299. static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
  3300. struct snd_ctl_elem_value *ucontrol)
  3301. {
  3302. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3303. int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
  3304. int mute = (!ucontrol->value.integer.value[0] &&
  3305. !ucontrol->value.integer.value[1]);
  3306. /* toggle GPIO1 according to the mute state */
  3307. snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
  3308. mute ? 0x02 : 0x0);
  3309. return ret;
  3310. }
  3311. static const struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
  3312. HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  3313. {
  3314. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3315. .name = "Master Playback Switch",
  3316. .subdevice = HDA_SUBDEV_AMP_FLAG,
  3317. .info = snd_hda_mixer_amp_switch_info,
  3318. .get = snd_hda_mixer_amp_switch_get,
  3319. .put = ad1884a_mobile_master_sw_put,
  3320. .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
  3321. },
  3322. HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  3323. HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  3324. HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  3325. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  3326. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  3327. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  3328. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  3329. HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
  3330. HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
  3331. HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  3332. HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
  3333. HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
  3334. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3335. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3336. { } /* end */
  3337. };
  3338. static const struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
  3339. HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  3340. /*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
  3341. {
  3342. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3343. .name = "Master Playback Switch",
  3344. .subdevice = HDA_SUBDEV_AMP_FLAG,
  3345. .info = snd_hda_mixer_amp_switch_info,
  3346. .get = snd_hda_mixer_amp_switch_get,
  3347. .put = ad1884a_mobile_master_sw_put,
  3348. .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
  3349. },
  3350. HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  3351. HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  3352. HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
  3353. HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
  3354. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3355. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3356. { } /* end */
  3357. };
  3358. /* mute internal speaker if HP is plugged */
  3359. static void ad1884a_hp_automute(struct hda_codec *codec)
  3360. {
  3361. unsigned int present;
  3362. present = snd_hda_jack_detect(codec, 0x11);
  3363. snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
  3364. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  3365. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
  3366. present ? 0x00 : 0x02);
  3367. }
  3368. /* switch to external mic if plugged */
  3369. static void ad1884a_hp_automic(struct hda_codec *codec)
  3370. {
  3371. unsigned int present;
  3372. present = snd_hda_jack_detect(codec, 0x14);
  3373. snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
  3374. present ? 0 : 1);
  3375. }
  3376. #define AD1884A_HP_EVENT 0x37
  3377. #define AD1884A_MIC_EVENT 0x36
  3378. /* unsolicited event for HP jack sensing */
  3379. static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
  3380. {
  3381. switch (res >> 26) {
  3382. case AD1884A_HP_EVENT:
  3383. ad1884a_hp_automute(codec);
  3384. break;
  3385. case AD1884A_MIC_EVENT:
  3386. ad1884a_hp_automic(codec);
  3387. break;
  3388. }
  3389. }
  3390. /* initialize jack-sensing, too */
  3391. static int ad1884a_hp_init(struct hda_codec *codec)
  3392. {
  3393. ad198x_init(codec);
  3394. ad1884a_hp_automute(codec);
  3395. ad1884a_hp_automic(codec);
  3396. return 0;
  3397. }
  3398. /* mute internal speaker if HP or docking HP is plugged */
  3399. static void ad1884a_laptop_automute(struct hda_codec *codec)
  3400. {
  3401. unsigned int present;
  3402. present = snd_hda_jack_detect(codec, 0x11);
  3403. if (!present)
  3404. present = snd_hda_jack_detect(codec, 0x12);
  3405. snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
  3406. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  3407. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
  3408. present ? 0x00 : 0x02);
  3409. }
  3410. /* switch to external mic if plugged */
  3411. static void ad1884a_laptop_automic(struct hda_codec *codec)
  3412. {
  3413. unsigned int idx;
  3414. if (snd_hda_jack_detect(codec, 0x14))
  3415. idx = 0;
  3416. else if (snd_hda_jack_detect(codec, 0x1c))
  3417. idx = 4;
  3418. else
  3419. idx = 1;
  3420. snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, idx);
  3421. }
  3422. /* unsolicited event for HP jack sensing */
  3423. static void ad1884a_laptop_unsol_event(struct hda_codec *codec,
  3424. unsigned int res)
  3425. {
  3426. switch (res >> 26) {
  3427. case AD1884A_HP_EVENT:
  3428. ad1884a_laptop_automute(codec);
  3429. break;
  3430. case AD1884A_MIC_EVENT:
  3431. ad1884a_laptop_automic(codec);
  3432. break;
  3433. }
  3434. }
  3435. /* initialize jack-sensing, too */
  3436. static int ad1884a_laptop_init(struct hda_codec *codec)
  3437. {
  3438. ad198x_init(codec);
  3439. ad1884a_laptop_automute(codec);
  3440. ad1884a_laptop_automic(codec);
  3441. return 0;
  3442. }
  3443. /* additional verbs for laptop model */
  3444. static const struct hda_verb ad1884a_laptop_verbs[] = {
  3445. /* Port-A (HP) pin - always unmuted */
  3446. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3447. /* Port-F (int speaker) mixer - route only from analog mixer */
  3448. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3449. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3450. /* Port-F (int speaker) pin */
  3451. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  3452. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3453. /* required for compaq 6530s/6531s speaker output */
  3454. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  3455. /* Port-C pin - internal mic-in */
  3456. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3457. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  3458. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  3459. /* Port-D (docking line-out) pin - default unmuted */
  3460. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3461. /* analog mix */
  3462. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3463. /* unsolicited event for pin-sense */
  3464. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  3465. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  3466. {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
  3467. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
  3468. /* allow to touch GPIO1 (for mute control) */
  3469. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  3470. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  3471. {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
  3472. { } /* end */
  3473. };
  3474. static const struct hda_verb ad1884a_mobile_verbs[] = {
  3475. /* DACs; unmute as default */
  3476. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  3477. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  3478. /* Port-A (HP) mixer - route only from analog mixer */
  3479. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3480. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3481. /* Port-A pin */
  3482. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3483. /* Port-A (HP) pin - always unmuted */
  3484. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3485. /* Port-B (mic jack) pin */
  3486. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3487. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  3488. /* Port-C (int mic) pin */
  3489. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3490. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  3491. /* Port-F (int speaker) mixer - route only from analog mixer */
  3492. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3493. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3494. /* Port-F pin */
  3495. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3496. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3497. /* Analog mixer; mute as default */
  3498. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3499. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3500. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3501. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3502. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3503. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  3504. /* Analog Mix output amp */
  3505. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3506. /* capture sources */
  3507. /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
  3508. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3509. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  3510. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3511. /* unsolicited event for pin-sense */
  3512. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  3513. {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
  3514. /* allow to touch GPIO1 (for mute control) */
  3515. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  3516. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  3517. {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
  3518. { } /* end */
  3519. };
  3520. /*
  3521. * Thinkpad X300
  3522. * 0x11 - HP
  3523. * 0x12 - speaker
  3524. * 0x14 - mic-in
  3525. * 0x17 - built-in mic
  3526. */
  3527. static const struct hda_verb ad1984a_thinkpad_verbs[] = {
  3528. /* HP unmute */
  3529. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3530. /* analog mix */
  3531. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3532. /* turn on EAPD */
  3533. {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  3534. /* unsolicited event for pin-sense */
  3535. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  3536. /* internal mic - dmic */
  3537. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  3538. /* set magic COEFs for dmic */
  3539. {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
  3540. {0x01, AC_VERB_SET_PROC_COEF, 0x08},
  3541. { } /* end */
  3542. };
  3543. static const struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
  3544. HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  3545. HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  3546. HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  3547. HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  3548. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  3549. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  3550. HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  3551. HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x17, 0x0, HDA_INPUT),
  3552. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3553. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3554. {
  3555. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3556. .name = "Capture Source",
  3557. .info = ad198x_mux_enum_info,
  3558. .get = ad198x_mux_enum_get,
  3559. .put = ad198x_mux_enum_put,
  3560. },
  3561. { } /* end */
  3562. };
  3563. static const struct hda_input_mux ad1984a_thinkpad_capture_source = {
  3564. .num_items = 3,
  3565. .items = {
  3566. { "Mic", 0x0 },
  3567. { "Internal Mic", 0x5 },
  3568. { "Mix", 0x3 },
  3569. },
  3570. };
  3571. /* mute internal speaker if HP is plugged */
  3572. static void ad1984a_thinkpad_automute(struct hda_codec *codec)
  3573. {
  3574. unsigned int present;
  3575. present = snd_hda_jack_detect(codec, 0x11);
  3576. snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
  3577. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  3578. }
  3579. /* unsolicited event for HP jack sensing */
  3580. static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
  3581. unsigned int res)
  3582. {
  3583. if ((res >> 26) != AD1884A_HP_EVENT)
  3584. return;
  3585. ad1984a_thinkpad_automute(codec);
  3586. }
  3587. /* initialize jack-sensing, too */
  3588. static int ad1984a_thinkpad_init(struct hda_codec *codec)
  3589. {
  3590. ad198x_init(codec);
  3591. ad1984a_thinkpad_automute(codec);
  3592. return 0;
  3593. }
  3594. /*
  3595. * Precision R5500
  3596. * 0x12 - HP/line-out
  3597. * 0x13 - speaker (mono)
  3598. * 0x15 - mic-in
  3599. */
  3600. static const struct hda_verb ad1984a_precision_verbs[] = {
  3601. /* Unmute main output path */
  3602. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  3603. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE + 0x1f}, /* 0dB */
  3604. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) + 0x17}, /* 0dB */
  3605. /* Analog mixer; mute as default */
  3606. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3607. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3608. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3609. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3610. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3611. /* Select mic as input */
  3612. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  3613. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE + 0x27}, /* 0dB */
  3614. /* Configure as mic */
  3615. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3616. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  3617. /* HP unmute */
  3618. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3619. /* turn on EAPD */
  3620. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  3621. /* unsolicited event for pin-sense */
  3622. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  3623. { } /* end */
  3624. };
  3625. static const struct snd_kcontrol_new ad1984a_precision_mixers[] = {
  3626. HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  3627. HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  3628. HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  3629. HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  3630. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  3631. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  3632. HDA_CODEC_VOLUME("Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
  3633. HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  3634. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  3635. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3636. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3637. { } /* end */
  3638. };
  3639. /* mute internal speaker if HP is plugged */
  3640. static void ad1984a_precision_automute(struct hda_codec *codec)
  3641. {
  3642. unsigned int present;
  3643. present = snd_hda_jack_detect(codec, 0x12);
  3644. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  3645. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  3646. }
  3647. /* unsolicited event for HP jack sensing */
  3648. static void ad1984a_precision_unsol_event(struct hda_codec *codec,
  3649. unsigned int res)
  3650. {
  3651. if ((res >> 26) != AD1884A_HP_EVENT)
  3652. return;
  3653. ad1984a_precision_automute(codec);
  3654. }
  3655. /* initialize jack-sensing, too */
  3656. static int ad1984a_precision_init(struct hda_codec *codec)
  3657. {
  3658. ad198x_init(codec);
  3659. ad1984a_precision_automute(codec);
  3660. return 0;
  3661. }
  3662. /*
  3663. * HP Touchsmart
  3664. * port-A (0x11) - front hp-out
  3665. * port-B (0x14) - unused
  3666. * port-C (0x15) - unused
  3667. * port-D (0x12) - rear line out
  3668. * port-E (0x1c) - front mic-in
  3669. * port-F (0x16) - Internal speakers
  3670. * digital-mic (0x17) - Internal mic
  3671. */
  3672. static const struct hda_verb ad1984a_touchsmart_verbs[] = {
  3673. /* DACs; unmute as default */
  3674. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  3675. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  3676. /* Port-A (HP) mixer - route only from analog mixer */
  3677. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3678. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3679. /* Port-A pin */
  3680. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3681. /* Port-A (HP) pin - always unmuted */
  3682. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3683. /* Port-E (int speaker) mixer - route only from analog mixer */
  3684. {0x25, AC_VERB_SET_AMP_GAIN_MUTE, 0x03},
  3685. /* Port-E pin */
  3686. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  3687. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3688. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3689. /* Port-F (int speaker) mixer - route only from analog mixer */
  3690. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3691. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3692. /* Port-F pin */
  3693. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3694. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3695. /* Analog mixer; mute as default */
  3696. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3697. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3698. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3699. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3700. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3701. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  3702. /* Analog Mix output amp */
  3703. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3704. /* capture sources */
  3705. /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
  3706. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3707. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  3708. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3709. /* unsolicited event for pin-sense */
  3710. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  3711. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
  3712. /* allow to touch GPIO1 (for mute control) */
  3713. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  3714. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  3715. {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
  3716. /* internal mic - dmic */
  3717. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  3718. /* set magic COEFs for dmic */
  3719. {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
  3720. {0x01, AC_VERB_SET_PROC_COEF, 0x08},
  3721. { } /* end */
  3722. };
  3723. static const struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
  3724. HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  3725. /* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
  3726. {
  3727. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3728. .subdevice = HDA_SUBDEV_AMP_FLAG,
  3729. .name = "Master Playback Switch",
  3730. .info = snd_hda_mixer_amp_switch_info,
  3731. .get = snd_hda_mixer_amp_switch_get,
  3732. .put = ad1884a_mobile_master_sw_put,
  3733. .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
  3734. },
  3735. HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  3736. HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  3737. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3738. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3739. HDA_CODEC_VOLUME("Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
  3740. HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x17, 0x0, HDA_INPUT),
  3741. { } /* end */
  3742. };
  3743. /* switch to external mic if plugged */
  3744. static void ad1984a_touchsmart_automic(struct hda_codec *codec)
  3745. {
  3746. if (snd_hda_jack_detect(codec, 0x1c))
  3747. snd_hda_codec_write(codec, 0x0c, 0,
  3748. AC_VERB_SET_CONNECT_SEL, 0x4);
  3749. else
  3750. snd_hda_codec_write(codec, 0x0c, 0,
  3751. AC_VERB_SET_CONNECT_SEL, 0x5);
  3752. }
  3753. /* unsolicited event for HP jack sensing */
  3754. static void ad1984a_touchsmart_unsol_event(struct hda_codec *codec,
  3755. unsigned int res)
  3756. {
  3757. switch (res >> 26) {
  3758. case AD1884A_HP_EVENT:
  3759. ad1884a_hp_automute(codec);
  3760. break;
  3761. case AD1884A_MIC_EVENT:
  3762. ad1984a_touchsmart_automic(codec);
  3763. break;
  3764. }
  3765. }
  3766. /* initialize jack-sensing, too */
  3767. static int ad1984a_touchsmart_init(struct hda_codec *codec)
  3768. {
  3769. ad198x_init(codec);
  3770. ad1884a_hp_automute(codec);
  3771. ad1984a_touchsmart_automic(codec);
  3772. return 0;
  3773. }
  3774. /*
  3775. */
  3776. enum {
  3777. AD1884A_AUTO,
  3778. AD1884A_DESKTOP,
  3779. AD1884A_LAPTOP,
  3780. AD1884A_MOBILE,
  3781. AD1884A_THINKPAD,
  3782. AD1984A_TOUCHSMART,
  3783. AD1984A_PRECISION,
  3784. AD1884A_MODELS
  3785. };
  3786. static const char * const ad1884a_models[AD1884A_MODELS] = {
  3787. [AD1884A_AUTO] = "auto",
  3788. [AD1884A_DESKTOP] = "desktop",
  3789. [AD1884A_LAPTOP] = "laptop",
  3790. [AD1884A_MOBILE] = "mobile",
  3791. [AD1884A_THINKPAD] = "thinkpad",
  3792. [AD1984A_TOUCHSMART] = "touchsmart",
  3793. [AD1984A_PRECISION] = "precision",
  3794. };
  3795. static const struct snd_pci_quirk ad1884a_cfg_tbl[] = {
  3796. SND_PCI_QUIRK(0x1028, 0x04ac, "Precision R5500", AD1984A_PRECISION),
  3797. SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
  3798. SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
  3799. SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
  3800. SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
  3801. SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
  3802. SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
  3803. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
  3804. SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
  3805. SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
  3806. SND_PCI_QUIRK(0x103c, 0x2a82, "Touchsmart", AD1984A_TOUCHSMART),
  3807. {}
  3808. };
  3809. static int patch_ad1884a(struct hda_codec *codec)
  3810. {
  3811. struct ad198x_spec *spec;
  3812. int err, board_config;
  3813. board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
  3814. ad1884a_models,
  3815. ad1884a_cfg_tbl);
  3816. if (board_config == AD1884_AUTO)
  3817. return patch_ad1884_auto(codec);
  3818. err = alloc_ad_spec(codec);
  3819. if (err < 0)
  3820. return err;
  3821. spec = codec->spec;
  3822. err = snd_hda_attach_beep_device(codec, 0x10);
  3823. if (err < 0) {
  3824. ad198x_free(codec);
  3825. return err;
  3826. }
  3827. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  3828. spec->multiout.max_channels = 2;
  3829. spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
  3830. spec->multiout.dac_nids = ad1884a_dac_nids;
  3831. spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
  3832. spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
  3833. spec->adc_nids = ad1884a_adc_nids;
  3834. spec->capsrc_nids = ad1884a_capsrc_nids;
  3835. spec->input_mux = &ad1884a_capture_source;
  3836. spec->num_mixers = 1;
  3837. spec->mixers[0] = ad1884a_base_mixers;
  3838. spec->num_init_verbs = 1;
  3839. spec->init_verbs[0] = ad1884a_init_verbs;
  3840. spec->spdif_route = 0;
  3841. #ifdef CONFIG_PM
  3842. spec->loopback.amplist = ad1884a_loopbacks;
  3843. #endif
  3844. codec->patch_ops = ad198x_patch_ops;
  3845. /* override some parameters */
  3846. switch (board_config) {
  3847. case AD1884A_LAPTOP:
  3848. spec->mixers[0] = ad1884a_laptop_mixers;
  3849. spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
  3850. spec->multiout.dig_out_nid = 0;
  3851. codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
  3852. codec->patch_ops.init = ad1884a_laptop_init;
  3853. /* set the upper-limit for mixer amp to 0dB for avoiding the
  3854. * possible damage by overloading
  3855. */
  3856. snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
  3857. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  3858. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  3859. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  3860. (1 << AC_AMPCAP_MUTE_SHIFT));
  3861. break;
  3862. case AD1884A_MOBILE:
  3863. spec->mixers[0] = ad1884a_mobile_mixers;
  3864. spec->init_verbs[0] = ad1884a_mobile_verbs;
  3865. spec->multiout.dig_out_nid = 0;
  3866. codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
  3867. codec->patch_ops.init = ad1884a_hp_init;
  3868. /* set the upper-limit for mixer amp to 0dB for avoiding the
  3869. * possible damage by overloading
  3870. */
  3871. snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
  3872. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  3873. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  3874. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  3875. (1 << AC_AMPCAP_MUTE_SHIFT));
  3876. break;
  3877. case AD1884A_THINKPAD:
  3878. spec->mixers[0] = ad1984a_thinkpad_mixers;
  3879. spec->init_verbs[spec->num_init_verbs++] =
  3880. ad1984a_thinkpad_verbs;
  3881. spec->multiout.dig_out_nid = 0;
  3882. spec->input_mux = &ad1984a_thinkpad_capture_source;
  3883. codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
  3884. codec->patch_ops.init = ad1984a_thinkpad_init;
  3885. break;
  3886. case AD1984A_PRECISION:
  3887. spec->mixers[0] = ad1984a_precision_mixers;
  3888. spec->init_verbs[spec->num_init_verbs++] =
  3889. ad1984a_precision_verbs;
  3890. spec->multiout.dig_out_nid = 0;
  3891. codec->patch_ops.unsol_event = ad1984a_precision_unsol_event;
  3892. codec->patch_ops.init = ad1984a_precision_init;
  3893. break;
  3894. case AD1984A_TOUCHSMART:
  3895. spec->mixers[0] = ad1984a_touchsmart_mixers;
  3896. spec->init_verbs[0] = ad1984a_touchsmart_verbs;
  3897. spec->multiout.dig_out_nid = 0;
  3898. codec->patch_ops.unsol_event = ad1984a_touchsmart_unsol_event;
  3899. codec->patch_ops.init = ad1984a_touchsmart_init;
  3900. /* set the upper-limit for mixer amp to 0dB for avoiding the
  3901. * possible damage by overloading
  3902. */
  3903. snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
  3904. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  3905. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  3906. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  3907. (1 << AC_AMPCAP_MUTE_SHIFT));
  3908. break;
  3909. }
  3910. codec->no_trigger_sense = 1;
  3911. codec->no_sticky_stream = 1;
  3912. return 0;
  3913. }
  3914. /*
  3915. * AD1882 / AD1882A
  3916. *
  3917. * port-A - front hp-out
  3918. * port-B - front mic-in
  3919. * port-C - rear line-in, shared surr-out (3stack)
  3920. * port-D - rear line-out
  3921. * port-E - rear mic-in, shared clfe-out (3stack)
  3922. * port-F - rear surr-out (6stack)
  3923. * port-G - rear clfe-out (6stack)
  3924. */
  3925. static const hda_nid_t ad1882_dac_nids[3] = {
  3926. 0x04, 0x03, 0x05
  3927. };
  3928. static const hda_nid_t ad1882_adc_nids[2] = {
  3929. 0x08, 0x09,
  3930. };
  3931. static const hda_nid_t ad1882_capsrc_nids[2] = {
  3932. 0x0c, 0x0d,
  3933. };
  3934. #define AD1882_SPDIF_OUT 0x02
  3935. /* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
  3936. static const struct hda_input_mux ad1882_capture_source = {
  3937. .num_items = 5,
  3938. .items = {
  3939. { "Front Mic", 0x1 },
  3940. { "Mic", 0x4 },
  3941. { "Line", 0x2 },
  3942. { "CD", 0x3 },
  3943. { "Mix", 0x7 },
  3944. },
  3945. };
  3946. /* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
  3947. static const struct hda_input_mux ad1882a_capture_source = {
  3948. .num_items = 5,
  3949. .items = {
  3950. { "Front Mic", 0x1 },
  3951. { "Mic", 0x4},
  3952. { "Line", 0x2 },
  3953. { "Digital Mic", 0x06 },
  3954. { "Mix", 0x7 },
  3955. },
  3956. };
  3957. static const struct snd_kcontrol_new ad1882_base_mixers[] = {
  3958. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  3959. HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  3960. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  3961. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  3962. HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  3963. HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  3964. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  3965. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
  3966. HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
  3967. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  3968. HDA_CODEC_VOLUME("Line-In Boost Volume", 0x3a, 0x0, HDA_OUTPUT),
  3969. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3970. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3971. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  3972. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  3973. {
  3974. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3975. /* The multiple "Capture Source" controls confuse alsamixer
  3976. * So call somewhat different..
  3977. */
  3978. /* .name = "Capture Source", */
  3979. .name = "Input Source",
  3980. .count = 2,
  3981. .info = ad198x_mux_enum_info,
  3982. .get = ad198x_mux_enum_get,
  3983. .put = ad198x_mux_enum_put,
  3984. },
  3985. /* SPDIF controls */
  3986. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  3987. {
  3988. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3989. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  3990. /* identical with ad1983 */
  3991. .info = ad1983_spdif_route_info,
  3992. .get = ad1983_spdif_route_get,
  3993. .put = ad1983_spdif_route_put,
  3994. },
  3995. { } /* end */
  3996. };
  3997. static const struct snd_kcontrol_new ad1882_loopback_mixers[] = {
  3998. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  3999. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  4000. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  4001. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  4002. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
  4003. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
  4004. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
  4005. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
  4006. { } /* end */
  4007. };
  4008. static const struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
  4009. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  4010. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  4011. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
  4012. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
  4013. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
  4014. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
  4015. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
  4016. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
  4017. HDA_CODEC_VOLUME("Digital Mic Boost Volume", 0x1f, 0x0, HDA_INPUT),
  4018. { } /* end */
  4019. };
  4020. static const struct snd_kcontrol_new ad1882_3stack_mixers[] = {
  4021. HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  4022. HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
  4023. HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
  4024. {
  4025. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4026. .name = "Channel Mode",
  4027. .info = ad198x_ch_mode_info,
  4028. .get = ad198x_ch_mode_get,
  4029. .put = ad198x_ch_mode_put,
  4030. },
  4031. { } /* end */
  4032. };
  4033. /* simple auto-mute control for AD1882 3-stack board */
  4034. #define AD1882_HP_EVENT 0x01
  4035. static void ad1882_3stack_automute(struct hda_codec *codec)
  4036. {
  4037. bool mute = snd_hda_jack_detect(codec, 0x11);
  4038. snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  4039. mute ? 0 : PIN_OUT);
  4040. }
  4041. static int ad1882_3stack_automute_init(struct hda_codec *codec)
  4042. {
  4043. ad198x_init(codec);
  4044. ad1882_3stack_automute(codec);
  4045. return 0;
  4046. }
  4047. static void ad1882_3stack_unsol_event(struct hda_codec *codec, unsigned int res)
  4048. {
  4049. switch (res >> 26) {
  4050. case AD1882_HP_EVENT:
  4051. ad1882_3stack_automute(codec);
  4052. break;
  4053. }
  4054. }
  4055. static const struct snd_kcontrol_new ad1882_6stack_mixers[] = {
  4056. HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  4057. HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
  4058. HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
  4059. { } /* end */
  4060. };
  4061. static const struct hda_verb ad1882_ch2_init[] = {
  4062. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  4063. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4064. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4065. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  4066. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4067. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4068. { } /* end */
  4069. };
  4070. static const struct hda_verb ad1882_ch4_init[] = {
  4071. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  4072. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4073. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4074. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  4075. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4076. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4077. { } /* end */
  4078. };
  4079. static const struct hda_verb ad1882_ch6_init[] = {
  4080. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  4081. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4082. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4083. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  4084. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4085. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4086. { } /* end */
  4087. };
  4088. static const struct hda_channel_mode ad1882_modes[3] = {
  4089. { 2, ad1882_ch2_init },
  4090. { 4, ad1882_ch4_init },
  4091. { 6, ad1882_ch6_init },
  4092. };
  4093. /*
  4094. * initialization verbs
  4095. */
  4096. static const struct hda_verb ad1882_init_verbs[] = {
  4097. /* DACs; mute as default */
  4098. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  4099. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  4100. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  4101. /* Port-A (HP) mixer */
  4102. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4103. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4104. /* Port-A pin */
  4105. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  4106. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4107. /* HP selector - select DAC2 */
  4108. {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
  4109. /* Port-D (Line-out) mixer */
  4110. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4111. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4112. /* Port-D pin */
  4113. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  4114. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4115. /* Mono-out mixer */
  4116. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4117. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4118. /* Mono-out pin */
  4119. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  4120. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4121. /* Port-B (front mic) pin */
  4122. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  4123. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4124. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
  4125. /* Port-C (line-in) pin */
  4126. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  4127. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4128. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
  4129. /* Port-C mixer - mute as input */
  4130. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4131. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4132. /* Port-E (mic-in) pin */
  4133. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  4134. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4135. {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
  4136. /* Port-E mixer - mute as input */
  4137. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4138. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4139. /* Port-F (surround) */
  4140. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  4141. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4142. /* Port-G (CLFE) */
  4143. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  4144. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4145. /* Analog mixer; mute as default */
  4146. /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
  4147. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4148. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4149. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  4150. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  4151. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  4152. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  4153. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  4154. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  4155. /* Analog Mix output amp */
  4156. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  4157. /* SPDIF output selector */
  4158. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  4159. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
  4160. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  4161. { } /* end */
  4162. };
  4163. static const struct hda_verb ad1882_3stack_automute_verbs[] = {
  4164. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1882_HP_EVENT},
  4165. { } /* end */
  4166. };
  4167. #ifdef CONFIG_PM
  4168. static const struct hda_amp_list ad1882_loopbacks[] = {
  4169. { 0x20, HDA_INPUT, 0 }, /* Front Mic */
  4170. { 0x20, HDA_INPUT, 1 }, /* Mic */
  4171. { 0x20, HDA_INPUT, 4 }, /* Line */
  4172. { 0x20, HDA_INPUT, 6 }, /* CD */
  4173. { } /* end */
  4174. };
  4175. #endif
  4176. /* models */
  4177. enum {
  4178. AD1882_AUTO,
  4179. AD1882_3STACK,
  4180. AD1882_6STACK,
  4181. AD1882_3STACK_AUTOMUTE,
  4182. AD1882_MODELS
  4183. };
  4184. static const char * const ad1882_models[AD1986A_MODELS] = {
  4185. [AD1882_AUTO] = "auto",
  4186. [AD1882_3STACK] = "3stack",
  4187. [AD1882_6STACK] = "6stack",
  4188. [AD1882_3STACK_AUTOMUTE] = "3stack-automute",
  4189. };
  4190. static int ad1882_parse_auto_config(struct hda_codec *codec)
  4191. {
  4192. struct ad198x_spec *spec = codec->spec;
  4193. spec->beep_dev_nid = 0x10;
  4194. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  4195. return ad198x_parse_auto_config(codec);
  4196. }
  4197. static int patch_ad1882(struct hda_codec *codec)
  4198. {
  4199. struct ad198x_spec *spec;
  4200. int err, board_config;
  4201. err = alloc_ad_spec(codec);
  4202. if (err < 0)
  4203. return err;
  4204. spec = codec->spec;
  4205. board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
  4206. ad1882_models, NULL);
  4207. if (board_config == AD1882_AUTO) {
  4208. err = ad1882_parse_auto_config(codec);
  4209. if (err < 0) {
  4210. ad198x_free(codec);
  4211. return err;
  4212. }
  4213. return 0;
  4214. }
  4215. err = snd_hda_attach_beep_device(codec, 0x10);
  4216. if (err < 0) {
  4217. ad198x_free(codec);
  4218. return err;
  4219. }
  4220. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  4221. spec->multiout.max_channels = 6;
  4222. spec->multiout.num_dacs = 3;
  4223. spec->multiout.dac_nids = ad1882_dac_nids;
  4224. spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
  4225. spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
  4226. spec->adc_nids = ad1882_adc_nids;
  4227. spec->capsrc_nids = ad1882_capsrc_nids;
  4228. if (codec->vendor_id == 0x11d41882)
  4229. spec->input_mux = &ad1882_capture_source;
  4230. else
  4231. spec->input_mux = &ad1882a_capture_source;
  4232. spec->num_mixers = 2;
  4233. spec->mixers[0] = ad1882_base_mixers;
  4234. if (codec->vendor_id == 0x11d41882)
  4235. spec->mixers[1] = ad1882_loopback_mixers;
  4236. else
  4237. spec->mixers[1] = ad1882a_loopback_mixers;
  4238. spec->num_init_verbs = 1;
  4239. spec->init_verbs[0] = ad1882_init_verbs;
  4240. spec->spdif_route = 0;
  4241. #ifdef CONFIG_PM
  4242. spec->loopback.amplist = ad1882_loopbacks;
  4243. #endif
  4244. spec->vmaster_nid = 0x04;
  4245. codec->patch_ops = ad198x_patch_ops;
  4246. /* override some parameters */
  4247. switch (board_config) {
  4248. default:
  4249. case AD1882_3STACK:
  4250. case AD1882_3STACK_AUTOMUTE:
  4251. spec->num_mixers = 3;
  4252. spec->mixers[2] = ad1882_3stack_mixers;
  4253. spec->channel_mode = ad1882_modes;
  4254. spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
  4255. spec->need_dac_fix = 1;
  4256. spec->multiout.max_channels = 2;
  4257. spec->multiout.num_dacs = 1;
  4258. if (board_config != AD1882_3STACK) {
  4259. spec->init_verbs[spec->num_init_verbs++] =
  4260. ad1882_3stack_automute_verbs;
  4261. codec->patch_ops.unsol_event = ad1882_3stack_unsol_event;
  4262. codec->patch_ops.init = ad1882_3stack_automute_init;
  4263. }
  4264. break;
  4265. case AD1882_6STACK:
  4266. spec->num_mixers = 3;
  4267. spec->mixers[2] = ad1882_6stack_mixers;
  4268. break;
  4269. }
  4270. codec->no_trigger_sense = 1;
  4271. codec->no_sticky_stream = 1;
  4272. return 0;
  4273. }
  4274. /*
  4275. * patch entries
  4276. */
  4277. static const struct hda_codec_preset snd_hda_preset_analog[] = {
  4278. { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
  4279. { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
  4280. { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
  4281. { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
  4282. { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
  4283. { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
  4284. { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
  4285. { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
  4286. { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
  4287. { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
  4288. { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
  4289. { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
  4290. { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
  4291. { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
  4292. { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
  4293. {} /* terminator */
  4294. };
  4295. MODULE_ALIAS("snd-hda-codec-id:11d4*");
  4296. MODULE_LICENSE("GPL");
  4297. MODULE_DESCRIPTION("Analog Devices HD-audio codec");
  4298. static struct hda_codec_preset_list analog_list = {
  4299. .preset = snd_hda_preset_analog,
  4300. .owner = THIS_MODULE,
  4301. };
  4302. static int __init patch_analog_init(void)
  4303. {
  4304. return snd_hda_add_codec_preset(&analog_list);
  4305. }
  4306. static void __exit patch_analog_exit(void)
  4307. {
  4308. snd_hda_delete_codec_preset(&analog_list);
  4309. }
  4310. module_init(patch_analog_init)
  4311. module_exit(patch_analog_exit)