patch_via.c 166 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
  5. *
  6. * (C) 2006-2009 VIA Technology, Inc.
  7. * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
  8. *
  9. * This driver is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This driver is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
  24. /* */
  25. /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
  26. /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
  27. /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
  28. /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
  29. /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
  30. /* 2007-09-17 Lydia Wang Add VT1708B codec support */
  31. /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
  32. /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
  33. /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
  34. /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
  35. /* 2008-04-09 Lydia Wang Add Independent HP feature */
  36. /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
  37. /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
  38. /* 2009-02-16 Logan Li Add support for VT1718S */
  39. /* 2009-03-13 Logan Li Add support for VT1716S */
  40. /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
  41. /* 2009-07-08 Lydia Wang Add support for VT2002P */
  42. /* 2009-07-21 Lydia Wang Add support for VT1812 */
  43. /* 2009-09-19 Lydia Wang Add support for VT1818S */
  44. /* */
  45. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  46. #include <linux/init.h>
  47. #include <linux/delay.h>
  48. #include <linux/slab.h>
  49. #include <sound/core.h>
  50. #include <sound/asoundef.h>
  51. #include "hda_codec.h"
  52. #include "hda_local.h"
  53. #define NID_MAPPING (-1)
  54. /* amp values */
  55. #define AMP_VAL_IDX_SHIFT 19
  56. #define AMP_VAL_IDX_MASK (0x0f<<19)
  57. /* Pin Widget NID */
  58. #define VT1708_HP_NID 0x13
  59. #define VT1708_DIGOUT_NID 0x14
  60. #define VT1708_DIGIN_NID 0x16
  61. #define VT1708_DIGIN_PIN 0x26
  62. #define VT1708_HP_PIN_NID 0x20
  63. #define VT1708_CD_PIN_NID 0x24
  64. #define VT1709_HP_DAC_NID 0x28
  65. #define VT1709_DIGOUT_NID 0x13
  66. #define VT1709_DIGIN_NID 0x17
  67. #define VT1709_DIGIN_PIN 0x25
  68. #define VT1708B_HP_NID 0x25
  69. #define VT1708B_DIGOUT_NID 0x12
  70. #define VT1708B_DIGIN_NID 0x15
  71. #define VT1708B_DIGIN_PIN 0x21
  72. #define VT1708S_HP_NID 0x25
  73. #define VT1708S_DIGOUT_NID 0x12
  74. #define VT1702_HP_NID 0x17
  75. #define VT1702_DIGOUT_NID 0x11
  76. enum VIA_HDA_CODEC {
  77. UNKNOWN = -1,
  78. VT1708,
  79. VT1709_10CH,
  80. VT1709_6CH,
  81. VT1708B_8CH,
  82. VT1708B_4CH,
  83. VT1708S,
  84. VT1708BCE,
  85. VT1702,
  86. VT1718S,
  87. VT1716S,
  88. VT2002P,
  89. VT1812,
  90. CODEC_TYPES,
  91. };
  92. struct via_spec {
  93. /* codec parameterization */
  94. struct snd_kcontrol_new *mixers[6];
  95. unsigned int num_mixers;
  96. struct hda_verb *init_verbs[5];
  97. unsigned int num_iverbs;
  98. char *stream_name_analog;
  99. struct hda_pcm_stream *stream_analog_playback;
  100. struct hda_pcm_stream *stream_analog_capture;
  101. char *stream_name_digital;
  102. struct hda_pcm_stream *stream_digital_playback;
  103. struct hda_pcm_stream *stream_digital_capture;
  104. /* playback */
  105. struct hda_multi_out multiout;
  106. hda_nid_t slave_dig_outs[2];
  107. /* capture */
  108. unsigned int num_adc_nids;
  109. hda_nid_t *adc_nids;
  110. hda_nid_t mux_nids[3];
  111. hda_nid_t dig_in_nid;
  112. hda_nid_t dig_in_pin;
  113. /* capture source */
  114. const struct hda_input_mux *input_mux;
  115. unsigned int cur_mux[3];
  116. /* PCM information */
  117. struct hda_pcm pcm_rec[3];
  118. /* dynamic controls, init_verbs and input_mux */
  119. struct auto_pin_cfg autocfg;
  120. struct snd_array kctls;
  121. struct hda_input_mux private_imux[2];
  122. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  123. /* HP mode source */
  124. const struct hda_input_mux *hp_mux;
  125. unsigned int hp_independent_mode;
  126. unsigned int hp_independent_mode_index;
  127. unsigned int smart51_enabled;
  128. unsigned int dmic_enabled;
  129. enum VIA_HDA_CODEC codec_type;
  130. /* work to check hp jack state */
  131. struct hda_codec *codec;
  132. struct delayed_work vt1708_hp_work;
  133. int vt1708_jack_detectect;
  134. int vt1708_hp_present;
  135. #ifdef CONFIG_SND_HDA_POWER_SAVE
  136. struct hda_loopback_check loopback;
  137. #endif
  138. };
  139. static struct via_spec * via_new_spec(struct hda_codec *codec)
  140. {
  141. struct via_spec *spec;
  142. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  143. if (spec == NULL)
  144. return NULL;
  145. codec->spec = spec;
  146. spec->codec = codec;
  147. return spec;
  148. }
  149. static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
  150. {
  151. u32 vendor_id = codec->vendor_id;
  152. u16 ven_id = vendor_id >> 16;
  153. u16 dev_id = vendor_id & 0xffff;
  154. enum VIA_HDA_CODEC codec_type;
  155. /* get codec type */
  156. if (ven_id != 0x1106)
  157. codec_type = UNKNOWN;
  158. else if (dev_id >= 0x1708 && dev_id <= 0x170b)
  159. codec_type = VT1708;
  160. else if (dev_id >= 0xe710 && dev_id <= 0xe713)
  161. codec_type = VT1709_10CH;
  162. else if (dev_id >= 0xe714 && dev_id <= 0xe717)
  163. codec_type = VT1709_6CH;
  164. else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
  165. codec_type = VT1708B_8CH;
  166. if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
  167. codec_type = VT1708BCE;
  168. } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
  169. codec_type = VT1708B_4CH;
  170. else if ((dev_id & 0xfff) == 0x397
  171. && (dev_id >> 12) < 8)
  172. codec_type = VT1708S;
  173. else if ((dev_id & 0xfff) == 0x398
  174. && (dev_id >> 12) < 8)
  175. codec_type = VT1702;
  176. else if ((dev_id & 0xfff) == 0x428
  177. && (dev_id >> 12) < 8)
  178. codec_type = VT1718S;
  179. else if (dev_id == 0x0433 || dev_id == 0xa721)
  180. codec_type = VT1716S;
  181. else if (dev_id == 0x0441 || dev_id == 0x4441)
  182. codec_type = VT1718S;
  183. else if (dev_id == 0x0438 || dev_id == 0x4438)
  184. codec_type = VT2002P;
  185. else if (dev_id == 0x0448)
  186. codec_type = VT1812;
  187. else if (dev_id == 0x0440)
  188. codec_type = VT1708S;
  189. else
  190. codec_type = UNKNOWN;
  191. return codec_type;
  192. };
  193. #define VIA_HP_EVENT 0x01
  194. #define VIA_GPIO_EVENT 0x02
  195. #define VIA_JACK_EVENT 0x04
  196. #define VIA_MONO_EVENT 0x08
  197. #define VIA_SPEAKER_EVENT 0x10
  198. #define VIA_BIND_HP_EVENT 0x20
  199. enum {
  200. VIA_CTL_WIDGET_VOL,
  201. VIA_CTL_WIDGET_MUTE,
  202. VIA_CTL_WIDGET_ANALOG_MUTE,
  203. VIA_CTL_WIDGET_BIND_PIN_MUTE,
  204. };
  205. enum {
  206. AUTO_SEQ_FRONT = 0,
  207. AUTO_SEQ_SURROUND,
  208. AUTO_SEQ_CENLFE,
  209. AUTO_SEQ_SIDE
  210. };
  211. static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
  212. static void set_jack_power_state(struct hda_codec *codec);
  213. static int is_aa_path_mute(struct hda_codec *codec);
  214. static void vt1708_start_hp_work(struct via_spec *spec)
  215. {
  216. if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
  217. return;
  218. snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
  219. !spec->vt1708_jack_detectect);
  220. if (!delayed_work_pending(&spec->vt1708_hp_work))
  221. schedule_delayed_work(&spec->vt1708_hp_work,
  222. msecs_to_jiffies(100));
  223. }
  224. static void vt1708_stop_hp_work(struct via_spec *spec)
  225. {
  226. if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
  227. return;
  228. if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
  229. && !is_aa_path_mute(spec->codec))
  230. return;
  231. snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
  232. !spec->vt1708_jack_detectect);
  233. cancel_delayed_work_sync(&spec->vt1708_hp_work);
  234. }
  235. static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
  236. struct snd_ctl_elem_value *ucontrol)
  237. {
  238. int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
  239. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  240. set_jack_power_state(codec);
  241. analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
  242. if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
  243. if (is_aa_path_mute(codec))
  244. vt1708_start_hp_work(codec->spec);
  245. else
  246. vt1708_stop_hp_work(codec->spec);
  247. }
  248. return change;
  249. }
  250. /* modify .put = snd_hda_mixer_amp_switch_put */
  251. #define ANALOG_INPUT_MUTE \
  252. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  253. .name = NULL, \
  254. .index = 0, \
  255. .info = snd_hda_mixer_amp_switch_info, \
  256. .get = snd_hda_mixer_amp_switch_get, \
  257. .put = analog_input_switch_put, \
  258. .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
  259. static void via_hp_bind_automute(struct hda_codec *codec);
  260. static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
  261. struct snd_ctl_elem_value *ucontrol)
  262. {
  263. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  264. struct via_spec *spec = codec->spec;
  265. int i;
  266. int change = 0;
  267. long *valp = ucontrol->value.integer.value;
  268. int lmute, rmute;
  269. if (strstr(kcontrol->id.name, "Switch") == NULL) {
  270. snd_printd("Invalid control!\n");
  271. return change;
  272. }
  273. change = snd_hda_mixer_amp_switch_put(kcontrol,
  274. ucontrol);
  275. /* Get mute value */
  276. lmute = *valp ? 0 : HDA_AMP_MUTE;
  277. valp++;
  278. rmute = *valp ? 0 : HDA_AMP_MUTE;
  279. /* Set hp pins */
  280. if (!spec->hp_independent_mode) {
  281. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  282. snd_hda_codec_amp_update(
  283. codec, spec->autocfg.hp_pins[i],
  284. 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  285. lmute);
  286. snd_hda_codec_amp_update(
  287. codec, spec->autocfg.hp_pins[i],
  288. 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  289. rmute);
  290. }
  291. }
  292. if (!lmute && !rmute) {
  293. /* Line Outs */
  294. for (i = 0; i < spec->autocfg.line_outs; i++)
  295. snd_hda_codec_amp_stereo(
  296. codec, spec->autocfg.line_out_pins[i],
  297. HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
  298. /* Speakers */
  299. for (i = 0; i < spec->autocfg.speaker_outs; i++)
  300. snd_hda_codec_amp_stereo(
  301. codec, spec->autocfg.speaker_pins[i],
  302. HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
  303. /* unmute */
  304. via_hp_bind_automute(codec);
  305. } else {
  306. if (lmute) {
  307. /* Mute all left channels */
  308. for (i = 1; i < spec->autocfg.line_outs; i++)
  309. snd_hda_codec_amp_update(
  310. codec,
  311. spec->autocfg.line_out_pins[i],
  312. 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  313. lmute);
  314. for (i = 0; i < spec->autocfg.speaker_outs; i++)
  315. snd_hda_codec_amp_update(
  316. codec,
  317. spec->autocfg.speaker_pins[i],
  318. 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  319. lmute);
  320. }
  321. if (rmute) {
  322. /* mute all right channels */
  323. for (i = 1; i < spec->autocfg.line_outs; i++)
  324. snd_hda_codec_amp_update(
  325. codec,
  326. spec->autocfg.line_out_pins[i],
  327. 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  328. rmute);
  329. for (i = 0; i < spec->autocfg.speaker_outs; i++)
  330. snd_hda_codec_amp_update(
  331. codec,
  332. spec->autocfg.speaker_pins[i],
  333. 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  334. rmute);
  335. }
  336. }
  337. return change;
  338. }
  339. #define BIND_PIN_MUTE \
  340. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  341. .name = NULL, \
  342. .index = 0, \
  343. .info = snd_hda_mixer_amp_switch_info, \
  344. .get = snd_hda_mixer_amp_switch_get, \
  345. .put = bind_pin_switch_put, \
  346. .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
  347. static struct snd_kcontrol_new via_control_templates[] = {
  348. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  349. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  350. ANALOG_INPUT_MUTE,
  351. BIND_PIN_MUTE,
  352. };
  353. static hda_nid_t vt1708_adc_nids[2] = {
  354. /* ADC1-2 */
  355. 0x15, 0x27
  356. };
  357. static hda_nid_t vt1709_adc_nids[3] = {
  358. /* ADC1-2 */
  359. 0x14, 0x15, 0x16
  360. };
  361. static hda_nid_t vt1708B_adc_nids[2] = {
  362. /* ADC1-2 */
  363. 0x13, 0x14
  364. };
  365. static hda_nid_t vt1708S_adc_nids[2] = {
  366. /* ADC1-2 */
  367. 0x13, 0x14
  368. };
  369. static hda_nid_t vt1702_adc_nids[3] = {
  370. /* ADC1-2 */
  371. 0x12, 0x20, 0x1F
  372. };
  373. static hda_nid_t vt1718S_adc_nids[2] = {
  374. /* ADC1-2 */
  375. 0x10, 0x11
  376. };
  377. static hda_nid_t vt1716S_adc_nids[2] = {
  378. /* ADC1-2 */
  379. 0x13, 0x14
  380. };
  381. static hda_nid_t vt2002P_adc_nids[2] = {
  382. /* ADC1-2 */
  383. 0x10, 0x11
  384. };
  385. static hda_nid_t vt1812_adc_nids[2] = {
  386. /* ADC1-2 */
  387. 0x10, 0x11
  388. };
  389. /* add dynamic controls */
  390. static int __via_add_control(struct via_spec *spec, int type, const char *name,
  391. int idx, unsigned long val)
  392. {
  393. struct snd_kcontrol_new *knew;
  394. snd_array_init(&spec->kctls, sizeof(*knew), 32);
  395. knew = snd_array_new(&spec->kctls);
  396. if (!knew)
  397. return -ENOMEM;
  398. *knew = via_control_templates[type];
  399. knew->name = kstrdup(name, GFP_KERNEL);
  400. if (!knew->name)
  401. return -ENOMEM;
  402. if (get_amp_nid_(val))
  403. knew->subdevice = HDA_SUBDEV_AMP_FLAG;
  404. knew->private_value = val;
  405. return 0;
  406. }
  407. #define via_add_control(spec, type, name, val) \
  408. __via_add_control(spec, type, name, 0, val)
  409. static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
  410. struct snd_kcontrol_new *tmpl)
  411. {
  412. struct snd_kcontrol_new *knew;
  413. snd_array_init(&spec->kctls, sizeof(*knew), 32);
  414. knew = snd_array_new(&spec->kctls);
  415. if (!knew)
  416. return NULL;
  417. *knew = *tmpl;
  418. knew->name = kstrdup(tmpl->name, GFP_KERNEL);
  419. if (!knew->name)
  420. return NULL;
  421. return knew;
  422. }
  423. static void via_free_kctls(struct hda_codec *codec)
  424. {
  425. struct via_spec *spec = codec->spec;
  426. if (spec->kctls.list) {
  427. struct snd_kcontrol_new *kctl = spec->kctls.list;
  428. int i;
  429. for (i = 0; i < spec->kctls.used; i++)
  430. kfree(kctl[i].name);
  431. }
  432. snd_array_free(&spec->kctls);
  433. }
  434. /* create input playback/capture controls for the given pin */
  435. static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
  436. int type_idx, int idx, int mix_nid)
  437. {
  438. char name[32];
  439. int err;
  440. sprintf(name, "%s Playback Volume", ctlname);
  441. err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
  442. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  443. if (err < 0)
  444. return err;
  445. sprintf(name, "%s Playback Switch", ctlname);
  446. err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
  447. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  448. if (err < 0)
  449. return err;
  450. return 0;
  451. }
  452. static void via_auto_set_output_and_unmute(struct hda_codec *codec,
  453. hda_nid_t nid, int pin_type,
  454. int dac_idx)
  455. {
  456. /* set as output */
  457. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  458. pin_type);
  459. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  460. AMP_OUT_UNMUTE);
  461. if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
  462. snd_hda_codec_write(codec, nid, 0,
  463. AC_VERB_SET_EAPD_BTLENABLE, 0x02);
  464. }
  465. static void via_auto_init_multi_out(struct hda_codec *codec)
  466. {
  467. struct via_spec *spec = codec->spec;
  468. int i;
  469. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  470. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  471. if (nid)
  472. via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
  473. }
  474. }
  475. static void via_auto_init_hp_out(struct hda_codec *codec)
  476. {
  477. struct via_spec *spec = codec->spec;
  478. hda_nid_t pin;
  479. int i;
  480. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  481. pin = spec->autocfg.hp_pins[i];
  482. if (pin) /* connect to front */
  483. via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
  484. }
  485. }
  486. static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
  487. static void via_auto_init_analog_input(struct hda_codec *codec)
  488. {
  489. struct via_spec *spec = codec->spec;
  490. const struct auto_pin_cfg *cfg = &spec->autocfg;
  491. unsigned int ctl;
  492. int i;
  493. for (i = 0; i < cfg->num_inputs; i++) {
  494. hda_nid_t nid = cfg->inputs[i].pin;
  495. if (spec->smart51_enabled && is_smart51_pins(spec, nid))
  496. ctl = PIN_OUT;
  497. else if (i == AUTO_PIN_MIC)
  498. ctl = PIN_VREF50;
  499. else
  500. ctl = PIN_IN;
  501. snd_hda_codec_write(codec, nid, 0,
  502. AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
  503. }
  504. }
  505. static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
  506. unsigned int *affected_parm)
  507. {
  508. unsigned parm;
  509. unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
  510. unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
  511. >> AC_DEFCFG_MISC_SHIFT
  512. & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
  513. unsigned present = snd_hda_jack_detect(codec, nid);
  514. struct via_spec *spec = codec->spec;
  515. if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
  516. || ((no_presence || present)
  517. && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
  518. *affected_parm = AC_PWRST_D0; /* if it's connected */
  519. parm = AC_PWRST_D0;
  520. } else
  521. parm = AC_PWRST_D3;
  522. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
  523. }
  524. static void set_jack_power_state(struct hda_codec *codec)
  525. {
  526. struct via_spec *spec = codec->spec;
  527. int imux_is_smixer;
  528. unsigned int parm;
  529. if (spec->codec_type == VT1702) {
  530. imux_is_smixer = snd_hda_codec_read(
  531. codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
  532. /* inputs */
  533. /* PW 1/2/5 (14h/15h/18h) */
  534. parm = AC_PWRST_D3;
  535. set_pin_power_state(codec, 0x14, &parm);
  536. set_pin_power_state(codec, 0x15, &parm);
  537. set_pin_power_state(codec, 0x18, &parm);
  538. if (imux_is_smixer)
  539. parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
  540. /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
  541. snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
  542. parm);
  543. snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
  544. parm);
  545. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
  546. parm);
  547. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
  548. parm);
  549. /* outputs */
  550. /* PW 3/4 (16h/17h) */
  551. parm = AC_PWRST_D3;
  552. set_pin_power_state(codec, 0x16, &parm);
  553. set_pin_power_state(codec, 0x17, &parm);
  554. /* MW0 (1ah), AOW 0/1 (10h/1dh) */
  555. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
  556. imux_is_smixer ? AC_PWRST_D0 : parm);
  557. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
  558. parm);
  559. snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
  560. parm);
  561. } else if (spec->codec_type == VT1708B_8CH
  562. || spec->codec_type == VT1708B_4CH
  563. || spec->codec_type == VT1708S) {
  564. /* SW0 (17h) = stereo mixer */
  565. int is_8ch = spec->codec_type != VT1708B_4CH;
  566. imux_is_smixer = snd_hda_codec_read(
  567. codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
  568. == ((spec->codec_type == VT1708S) ? 5 : 0);
  569. /* inputs */
  570. /* PW 1/2/5 (1ah/1bh/1eh) */
  571. parm = AC_PWRST_D3;
  572. set_pin_power_state(codec, 0x1a, &parm);
  573. set_pin_power_state(codec, 0x1b, &parm);
  574. set_pin_power_state(codec, 0x1e, &parm);
  575. if (imux_is_smixer)
  576. parm = AC_PWRST_D0;
  577. /* SW0 (17h), AIW 0/1 (13h/14h) */
  578. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
  579. parm);
  580. snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
  581. parm);
  582. snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
  583. parm);
  584. /* outputs */
  585. /* PW0 (19h), SW1 (18h), AOW1 (11h) */
  586. parm = AC_PWRST_D3;
  587. set_pin_power_state(codec, 0x19, &parm);
  588. if (spec->smart51_enabled)
  589. parm = AC_PWRST_D0;
  590. snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
  591. parm);
  592. snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
  593. parm);
  594. /* PW6 (22h), SW2 (26h), AOW2 (24h) */
  595. if (is_8ch) {
  596. parm = AC_PWRST_D3;
  597. set_pin_power_state(codec, 0x22, &parm);
  598. if (spec->smart51_enabled)
  599. parm = AC_PWRST_D0;
  600. snd_hda_codec_write(codec, 0x26, 0,
  601. AC_VERB_SET_POWER_STATE, parm);
  602. snd_hda_codec_write(codec, 0x24, 0,
  603. AC_VERB_SET_POWER_STATE, parm);
  604. }
  605. /* PW 3/4/7 (1ch/1dh/23h) */
  606. parm = AC_PWRST_D3;
  607. /* force to D0 for internal Speaker */
  608. set_pin_power_state(codec, 0x1c, &parm);
  609. set_pin_power_state(codec, 0x1d, &parm);
  610. if (is_8ch)
  611. set_pin_power_state(codec, 0x23, &parm);
  612. /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
  613. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
  614. imux_is_smixer ? AC_PWRST_D0 : parm);
  615. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
  616. parm);
  617. if (is_8ch) {
  618. snd_hda_codec_write(codec, 0x25, 0,
  619. AC_VERB_SET_POWER_STATE, parm);
  620. snd_hda_codec_write(codec, 0x27, 0,
  621. AC_VERB_SET_POWER_STATE, parm);
  622. }
  623. } else if (spec->codec_type == VT1718S) {
  624. /* MUX6 (1eh) = stereo mixer */
  625. imux_is_smixer = snd_hda_codec_read(
  626. codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
  627. /* inputs */
  628. /* PW 5/6/7 (29h/2ah/2bh) */
  629. parm = AC_PWRST_D3;
  630. set_pin_power_state(codec, 0x29, &parm);
  631. set_pin_power_state(codec, 0x2a, &parm);
  632. set_pin_power_state(codec, 0x2b, &parm);
  633. if (imux_is_smixer)
  634. parm = AC_PWRST_D0;
  635. /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
  636. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
  637. parm);
  638. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
  639. parm);
  640. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
  641. parm);
  642. snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
  643. parm);
  644. /* outputs */
  645. /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
  646. parm = AC_PWRST_D3;
  647. set_pin_power_state(codec, 0x27, &parm);
  648. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
  649. parm);
  650. snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
  651. parm);
  652. /* PW2 (26h), AOW2 (ah) */
  653. parm = AC_PWRST_D3;
  654. set_pin_power_state(codec, 0x26, &parm);
  655. snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
  656. parm);
  657. /* PW0/1 (24h/25h) */
  658. parm = AC_PWRST_D3;
  659. set_pin_power_state(codec, 0x24, &parm);
  660. set_pin_power_state(codec, 0x25, &parm);
  661. if (!spec->hp_independent_mode) /* check for redirected HP */
  662. set_pin_power_state(codec, 0x28, &parm);
  663. snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
  664. parm);
  665. snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
  666. parm);
  667. /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
  668. snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
  669. imux_is_smixer ? AC_PWRST_D0 : parm);
  670. if (spec->hp_independent_mode) {
  671. /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
  672. parm = AC_PWRST_D3;
  673. set_pin_power_state(codec, 0x28, &parm);
  674. snd_hda_codec_write(codec, 0x1b, 0,
  675. AC_VERB_SET_POWER_STATE, parm);
  676. snd_hda_codec_write(codec, 0x34, 0,
  677. AC_VERB_SET_POWER_STATE, parm);
  678. snd_hda_codec_write(codec, 0xc, 0,
  679. AC_VERB_SET_POWER_STATE, parm);
  680. }
  681. } else if (spec->codec_type == VT1716S) {
  682. unsigned int mono_out, present;
  683. /* SW0 (17h) = stereo mixer */
  684. imux_is_smixer = snd_hda_codec_read(
  685. codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
  686. /* inputs */
  687. /* PW 1/2/5 (1ah/1bh/1eh) */
  688. parm = AC_PWRST_D3;
  689. set_pin_power_state(codec, 0x1a, &parm);
  690. set_pin_power_state(codec, 0x1b, &parm);
  691. set_pin_power_state(codec, 0x1e, &parm);
  692. if (imux_is_smixer)
  693. parm = AC_PWRST_D0;
  694. /* SW0 (17h), AIW0(13h) */
  695. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
  696. parm);
  697. snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
  698. parm);
  699. parm = AC_PWRST_D3;
  700. set_pin_power_state(codec, 0x1e, &parm);
  701. /* PW11 (22h) */
  702. if (spec->dmic_enabled)
  703. set_pin_power_state(codec, 0x22, &parm);
  704. else
  705. snd_hda_codec_write(
  706. codec, 0x22, 0,
  707. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  708. /* SW2(26h), AIW1(14h) */
  709. snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
  710. parm);
  711. snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
  712. parm);
  713. /* outputs */
  714. /* PW0 (19h), SW1 (18h), AOW1 (11h) */
  715. parm = AC_PWRST_D3;
  716. set_pin_power_state(codec, 0x19, &parm);
  717. /* Smart 5.1 PW2(1bh) */
  718. if (spec->smart51_enabled)
  719. set_pin_power_state(codec, 0x1b, &parm);
  720. snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
  721. parm);
  722. snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
  723. parm);
  724. /* PW7 (23h), SW3 (27h), AOW3 (25h) */
  725. parm = AC_PWRST_D3;
  726. set_pin_power_state(codec, 0x23, &parm);
  727. /* Smart 5.1 PW1(1ah) */
  728. if (spec->smart51_enabled)
  729. set_pin_power_state(codec, 0x1a, &parm);
  730. snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
  731. parm);
  732. /* Smart 5.1 PW5(1eh) */
  733. if (spec->smart51_enabled)
  734. set_pin_power_state(codec, 0x1e, &parm);
  735. snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
  736. parm);
  737. /* Mono out */
  738. /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
  739. present = snd_hda_jack_detect(codec, 0x1c);
  740. if (present)
  741. mono_out = 0;
  742. else {
  743. present = snd_hda_jack_detect(codec, 0x1d);
  744. if (!spec->hp_independent_mode && present)
  745. mono_out = 0;
  746. else
  747. mono_out = 1;
  748. }
  749. parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
  750. snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
  751. parm);
  752. snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
  753. parm);
  754. snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
  755. parm);
  756. /* PW 3/4 (1ch/1dh) */
  757. parm = AC_PWRST_D3;
  758. set_pin_power_state(codec, 0x1c, &parm);
  759. set_pin_power_state(codec, 0x1d, &parm);
  760. /* HP Independent Mode, power on AOW3 */
  761. if (spec->hp_independent_mode)
  762. snd_hda_codec_write(codec, 0x25, 0,
  763. AC_VERB_SET_POWER_STATE, parm);
  764. /* force to D0 for internal Speaker */
  765. /* MW0 (16h), AOW0 (10h) */
  766. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
  767. imux_is_smixer ? AC_PWRST_D0 : parm);
  768. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
  769. mono_out ? AC_PWRST_D0 : parm);
  770. } else if (spec->codec_type == VT2002P) {
  771. unsigned int present;
  772. /* MUX9 (1eh) = stereo mixer */
  773. imux_is_smixer = snd_hda_codec_read(
  774. codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
  775. /* inputs */
  776. /* PW 5/6/7 (29h/2ah/2bh) */
  777. parm = AC_PWRST_D3;
  778. set_pin_power_state(codec, 0x29, &parm);
  779. set_pin_power_state(codec, 0x2a, &parm);
  780. set_pin_power_state(codec, 0x2b, &parm);
  781. if (imux_is_smixer)
  782. parm = AC_PWRST_D0;
  783. /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
  784. snd_hda_codec_write(codec, 0x1e, 0,
  785. AC_VERB_SET_POWER_STATE, parm);
  786. snd_hda_codec_write(codec, 0x1f, 0,
  787. AC_VERB_SET_POWER_STATE, parm);
  788. snd_hda_codec_write(codec, 0x10, 0,
  789. AC_VERB_SET_POWER_STATE, parm);
  790. snd_hda_codec_write(codec, 0x11, 0,
  791. AC_VERB_SET_POWER_STATE, parm);
  792. /* outputs */
  793. /* AOW0 (8h)*/
  794. snd_hda_codec_write(codec, 0x8, 0,
  795. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  796. /* PW4 (26h), MW4 (1ch), MUX4(37h) */
  797. parm = AC_PWRST_D3;
  798. set_pin_power_state(codec, 0x26, &parm);
  799. snd_hda_codec_write(codec, 0x1c, 0,
  800. AC_VERB_SET_POWER_STATE, parm);
  801. snd_hda_codec_write(codec, 0x37,
  802. 0, AC_VERB_SET_POWER_STATE, parm);
  803. /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
  804. parm = AC_PWRST_D3;
  805. set_pin_power_state(codec, 0x25, &parm);
  806. snd_hda_codec_write(codec, 0x19, 0,
  807. AC_VERB_SET_POWER_STATE, parm);
  808. snd_hda_codec_write(codec, 0x35, 0,
  809. AC_VERB_SET_POWER_STATE, parm);
  810. if (spec->hp_independent_mode) {
  811. snd_hda_codec_write(codec, 0x9, 0,
  812. AC_VERB_SET_POWER_STATE, parm);
  813. }
  814. /* Class-D */
  815. /* PW0 (24h), MW0(18h), MUX0(34h) */
  816. present = snd_hda_jack_detect(codec, 0x25);
  817. parm = AC_PWRST_D3;
  818. set_pin_power_state(codec, 0x24, &parm);
  819. if (present) {
  820. snd_hda_codec_write(
  821. codec, 0x18, 0,
  822. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  823. snd_hda_codec_write(
  824. codec, 0x34, 0,
  825. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  826. } else {
  827. snd_hda_codec_write(
  828. codec, 0x18, 0,
  829. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  830. snd_hda_codec_write(
  831. codec, 0x34, 0,
  832. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  833. }
  834. /* Mono Out */
  835. /* PW15 (31h), MW8(17h), MUX8(3bh) */
  836. present = snd_hda_jack_detect(codec, 0x26);
  837. parm = AC_PWRST_D3;
  838. set_pin_power_state(codec, 0x31, &parm);
  839. if (present) {
  840. snd_hda_codec_write(
  841. codec, 0x17, 0,
  842. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  843. snd_hda_codec_write(
  844. codec, 0x3b, 0,
  845. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  846. } else {
  847. snd_hda_codec_write(
  848. codec, 0x17, 0,
  849. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  850. snd_hda_codec_write(
  851. codec, 0x3b, 0,
  852. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  853. }
  854. /* MW9 (21h) */
  855. if (imux_is_smixer || !is_aa_path_mute(codec))
  856. snd_hda_codec_write(
  857. codec, 0x21, 0,
  858. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  859. else
  860. snd_hda_codec_write(
  861. codec, 0x21, 0,
  862. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  863. } else if (spec->codec_type == VT1812) {
  864. unsigned int present;
  865. /* MUX10 (1eh) = stereo mixer */
  866. imux_is_smixer = snd_hda_codec_read(
  867. codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
  868. /* inputs */
  869. /* PW 5/6/7 (29h/2ah/2bh) */
  870. parm = AC_PWRST_D3;
  871. set_pin_power_state(codec, 0x29, &parm);
  872. set_pin_power_state(codec, 0x2a, &parm);
  873. set_pin_power_state(codec, 0x2b, &parm);
  874. if (imux_is_smixer)
  875. parm = AC_PWRST_D0;
  876. /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
  877. snd_hda_codec_write(codec, 0x1e, 0,
  878. AC_VERB_SET_POWER_STATE, parm);
  879. snd_hda_codec_write(codec, 0x1f, 0,
  880. AC_VERB_SET_POWER_STATE, parm);
  881. snd_hda_codec_write(codec, 0x10, 0,
  882. AC_VERB_SET_POWER_STATE, parm);
  883. snd_hda_codec_write(codec, 0x11, 0,
  884. AC_VERB_SET_POWER_STATE, parm);
  885. /* outputs */
  886. /* AOW0 (8h)*/
  887. snd_hda_codec_write(codec, 0x8, 0,
  888. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  889. /* PW4 (28h), MW4 (18h), MUX4(38h) */
  890. parm = AC_PWRST_D3;
  891. set_pin_power_state(codec, 0x28, &parm);
  892. snd_hda_codec_write(codec, 0x18, 0,
  893. AC_VERB_SET_POWER_STATE, parm);
  894. snd_hda_codec_write(codec, 0x38, 0,
  895. AC_VERB_SET_POWER_STATE, parm);
  896. /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
  897. parm = AC_PWRST_D3;
  898. set_pin_power_state(codec, 0x25, &parm);
  899. snd_hda_codec_write(codec, 0x15, 0,
  900. AC_VERB_SET_POWER_STATE, parm);
  901. snd_hda_codec_write(codec, 0x35, 0,
  902. AC_VERB_SET_POWER_STATE, parm);
  903. if (spec->hp_independent_mode) {
  904. snd_hda_codec_write(codec, 0x9, 0,
  905. AC_VERB_SET_POWER_STATE, parm);
  906. }
  907. /* Internal Speaker */
  908. /* PW0 (24h), MW0(14h), MUX0(34h) */
  909. present = snd_hda_jack_detect(codec, 0x25);
  910. parm = AC_PWRST_D3;
  911. set_pin_power_state(codec, 0x24, &parm);
  912. if (present) {
  913. snd_hda_codec_write(codec, 0x14, 0,
  914. AC_VERB_SET_POWER_STATE,
  915. AC_PWRST_D3);
  916. snd_hda_codec_write(codec, 0x34, 0,
  917. AC_VERB_SET_POWER_STATE,
  918. AC_PWRST_D3);
  919. } else {
  920. snd_hda_codec_write(codec, 0x14, 0,
  921. AC_VERB_SET_POWER_STATE,
  922. AC_PWRST_D0);
  923. snd_hda_codec_write(codec, 0x34, 0,
  924. AC_VERB_SET_POWER_STATE,
  925. AC_PWRST_D0);
  926. }
  927. /* Mono Out */
  928. /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
  929. present = snd_hda_jack_detect(codec, 0x28);
  930. parm = AC_PWRST_D3;
  931. set_pin_power_state(codec, 0x31, &parm);
  932. if (present) {
  933. snd_hda_codec_write(codec, 0x1c, 0,
  934. AC_VERB_SET_POWER_STATE,
  935. AC_PWRST_D3);
  936. snd_hda_codec_write(codec, 0x3c, 0,
  937. AC_VERB_SET_POWER_STATE,
  938. AC_PWRST_D3);
  939. snd_hda_codec_write(codec, 0x3e, 0,
  940. AC_VERB_SET_POWER_STATE,
  941. AC_PWRST_D3);
  942. } else {
  943. snd_hda_codec_write(codec, 0x1c, 0,
  944. AC_VERB_SET_POWER_STATE,
  945. AC_PWRST_D0);
  946. snd_hda_codec_write(codec, 0x3c, 0,
  947. AC_VERB_SET_POWER_STATE,
  948. AC_PWRST_D0);
  949. snd_hda_codec_write(codec, 0x3e, 0,
  950. AC_VERB_SET_POWER_STATE,
  951. AC_PWRST_D0);
  952. }
  953. /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
  954. parm = AC_PWRST_D3;
  955. set_pin_power_state(codec, 0x33, &parm);
  956. snd_hda_codec_write(codec, 0x1d, 0,
  957. AC_VERB_SET_POWER_STATE, parm);
  958. snd_hda_codec_write(codec, 0x3d, 0,
  959. AC_VERB_SET_POWER_STATE, parm);
  960. /* MW9 (21h) */
  961. if (imux_is_smixer || !is_aa_path_mute(codec))
  962. snd_hda_codec_write(
  963. codec, 0x21, 0,
  964. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  965. else
  966. snd_hda_codec_write(
  967. codec, 0x21, 0,
  968. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  969. }
  970. }
  971. /*
  972. * input MUX handling
  973. */
  974. static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
  975. struct snd_ctl_elem_info *uinfo)
  976. {
  977. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  978. struct via_spec *spec = codec->spec;
  979. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  980. }
  981. static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
  982. struct snd_ctl_elem_value *ucontrol)
  983. {
  984. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  985. struct via_spec *spec = codec->spec;
  986. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  987. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  988. return 0;
  989. }
  990. static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
  991. struct snd_ctl_elem_value *ucontrol)
  992. {
  993. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  994. struct via_spec *spec = codec->spec;
  995. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  996. if (!spec->mux_nids[adc_idx])
  997. return -EINVAL;
  998. /* switch to D0 beofre change index */
  999. if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
  1000. AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
  1001. snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
  1002. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  1003. /* update jack power state */
  1004. set_jack_power_state(codec);
  1005. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  1006. spec->mux_nids[adc_idx],
  1007. &spec->cur_mux[adc_idx]);
  1008. }
  1009. static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
  1010. struct snd_ctl_elem_info *uinfo)
  1011. {
  1012. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1013. struct via_spec *spec = codec->spec;
  1014. return snd_hda_input_mux_info(spec->hp_mux, uinfo);
  1015. }
  1016. static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
  1017. struct snd_ctl_elem_value *ucontrol)
  1018. {
  1019. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1020. hda_nid_t nid = kcontrol->private_value;
  1021. unsigned int pinsel;
  1022. /* use !! to translate conn sel 2 for VT1718S */
  1023. pinsel = !!snd_hda_codec_read(codec, nid, 0,
  1024. AC_VERB_GET_CONNECT_SEL,
  1025. 0x00);
  1026. ucontrol->value.enumerated.item[0] = pinsel;
  1027. return 0;
  1028. }
  1029. static void activate_ctl(struct hda_codec *codec, const char *name, int active)
  1030. {
  1031. struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
  1032. if (ctl) {
  1033. ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  1034. ctl->vd[0].access |= active
  1035. ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  1036. snd_ctl_notify(codec->bus->card,
  1037. SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
  1038. }
  1039. }
  1040. static hda_nid_t side_mute_channel(struct via_spec *spec)
  1041. {
  1042. switch (spec->codec_type) {
  1043. case VT1708: return 0x1b;
  1044. case VT1709_10CH: return 0x29;
  1045. case VT1708B_8CH: /* fall thru */
  1046. case VT1708S: return 0x27;
  1047. default: return 0;
  1048. }
  1049. }
  1050. static int update_side_mute_status(struct hda_codec *codec)
  1051. {
  1052. /* mute side channel */
  1053. struct via_spec *spec = codec->spec;
  1054. unsigned int parm = spec->hp_independent_mode
  1055. ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
  1056. hda_nid_t sw3 = side_mute_channel(spec);
  1057. if (sw3)
  1058. snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  1059. parm);
  1060. return 0;
  1061. }
  1062. static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
  1063. struct snd_ctl_elem_value *ucontrol)
  1064. {
  1065. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1066. struct via_spec *spec = codec->spec;
  1067. hda_nid_t nid = kcontrol->private_value;
  1068. unsigned int pinsel = ucontrol->value.enumerated.item[0];
  1069. /* Get Independent Mode index of headphone pin widget */
  1070. spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
  1071. ? 1 : 0;
  1072. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
  1073. if (spec->multiout.hp_nid && spec->multiout.hp_nid
  1074. != spec->multiout.dac_nids[HDA_FRONT])
  1075. snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
  1076. 0, 0, 0);
  1077. update_side_mute_status(codec);
  1078. /* update HP volume/swtich active state */
  1079. if (spec->codec_type == VT1708S
  1080. || spec->codec_type == VT1702
  1081. || spec->codec_type == VT1718S
  1082. || spec->codec_type == VT1716S
  1083. || spec->codec_type == VT2002P
  1084. || spec->codec_type == VT1812) {
  1085. activate_ctl(codec, "Headphone Playback Volume",
  1086. spec->hp_independent_mode);
  1087. activate_ctl(codec, "Headphone Playback Switch",
  1088. spec->hp_independent_mode);
  1089. }
  1090. return 0;
  1091. }
  1092. static struct snd_kcontrol_new via_hp_mixer[2] = {
  1093. {
  1094. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1095. .name = "Independent HP",
  1096. .info = via_independent_hp_info,
  1097. .get = via_independent_hp_get,
  1098. .put = via_independent_hp_put,
  1099. },
  1100. {
  1101. .iface = NID_MAPPING,
  1102. .name = "Independent HP",
  1103. },
  1104. };
  1105. static int via_hp_build(struct hda_codec *codec)
  1106. {
  1107. struct via_spec *spec = codec->spec;
  1108. struct snd_kcontrol_new *knew;
  1109. hda_nid_t nid;
  1110. int nums;
  1111. hda_nid_t conn[HDA_MAX_CONNECTIONS];
  1112. switch (spec->codec_type) {
  1113. case VT1718S:
  1114. nid = 0x34;
  1115. break;
  1116. case VT2002P:
  1117. nid = 0x35;
  1118. break;
  1119. case VT1812:
  1120. nid = 0x3d;
  1121. break;
  1122. default:
  1123. nid = spec->autocfg.hp_pins[0];
  1124. break;
  1125. }
  1126. nums = snd_hda_get_connections(codec, nid, conn, HDA_MAX_CONNECTIONS);
  1127. if (nums <= 1)
  1128. return 0;
  1129. knew = via_clone_control(spec, &via_hp_mixer[0]);
  1130. if (knew == NULL)
  1131. return -ENOMEM;
  1132. knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
  1133. knew->private_value = nid;
  1134. knew = via_clone_control(spec, &via_hp_mixer[1]);
  1135. if (knew == NULL)
  1136. return -ENOMEM;
  1137. knew->subdevice = side_mute_channel(spec);
  1138. return 0;
  1139. }
  1140. static void notify_aa_path_ctls(struct hda_codec *codec)
  1141. {
  1142. int i;
  1143. struct snd_ctl_elem_id id;
  1144. const char *labels[] = {"Mic", "Front Mic", "Line"};
  1145. memset(&id, 0, sizeof(id));
  1146. id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  1147. for (i = 0; i < ARRAY_SIZE(labels); i++) {
  1148. sprintf(id.name, "%s Playback Volume", labels[i]);
  1149. snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
  1150. &id);
  1151. }
  1152. }
  1153. static void mute_aa_path(struct hda_codec *codec, int mute)
  1154. {
  1155. struct via_spec *spec = codec->spec;
  1156. hda_nid_t nid_mixer;
  1157. int start_idx;
  1158. int end_idx;
  1159. int i;
  1160. /* get nid of MW0 and start & end index */
  1161. switch (spec->codec_type) {
  1162. case VT1708:
  1163. nid_mixer = 0x17;
  1164. start_idx = 2;
  1165. end_idx = 4;
  1166. break;
  1167. case VT1709_10CH:
  1168. case VT1709_6CH:
  1169. nid_mixer = 0x18;
  1170. start_idx = 2;
  1171. end_idx = 4;
  1172. break;
  1173. case VT1708B_8CH:
  1174. case VT1708B_4CH:
  1175. case VT1708S:
  1176. case VT1716S:
  1177. nid_mixer = 0x16;
  1178. start_idx = 2;
  1179. end_idx = 4;
  1180. break;
  1181. default:
  1182. return;
  1183. }
  1184. /* check AA path's mute status */
  1185. for (i = start_idx; i <= end_idx; i++) {
  1186. int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
  1187. snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
  1188. HDA_AMP_MUTE, val);
  1189. }
  1190. }
  1191. static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
  1192. {
  1193. const struct auto_pin_cfg *cfg = &spec->autocfg;
  1194. int i;
  1195. for (i = 0; i < cfg->num_inputs; i++) {
  1196. if (pin == cfg->inputs[i].pin)
  1197. return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
  1198. }
  1199. return 0;
  1200. }
  1201. static int via_smart51_info(struct snd_kcontrol *kcontrol,
  1202. struct snd_ctl_elem_info *uinfo)
  1203. {
  1204. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1205. uinfo->count = 1;
  1206. uinfo->value.integer.min = 0;
  1207. uinfo->value.integer.max = 1;
  1208. return 0;
  1209. }
  1210. static int via_smart51_get(struct snd_kcontrol *kcontrol,
  1211. struct snd_ctl_elem_value *ucontrol)
  1212. {
  1213. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1214. struct via_spec *spec = codec->spec;
  1215. const struct auto_pin_cfg *cfg = &spec->autocfg;
  1216. int on = 1;
  1217. int i;
  1218. for (i = 0; i < cfg->num_inputs; i++) {
  1219. hda_nid_t nid = cfg->inputs[i].pin;
  1220. int ctl = snd_hda_codec_read(codec, nid, 0,
  1221. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  1222. if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
  1223. continue;
  1224. if (cfg->inputs[i].type == AUTO_PIN_MIC &&
  1225. spec->hp_independent_mode && spec->codec_type != VT1718S)
  1226. continue; /* ignore FMic for independent HP */
  1227. if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
  1228. on = 0;
  1229. }
  1230. *ucontrol->value.integer.value = on;
  1231. return 0;
  1232. }
  1233. static int via_smart51_put(struct snd_kcontrol *kcontrol,
  1234. struct snd_ctl_elem_value *ucontrol)
  1235. {
  1236. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1237. struct via_spec *spec = codec->spec;
  1238. const struct auto_pin_cfg *cfg = &spec->autocfg;
  1239. int out_in = *ucontrol->value.integer.value
  1240. ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
  1241. int i;
  1242. for (i = 0; i < cfg->num_inputs; i++) {
  1243. hda_nid_t nid = cfg->inputs[i].pin;
  1244. unsigned int parm;
  1245. if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
  1246. continue;
  1247. if (cfg->inputs[i].type == AUTO_PIN_MIC &&
  1248. spec->hp_independent_mode && spec->codec_type != VT1718S)
  1249. continue; /* don't retask FMic for independent HP */
  1250. parm = snd_hda_codec_read(codec, nid, 0,
  1251. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  1252. parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  1253. parm |= out_in;
  1254. snd_hda_codec_write(codec, nid, 0,
  1255. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1256. parm);
  1257. if (out_in == AC_PINCTL_OUT_EN) {
  1258. mute_aa_path(codec, 1);
  1259. notify_aa_path_ctls(codec);
  1260. }
  1261. if (spec->codec_type == VT1718S) {
  1262. snd_hda_codec_amp_stereo(
  1263. codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  1264. HDA_AMP_UNMUTE);
  1265. }
  1266. if (cfg->inputs[i].type == AUTO_PIN_MIC) {
  1267. if (spec->codec_type == VT1708S
  1268. || spec->codec_type == VT1716S) {
  1269. /* input = index 1 (AOW3) */
  1270. snd_hda_codec_write(
  1271. codec, nid, 0,
  1272. AC_VERB_SET_CONNECT_SEL, 1);
  1273. snd_hda_codec_amp_stereo(
  1274. codec, nid, HDA_OUTPUT,
  1275. 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
  1276. }
  1277. }
  1278. }
  1279. spec->smart51_enabled = *ucontrol->value.integer.value;
  1280. set_jack_power_state(codec);
  1281. return 1;
  1282. }
  1283. static struct snd_kcontrol_new via_smart51_mixer[2] = {
  1284. {
  1285. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1286. .name = "Smart 5.1",
  1287. .count = 1,
  1288. .info = via_smart51_info,
  1289. .get = via_smart51_get,
  1290. .put = via_smart51_put,
  1291. },
  1292. {
  1293. .iface = NID_MAPPING,
  1294. .name = "Smart 5.1",
  1295. }
  1296. };
  1297. static int via_smart51_build(struct via_spec *spec)
  1298. {
  1299. struct snd_kcontrol_new *knew;
  1300. const struct auto_pin_cfg *cfg = &spec->autocfg;
  1301. hda_nid_t nid;
  1302. int i;
  1303. knew = via_clone_control(spec, &via_smart51_mixer[0]);
  1304. if (knew == NULL)
  1305. return -ENOMEM;
  1306. for (i = 0; i < cfg->num_inputs; i++) {
  1307. nid = cfg->inputs[i].pin;
  1308. if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
  1309. knew = via_clone_control(spec, &via_smart51_mixer[1]);
  1310. if (knew == NULL)
  1311. return -ENOMEM;
  1312. knew->subdevice = nid;
  1313. break;
  1314. }
  1315. }
  1316. return 0;
  1317. }
  1318. /* capture mixer elements */
  1319. static struct snd_kcontrol_new vt1708_capture_mixer[] = {
  1320. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
  1321. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
  1322. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
  1323. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
  1324. {
  1325. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1326. /* The multiple "Capture Source" controls confuse alsamixer
  1327. * So call somewhat different..
  1328. */
  1329. /* .name = "Capture Source", */
  1330. .name = "Input Source",
  1331. .count = 1,
  1332. .info = via_mux_enum_info,
  1333. .get = via_mux_enum_get,
  1334. .put = via_mux_enum_put,
  1335. },
  1336. { } /* end */
  1337. };
  1338. /* check AA path's mute statue */
  1339. static int is_aa_path_mute(struct hda_codec *codec)
  1340. {
  1341. int mute = 1;
  1342. hda_nid_t nid_mixer;
  1343. int start_idx;
  1344. int end_idx;
  1345. int i;
  1346. struct via_spec *spec = codec->spec;
  1347. /* get nid of MW0 and start & end index */
  1348. switch (spec->codec_type) {
  1349. case VT1708B_8CH:
  1350. case VT1708B_4CH:
  1351. case VT1708S:
  1352. case VT1716S:
  1353. nid_mixer = 0x16;
  1354. start_idx = 2;
  1355. end_idx = 4;
  1356. break;
  1357. case VT1702:
  1358. nid_mixer = 0x1a;
  1359. start_idx = 1;
  1360. end_idx = 3;
  1361. break;
  1362. case VT1718S:
  1363. nid_mixer = 0x21;
  1364. start_idx = 1;
  1365. end_idx = 3;
  1366. break;
  1367. case VT2002P:
  1368. case VT1812:
  1369. nid_mixer = 0x21;
  1370. start_idx = 0;
  1371. end_idx = 2;
  1372. break;
  1373. default:
  1374. return 0;
  1375. }
  1376. /* check AA path's mute status */
  1377. for (i = start_idx; i <= end_idx; i++) {
  1378. unsigned int con_list = snd_hda_codec_read(
  1379. codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
  1380. int shift = 8 * (i % 4);
  1381. hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
  1382. unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
  1383. if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
  1384. /* check mute status while the pin is connected */
  1385. int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
  1386. HDA_INPUT, i) >> 7;
  1387. int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
  1388. HDA_INPUT, i) >> 7;
  1389. if (!mute_l || !mute_r) {
  1390. mute = 0;
  1391. break;
  1392. }
  1393. }
  1394. }
  1395. return mute;
  1396. }
  1397. /* enter/exit analog low-current mode */
  1398. static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
  1399. {
  1400. struct via_spec *spec = codec->spec;
  1401. static int saved_stream_idle = 1; /* saved stream idle status */
  1402. int enable = is_aa_path_mute(codec);
  1403. unsigned int verb = 0;
  1404. unsigned int parm = 0;
  1405. if (stream_idle == -1) /* stream status did not change */
  1406. enable = enable && saved_stream_idle;
  1407. else {
  1408. enable = enable && stream_idle;
  1409. saved_stream_idle = stream_idle;
  1410. }
  1411. /* decide low current mode's verb & parameter */
  1412. switch (spec->codec_type) {
  1413. case VT1708B_8CH:
  1414. case VT1708B_4CH:
  1415. verb = 0xf70;
  1416. parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
  1417. break;
  1418. case VT1708S:
  1419. case VT1718S:
  1420. case VT1716S:
  1421. verb = 0xf73;
  1422. parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
  1423. break;
  1424. case VT1702:
  1425. verb = 0xf73;
  1426. parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
  1427. break;
  1428. case VT2002P:
  1429. case VT1812:
  1430. verb = 0xf93;
  1431. parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
  1432. break;
  1433. default:
  1434. return; /* other codecs are not supported */
  1435. }
  1436. /* send verb */
  1437. snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
  1438. }
  1439. /*
  1440. * generic initialization of ADC, input mixers and output mixers
  1441. */
  1442. static struct hda_verb vt1708_volume_init_verbs[] = {
  1443. /*
  1444. * Unmute ADC0-1 and set the default input to mic-in
  1445. */
  1446. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1447. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1448. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  1449. * mixer widget
  1450. */
  1451. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  1452. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1453. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1454. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  1455. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  1456. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  1457. /*
  1458. * Set up output mixers (0x19 - 0x1b)
  1459. */
  1460. /* set vol=0 to output mixers */
  1461. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1462. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1463. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1464. /* Setup default input MW0 to PW4 */
  1465. {0x20, AC_VERB_SET_CONNECT_SEL, 0},
  1466. /* PW9 Output enable */
  1467. {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  1468. { }
  1469. };
  1470. static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1471. struct hda_codec *codec,
  1472. struct snd_pcm_substream *substream)
  1473. {
  1474. struct via_spec *spec = codec->spec;
  1475. int idle = substream->pstr->substream_opened == 1
  1476. && substream->ref_count == 0;
  1477. analog_low_current_mode(codec, idle);
  1478. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  1479. hinfo);
  1480. }
  1481. static void playback_multi_pcm_prep_0(struct hda_codec *codec,
  1482. unsigned int stream_tag,
  1483. unsigned int format,
  1484. struct snd_pcm_substream *substream)
  1485. {
  1486. struct via_spec *spec = codec->spec;
  1487. struct hda_multi_out *mout = &spec->multiout;
  1488. hda_nid_t *nids = mout->dac_nids;
  1489. int chs = substream->runtime->channels;
  1490. int i;
  1491. mutex_lock(&codec->spdif_mutex);
  1492. if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
  1493. if (chs == 2 &&
  1494. snd_hda_is_supported_format(codec, mout->dig_out_nid,
  1495. format) &&
  1496. !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
  1497. mout->dig_out_used = HDA_DIG_ANALOG_DUP;
  1498. /* turn off SPDIF once; otherwise the IEC958 bits won't
  1499. * be updated */
  1500. if (codec->spdif_ctls & AC_DIG1_ENABLE)
  1501. snd_hda_codec_write(codec, mout->dig_out_nid, 0,
  1502. AC_VERB_SET_DIGI_CONVERT_1,
  1503. codec->spdif_ctls &
  1504. ~AC_DIG1_ENABLE & 0xff);
  1505. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  1506. stream_tag, 0, format);
  1507. /* turn on again (if needed) */
  1508. if (codec->spdif_ctls & AC_DIG1_ENABLE)
  1509. snd_hda_codec_write(codec, mout->dig_out_nid, 0,
  1510. AC_VERB_SET_DIGI_CONVERT_1,
  1511. codec->spdif_ctls & 0xff);
  1512. } else {
  1513. mout->dig_out_used = 0;
  1514. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  1515. 0, 0, 0);
  1516. }
  1517. }
  1518. mutex_unlock(&codec->spdif_mutex);
  1519. /* front */
  1520. snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
  1521. 0, format);
  1522. if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
  1523. && !spec->hp_independent_mode)
  1524. /* headphone out will just decode front left/right (stereo) */
  1525. snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
  1526. 0, format);
  1527. /* extra outputs copied from front */
  1528. for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
  1529. if (mout->extra_out_nid[i])
  1530. snd_hda_codec_setup_stream(codec,
  1531. mout->extra_out_nid[i],
  1532. stream_tag, 0, format);
  1533. /* surrounds */
  1534. for (i = 1; i < mout->num_dacs; i++) {
  1535. if (chs >= (i + 1) * 2) /* independent out */
  1536. snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
  1537. i * 2, format);
  1538. else /* copy front */
  1539. snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
  1540. 0, format);
  1541. }
  1542. }
  1543. static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
  1544. struct hda_codec *codec,
  1545. unsigned int stream_tag,
  1546. unsigned int format,
  1547. struct snd_pcm_substream *substream)
  1548. {
  1549. struct via_spec *spec = codec->spec;
  1550. struct hda_multi_out *mout = &spec->multiout;
  1551. hda_nid_t *nids = mout->dac_nids;
  1552. if (substream->number == 0)
  1553. playback_multi_pcm_prep_0(codec, stream_tag, format,
  1554. substream);
  1555. else {
  1556. if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
  1557. spec->hp_independent_mode)
  1558. snd_hda_codec_setup_stream(codec, mout->hp_nid,
  1559. stream_tag, 0, format);
  1560. }
  1561. vt1708_start_hp_work(spec);
  1562. return 0;
  1563. }
  1564. static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1565. struct hda_codec *codec,
  1566. struct snd_pcm_substream *substream)
  1567. {
  1568. struct via_spec *spec = codec->spec;
  1569. struct hda_multi_out *mout = &spec->multiout;
  1570. hda_nid_t *nids = mout->dac_nids;
  1571. int i;
  1572. if (substream->number == 0) {
  1573. for (i = 0; i < mout->num_dacs; i++)
  1574. snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
  1575. if (mout->hp_nid && !spec->hp_independent_mode)
  1576. snd_hda_codec_setup_stream(codec, mout->hp_nid,
  1577. 0, 0, 0);
  1578. for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
  1579. if (mout->extra_out_nid[i])
  1580. snd_hda_codec_setup_stream(codec,
  1581. mout->extra_out_nid[i],
  1582. 0, 0, 0);
  1583. mutex_lock(&codec->spdif_mutex);
  1584. if (mout->dig_out_nid &&
  1585. mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
  1586. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  1587. 0, 0, 0);
  1588. mout->dig_out_used = 0;
  1589. }
  1590. mutex_unlock(&codec->spdif_mutex);
  1591. } else {
  1592. if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
  1593. spec->hp_independent_mode)
  1594. snd_hda_codec_setup_stream(codec, mout->hp_nid,
  1595. 0, 0, 0);
  1596. }
  1597. vt1708_stop_hp_work(spec);
  1598. return 0;
  1599. }
  1600. /*
  1601. * Digital out
  1602. */
  1603. static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1604. struct hda_codec *codec,
  1605. struct snd_pcm_substream *substream)
  1606. {
  1607. struct via_spec *spec = codec->spec;
  1608. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1609. }
  1610. static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1611. struct hda_codec *codec,
  1612. struct snd_pcm_substream *substream)
  1613. {
  1614. struct via_spec *spec = codec->spec;
  1615. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1616. }
  1617. static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1618. struct hda_codec *codec,
  1619. unsigned int stream_tag,
  1620. unsigned int format,
  1621. struct snd_pcm_substream *substream)
  1622. {
  1623. struct via_spec *spec = codec->spec;
  1624. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1625. stream_tag, format, substream);
  1626. }
  1627. static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1628. struct hda_codec *codec,
  1629. struct snd_pcm_substream *substream)
  1630. {
  1631. struct via_spec *spec = codec->spec;
  1632. snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  1633. return 0;
  1634. }
  1635. /*
  1636. * Analog capture
  1637. */
  1638. static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1639. struct hda_codec *codec,
  1640. unsigned int stream_tag,
  1641. unsigned int format,
  1642. struct snd_pcm_substream *substream)
  1643. {
  1644. struct via_spec *spec = codec->spec;
  1645. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  1646. stream_tag, 0, format);
  1647. return 0;
  1648. }
  1649. static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1650. struct hda_codec *codec,
  1651. struct snd_pcm_substream *substream)
  1652. {
  1653. struct via_spec *spec = codec->spec;
  1654. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  1655. return 0;
  1656. }
  1657. static struct hda_pcm_stream vt1708_pcm_analog_playback = {
  1658. .substreams = 2,
  1659. .channels_min = 2,
  1660. .channels_max = 8,
  1661. .nid = 0x10, /* NID to query formats and rates */
  1662. .ops = {
  1663. .open = via_playback_pcm_open,
  1664. .prepare = via_playback_multi_pcm_prepare,
  1665. .cleanup = via_playback_multi_pcm_cleanup
  1666. },
  1667. };
  1668. static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
  1669. .substreams = 2,
  1670. .channels_min = 2,
  1671. .channels_max = 8,
  1672. .nid = 0x10, /* NID to query formats and rates */
  1673. /* We got noisy outputs on the right channel on VT1708 when
  1674. * 24bit samples are used. Until any workaround is found,
  1675. * disable the 24bit format, so far.
  1676. */
  1677. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1678. .ops = {
  1679. .open = via_playback_pcm_open,
  1680. .prepare = via_playback_multi_pcm_prepare,
  1681. .cleanup = via_playback_multi_pcm_cleanup
  1682. },
  1683. };
  1684. static struct hda_pcm_stream vt1708_pcm_analog_capture = {
  1685. .substreams = 2,
  1686. .channels_min = 2,
  1687. .channels_max = 2,
  1688. .nid = 0x15, /* NID to query formats and rates */
  1689. .ops = {
  1690. .prepare = via_capture_pcm_prepare,
  1691. .cleanup = via_capture_pcm_cleanup
  1692. },
  1693. };
  1694. static struct hda_pcm_stream vt1708_pcm_digital_playback = {
  1695. .substreams = 1,
  1696. .channels_min = 2,
  1697. .channels_max = 2,
  1698. /* NID is set in via_build_pcms */
  1699. .ops = {
  1700. .open = via_dig_playback_pcm_open,
  1701. .close = via_dig_playback_pcm_close,
  1702. .prepare = via_dig_playback_pcm_prepare,
  1703. .cleanup = via_dig_playback_pcm_cleanup
  1704. },
  1705. };
  1706. static struct hda_pcm_stream vt1708_pcm_digital_capture = {
  1707. .substreams = 1,
  1708. .channels_min = 2,
  1709. .channels_max = 2,
  1710. };
  1711. static int via_build_controls(struct hda_codec *codec)
  1712. {
  1713. struct via_spec *spec = codec->spec;
  1714. struct snd_kcontrol *kctl;
  1715. struct snd_kcontrol_new *knew;
  1716. int err, i;
  1717. for (i = 0; i < spec->num_mixers; i++) {
  1718. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  1719. if (err < 0)
  1720. return err;
  1721. }
  1722. if (spec->multiout.dig_out_nid) {
  1723. err = snd_hda_create_spdif_out_ctls(codec,
  1724. spec->multiout.dig_out_nid);
  1725. if (err < 0)
  1726. return err;
  1727. err = snd_hda_create_spdif_share_sw(codec,
  1728. &spec->multiout);
  1729. if (err < 0)
  1730. return err;
  1731. spec->multiout.share_spdif = 1;
  1732. }
  1733. if (spec->dig_in_nid) {
  1734. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  1735. if (err < 0)
  1736. return err;
  1737. }
  1738. /* assign Capture Source enums to NID */
  1739. kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
  1740. for (i = 0; kctl && i < kctl->count; i++) {
  1741. err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
  1742. if (err < 0)
  1743. return err;
  1744. }
  1745. /* other nid->control mapping */
  1746. for (i = 0; i < spec->num_mixers; i++) {
  1747. for (knew = spec->mixers[i]; knew->name; knew++) {
  1748. if (knew->iface != NID_MAPPING)
  1749. continue;
  1750. kctl = snd_hda_find_mixer_ctl(codec, knew->name);
  1751. if (kctl == NULL)
  1752. continue;
  1753. err = snd_hda_add_nid(codec, kctl, 0,
  1754. knew->subdevice);
  1755. }
  1756. }
  1757. /* init power states */
  1758. set_jack_power_state(codec);
  1759. analog_low_current_mode(codec, 1);
  1760. via_free_kctls(codec); /* no longer needed */
  1761. return 0;
  1762. }
  1763. static int via_build_pcms(struct hda_codec *codec)
  1764. {
  1765. struct via_spec *spec = codec->spec;
  1766. struct hda_pcm *info = spec->pcm_rec;
  1767. codec->num_pcms = 1;
  1768. codec->pcm_info = info;
  1769. info->name = spec->stream_name_analog;
  1770. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  1771. *(spec->stream_analog_playback);
  1772. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  1773. spec->multiout.dac_nids[0];
  1774. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
  1775. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  1776. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  1777. spec->multiout.max_channels;
  1778. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  1779. codec->num_pcms++;
  1780. info++;
  1781. info->name = spec->stream_name_digital;
  1782. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  1783. if (spec->multiout.dig_out_nid) {
  1784. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  1785. *(spec->stream_digital_playback);
  1786. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  1787. spec->multiout.dig_out_nid;
  1788. }
  1789. if (spec->dig_in_nid) {
  1790. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  1791. *(spec->stream_digital_capture);
  1792. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  1793. spec->dig_in_nid;
  1794. }
  1795. }
  1796. return 0;
  1797. }
  1798. static void via_free(struct hda_codec *codec)
  1799. {
  1800. struct via_spec *spec = codec->spec;
  1801. if (!spec)
  1802. return;
  1803. via_free_kctls(codec);
  1804. vt1708_stop_hp_work(spec);
  1805. kfree(codec->spec);
  1806. }
  1807. /* mute internal speaker if HP is plugged */
  1808. static void via_hp_automute(struct hda_codec *codec)
  1809. {
  1810. unsigned int present = 0;
  1811. struct via_spec *spec = codec->spec;
  1812. present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
  1813. if (!spec->hp_independent_mode) {
  1814. struct snd_ctl_elem_id id;
  1815. /* auto mute */
  1816. snd_hda_codec_amp_stereo(
  1817. codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
  1818. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  1819. /* notify change */
  1820. memset(&id, 0, sizeof(id));
  1821. id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  1822. strcpy(id.name, "Front Playback Switch");
  1823. snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
  1824. &id);
  1825. }
  1826. }
  1827. /* mute mono out if HP or Line out is plugged */
  1828. static void via_mono_automute(struct hda_codec *codec)
  1829. {
  1830. unsigned int hp_present, lineout_present;
  1831. struct via_spec *spec = codec->spec;
  1832. if (spec->codec_type != VT1716S)
  1833. return;
  1834. lineout_present = snd_hda_jack_detect(codec,
  1835. spec->autocfg.line_out_pins[0]);
  1836. /* Mute Mono Out if Line Out is plugged */
  1837. if (lineout_present) {
  1838. snd_hda_codec_amp_stereo(
  1839. codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
  1840. return;
  1841. }
  1842. hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
  1843. if (!spec->hp_independent_mode)
  1844. snd_hda_codec_amp_stereo(
  1845. codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  1846. hp_present ? HDA_AMP_MUTE : 0);
  1847. }
  1848. static void via_gpio_control(struct hda_codec *codec)
  1849. {
  1850. unsigned int gpio_data;
  1851. unsigned int vol_counter;
  1852. unsigned int vol;
  1853. unsigned int master_vol;
  1854. struct via_spec *spec = codec->spec;
  1855. gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
  1856. AC_VERB_GET_GPIO_DATA, 0) & 0x03;
  1857. vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
  1858. 0xF84, 0) & 0x3F0000) >> 16;
  1859. vol = vol_counter & 0x1F;
  1860. master_vol = snd_hda_codec_read(codec, 0x1A, 0,
  1861. AC_VERB_GET_AMP_GAIN_MUTE,
  1862. AC_AMP_GET_INPUT);
  1863. if (gpio_data == 0x02) {
  1864. /* unmute line out */
  1865. snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
  1866. HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
  1867. if (vol_counter & 0x20) {
  1868. /* decrease volume */
  1869. if (vol > master_vol)
  1870. vol = master_vol;
  1871. snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
  1872. 0, HDA_AMP_VOLMASK,
  1873. master_vol-vol);
  1874. } else {
  1875. /* increase volume */
  1876. snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
  1877. HDA_AMP_VOLMASK,
  1878. ((master_vol+vol) > 0x2A) ? 0x2A :
  1879. (master_vol+vol));
  1880. }
  1881. } else if (!(gpio_data & 0x02)) {
  1882. /* mute line out */
  1883. snd_hda_codec_amp_stereo(codec,
  1884. spec->autocfg.line_out_pins[0],
  1885. HDA_OUTPUT, 0, HDA_AMP_MUTE,
  1886. HDA_AMP_MUTE);
  1887. }
  1888. }
  1889. /* mute Internal-Speaker if HP is plugged */
  1890. static void via_speaker_automute(struct hda_codec *codec)
  1891. {
  1892. unsigned int hp_present;
  1893. struct via_spec *spec = codec->spec;
  1894. if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
  1895. return;
  1896. hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
  1897. if (!spec->hp_independent_mode) {
  1898. struct snd_ctl_elem_id id;
  1899. snd_hda_codec_amp_stereo(
  1900. codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
  1901. HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
  1902. /* notify change */
  1903. memset(&id, 0, sizeof(id));
  1904. id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  1905. strcpy(id.name, "Speaker Playback Switch");
  1906. snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
  1907. &id);
  1908. }
  1909. }
  1910. /* mute line-out and internal speaker if HP is plugged */
  1911. static void via_hp_bind_automute(struct hda_codec *codec)
  1912. {
  1913. /* use long instead of int below just to avoid an internal compiler
  1914. * error with gcc 4.0.x
  1915. */
  1916. unsigned long hp_present, present = 0;
  1917. struct via_spec *spec = codec->spec;
  1918. int i;
  1919. if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
  1920. return;
  1921. hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
  1922. present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
  1923. if (!spec->hp_independent_mode) {
  1924. /* Mute Line-Outs */
  1925. for (i = 0; i < spec->autocfg.line_outs; i++)
  1926. snd_hda_codec_amp_stereo(
  1927. codec, spec->autocfg.line_out_pins[i],
  1928. HDA_OUTPUT, 0,
  1929. HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
  1930. if (hp_present)
  1931. present = hp_present;
  1932. }
  1933. /* Speakers */
  1934. for (i = 0; i < spec->autocfg.speaker_outs; i++)
  1935. snd_hda_codec_amp_stereo(
  1936. codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
  1937. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  1938. }
  1939. /* unsolicited event for jack sensing */
  1940. static void via_unsol_event(struct hda_codec *codec,
  1941. unsigned int res)
  1942. {
  1943. res >>= 26;
  1944. if (res & VIA_HP_EVENT)
  1945. via_hp_automute(codec);
  1946. if (res & VIA_GPIO_EVENT)
  1947. via_gpio_control(codec);
  1948. if (res & VIA_JACK_EVENT)
  1949. set_jack_power_state(codec);
  1950. if (res & VIA_MONO_EVENT)
  1951. via_mono_automute(codec);
  1952. if (res & VIA_SPEAKER_EVENT)
  1953. via_speaker_automute(codec);
  1954. if (res & VIA_BIND_HP_EVENT)
  1955. via_hp_bind_automute(codec);
  1956. }
  1957. static int via_init(struct hda_codec *codec)
  1958. {
  1959. struct via_spec *spec = codec->spec;
  1960. int i;
  1961. for (i = 0; i < spec->num_iverbs; i++)
  1962. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  1963. spec->codec_type = get_codec_type(codec);
  1964. if (spec->codec_type == VT1708BCE)
  1965. spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
  1966. same */
  1967. /* Lydia Add for EAPD enable */
  1968. if (!spec->dig_in_nid) { /* No Digital In connection */
  1969. if (spec->dig_in_pin) {
  1970. snd_hda_codec_write(codec, spec->dig_in_pin, 0,
  1971. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1972. PIN_OUT);
  1973. snd_hda_codec_write(codec, spec->dig_in_pin, 0,
  1974. AC_VERB_SET_EAPD_BTLENABLE, 0x02);
  1975. }
  1976. } else /* enable SPDIF-input pin */
  1977. snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
  1978. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
  1979. /* assign slave outs */
  1980. if (spec->slave_dig_outs[0])
  1981. codec->slave_dig_outs = spec->slave_dig_outs;
  1982. return 0;
  1983. }
  1984. #ifdef SND_HDA_NEEDS_RESUME
  1985. static int via_suspend(struct hda_codec *codec, pm_message_t state)
  1986. {
  1987. struct via_spec *spec = codec->spec;
  1988. vt1708_stop_hp_work(spec);
  1989. return 0;
  1990. }
  1991. #endif
  1992. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1993. static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  1994. {
  1995. struct via_spec *spec = codec->spec;
  1996. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  1997. }
  1998. #endif
  1999. /*
  2000. */
  2001. static struct hda_codec_ops via_patch_ops = {
  2002. .build_controls = via_build_controls,
  2003. .build_pcms = via_build_pcms,
  2004. .init = via_init,
  2005. .free = via_free,
  2006. #ifdef SND_HDA_NEEDS_RESUME
  2007. .suspend = via_suspend,
  2008. #endif
  2009. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2010. .check_power_status = via_check_power_status,
  2011. #endif
  2012. };
  2013. /* fill in the dac_nids table from the parsed pin configuration */
  2014. static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
  2015. const struct auto_pin_cfg *cfg)
  2016. {
  2017. int i;
  2018. hda_nid_t nid;
  2019. spec->multiout.num_dacs = cfg->line_outs;
  2020. spec->multiout.dac_nids = spec->private_dac_nids;
  2021. for (i = 0; i < 4; i++) {
  2022. nid = cfg->line_out_pins[i];
  2023. if (nid) {
  2024. /* config dac list */
  2025. switch (i) {
  2026. case AUTO_SEQ_FRONT:
  2027. spec->multiout.dac_nids[i] = 0x10;
  2028. break;
  2029. case AUTO_SEQ_CENLFE:
  2030. spec->multiout.dac_nids[i] = 0x12;
  2031. break;
  2032. case AUTO_SEQ_SURROUND:
  2033. spec->multiout.dac_nids[i] = 0x11;
  2034. break;
  2035. case AUTO_SEQ_SIDE:
  2036. spec->multiout.dac_nids[i] = 0x13;
  2037. break;
  2038. }
  2039. }
  2040. }
  2041. return 0;
  2042. }
  2043. /* add playback controls from the parsed DAC table */
  2044. static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
  2045. const struct auto_pin_cfg *cfg)
  2046. {
  2047. char name[32];
  2048. static const char * const chname[4] = {
  2049. "Front", "Surround", "C/LFE", "Side"
  2050. };
  2051. hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
  2052. int i, err;
  2053. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  2054. nid = cfg->line_out_pins[i];
  2055. if (!nid)
  2056. continue;
  2057. nid_vol = nid_vols[i];
  2058. if (i == AUTO_SEQ_CENLFE) {
  2059. /* Center/LFE */
  2060. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2061. "Center Playback Volume",
  2062. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  2063. HDA_OUTPUT));
  2064. if (err < 0)
  2065. return err;
  2066. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2067. "LFE Playback Volume",
  2068. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  2069. HDA_OUTPUT));
  2070. if (err < 0)
  2071. return err;
  2072. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2073. "Center Playback Switch",
  2074. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  2075. HDA_OUTPUT));
  2076. if (err < 0)
  2077. return err;
  2078. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2079. "LFE Playback Switch",
  2080. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  2081. HDA_OUTPUT));
  2082. if (err < 0)
  2083. return err;
  2084. } else if (i == AUTO_SEQ_FRONT) {
  2085. /* add control to mixer index 0 */
  2086. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2087. "Master Front Playback Volume",
  2088. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2089. HDA_INPUT));
  2090. if (err < 0)
  2091. return err;
  2092. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2093. "Master Front Playback Switch",
  2094. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2095. HDA_INPUT));
  2096. if (err < 0)
  2097. return err;
  2098. /* add control to PW3 */
  2099. sprintf(name, "%s Playback Volume", chname[i]);
  2100. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2101. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  2102. HDA_OUTPUT));
  2103. if (err < 0)
  2104. return err;
  2105. sprintf(name, "%s Playback Switch", chname[i]);
  2106. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2107. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  2108. HDA_OUTPUT));
  2109. if (err < 0)
  2110. return err;
  2111. } else {
  2112. sprintf(name, "%s Playback Volume", chname[i]);
  2113. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2114. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2115. HDA_OUTPUT));
  2116. if (err < 0)
  2117. return err;
  2118. sprintf(name, "%s Playback Switch", chname[i]);
  2119. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2120. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2121. HDA_OUTPUT));
  2122. if (err < 0)
  2123. return err;
  2124. }
  2125. }
  2126. return 0;
  2127. }
  2128. static void create_hp_imux(struct via_spec *spec)
  2129. {
  2130. int i;
  2131. struct hda_input_mux *imux = &spec->private_imux[1];
  2132. static const char * const texts[] = { "OFF", "ON", NULL};
  2133. /* for hp mode select */
  2134. for (i = 0; texts[i]; i++)
  2135. snd_hda_add_imux_item(imux, texts[i], i, NULL);
  2136. spec->hp_mux = &spec->private_imux[1];
  2137. }
  2138. static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  2139. {
  2140. int err;
  2141. if (!pin)
  2142. return 0;
  2143. spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
  2144. spec->hp_independent_mode_index = 1;
  2145. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2146. "Headphone Playback Volume",
  2147. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2148. if (err < 0)
  2149. return err;
  2150. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2151. "Headphone Playback Switch",
  2152. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2153. if (err < 0)
  2154. return err;
  2155. create_hp_imux(spec);
  2156. return 0;
  2157. }
  2158. /* create playback/capture controls for input pins */
  2159. static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
  2160. const struct auto_pin_cfg *cfg,
  2161. hda_nid_t cap_nid,
  2162. hda_nid_t pin_idxs[], int num_idxs)
  2163. {
  2164. struct via_spec *spec = codec->spec;
  2165. struct hda_input_mux *imux = &spec->private_imux[0];
  2166. int i, err, idx, type, type_idx = 0;
  2167. /* for internal loopback recording select */
  2168. for (idx = 0; idx < num_idxs; idx++) {
  2169. if (pin_idxs[idx] == 0xff) {
  2170. snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
  2171. break;
  2172. }
  2173. }
  2174. for (i = 0; i < cfg->num_inputs; i++) {
  2175. const char *label;
  2176. type = cfg->inputs[i].type;
  2177. for (idx = 0; idx < num_idxs; idx++)
  2178. if (pin_idxs[idx] == cfg->inputs[i].pin)
  2179. break;
  2180. if (idx >= num_idxs)
  2181. continue;
  2182. if (i > 0 && type == cfg->inputs[i - 1].type)
  2183. type_idx++;
  2184. else
  2185. type_idx = 0;
  2186. label = hda_get_autocfg_input_label(codec, cfg, i);
  2187. err = via_new_analog_input(spec, label, type_idx, idx, cap_nid);
  2188. if (err < 0)
  2189. return err;
  2190. snd_hda_add_imux_item(imux, label, idx, NULL);
  2191. }
  2192. return 0;
  2193. }
  2194. /* create playback/capture controls for input pins */
  2195. static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
  2196. const struct auto_pin_cfg *cfg)
  2197. {
  2198. static hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
  2199. return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
  2200. ARRAY_SIZE(pin_idxs));
  2201. }
  2202. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2203. static struct hda_amp_list vt1708_loopbacks[] = {
  2204. { 0x17, HDA_INPUT, 1 },
  2205. { 0x17, HDA_INPUT, 2 },
  2206. { 0x17, HDA_INPUT, 3 },
  2207. { 0x17, HDA_INPUT, 4 },
  2208. { } /* end */
  2209. };
  2210. #endif
  2211. static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
  2212. {
  2213. unsigned int def_conf;
  2214. unsigned char seqassoc;
  2215. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  2216. seqassoc = (unsigned char) get_defcfg_association(def_conf);
  2217. seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
  2218. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
  2219. && (seqassoc == 0xf0 || seqassoc == 0xff)) {
  2220. def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
  2221. snd_hda_codec_set_pincfg(codec, nid, def_conf);
  2222. }
  2223. return;
  2224. }
  2225. static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
  2226. struct snd_ctl_elem_value *ucontrol)
  2227. {
  2228. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2229. struct via_spec *spec = codec->spec;
  2230. if (spec->codec_type != VT1708)
  2231. return 0;
  2232. spec->vt1708_jack_detectect =
  2233. !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
  2234. ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
  2235. return 0;
  2236. }
  2237. static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
  2238. struct snd_ctl_elem_value *ucontrol)
  2239. {
  2240. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2241. struct via_spec *spec = codec->spec;
  2242. int change;
  2243. if (spec->codec_type != VT1708)
  2244. return 0;
  2245. spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
  2246. change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
  2247. == !spec->vt1708_jack_detectect;
  2248. if (spec->vt1708_jack_detectect) {
  2249. mute_aa_path(codec, 1);
  2250. notify_aa_path_ctls(codec);
  2251. }
  2252. return change;
  2253. }
  2254. static struct snd_kcontrol_new vt1708_jack_detectect[] = {
  2255. {
  2256. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2257. .name = "Jack Detect",
  2258. .count = 1,
  2259. .info = snd_ctl_boolean_mono_info,
  2260. .get = vt1708_jack_detectect_get,
  2261. .put = vt1708_jack_detectect_put,
  2262. },
  2263. {} /* end */
  2264. };
  2265. static int vt1708_parse_auto_config(struct hda_codec *codec)
  2266. {
  2267. struct via_spec *spec = codec->spec;
  2268. int err;
  2269. /* Add HP and CD pin config connect bit re-config action */
  2270. vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
  2271. vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
  2272. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2273. if (err < 0)
  2274. return err;
  2275. err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
  2276. if (err < 0)
  2277. return err;
  2278. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2279. return 0; /* can't find valid BIOS pin config */
  2280. err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
  2281. if (err < 0)
  2282. return err;
  2283. err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  2284. if (err < 0)
  2285. return err;
  2286. err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
  2287. if (err < 0)
  2288. return err;
  2289. /* add jack detect on/off control */
  2290. err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
  2291. if (err < 0)
  2292. return err;
  2293. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2294. if (spec->autocfg.dig_outs)
  2295. spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
  2296. spec->dig_in_pin = VT1708_DIGIN_PIN;
  2297. if (spec->autocfg.dig_in_pin)
  2298. spec->dig_in_nid = VT1708_DIGIN_NID;
  2299. if (spec->kctls.list)
  2300. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2301. spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
  2302. spec->input_mux = &spec->private_imux[0];
  2303. if (spec->hp_mux)
  2304. via_hp_build(codec);
  2305. via_smart51_build(spec);
  2306. return 1;
  2307. }
  2308. /* init callback for auto-configuration model -- overriding the default init */
  2309. static int via_auto_init(struct hda_codec *codec)
  2310. {
  2311. struct via_spec *spec = codec->spec;
  2312. via_init(codec);
  2313. via_auto_init_multi_out(codec);
  2314. via_auto_init_hp_out(codec);
  2315. via_auto_init_analog_input(codec);
  2316. if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
  2317. via_hp_bind_automute(codec);
  2318. } else {
  2319. via_hp_automute(codec);
  2320. via_speaker_automute(codec);
  2321. }
  2322. return 0;
  2323. }
  2324. static void vt1708_update_hp_jack_state(struct work_struct *work)
  2325. {
  2326. struct via_spec *spec = container_of(work, struct via_spec,
  2327. vt1708_hp_work.work);
  2328. if (spec->codec_type != VT1708)
  2329. return;
  2330. /* if jack state toggled */
  2331. if (spec->vt1708_hp_present
  2332. != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
  2333. spec->vt1708_hp_present ^= 1;
  2334. via_hp_automute(spec->codec);
  2335. }
  2336. vt1708_start_hp_work(spec);
  2337. }
  2338. static int get_mux_nids(struct hda_codec *codec)
  2339. {
  2340. struct via_spec *spec = codec->spec;
  2341. hda_nid_t nid, conn[8];
  2342. unsigned int type;
  2343. int i, n;
  2344. for (i = 0; i < spec->num_adc_nids; i++) {
  2345. nid = spec->adc_nids[i];
  2346. while (nid) {
  2347. type = get_wcaps_type(get_wcaps(codec, nid));
  2348. if (type == AC_WID_PIN)
  2349. break;
  2350. n = snd_hda_get_connections(codec, nid, conn,
  2351. ARRAY_SIZE(conn));
  2352. if (n <= 0)
  2353. break;
  2354. if (n > 1) {
  2355. spec->mux_nids[i] = nid;
  2356. break;
  2357. }
  2358. nid = conn[0];
  2359. }
  2360. }
  2361. return 0;
  2362. }
  2363. static int patch_vt1708(struct hda_codec *codec)
  2364. {
  2365. struct via_spec *spec;
  2366. int err;
  2367. /* create a codec specific record */
  2368. spec = via_new_spec(codec);
  2369. if (spec == NULL)
  2370. return -ENOMEM;
  2371. /* automatic parse from the BIOS config */
  2372. err = vt1708_parse_auto_config(codec);
  2373. if (err < 0) {
  2374. via_free(codec);
  2375. return err;
  2376. } else if (!err) {
  2377. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  2378. "from BIOS. Using genenic mode...\n");
  2379. }
  2380. spec->stream_name_analog = "VT1708 Analog";
  2381. spec->stream_analog_playback = &vt1708_pcm_analog_playback;
  2382. /* disable 32bit format on VT1708 */
  2383. if (codec->vendor_id == 0x11061708)
  2384. spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
  2385. spec->stream_analog_capture = &vt1708_pcm_analog_capture;
  2386. spec->stream_name_digital = "VT1708 Digital";
  2387. spec->stream_digital_playback = &vt1708_pcm_digital_playback;
  2388. spec->stream_digital_capture = &vt1708_pcm_digital_capture;
  2389. if (!spec->adc_nids && spec->input_mux) {
  2390. spec->adc_nids = vt1708_adc_nids;
  2391. spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
  2392. get_mux_nids(codec);
  2393. spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
  2394. spec->num_mixers++;
  2395. }
  2396. codec->patch_ops = via_patch_ops;
  2397. codec->patch_ops.init = via_auto_init;
  2398. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2399. spec->loopback.amplist = vt1708_loopbacks;
  2400. #endif
  2401. INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
  2402. return 0;
  2403. }
  2404. /* capture mixer elements */
  2405. static struct snd_kcontrol_new vt1709_capture_mixer[] = {
  2406. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
  2407. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
  2408. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
  2409. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
  2410. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
  2411. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
  2412. {
  2413. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2414. /* The multiple "Capture Source" controls confuse alsamixer
  2415. * So call somewhat different..
  2416. */
  2417. /* .name = "Capture Source", */
  2418. .name = "Input Source",
  2419. .count = 1,
  2420. .info = via_mux_enum_info,
  2421. .get = via_mux_enum_get,
  2422. .put = via_mux_enum_put,
  2423. },
  2424. { } /* end */
  2425. };
  2426. static struct hda_verb vt1709_uniwill_init_verbs[] = {
  2427. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
  2428. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
  2429. { }
  2430. };
  2431. /*
  2432. * generic initialization of ADC, input mixers and output mixers
  2433. */
  2434. static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
  2435. /*
  2436. * Unmute ADC0-2 and set the default input to mic-in
  2437. */
  2438. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2439. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2440. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2441. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  2442. * mixer widget
  2443. */
  2444. /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  2445. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2446. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2447. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2448. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2449. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2450. /*
  2451. * Set up output selector (0x1a, 0x1b, 0x29)
  2452. */
  2453. /* set vol=0 to output mixers */
  2454. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2455. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2456. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2457. /*
  2458. * Unmute PW3 and PW4
  2459. */
  2460. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2461. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2462. /* Set input of PW4 as MW0 */
  2463. {0x20, AC_VERB_SET_CONNECT_SEL, 0},
  2464. /* PW9 Output enable */
  2465. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2466. { }
  2467. };
  2468. static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
  2469. .substreams = 1,
  2470. .channels_min = 2,
  2471. .channels_max = 10,
  2472. .nid = 0x10, /* NID to query formats and rates */
  2473. .ops = {
  2474. .open = via_playback_pcm_open,
  2475. .prepare = via_playback_multi_pcm_prepare,
  2476. .cleanup = via_playback_multi_pcm_cleanup,
  2477. },
  2478. };
  2479. static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
  2480. .substreams = 1,
  2481. .channels_min = 2,
  2482. .channels_max = 6,
  2483. .nid = 0x10, /* NID to query formats and rates */
  2484. .ops = {
  2485. .open = via_playback_pcm_open,
  2486. .prepare = via_playback_multi_pcm_prepare,
  2487. .cleanup = via_playback_multi_pcm_cleanup,
  2488. },
  2489. };
  2490. static struct hda_pcm_stream vt1709_pcm_analog_capture = {
  2491. .substreams = 2,
  2492. .channels_min = 2,
  2493. .channels_max = 2,
  2494. .nid = 0x14, /* NID to query formats and rates */
  2495. .ops = {
  2496. .prepare = via_capture_pcm_prepare,
  2497. .cleanup = via_capture_pcm_cleanup
  2498. },
  2499. };
  2500. static struct hda_pcm_stream vt1709_pcm_digital_playback = {
  2501. .substreams = 1,
  2502. .channels_min = 2,
  2503. .channels_max = 2,
  2504. /* NID is set in via_build_pcms */
  2505. .ops = {
  2506. .open = via_dig_playback_pcm_open,
  2507. .close = via_dig_playback_pcm_close
  2508. },
  2509. };
  2510. static struct hda_pcm_stream vt1709_pcm_digital_capture = {
  2511. .substreams = 1,
  2512. .channels_min = 2,
  2513. .channels_max = 2,
  2514. };
  2515. static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
  2516. const struct auto_pin_cfg *cfg)
  2517. {
  2518. int i;
  2519. hda_nid_t nid;
  2520. if (cfg->line_outs == 4) /* 10 channels */
  2521. spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
  2522. else if (cfg->line_outs == 3) /* 6 channels */
  2523. spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
  2524. spec->multiout.dac_nids = spec->private_dac_nids;
  2525. if (cfg->line_outs == 4) { /* 10 channels */
  2526. for (i = 0; i < cfg->line_outs; i++) {
  2527. nid = cfg->line_out_pins[i];
  2528. if (nid) {
  2529. /* config dac list */
  2530. switch (i) {
  2531. case AUTO_SEQ_FRONT:
  2532. /* AOW0 */
  2533. spec->multiout.dac_nids[i] = 0x10;
  2534. break;
  2535. case AUTO_SEQ_CENLFE:
  2536. /* AOW2 */
  2537. spec->multiout.dac_nids[i] = 0x12;
  2538. break;
  2539. case AUTO_SEQ_SURROUND:
  2540. /* AOW3 */
  2541. spec->multiout.dac_nids[i] = 0x11;
  2542. break;
  2543. case AUTO_SEQ_SIDE:
  2544. /* AOW1 */
  2545. spec->multiout.dac_nids[i] = 0x27;
  2546. break;
  2547. default:
  2548. break;
  2549. }
  2550. }
  2551. }
  2552. spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
  2553. } else if (cfg->line_outs == 3) { /* 6 channels */
  2554. for (i = 0; i < cfg->line_outs; i++) {
  2555. nid = cfg->line_out_pins[i];
  2556. if (nid) {
  2557. /* config dac list */
  2558. switch (i) {
  2559. case AUTO_SEQ_FRONT:
  2560. /* AOW0 */
  2561. spec->multiout.dac_nids[i] = 0x10;
  2562. break;
  2563. case AUTO_SEQ_CENLFE:
  2564. /* AOW2 */
  2565. spec->multiout.dac_nids[i] = 0x12;
  2566. break;
  2567. case AUTO_SEQ_SURROUND:
  2568. /* AOW1 */
  2569. spec->multiout.dac_nids[i] = 0x11;
  2570. break;
  2571. default:
  2572. break;
  2573. }
  2574. }
  2575. }
  2576. }
  2577. return 0;
  2578. }
  2579. /* add playback controls from the parsed DAC table */
  2580. static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
  2581. const struct auto_pin_cfg *cfg)
  2582. {
  2583. char name[32];
  2584. static const char * const chname[4] = {
  2585. "Front", "Surround", "C/LFE", "Side"
  2586. };
  2587. hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
  2588. int i, err;
  2589. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  2590. nid = cfg->line_out_pins[i];
  2591. if (!nid)
  2592. continue;
  2593. nid_vol = nid_vols[i];
  2594. if (i == AUTO_SEQ_CENLFE) {
  2595. /* Center/LFE */
  2596. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2597. "Center Playback Volume",
  2598. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  2599. HDA_OUTPUT));
  2600. if (err < 0)
  2601. return err;
  2602. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2603. "LFE Playback Volume",
  2604. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  2605. HDA_OUTPUT));
  2606. if (err < 0)
  2607. return err;
  2608. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2609. "Center Playback Switch",
  2610. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  2611. HDA_OUTPUT));
  2612. if (err < 0)
  2613. return err;
  2614. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2615. "LFE Playback Switch",
  2616. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  2617. HDA_OUTPUT));
  2618. if (err < 0)
  2619. return err;
  2620. } else if (i == AUTO_SEQ_FRONT) {
  2621. /* ADD control to mixer index 0 */
  2622. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2623. "Master Front Playback Volume",
  2624. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2625. HDA_INPUT));
  2626. if (err < 0)
  2627. return err;
  2628. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2629. "Master Front Playback Switch",
  2630. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2631. HDA_INPUT));
  2632. if (err < 0)
  2633. return err;
  2634. /* add control to PW3 */
  2635. sprintf(name, "%s Playback Volume", chname[i]);
  2636. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2637. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  2638. HDA_OUTPUT));
  2639. if (err < 0)
  2640. return err;
  2641. sprintf(name, "%s Playback Switch", chname[i]);
  2642. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2643. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  2644. HDA_OUTPUT));
  2645. if (err < 0)
  2646. return err;
  2647. } else if (i == AUTO_SEQ_SURROUND) {
  2648. sprintf(name, "%s Playback Volume", chname[i]);
  2649. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2650. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2651. HDA_OUTPUT));
  2652. if (err < 0)
  2653. return err;
  2654. sprintf(name, "%s Playback Switch", chname[i]);
  2655. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2656. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2657. HDA_OUTPUT));
  2658. if (err < 0)
  2659. return err;
  2660. } else if (i == AUTO_SEQ_SIDE) {
  2661. sprintf(name, "%s Playback Volume", chname[i]);
  2662. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2663. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2664. HDA_OUTPUT));
  2665. if (err < 0)
  2666. return err;
  2667. sprintf(name, "%s Playback Switch", chname[i]);
  2668. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2669. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2670. HDA_OUTPUT));
  2671. if (err < 0)
  2672. return err;
  2673. }
  2674. }
  2675. return 0;
  2676. }
  2677. static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  2678. {
  2679. int err;
  2680. if (!pin)
  2681. return 0;
  2682. if (spec->multiout.num_dacs == 5) /* 10 channels */
  2683. spec->multiout.hp_nid = VT1709_HP_DAC_NID;
  2684. else if (spec->multiout.num_dacs == 3) /* 6 channels */
  2685. spec->multiout.hp_nid = 0;
  2686. spec->hp_independent_mode_index = 1;
  2687. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2688. "Headphone Playback Volume",
  2689. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2690. if (err < 0)
  2691. return err;
  2692. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2693. "Headphone Playback Switch",
  2694. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2695. if (err < 0)
  2696. return err;
  2697. return 0;
  2698. }
  2699. /* create playback/capture controls for input pins */
  2700. static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
  2701. const struct auto_pin_cfg *cfg)
  2702. {
  2703. static hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
  2704. return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
  2705. ARRAY_SIZE(pin_idxs));
  2706. }
  2707. static int vt1709_parse_auto_config(struct hda_codec *codec)
  2708. {
  2709. struct via_spec *spec = codec->spec;
  2710. int err;
  2711. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2712. if (err < 0)
  2713. return err;
  2714. err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
  2715. if (err < 0)
  2716. return err;
  2717. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2718. return 0; /* can't find valid BIOS pin config */
  2719. err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
  2720. if (err < 0)
  2721. return err;
  2722. err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  2723. if (err < 0)
  2724. return err;
  2725. err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
  2726. if (err < 0)
  2727. return err;
  2728. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2729. if (spec->autocfg.dig_outs)
  2730. spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
  2731. spec->dig_in_pin = VT1709_DIGIN_PIN;
  2732. if (spec->autocfg.dig_in_pin)
  2733. spec->dig_in_nid = VT1709_DIGIN_NID;
  2734. if (spec->kctls.list)
  2735. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2736. spec->input_mux = &spec->private_imux[0];
  2737. if (spec->hp_mux)
  2738. via_hp_build(codec);
  2739. via_smart51_build(spec);
  2740. return 1;
  2741. }
  2742. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2743. static struct hda_amp_list vt1709_loopbacks[] = {
  2744. { 0x18, HDA_INPUT, 1 },
  2745. { 0x18, HDA_INPUT, 2 },
  2746. { 0x18, HDA_INPUT, 3 },
  2747. { 0x18, HDA_INPUT, 4 },
  2748. { } /* end */
  2749. };
  2750. #endif
  2751. static int patch_vt1709_10ch(struct hda_codec *codec)
  2752. {
  2753. struct via_spec *spec;
  2754. int err;
  2755. /* create a codec specific record */
  2756. spec = via_new_spec(codec);
  2757. if (spec == NULL)
  2758. return -ENOMEM;
  2759. err = vt1709_parse_auto_config(codec);
  2760. if (err < 0) {
  2761. via_free(codec);
  2762. return err;
  2763. } else if (!err) {
  2764. printk(KERN_INFO "hda_codec: Cannot set up configuration. "
  2765. "Using genenic mode...\n");
  2766. }
  2767. spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
  2768. spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
  2769. spec->stream_name_analog = "VT1709 Analog";
  2770. spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
  2771. spec->stream_analog_capture = &vt1709_pcm_analog_capture;
  2772. spec->stream_name_digital = "VT1709 Digital";
  2773. spec->stream_digital_playback = &vt1709_pcm_digital_playback;
  2774. spec->stream_digital_capture = &vt1709_pcm_digital_capture;
  2775. if (!spec->adc_nids && spec->input_mux) {
  2776. spec->adc_nids = vt1709_adc_nids;
  2777. spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
  2778. get_mux_nids(codec);
  2779. spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
  2780. spec->num_mixers++;
  2781. }
  2782. codec->patch_ops = via_patch_ops;
  2783. codec->patch_ops.init = via_auto_init;
  2784. codec->patch_ops.unsol_event = via_unsol_event;
  2785. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2786. spec->loopback.amplist = vt1709_loopbacks;
  2787. #endif
  2788. return 0;
  2789. }
  2790. /*
  2791. * generic initialization of ADC, input mixers and output mixers
  2792. */
  2793. static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
  2794. /*
  2795. * Unmute ADC0-2 and set the default input to mic-in
  2796. */
  2797. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2798. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2799. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2800. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  2801. * mixer widget
  2802. */
  2803. /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  2804. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2805. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2806. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2807. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2808. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2809. /*
  2810. * Set up output selector (0x1a, 0x1b, 0x29)
  2811. */
  2812. /* set vol=0 to output mixers */
  2813. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2814. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2815. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2816. /*
  2817. * Unmute PW3 and PW4
  2818. */
  2819. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2820. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2821. /* Set input of PW4 as MW0 */
  2822. {0x20, AC_VERB_SET_CONNECT_SEL, 0},
  2823. /* PW9 Output enable */
  2824. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2825. { }
  2826. };
  2827. static int patch_vt1709_6ch(struct hda_codec *codec)
  2828. {
  2829. struct via_spec *spec;
  2830. int err;
  2831. /* create a codec specific record */
  2832. spec = via_new_spec(codec);
  2833. if (spec == NULL)
  2834. return -ENOMEM;
  2835. err = vt1709_parse_auto_config(codec);
  2836. if (err < 0) {
  2837. via_free(codec);
  2838. return err;
  2839. } else if (!err) {
  2840. printk(KERN_INFO "hda_codec: Cannot set up configuration. "
  2841. "Using genenic mode...\n");
  2842. }
  2843. spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
  2844. spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
  2845. spec->stream_name_analog = "VT1709 Analog";
  2846. spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
  2847. spec->stream_analog_capture = &vt1709_pcm_analog_capture;
  2848. spec->stream_name_digital = "VT1709 Digital";
  2849. spec->stream_digital_playback = &vt1709_pcm_digital_playback;
  2850. spec->stream_digital_capture = &vt1709_pcm_digital_capture;
  2851. if (!spec->adc_nids && spec->input_mux) {
  2852. spec->adc_nids = vt1709_adc_nids;
  2853. spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
  2854. get_mux_nids(codec);
  2855. spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
  2856. spec->num_mixers++;
  2857. }
  2858. codec->patch_ops = via_patch_ops;
  2859. codec->patch_ops.init = via_auto_init;
  2860. codec->patch_ops.unsol_event = via_unsol_event;
  2861. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2862. spec->loopback.amplist = vt1709_loopbacks;
  2863. #endif
  2864. return 0;
  2865. }
  2866. /* capture mixer elements */
  2867. static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
  2868. HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
  2869. HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
  2870. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
  2871. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
  2872. {
  2873. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2874. /* The multiple "Capture Source" controls confuse alsamixer
  2875. * So call somewhat different..
  2876. */
  2877. /* .name = "Capture Source", */
  2878. .name = "Input Source",
  2879. .count = 1,
  2880. .info = via_mux_enum_info,
  2881. .get = via_mux_enum_get,
  2882. .put = via_mux_enum_put,
  2883. },
  2884. { } /* end */
  2885. };
  2886. /*
  2887. * generic initialization of ADC, input mixers and output mixers
  2888. */
  2889. static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
  2890. /*
  2891. * Unmute ADC0-1 and set the default input to mic-in
  2892. */
  2893. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2894. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2895. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  2896. * mixer widget
  2897. */
  2898. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  2899. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2900. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2901. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2902. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2903. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2904. /*
  2905. * Set up output mixers
  2906. */
  2907. /* set vol=0 to output mixers */
  2908. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2909. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2910. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2911. /* Setup default input to PW4 */
  2912. {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
  2913. /* PW9 Output enable */
  2914. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2915. /* PW10 Input enable */
  2916. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  2917. { }
  2918. };
  2919. static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
  2920. /*
  2921. * Unmute ADC0-1 and set the default input to mic-in
  2922. */
  2923. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2924. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2925. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  2926. * mixer widget
  2927. */
  2928. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  2929. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2930. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2931. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2932. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2933. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2934. /*
  2935. * Set up output mixers
  2936. */
  2937. /* set vol=0 to output mixers */
  2938. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2939. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2940. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2941. /* Setup default input of PW4 to MW0 */
  2942. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
  2943. /* PW9 Output enable */
  2944. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2945. /* PW10 Input enable */
  2946. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  2947. { }
  2948. };
  2949. static struct hda_verb vt1708B_uniwill_init_verbs[] = {
  2950. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
  2951. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
  2952. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2953. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2954. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2955. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2956. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2957. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2958. {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2959. { }
  2960. };
  2961. static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
  2962. struct hda_codec *codec,
  2963. struct snd_pcm_substream *substream)
  2964. {
  2965. int idle = substream->pstr->substream_opened == 1
  2966. && substream->ref_count == 0;
  2967. analog_low_current_mode(codec, idle);
  2968. return 0;
  2969. }
  2970. static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
  2971. .substreams = 2,
  2972. .channels_min = 2,
  2973. .channels_max = 8,
  2974. .nid = 0x10, /* NID to query formats and rates */
  2975. .ops = {
  2976. .open = via_playback_pcm_open,
  2977. .prepare = via_playback_multi_pcm_prepare,
  2978. .cleanup = via_playback_multi_pcm_cleanup,
  2979. .close = via_pcm_open_close
  2980. },
  2981. };
  2982. static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
  2983. .substreams = 2,
  2984. .channels_min = 2,
  2985. .channels_max = 4,
  2986. .nid = 0x10, /* NID to query formats and rates */
  2987. .ops = {
  2988. .open = via_playback_pcm_open,
  2989. .prepare = via_playback_multi_pcm_prepare,
  2990. .cleanup = via_playback_multi_pcm_cleanup
  2991. },
  2992. };
  2993. static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
  2994. .substreams = 2,
  2995. .channels_min = 2,
  2996. .channels_max = 2,
  2997. .nid = 0x13, /* NID to query formats and rates */
  2998. .ops = {
  2999. .open = via_pcm_open_close,
  3000. .prepare = via_capture_pcm_prepare,
  3001. .cleanup = via_capture_pcm_cleanup,
  3002. .close = via_pcm_open_close
  3003. },
  3004. };
  3005. static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
  3006. .substreams = 1,
  3007. .channels_min = 2,
  3008. .channels_max = 2,
  3009. /* NID is set in via_build_pcms */
  3010. .ops = {
  3011. .open = via_dig_playback_pcm_open,
  3012. .close = via_dig_playback_pcm_close,
  3013. .prepare = via_dig_playback_pcm_prepare,
  3014. .cleanup = via_dig_playback_pcm_cleanup
  3015. },
  3016. };
  3017. static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
  3018. .substreams = 1,
  3019. .channels_min = 2,
  3020. .channels_max = 2,
  3021. };
  3022. /* fill in the dac_nids table from the parsed pin configuration */
  3023. static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
  3024. const struct auto_pin_cfg *cfg)
  3025. {
  3026. int i;
  3027. hda_nid_t nid;
  3028. spec->multiout.num_dacs = cfg->line_outs;
  3029. spec->multiout.dac_nids = spec->private_dac_nids;
  3030. for (i = 0; i < 4; i++) {
  3031. nid = cfg->line_out_pins[i];
  3032. if (nid) {
  3033. /* config dac list */
  3034. switch (i) {
  3035. case AUTO_SEQ_FRONT:
  3036. spec->multiout.dac_nids[i] = 0x10;
  3037. break;
  3038. case AUTO_SEQ_CENLFE:
  3039. spec->multiout.dac_nids[i] = 0x24;
  3040. break;
  3041. case AUTO_SEQ_SURROUND:
  3042. spec->multiout.dac_nids[i] = 0x11;
  3043. break;
  3044. case AUTO_SEQ_SIDE:
  3045. spec->multiout.dac_nids[i] = 0x25;
  3046. break;
  3047. }
  3048. }
  3049. }
  3050. return 0;
  3051. }
  3052. /* add playback controls from the parsed DAC table */
  3053. static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
  3054. const struct auto_pin_cfg *cfg)
  3055. {
  3056. char name[32];
  3057. static const char * const chname[4] = {
  3058. "Front", "Surround", "C/LFE", "Side"
  3059. };
  3060. hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
  3061. hda_nid_t nid, nid_vol = 0;
  3062. int i, err;
  3063. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  3064. nid = cfg->line_out_pins[i];
  3065. if (!nid)
  3066. continue;
  3067. nid_vol = nid_vols[i];
  3068. if (i == AUTO_SEQ_CENLFE) {
  3069. /* Center/LFE */
  3070. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3071. "Center Playback Volume",
  3072. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  3073. HDA_OUTPUT));
  3074. if (err < 0)
  3075. return err;
  3076. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3077. "LFE Playback Volume",
  3078. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  3079. HDA_OUTPUT));
  3080. if (err < 0)
  3081. return err;
  3082. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3083. "Center Playback Switch",
  3084. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  3085. HDA_OUTPUT));
  3086. if (err < 0)
  3087. return err;
  3088. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3089. "LFE Playback Switch",
  3090. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  3091. HDA_OUTPUT));
  3092. if (err < 0)
  3093. return err;
  3094. } else if (i == AUTO_SEQ_FRONT) {
  3095. /* add control to mixer index 0 */
  3096. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3097. "Master Front Playback Volume",
  3098. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  3099. HDA_INPUT));
  3100. if (err < 0)
  3101. return err;
  3102. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3103. "Master Front Playback Switch",
  3104. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  3105. HDA_INPUT));
  3106. if (err < 0)
  3107. return err;
  3108. /* add control to PW3 */
  3109. sprintf(name, "%s Playback Volume", chname[i]);
  3110. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  3111. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  3112. HDA_OUTPUT));
  3113. if (err < 0)
  3114. return err;
  3115. sprintf(name, "%s Playback Switch", chname[i]);
  3116. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  3117. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  3118. HDA_OUTPUT));
  3119. if (err < 0)
  3120. return err;
  3121. } else {
  3122. sprintf(name, "%s Playback Volume", chname[i]);
  3123. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  3124. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  3125. HDA_OUTPUT));
  3126. if (err < 0)
  3127. return err;
  3128. sprintf(name, "%s Playback Switch", chname[i]);
  3129. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  3130. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  3131. HDA_OUTPUT));
  3132. if (err < 0)
  3133. return err;
  3134. }
  3135. }
  3136. return 0;
  3137. }
  3138. static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  3139. {
  3140. int err;
  3141. if (!pin)
  3142. return 0;
  3143. spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
  3144. spec->hp_independent_mode_index = 1;
  3145. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3146. "Headphone Playback Volume",
  3147. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  3148. if (err < 0)
  3149. return err;
  3150. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3151. "Headphone Playback Switch",
  3152. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  3153. if (err < 0)
  3154. return err;
  3155. create_hp_imux(spec);
  3156. return 0;
  3157. }
  3158. /* create playback/capture controls for input pins */
  3159. static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
  3160. const struct auto_pin_cfg *cfg)
  3161. {
  3162. static hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
  3163. return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
  3164. ARRAY_SIZE(pin_idxs));
  3165. }
  3166. static int vt1708B_parse_auto_config(struct hda_codec *codec)
  3167. {
  3168. struct via_spec *spec = codec->spec;
  3169. int err;
  3170. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  3171. if (err < 0)
  3172. return err;
  3173. err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
  3174. if (err < 0)
  3175. return err;
  3176. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  3177. return 0; /* can't find valid BIOS pin config */
  3178. err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
  3179. if (err < 0)
  3180. return err;
  3181. err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  3182. if (err < 0)
  3183. return err;
  3184. err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
  3185. if (err < 0)
  3186. return err;
  3187. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3188. if (spec->autocfg.dig_outs)
  3189. spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
  3190. spec->dig_in_pin = VT1708B_DIGIN_PIN;
  3191. if (spec->autocfg.dig_in_pin)
  3192. spec->dig_in_nid = VT1708B_DIGIN_NID;
  3193. if (spec->kctls.list)
  3194. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  3195. spec->input_mux = &spec->private_imux[0];
  3196. if (spec->hp_mux)
  3197. via_hp_build(codec);
  3198. via_smart51_build(spec);
  3199. return 1;
  3200. }
  3201. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3202. static struct hda_amp_list vt1708B_loopbacks[] = {
  3203. { 0x16, HDA_INPUT, 1 },
  3204. { 0x16, HDA_INPUT, 2 },
  3205. { 0x16, HDA_INPUT, 3 },
  3206. { 0x16, HDA_INPUT, 4 },
  3207. { } /* end */
  3208. };
  3209. #endif
  3210. static int patch_vt1708S(struct hda_codec *codec);
  3211. static int patch_vt1708B_8ch(struct hda_codec *codec)
  3212. {
  3213. struct via_spec *spec;
  3214. int err;
  3215. if (get_codec_type(codec) == VT1708BCE)
  3216. return patch_vt1708S(codec);
  3217. /* create a codec specific record */
  3218. spec = via_new_spec(codec);
  3219. if (spec == NULL)
  3220. return -ENOMEM;
  3221. /* automatic parse from the BIOS config */
  3222. err = vt1708B_parse_auto_config(codec);
  3223. if (err < 0) {
  3224. via_free(codec);
  3225. return err;
  3226. } else if (!err) {
  3227. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  3228. "from BIOS. Using genenic mode...\n");
  3229. }
  3230. spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
  3231. spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
  3232. spec->stream_name_analog = "VT1708B Analog";
  3233. spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
  3234. spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
  3235. spec->stream_name_digital = "VT1708B Digital";
  3236. spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
  3237. spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
  3238. if (!spec->adc_nids && spec->input_mux) {
  3239. spec->adc_nids = vt1708B_adc_nids;
  3240. spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
  3241. get_mux_nids(codec);
  3242. spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
  3243. spec->num_mixers++;
  3244. }
  3245. codec->patch_ops = via_patch_ops;
  3246. codec->patch_ops.init = via_auto_init;
  3247. codec->patch_ops.unsol_event = via_unsol_event;
  3248. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3249. spec->loopback.amplist = vt1708B_loopbacks;
  3250. #endif
  3251. return 0;
  3252. }
  3253. static int patch_vt1708B_4ch(struct hda_codec *codec)
  3254. {
  3255. struct via_spec *spec;
  3256. int err;
  3257. /* create a codec specific record */
  3258. spec = via_new_spec(codec);
  3259. if (spec == NULL)
  3260. return -ENOMEM;
  3261. /* automatic parse from the BIOS config */
  3262. err = vt1708B_parse_auto_config(codec);
  3263. if (err < 0) {
  3264. via_free(codec);
  3265. return err;
  3266. } else if (!err) {
  3267. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  3268. "from BIOS. Using genenic mode...\n");
  3269. }
  3270. spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
  3271. spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
  3272. spec->stream_name_analog = "VT1708B Analog";
  3273. spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
  3274. spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
  3275. spec->stream_name_digital = "VT1708B Digital";
  3276. spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
  3277. spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
  3278. if (!spec->adc_nids && spec->input_mux) {
  3279. spec->adc_nids = vt1708B_adc_nids;
  3280. spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
  3281. get_mux_nids(codec);
  3282. spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
  3283. spec->num_mixers++;
  3284. }
  3285. codec->patch_ops = via_patch_ops;
  3286. codec->patch_ops.init = via_auto_init;
  3287. codec->patch_ops.unsol_event = via_unsol_event;
  3288. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3289. spec->loopback.amplist = vt1708B_loopbacks;
  3290. #endif
  3291. return 0;
  3292. }
  3293. /* Patch for VT1708S */
  3294. /* capture mixer elements */
  3295. static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
  3296. HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
  3297. HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
  3298. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
  3299. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
  3300. HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
  3301. HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
  3302. HDA_INPUT),
  3303. {
  3304. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3305. /* The multiple "Capture Source" controls confuse alsamixer
  3306. * So call somewhat different..
  3307. */
  3308. /* .name = "Capture Source", */
  3309. .name = "Input Source",
  3310. .count = 1,
  3311. .info = via_mux_enum_info,
  3312. .get = via_mux_enum_get,
  3313. .put = via_mux_enum_put,
  3314. },
  3315. { } /* end */
  3316. };
  3317. static struct hda_verb vt1708S_volume_init_verbs[] = {
  3318. /* Unmute ADC0-1 and set the default input to mic-in */
  3319. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3320. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3321. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
  3322. * analog-loopback mixer widget */
  3323. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  3324. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3325. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3326. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  3327. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  3328. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  3329. /* Setup default input of PW4 to MW0 */
  3330. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
  3331. /* PW9, PW10 Output enable */
  3332. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  3333. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  3334. /* Enable Mic Boost Volume backdoor */
  3335. {0x1, 0xf98, 0x1},
  3336. /* don't bybass mixer */
  3337. {0x1, 0xf88, 0xc0},
  3338. { }
  3339. };
  3340. static struct hda_verb vt1708S_uniwill_init_verbs[] = {
  3341. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
  3342. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
  3343. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3344. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3345. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3346. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3347. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3348. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3349. {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3350. { }
  3351. };
  3352. static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
  3353. .substreams = 2,
  3354. .channels_min = 2,
  3355. .channels_max = 8,
  3356. .nid = 0x10, /* NID to query formats and rates */
  3357. .ops = {
  3358. .open = via_playback_pcm_open,
  3359. .prepare = via_playback_multi_pcm_prepare,
  3360. .cleanup = via_playback_multi_pcm_cleanup,
  3361. .close = via_pcm_open_close
  3362. },
  3363. };
  3364. static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
  3365. .substreams = 2,
  3366. .channels_min = 2,
  3367. .channels_max = 2,
  3368. .nid = 0x13, /* NID to query formats and rates */
  3369. .ops = {
  3370. .open = via_pcm_open_close,
  3371. .prepare = via_capture_pcm_prepare,
  3372. .cleanup = via_capture_pcm_cleanup,
  3373. .close = via_pcm_open_close
  3374. },
  3375. };
  3376. static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
  3377. .substreams = 1,
  3378. .channels_min = 2,
  3379. .channels_max = 2,
  3380. /* NID is set in via_build_pcms */
  3381. .ops = {
  3382. .open = via_dig_playback_pcm_open,
  3383. .close = via_dig_playback_pcm_close,
  3384. .prepare = via_dig_playback_pcm_prepare,
  3385. .cleanup = via_dig_playback_pcm_cleanup
  3386. },
  3387. };
  3388. /* fill in the dac_nids table from the parsed pin configuration */
  3389. static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
  3390. const struct auto_pin_cfg *cfg)
  3391. {
  3392. int i;
  3393. hda_nid_t nid;
  3394. spec->multiout.num_dacs = cfg->line_outs;
  3395. spec->multiout.dac_nids = spec->private_dac_nids;
  3396. for (i = 0; i < 4; i++) {
  3397. nid = cfg->line_out_pins[i];
  3398. if (nid) {
  3399. /* config dac list */
  3400. switch (i) {
  3401. case AUTO_SEQ_FRONT:
  3402. spec->multiout.dac_nids[i] = 0x10;
  3403. break;
  3404. case AUTO_SEQ_CENLFE:
  3405. spec->multiout.dac_nids[i] = 0x24;
  3406. break;
  3407. case AUTO_SEQ_SURROUND:
  3408. spec->multiout.dac_nids[i] = 0x11;
  3409. break;
  3410. case AUTO_SEQ_SIDE:
  3411. spec->multiout.dac_nids[i] = 0x25;
  3412. break;
  3413. }
  3414. }
  3415. }
  3416. /* for Smart 5.1, line/mic inputs double as output pins */
  3417. if (cfg->line_outs == 1) {
  3418. spec->multiout.num_dacs = 3;
  3419. spec->multiout.dac_nids[AUTO_SEQ_SURROUND] = 0x11;
  3420. spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x24;
  3421. }
  3422. return 0;
  3423. }
  3424. /* add playback controls from the parsed DAC table */
  3425. static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
  3426. const struct auto_pin_cfg *cfg)
  3427. {
  3428. char name[32];
  3429. static const char * const chname[4] = {
  3430. "Front", "Surround", "C/LFE", "Side"
  3431. };
  3432. hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
  3433. hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
  3434. hda_nid_t nid, nid_vol, nid_mute;
  3435. int i, err;
  3436. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  3437. nid = cfg->line_out_pins[i];
  3438. /* for Smart 5.1, there are always at least six channels */
  3439. if (!nid && i > AUTO_SEQ_CENLFE)
  3440. continue;
  3441. nid_vol = nid_vols[i];
  3442. nid_mute = nid_mutes[i];
  3443. if (i == AUTO_SEQ_CENLFE) {
  3444. /* Center/LFE */
  3445. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3446. "Center Playback Volume",
  3447. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  3448. HDA_OUTPUT));
  3449. if (err < 0)
  3450. return err;
  3451. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3452. "LFE Playback Volume",
  3453. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  3454. HDA_OUTPUT));
  3455. if (err < 0)
  3456. return err;
  3457. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3458. "Center Playback Switch",
  3459. HDA_COMPOSE_AMP_VAL(nid_mute,
  3460. 1, 0,
  3461. HDA_OUTPUT));
  3462. if (err < 0)
  3463. return err;
  3464. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3465. "LFE Playback Switch",
  3466. HDA_COMPOSE_AMP_VAL(nid_mute,
  3467. 2, 0,
  3468. HDA_OUTPUT));
  3469. if (err < 0)
  3470. return err;
  3471. } else if (i == AUTO_SEQ_FRONT) {
  3472. /* add control to mixer index 0 */
  3473. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3474. "Master Front Playback Volume",
  3475. HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
  3476. HDA_INPUT));
  3477. if (err < 0)
  3478. return err;
  3479. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3480. "Master Front Playback Switch",
  3481. HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
  3482. HDA_INPUT));
  3483. if (err < 0)
  3484. return err;
  3485. /* Front */
  3486. sprintf(name, "%s Playback Volume", chname[i]);
  3487. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  3488. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  3489. HDA_OUTPUT));
  3490. if (err < 0)
  3491. return err;
  3492. sprintf(name, "%s Playback Switch", chname[i]);
  3493. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  3494. HDA_COMPOSE_AMP_VAL(nid_mute,
  3495. 3, 0,
  3496. HDA_OUTPUT));
  3497. if (err < 0)
  3498. return err;
  3499. } else {
  3500. sprintf(name, "%s Playback Volume", chname[i]);
  3501. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  3502. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  3503. HDA_OUTPUT));
  3504. if (err < 0)
  3505. return err;
  3506. sprintf(name, "%s Playback Switch", chname[i]);
  3507. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  3508. HDA_COMPOSE_AMP_VAL(nid_mute,
  3509. 3, 0,
  3510. HDA_OUTPUT));
  3511. if (err < 0)
  3512. return err;
  3513. }
  3514. }
  3515. return 0;
  3516. }
  3517. static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  3518. {
  3519. int err;
  3520. if (!pin)
  3521. return 0;
  3522. spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
  3523. spec->hp_independent_mode_index = 1;
  3524. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3525. "Headphone Playback Volume",
  3526. HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
  3527. if (err < 0)
  3528. return err;
  3529. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3530. "Headphone Playback Switch",
  3531. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  3532. if (err < 0)
  3533. return err;
  3534. create_hp_imux(spec);
  3535. return 0;
  3536. }
  3537. /* create playback/capture controls for input pins */
  3538. static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
  3539. const struct auto_pin_cfg *cfg)
  3540. {
  3541. static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
  3542. return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
  3543. ARRAY_SIZE(pin_idxs));
  3544. }
  3545. /* fill out digital output widgets; one for master and one for slave outputs */
  3546. static void fill_dig_outs(struct hda_codec *codec)
  3547. {
  3548. struct via_spec *spec = codec->spec;
  3549. int i;
  3550. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  3551. hda_nid_t nid;
  3552. int conn;
  3553. nid = spec->autocfg.dig_out_pins[i];
  3554. if (!nid)
  3555. continue;
  3556. conn = snd_hda_get_connections(codec, nid, &nid, 1);
  3557. if (conn < 1)
  3558. continue;
  3559. if (!spec->multiout.dig_out_nid)
  3560. spec->multiout.dig_out_nid = nid;
  3561. else {
  3562. spec->slave_dig_outs[0] = nid;
  3563. break; /* at most two dig outs */
  3564. }
  3565. }
  3566. }
  3567. static int vt1708S_parse_auto_config(struct hda_codec *codec)
  3568. {
  3569. struct via_spec *spec = codec->spec;
  3570. int err;
  3571. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  3572. if (err < 0)
  3573. return err;
  3574. err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
  3575. if (err < 0)
  3576. return err;
  3577. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  3578. return 0; /* can't find valid BIOS pin config */
  3579. err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
  3580. if (err < 0)
  3581. return err;
  3582. err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  3583. if (err < 0)
  3584. return err;
  3585. err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
  3586. if (err < 0)
  3587. return err;
  3588. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3589. fill_dig_outs(codec);
  3590. if (spec->kctls.list)
  3591. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  3592. spec->input_mux = &spec->private_imux[0];
  3593. if (spec->hp_mux)
  3594. via_hp_build(codec);
  3595. via_smart51_build(spec);
  3596. return 1;
  3597. }
  3598. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3599. static struct hda_amp_list vt1708S_loopbacks[] = {
  3600. { 0x16, HDA_INPUT, 1 },
  3601. { 0x16, HDA_INPUT, 2 },
  3602. { 0x16, HDA_INPUT, 3 },
  3603. { 0x16, HDA_INPUT, 4 },
  3604. { } /* end */
  3605. };
  3606. #endif
  3607. static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
  3608. int offset, int num_steps, int step_size)
  3609. {
  3610. snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
  3611. (offset << AC_AMPCAP_OFFSET_SHIFT) |
  3612. (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
  3613. (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
  3614. (0 << AC_AMPCAP_MUTE_SHIFT));
  3615. }
  3616. static int patch_vt1708S(struct hda_codec *codec)
  3617. {
  3618. struct via_spec *spec;
  3619. int err;
  3620. /* create a codec specific record */
  3621. spec = via_new_spec(codec);
  3622. if (spec == NULL)
  3623. return -ENOMEM;
  3624. /* automatic parse from the BIOS config */
  3625. err = vt1708S_parse_auto_config(codec);
  3626. if (err < 0) {
  3627. via_free(codec);
  3628. return err;
  3629. } else if (!err) {
  3630. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  3631. "from BIOS. Using genenic mode...\n");
  3632. }
  3633. spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
  3634. spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
  3635. if (codec->vendor_id == 0x11060440)
  3636. spec->stream_name_analog = "VT1818S Analog";
  3637. else
  3638. spec->stream_name_analog = "VT1708S Analog";
  3639. spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
  3640. spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
  3641. if (codec->vendor_id == 0x11060440)
  3642. spec->stream_name_digital = "VT1818S Digital";
  3643. else
  3644. spec->stream_name_digital = "VT1708S Digital";
  3645. spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
  3646. if (!spec->adc_nids && spec->input_mux) {
  3647. spec->adc_nids = vt1708S_adc_nids;
  3648. spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
  3649. get_mux_nids(codec);
  3650. override_mic_boost(codec, 0x1a, 0, 3, 40);
  3651. override_mic_boost(codec, 0x1e, 0, 3, 40);
  3652. spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
  3653. spec->num_mixers++;
  3654. }
  3655. codec->patch_ops = via_patch_ops;
  3656. codec->patch_ops.init = via_auto_init;
  3657. codec->patch_ops.unsol_event = via_unsol_event;
  3658. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3659. spec->loopback.amplist = vt1708S_loopbacks;
  3660. #endif
  3661. /* correct names for VT1708BCE */
  3662. if (get_codec_type(codec) == VT1708BCE) {
  3663. kfree(codec->chip_name);
  3664. codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
  3665. snprintf(codec->bus->card->mixername,
  3666. sizeof(codec->bus->card->mixername),
  3667. "%s %s", codec->vendor_name, codec->chip_name);
  3668. spec->stream_name_analog = "VT1708BCE Analog";
  3669. spec->stream_name_digital = "VT1708BCE Digital";
  3670. }
  3671. return 0;
  3672. }
  3673. /* Patch for VT1702 */
  3674. /* capture mixer elements */
  3675. static struct snd_kcontrol_new vt1702_capture_mixer[] = {
  3676. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
  3677. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
  3678. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
  3679. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
  3680. HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
  3681. HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
  3682. HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
  3683. HDA_INPUT),
  3684. {
  3685. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3686. /* The multiple "Capture Source" controls confuse alsamixer
  3687. * So call somewhat different..
  3688. */
  3689. /* .name = "Capture Source", */
  3690. .name = "Input Source",
  3691. .count = 1,
  3692. .info = via_mux_enum_info,
  3693. .get = via_mux_enum_get,
  3694. .put = via_mux_enum_put,
  3695. },
  3696. { } /* end */
  3697. };
  3698. static struct hda_verb vt1702_volume_init_verbs[] = {
  3699. /*
  3700. * Unmute ADC0-1 and set the default input to mic-in
  3701. */
  3702. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3703. {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3704. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3705. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  3706. * mixer widget
  3707. */
  3708. /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
  3709. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3710. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3711. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  3712. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  3713. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3714. /* Setup default input of PW4 to MW0 */
  3715. {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
  3716. /* PW6 PW7 Output enable */
  3717. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  3718. {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  3719. /* mixer enable */
  3720. {0x1, 0xF88, 0x3},
  3721. /* GPIO 0~2 */
  3722. {0x1, 0xF82, 0x3F},
  3723. { }
  3724. };
  3725. static struct hda_verb vt1702_uniwill_init_verbs[] = {
  3726. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
  3727. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
  3728. {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3729. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3730. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3731. {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3732. { }
  3733. };
  3734. static struct hda_pcm_stream vt1702_pcm_analog_playback = {
  3735. .substreams = 2,
  3736. .channels_min = 2,
  3737. .channels_max = 2,
  3738. .nid = 0x10, /* NID to query formats and rates */
  3739. .ops = {
  3740. .open = via_playback_pcm_open,
  3741. .prepare = via_playback_multi_pcm_prepare,
  3742. .cleanup = via_playback_multi_pcm_cleanup,
  3743. .close = via_pcm_open_close
  3744. },
  3745. };
  3746. static struct hda_pcm_stream vt1702_pcm_analog_capture = {
  3747. .substreams = 3,
  3748. .channels_min = 2,
  3749. .channels_max = 2,
  3750. .nid = 0x12, /* NID to query formats and rates */
  3751. .ops = {
  3752. .open = via_pcm_open_close,
  3753. .prepare = via_capture_pcm_prepare,
  3754. .cleanup = via_capture_pcm_cleanup,
  3755. .close = via_pcm_open_close
  3756. },
  3757. };
  3758. static struct hda_pcm_stream vt1702_pcm_digital_playback = {
  3759. .substreams = 2,
  3760. .channels_min = 2,
  3761. .channels_max = 2,
  3762. /* NID is set in via_build_pcms */
  3763. .ops = {
  3764. .open = via_dig_playback_pcm_open,
  3765. .close = via_dig_playback_pcm_close,
  3766. .prepare = via_dig_playback_pcm_prepare,
  3767. .cleanup = via_dig_playback_pcm_cleanup
  3768. },
  3769. };
  3770. /* fill in the dac_nids table from the parsed pin configuration */
  3771. static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
  3772. const struct auto_pin_cfg *cfg)
  3773. {
  3774. spec->multiout.num_dacs = 1;
  3775. spec->multiout.dac_nids = spec->private_dac_nids;
  3776. if (cfg->line_out_pins[0]) {
  3777. /* config dac list */
  3778. spec->multiout.dac_nids[0] = 0x10;
  3779. }
  3780. return 0;
  3781. }
  3782. /* add playback controls from the parsed DAC table */
  3783. static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
  3784. const struct auto_pin_cfg *cfg)
  3785. {
  3786. int err;
  3787. if (!cfg->line_out_pins[0])
  3788. return -1;
  3789. /* add control to mixer index 0 */
  3790. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3791. "Master Front Playback Volume",
  3792. HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
  3793. if (err < 0)
  3794. return err;
  3795. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3796. "Master Front Playback Switch",
  3797. HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
  3798. if (err < 0)
  3799. return err;
  3800. /* Front */
  3801. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3802. "Front Playback Volume",
  3803. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
  3804. if (err < 0)
  3805. return err;
  3806. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3807. "Front Playback Switch",
  3808. HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
  3809. if (err < 0)
  3810. return err;
  3811. return 0;
  3812. }
  3813. static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  3814. {
  3815. int err, i;
  3816. struct hda_input_mux *imux;
  3817. static const char * const texts[] = { "ON", "OFF", NULL};
  3818. if (!pin)
  3819. return 0;
  3820. spec->multiout.hp_nid = 0x1D;
  3821. spec->hp_independent_mode_index = 0;
  3822. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3823. "Headphone Playback Volume",
  3824. HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
  3825. if (err < 0)
  3826. return err;
  3827. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3828. "Headphone Playback Switch",
  3829. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  3830. if (err < 0)
  3831. return err;
  3832. imux = &spec->private_imux[1];
  3833. /* for hp mode select */
  3834. for (i = 0; texts[i]; i++)
  3835. snd_hda_add_imux_item(imux, texts[i], i, NULL);
  3836. spec->hp_mux = &spec->private_imux[1];
  3837. return 0;
  3838. }
  3839. /* create playback/capture controls for input pins */
  3840. static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
  3841. const struct auto_pin_cfg *cfg)
  3842. {
  3843. static hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
  3844. return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
  3845. ARRAY_SIZE(pin_idxs));
  3846. }
  3847. static int vt1702_parse_auto_config(struct hda_codec *codec)
  3848. {
  3849. struct via_spec *spec = codec->spec;
  3850. int err;
  3851. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  3852. if (err < 0)
  3853. return err;
  3854. err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
  3855. if (err < 0)
  3856. return err;
  3857. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  3858. return 0; /* can't find valid BIOS pin config */
  3859. err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
  3860. if (err < 0)
  3861. return err;
  3862. err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  3863. if (err < 0)
  3864. return err;
  3865. /* limit AA path volume to 0 dB */
  3866. snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
  3867. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  3868. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  3869. (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  3870. (1 << AC_AMPCAP_MUTE_SHIFT));
  3871. err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
  3872. if (err < 0)
  3873. return err;
  3874. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3875. fill_dig_outs(codec);
  3876. if (spec->kctls.list)
  3877. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  3878. spec->input_mux = &spec->private_imux[0];
  3879. if (spec->hp_mux)
  3880. via_hp_build(codec);
  3881. return 1;
  3882. }
  3883. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3884. static struct hda_amp_list vt1702_loopbacks[] = {
  3885. { 0x1A, HDA_INPUT, 1 },
  3886. { 0x1A, HDA_INPUT, 2 },
  3887. { 0x1A, HDA_INPUT, 3 },
  3888. { 0x1A, HDA_INPUT, 4 },
  3889. { } /* end */
  3890. };
  3891. #endif
  3892. static int patch_vt1702(struct hda_codec *codec)
  3893. {
  3894. struct via_spec *spec;
  3895. int err;
  3896. /* create a codec specific record */
  3897. spec = via_new_spec(codec);
  3898. if (spec == NULL)
  3899. return -ENOMEM;
  3900. /* automatic parse from the BIOS config */
  3901. err = vt1702_parse_auto_config(codec);
  3902. if (err < 0) {
  3903. via_free(codec);
  3904. return err;
  3905. } else if (!err) {
  3906. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  3907. "from BIOS. Using genenic mode...\n");
  3908. }
  3909. spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
  3910. spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
  3911. spec->stream_name_analog = "VT1702 Analog";
  3912. spec->stream_analog_playback = &vt1702_pcm_analog_playback;
  3913. spec->stream_analog_capture = &vt1702_pcm_analog_capture;
  3914. spec->stream_name_digital = "VT1702 Digital";
  3915. spec->stream_digital_playback = &vt1702_pcm_digital_playback;
  3916. if (!spec->adc_nids && spec->input_mux) {
  3917. spec->adc_nids = vt1702_adc_nids;
  3918. spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
  3919. get_mux_nids(codec);
  3920. spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
  3921. spec->num_mixers++;
  3922. }
  3923. codec->patch_ops = via_patch_ops;
  3924. codec->patch_ops.init = via_auto_init;
  3925. codec->patch_ops.unsol_event = via_unsol_event;
  3926. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3927. spec->loopback.amplist = vt1702_loopbacks;
  3928. #endif
  3929. return 0;
  3930. }
  3931. /* Patch for VT1718S */
  3932. /* capture mixer elements */
  3933. static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
  3934. HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
  3935. HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
  3936. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
  3937. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
  3938. HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
  3939. HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
  3940. HDA_INPUT),
  3941. {
  3942. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3943. /* The multiple "Capture Source" controls confuse alsamixer
  3944. * So call somewhat different..
  3945. */
  3946. .name = "Input Source",
  3947. .count = 2,
  3948. .info = via_mux_enum_info,
  3949. .get = via_mux_enum_get,
  3950. .put = via_mux_enum_put,
  3951. },
  3952. { } /* end */
  3953. };
  3954. static struct hda_verb vt1718S_volume_init_verbs[] = {
  3955. /*
  3956. * Unmute ADC0-1 and set the default input to mic-in
  3957. */
  3958. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3959. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3960. /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  3961. * mixer widget
  3962. */
  3963. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  3964. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3965. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3966. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3967. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3968. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  3969. /* Setup default input of Front HP to MW9 */
  3970. {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
  3971. /* PW9 PW10 Output enable */
  3972. {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
  3973. {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
  3974. /* PW11 Input enable */
  3975. {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
  3976. /* Enable Boost Volume backdoor */
  3977. {0x1, 0xf88, 0x8},
  3978. /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
  3979. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3980. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3981. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3982. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3983. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3984. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3985. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3986. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3987. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3988. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3989. /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
  3990. {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
  3991. {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
  3992. /* Unmute MW4's index 0 */
  3993. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3994. { }
  3995. };
  3996. static struct hda_verb vt1718S_uniwill_init_verbs[] = {
  3997. {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
  3998. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
  3999. {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4000. {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4001. {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4002. {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4003. {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4004. {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4005. {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4006. { }
  4007. };
  4008. static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
  4009. .substreams = 2,
  4010. .channels_min = 2,
  4011. .channels_max = 10,
  4012. .nid = 0x8, /* NID to query formats and rates */
  4013. .ops = {
  4014. .open = via_playback_pcm_open,
  4015. .prepare = via_playback_multi_pcm_prepare,
  4016. .cleanup = via_playback_multi_pcm_cleanup,
  4017. .close = via_pcm_open_close,
  4018. },
  4019. };
  4020. static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
  4021. .substreams = 2,
  4022. .channels_min = 2,
  4023. .channels_max = 2,
  4024. .nid = 0x10, /* NID to query formats and rates */
  4025. .ops = {
  4026. .open = via_pcm_open_close,
  4027. .prepare = via_capture_pcm_prepare,
  4028. .cleanup = via_capture_pcm_cleanup,
  4029. .close = via_pcm_open_close,
  4030. },
  4031. };
  4032. static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
  4033. .substreams = 2,
  4034. .channels_min = 2,
  4035. .channels_max = 2,
  4036. /* NID is set in via_build_pcms */
  4037. .ops = {
  4038. .open = via_dig_playback_pcm_open,
  4039. .close = via_dig_playback_pcm_close,
  4040. .prepare = via_dig_playback_pcm_prepare,
  4041. .cleanup = via_dig_playback_pcm_cleanup
  4042. },
  4043. };
  4044. static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
  4045. .substreams = 1,
  4046. .channels_min = 2,
  4047. .channels_max = 2,
  4048. };
  4049. /* fill in the dac_nids table from the parsed pin configuration */
  4050. static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
  4051. const struct auto_pin_cfg *cfg)
  4052. {
  4053. int i;
  4054. hda_nid_t nid;
  4055. spec->multiout.num_dacs = cfg->line_outs;
  4056. spec->multiout.dac_nids = spec->private_dac_nids;
  4057. for (i = 0; i < 4; i++) {
  4058. nid = cfg->line_out_pins[i];
  4059. if (nid) {
  4060. /* config dac list */
  4061. switch (i) {
  4062. case AUTO_SEQ_FRONT:
  4063. spec->multiout.dac_nids[i] = 0x8;
  4064. break;
  4065. case AUTO_SEQ_CENLFE:
  4066. spec->multiout.dac_nids[i] = 0xa;
  4067. break;
  4068. case AUTO_SEQ_SURROUND:
  4069. spec->multiout.dac_nids[i] = 0x9;
  4070. break;
  4071. case AUTO_SEQ_SIDE:
  4072. spec->multiout.dac_nids[i] = 0xb;
  4073. break;
  4074. }
  4075. }
  4076. }
  4077. return 0;
  4078. }
  4079. /* add playback controls from the parsed DAC table */
  4080. static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
  4081. const struct auto_pin_cfg *cfg)
  4082. {
  4083. char name[32];
  4084. static const char * const chname[4] = {
  4085. "Front", "Surround", "C/LFE", "Side"
  4086. };
  4087. hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
  4088. hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
  4089. hda_nid_t nid, nid_vol, nid_mute = 0;
  4090. int i, err;
  4091. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  4092. nid = cfg->line_out_pins[i];
  4093. if (!nid)
  4094. continue;
  4095. nid_vol = nid_vols[i];
  4096. nid_mute = nid_mutes[i];
  4097. if (i == AUTO_SEQ_CENLFE) {
  4098. /* Center/LFE */
  4099. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  4100. "Center Playback Volume",
  4101. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  4102. HDA_OUTPUT));
  4103. if (err < 0)
  4104. return err;
  4105. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  4106. "LFE Playback Volume",
  4107. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  4108. HDA_OUTPUT));
  4109. if (err < 0)
  4110. return err;
  4111. err = via_add_control(
  4112. spec, VIA_CTL_WIDGET_MUTE,
  4113. "Center Playback Switch",
  4114. HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
  4115. HDA_OUTPUT));
  4116. if (err < 0)
  4117. return err;
  4118. err = via_add_control(
  4119. spec, VIA_CTL_WIDGET_MUTE,
  4120. "LFE Playback Switch",
  4121. HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
  4122. HDA_OUTPUT));
  4123. if (err < 0)
  4124. return err;
  4125. } else if (i == AUTO_SEQ_FRONT) {
  4126. /* Front */
  4127. sprintf(name, "%s Playback Volume", chname[i]);
  4128. err = via_add_control(
  4129. spec, VIA_CTL_WIDGET_VOL, name,
  4130. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
  4131. if (err < 0)
  4132. return err;
  4133. sprintf(name, "%s Playback Switch", chname[i]);
  4134. err = via_add_control(
  4135. spec, VIA_CTL_WIDGET_MUTE, name,
  4136. HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
  4137. HDA_OUTPUT));
  4138. if (err < 0)
  4139. return err;
  4140. } else {
  4141. sprintf(name, "%s Playback Volume", chname[i]);
  4142. err = via_add_control(
  4143. spec, VIA_CTL_WIDGET_VOL, name,
  4144. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
  4145. if (err < 0)
  4146. return err;
  4147. sprintf(name, "%s Playback Switch", chname[i]);
  4148. err = via_add_control(
  4149. spec, VIA_CTL_WIDGET_MUTE, name,
  4150. HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
  4151. HDA_OUTPUT));
  4152. if (err < 0)
  4153. return err;
  4154. }
  4155. }
  4156. return 0;
  4157. }
  4158. static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  4159. {
  4160. int err;
  4161. if (!pin)
  4162. return 0;
  4163. spec->multiout.hp_nid = 0xc; /* AOW4 */
  4164. spec->hp_independent_mode_index = 1;
  4165. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  4166. "Headphone Playback Volume",
  4167. HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
  4168. if (err < 0)
  4169. return err;
  4170. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  4171. "Headphone Playback Switch",
  4172. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  4173. if (err < 0)
  4174. return err;
  4175. create_hp_imux(spec);
  4176. return 0;
  4177. }
  4178. /* create playback/capture controls for input pins */
  4179. static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
  4180. const struct auto_pin_cfg *cfg)
  4181. {
  4182. static hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
  4183. return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
  4184. ARRAY_SIZE(pin_idxs));
  4185. }
  4186. static int vt1718S_parse_auto_config(struct hda_codec *codec)
  4187. {
  4188. struct via_spec *spec = codec->spec;
  4189. int err;
  4190. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  4191. if (err < 0)
  4192. return err;
  4193. err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
  4194. if (err < 0)
  4195. return err;
  4196. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  4197. return 0; /* can't find valid BIOS pin config */
  4198. err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
  4199. if (err < 0)
  4200. return err;
  4201. err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  4202. if (err < 0)
  4203. return err;
  4204. err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
  4205. if (err < 0)
  4206. return err;
  4207. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  4208. fill_dig_outs(codec);
  4209. if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
  4210. spec->dig_in_nid = 0x13;
  4211. if (spec->kctls.list)
  4212. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  4213. spec->input_mux = &spec->private_imux[0];
  4214. if (spec->hp_mux)
  4215. via_hp_build(codec);
  4216. via_smart51_build(spec);
  4217. return 1;
  4218. }
  4219. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4220. static struct hda_amp_list vt1718S_loopbacks[] = {
  4221. { 0x21, HDA_INPUT, 1 },
  4222. { 0x21, HDA_INPUT, 2 },
  4223. { 0x21, HDA_INPUT, 3 },
  4224. { 0x21, HDA_INPUT, 4 },
  4225. { } /* end */
  4226. };
  4227. #endif
  4228. static int patch_vt1718S(struct hda_codec *codec)
  4229. {
  4230. struct via_spec *spec;
  4231. int err;
  4232. /* create a codec specific record */
  4233. spec = via_new_spec(codec);
  4234. if (spec == NULL)
  4235. return -ENOMEM;
  4236. /* automatic parse from the BIOS config */
  4237. err = vt1718S_parse_auto_config(codec);
  4238. if (err < 0) {
  4239. via_free(codec);
  4240. return err;
  4241. } else if (!err) {
  4242. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  4243. "from BIOS. Using genenic mode...\n");
  4244. }
  4245. spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
  4246. spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
  4247. if (codec->vendor_id == 0x11060441)
  4248. spec->stream_name_analog = "VT2020 Analog";
  4249. else if (codec->vendor_id == 0x11064441)
  4250. spec->stream_name_analog = "VT1828S Analog";
  4251. else
  4252. spec->stream_name_analog = "VT1718S Analog";
  4253. spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
  4254. spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
  4255. if (codec->vendor_id == 0x11060441)
  4256. spec->stream_name_digital = "VT2020 Digital";
  4257. else if (codec->vendor_id == 0x11064441)
  4258. spec->stream_name_digital = "VT1828S Digital";
  4259. else
  4260. spec->stream_name_digital = "VT1718S Digital";
  4261. spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
  4262. if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
  4263. spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
  4264. if (!spec->adc_nids && spec->input_mux) {
  4265. spec->adc_nids = vt1718S_adc_nids;
  4266. spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
  4267. get_mux_nids(codec);
  4268. override_mic_boost(codec, 0x2b, 0, 3, 40);
  4269. override_mic_boost(codec, 0x29, 0, 3, 40);
  4270. spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
  4271. spec->num_mixers++;
  4272. }
  4273. codec->patch_ops = via_patch_ops;
  4274. codec->patch_ops.init = via_auto_init;
  4275. codec->patch_ops.unsol_event = via_unsol_event;
  4276. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4277. spec->loopback.amplist = vt1718S_loopbacks;
  4278. #endif
  4279. return 0;
  4280. }
  4281. /* Patch for VT1716S */
  4282. static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
  4283. struct snd_ctl_elem_info *uinfo)
  4284. {
  4285. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  4286. uinfo->count = 1;
  4287. uinfo->value.integer.min = 0;
  4288. uinfo->value.integer.max = 1;
  4289. return 0;
  4290. }
  4291. static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
  4292. struct snd_ctl_elem_value *ucontrol)
  4293. {
  4294. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  4295. int index = 0;
  4296. index = snd_hda_codec_read(codec, 0x26, 0,
  4297. AC_VERB_GET_CONNECT_SEL, 0);
  4298. if (index != -1)
  4299. *ucontrol->value.integer.value = index;
  4300. return 0;
  4301. }
  4302. static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
  4303. struct snd_ctl_elem_value *ucontrol)
  4304. {
  4305. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  4306. struct via_spec *spec = codec->spec;
  4307. int index = *ucontrol->value.integer.value;
  4308. snd_hda_codec_write(codec, 0x26, 0,
  4309. AC_VERB_SET_CONNECT_SEL, index);
  4310. spec->dmic_enabled = index;
  4311. set_jack_power_state(codec);
  4312. return 1;
  4313. }
  4314. /* capture mixer elements */
  4315. static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
  4316. HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
  4317. HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
  4318. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
  4319. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
  4320. HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
  4321. HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
  4322. HDA_INPUT),
  4323. {
  4324. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4325. .name = "Input Source",
  4326. .count = 1,
  4327. .info = via_mux_enum_info,
  4328. .get = via_mux_enum_get,
  4329. .put = via_mux_enum_put,
  4330. },
  4331. { } /* end */
  4332. };
  4333. static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
  4334. HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
  4335. {
  4336. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4337. .name = "Digital Mic Capture Switch",
  4338. .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
  4339. .count = 1,
  4340. .info = vt1716s_dmic_info,
  4341. .get = vt1716s_dmic_get,
  4342. .put = vt1716s_dmic_put,
  4343. },
  4344. {} /* end */
  4345. };
  4346. /* mono-out mixer elements */
  4347. static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
  4348. HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
  4349. { } /* end */
  4350. };
  4351. static struct hda_verb vt1716S_volume_init_verbs[] = {
  4352. /*
  4353. * Unmute ADC0-1 and set the default input to mic-in
  4354. */
  4355. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4356. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4357. /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  4358. * mixer widget
  4359. */
  4360. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  4361. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4362. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4363. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  4364. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  4365. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  4366. /* MUX Indices: Stereo Mixer = 5 */
  4367. {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
  4368. /* Setup default input of PW4 to MW0 */
  4369. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
  4370. /* Setup default input of SW1 as MW0 */
  4371. {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
  4372. /* Setup default input of SW4 as AOW0 */
  4373. {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
  4374. /* PW9 PW10 Output enable */
  4375. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  4376. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  4377. /* Unmute SW1, PW12 */
  4378. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4379. {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4380. /* PW12 Output enable */
  4381. {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  4382. /* Enable Boost Volume backdoor */
  4383. {0x1, 0xf8a, 0x80},
  4384. /* don't bybass mixer */
  4385. {0x1, 0xf88, 0xc0},
  4386. /* Enable mono output */
  4387. {0x1, 0xf90, 0x08},
  4388. { }
  4389. };
  4390. static struct hda_verb vt1716S_uniwill_init_verbs[] = {
  4391. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
  4392. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
  4393. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4394. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4395. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4396. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
  4397. AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
  4398. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4399. {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4400. { }
  4401. };
  4402. static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
  4403. .substreams = 2,
  4404. .channels_min = 2,
  4405. .channels_max = 6,
  4406. .nid = 0x10, /* NID to query formats and rates */
  4407. .ops = {
  4408. .open = via_playback_pcm_open,
  4409. .prepare = via_playback_multi_pcm_prepare,
  4410. .cleanup = via_playback_multi_pcm_cleanup,
  4411. .close = via_pcm_open_close,
  4412. },
  4413. };
  4414. static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
  4415. .substreams = 2,
  4416. .channels_min = 2,
  4417. .channels_max = 2,
  4418. .nid = 0x13, /* NID to query formats and rates */
  4419. .ops = {
  4420. .open = via_pcm_open_close,
  4421. .prepare = via_capture_pcm_prepare,
  4422. .cleanup = via_capture_pcm_cleanup,
  4423. .close = via_pcm_open_close,
  4424. },
  4425. };
  4426. static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
  4427. .substreams = 2,
  4428. .channels_min = 2,
  4429. .channels_max = 2,
  4430. /* NID is set in via_build_pcms */
  4431. .ops = {
  4432. .open = via_dig_playback_pcm_open,
  4433. .close = via_dig_playback_pcm_close,
  4434. .prepare = via_dig_playback_pcm_prepare,
  4435. .cleanup = via_dig_playback_pcm_cleanup
  4436. },
  4437. };
  4438. /* fill in the dac_nids table from the parsed pin configuration */
  4439. static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
  4440. const struct auto_pin_cfg *cfg)
  4441. { int i;
  4442. hda_nid_t nid;
  4443. spec->multiout.num_dacs = cfg->line_outs;
  4444. spec->multiout.dac_nids = spec->private_dac_nids;
  4445. for (i = 0; i < 3; i++) {
  4446. nid = cfg->line_out_pins[i];
  4447. if (nid) {
  4448. /* config dac list */
  4449. switch (i) {
  4450. case AUTO_SEQ_FRONT:
  4451. spec->multiout.dac_nids[i] = 0x10;
  4452. break;
  4453. case AUTO_SEQ_CENLFE:
  4454. spec->multiout.dac_nids[i] = 0x25;
  4455. break;
  4456. case AUTO_SEQ_SURROUND:
  4457. spec->multiout.dac_nids[i] = 0x11;
  4458. break;
  4459. }
  4460. }
  4461. }
  4462. return 0;
  4463. }
  4464. /* add playback controls from the parsed DAC table */
  4465. static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
  4466. const struct auto_pin_cfg *cfg)
  4467. {
  4468. char name[32];
  4469. static const char * const chname[3] = {
  4470. "Front", "Surround", "C/LFE"
  4471. };
  4472. hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
  4473. hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
  4474. hda_nid_t nid, nid_vol, nid_mute;
  4475. int i, err;
  4476. for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
  4477. nid = cfg->line_out_pins[i];
  4478. if (!nid)
  4479. continue;
  4480. nid_vol = nid_vols[i];
  4481. nid_mute = nid_mutes[i];
  4482. if (i == AUTO_SEQ_CENLFE) {
  4483. err = via_add_control(
  4484. spec, VIA_CTL_WIDGET_VOL,
  4485. "Center Playback Volume",
  4486. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
  4487. if (err < 0)
  4488. return err;
  4489. err = via_add_control(
  4490. spec, VIA_CTL_WIDGET_VOL,
  4491. "LFE Playback Volume",
  4492. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
  4493. if (err < 0)
  4494. return err;
  4495. err = via_add_control(
  4496. spec, VIA_CTL_WIDGET_MUTE,
  4497. "Center Playback Switch",
  4498. HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
  4499. HDA_OUTPUT));
  4500. if (err < 0)
  4501. return err;
  4502. err = via_add_control(
  4503. spec, VIA_CTL_WIDGET_MUTE,
  4504. "LFE Playback Switch",
  4505. HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
  4506. HDA_OUTPUT));
  4507. if (err < 0)
  4508. return err;
  4509. } else if (i == AUTO_SEQ_FRONT) {
  4510. err = via_add_control(
  4511. spec, VIA_CTL_WIDGET_VOL,
  4512. "Master Front Playback Volume",
  4513. HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
  4514. if (err < 0)
  4515. return err;
  4516. err = via_add_control(
  4517. spec, VIA_CTL_WIDGET_MUTE,
  4518. "Master Front Playback Switch",
  4519. HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
  4520. if (err < 0)
  4521. return err;
  4522. sprintf(name, "%s Playback Volume", chname[i]);
  4523. err = via_add_control(
  4524. spec, VIA_CTL_WIDGET_VOL, name,
  4525. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
  4526. if (err < 0)
  4527. return err;
  4528. sprintf(name, "%s Playback Switch", chname[i]);
  4529. err = via_add_control(
  4530. spec, VIA_CTL_WIDGET_MUTE, name,
  4531. HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
  4532. HDA_OUTPUT));
  4533. if (err < 0)
  4534. return err;
  4535. } else {
  4536. sprintf(name, "%s Playback Volume", chname[i]);
  4537. err = via_add_control(
  4538. spec, VIA_CTL_WIDGET_VOL, name,
  4539. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
  4540. if (err < 0)
  4541. return err;
  4542. sprintf(name, "%s Playback Switch", chname[i]);
  4543. err = via_add_control(
  4544. spec, VIA_CTL_WIDGET_MUTE, name,
  4545. HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
  4546. HDA_OUTPUT));
  4547. if (err < 0)
  4548. return err;
  4549. }
  4550. }
  4551. return 0;
  4552. }
  4553. static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  4554. {
  4555. int err;
  4556. if (!pin)
  4557. return 0;
  4558. spec->multiout.hp_nid = 0x25; /* AOW3 */
  4559. spec->hp_independent_mode_index = 1;
  4560. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  4561. "Headphone Playback Volume",
  4562. HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
  4563. if (err < 0)
  4564. return err;
  4565. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  4566. "Headphone Playback Switch",
  4567. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  4568. if (err < 0)
  4569. return err;
  4570. create_hp_imux(spec);
  4571. return 0;
  4572. }
  4573. /* create playback/capture controls for input pins */
  4574. static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
  4575. const struct auto_pin_cfg *cfg)
  4576. {
  4577. static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
  4578. return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
  4579. ARRAY_SIZE(pin_idxs));
  4580. }
  4581. static int vt1716S_parse_auto_config(struct hda_codec *codec)
  4582. {
  4583. struct via_spec *spec = codec->spec;
  4584. int err;
  4585. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  4586. if (err < 0)
  4587. return err;
  4588. err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
  4589. if (err < 0)
  4590. return err;
  4591. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  4592. return 0; /* can't find valid BIOS pin config */
  4593. err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
  4594. if (err < 0)
  4595. return err;
  4596. err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  4597. if (err < 0)
  4598. return err;
  4599. err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
  4600. if (err < 0)
  4601. return err;
  4602. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  4603. fill_dig_outs(codec);
  4604. if (spec->kctls.list)
  4605. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  4606. spec->input_mux = &spec->private_imux[0];
  4607. if (spec->hp_mux)
  4608. via_hp_build(codec);
  4609. via_smart51_build(spec);
  4610. return 1;
  4611. }
  4612. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4613. static struct hda_amp_list vt1716S_loopbacks[] = {
  4614. { 0x16, HDA_INPUT, 1 },
  4615. { 0x16, HDA_INPUT, 2 },
  4616. { 0x16, HDA_INPUT, 3 },
  4617. { 0x16, HDA_INPUT, 4 },
  4618. { } /* end */
  4619. };
  4620. #endif
  4621. static int patch_vt1716S(struct hda_codec *codec)
  4622. {
  4623. struct via_spec *spec;
  4624. int err;
  4625. /* create a codec specific record */
  4626. spec = via_new_spec(codec);
  4627. if (spec == NULL)
  4628. return -ENOMEM;
  4629. /* automatic parse from the BIOS config */
  4630. err = vt1716S_parse_auto_config(codec);
  4631. if (err < 0) {
  4632. via_free(codec);
  4633. return err;
  4634. } else if (!err) {
  4635. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  4636. "from BIOS. Using genenic mode...\n");
  4637. }
  4638. spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
  4639. spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
  4640. spec->stream_name_analog = "VT1716S Analog";
  4641. spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
  4642. spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
  4643. spec->stream_name_digital = "VT1716S Digital";
  4644. spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
  4645. if (!spec->adc_nids && spec->input_mux) {
  4646. spec->adc_nids = vt1716S_adc_nids;
  4647. spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
  4648. get_mux_nids(codec);
  4649. override_mic_boost(codec, 0x1a, 0, 3, 40);
  4650. override_mic_boost(codec, 0x1e, 0, 3, 40);
  4651. spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
  4652. spec->num_mixers++;
  4653. }
  4654. spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
  4655. spec->num_mixers++;
  4656. spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
  4657. codec->patch_ops = via_patch_ops;
  4658. codec->patch_ops.init = via_auto_init;
  4659. codec->patch_ops.unsol_event = via_unsol_event;
  4660. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4661. spec->loopback.amplist = vt1716S_loopbacks;
  4662. #endif
  4663. return 0;
  4664. }
  4665. /* for vt2002P */
  4666. /* capture mixer elements */
  4667. static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
  4668. HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
  4669. HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
  4670. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
  4671. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
  4672. HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
  4673. HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
  4674. HDA_INPUT),
  4675. {
  4676. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4677. /* The multiple "Capture Source" controls confuse alsamixer
  4678. * So call somewhat different..
  4679. */
  4680. /* .name = "Capture Source", */
  4681. .name = "Input Source",
  4682. .count = 2,
  4683. .info = via_mux_enum_info,
  4684. .get = via_mux_enum_get,
  4685. .put = via_mux_enum_put,
  4686. },
  4687. { } /* end */
  4688. };
  4689. static struct hda_verb vt2002P_volume_init_verbs[] = {
  4690. /*
  4691. * Unmute ADC0-1 and set the default input to mic-in
  4692. */
  4693. {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4694. {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4695. /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  4696. * mixer widget
  4697. */
  4698. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  4699. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4700. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4701. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  4702. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  4703. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  4704. /* MUX Indices: Mic = 0 */
  4705. {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
  4706. {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
  4707. /* PW9 Output enable */
  4708. {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
  4709. /* Enable Boost Volume backdoor */
  4710. {0x1, 0xfb9, 0x24},
  4711. /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
  4712. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4713. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4714. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4715. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4716. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4717. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4718. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4719. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4720. /* set MUX0/1/4/8 = 0 (AOW0) */
  4721. {0x34, AC_VERB_SET_CONNECT_SEL, 0},
  4722. {0x35, AC_VERB_SET_CONNECT_SEL, 0},
  4723. {0x37, AC_VERB_SET_CONNECT_SEL, 0},
  4724. {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
  4725. /* set PW0 index=0 (MW0) */
  4726. {0x24, AC_VERB_SET_CONNECT_SEL, 0},
  4727. /* Enable AOW0 to MW9 */
  4728. {0x1, 0xfb8, 0x88},
  4729. { }
  4730. };
  4731. static struct hda_verb vt2002P_uniwill_init_verbs[] = {
  4732. {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
  4733. AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
  4734. {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
  4735. AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
  4736. {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4737. {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4738. {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4739. { }
  4740. };
  4741. static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
  4742. .substreams = 2,
  4743. .channels_min = 2,
  4744. .channels_max = 2,
  4745. .nid = 0x8, /* NID to query formats and rates */
  4746. .ops = {
  4747. .open = via_playback_pcm_open,
  4748. .prepare = via_playback_multi_pcm_prepare,
  4749. .cleanup = via_playback_multi_pcm_cleanup,
  4750. .close = via_pcm_open_close,
  4751. },
  4752. };
  4753. static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
  4754. .substreams = 2,
  4755. .channels_min = 2,
  4756. .channels_max = 2,
  4757. .nid = 0x10, /* NID to query formats and rates */
  4758. .ops = {
  4759. .open = via_pcm_open_close,
  4760. .prepare = via_capture_pcm_prepare,
  4761. .cleanup = via_capture_pcm_cleanup,
  4762. .close = via_pcm_open_close,
  4763. },
  4764. };
  4765. static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
  4766. .substreams = 1,
  4767. .channels_min = 2,
  4768. .channels_max = 2,
  4769. /* NID is set in via_build_pcms */
  4770. .ops = {
  4771. .open = via_dig_playback_pcm_open,
  4772. .close = via_dig_playback_pcm_close,
  4773. .prepare = via_dig_playback_pcm_prepare,
  4774. .cleanup = via_dig_playback_pcm_cleanup
  4775. },
  4776. };
  4777. /* fill in the dac_nids table from the parsed pin configuration */
  4778. static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
  4779. const struct auto_pin_cfg *cfg)
  4780. {
  4781. spec->multiout.num_dacs = 1;
  4782. spec->multiout.dac_nids = spec->private_dac_nids;
  4783. if (cfg->line_out_pins[0])
  4784. spec->multiout.dac_nids[0] = 0x8;
  4785. return 0;
  4786. }
  4787. /* add playback controls from the parsed DAC table */
  4788. static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
  4789. const struct auto_pin_cfg *cfg)
  4790. {
  4791. int err;
  4792. if (!cfg->line_out_pins[0])
  4793. return -1;
  4794. /* Line-Out: PortE */
  4795. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  4796. "Master Front Playback Volume",
  4797. HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
  4798. if (err < 0)
  4799. return err;
  4800. err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
  4801. "Master Front Playback Switch",
  4802. HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
  4803. if (err < 0)
  4804. return err;
  4805. return 0;
  4806. }
  4807. static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  4808. {
  4809. int err;
  4810. if (!pin)
  4811. return 0;
  4812. spec->multiout.hp_nid = 0x9;
  4813. spec->hp_independent_mode_index = 1;
  4814. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  4815. "Headphone Playback Volume",
  4816. HDA_COMPOSE_AMP_VAL(
  4817. spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
  4818. if (err < 0)
  4819. return err;
  4820. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  4821. "Headphone Playback Switch",
  4822. HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
  4823. if (err < 0)
  4824. return err;
  4825. create_hp_imux(spec);
  4826. return 0;
  4827. }
  4828. /* create playback/capture controls for input pins */
  4829. static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
  4830. const struct auto_pin_cfg *cfg)
  4831. {
  4832. struct via_spec *spec = codec->spec;
  4833. struct hda_input_mux *imux = &spec->private_imux[0];
  4834. static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
  4835. int err;
  4836. err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
  4837. ARRAY_SIZE(pin_idxs));
  4838. if (err < 0)
  4839. return err;
  4840. /* build volume/mute control of loopback */
  4841. err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
  4842. if (err < 0)
  4843. return err;
  4844. /* for digital mic select */
  4845. snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
  4846. return 0;
  4847. }
  4848. static int vt2002P_parse_auto_config(struct hda_codec *codec)
  4849. {
  4850. struct via_spec *spec = codec->spec;
  4851. int err;
  4852. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  4853. if (err < 0)
  4854. return err;
  4855. err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
  4856. if (err < 0)
  4857. return err;
  4858. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  4859. return 0; /* can't find valid BIOS pin config */
  4860. err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
  4861. if (err < 0)
  4862. return err;
  4863. err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  4864. if (err < 0)
  4865. return err;
  4866. err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
  4867. if (err < 0)
  4868. return err;
  4869. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  4870. fill_dig_outs(codec);
  4871. if (spec->kctls.list)
  4872. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  4873. spec->input_mux = &spec->private_imux[0];
  4874. if (spec->hp_mux)
  4875. via_hp_build(codec);
  4876. return 1;
  4877. }
  4878. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4879. static struct hda_amp_list vt2002P_loopbacks[] = {
  4880. { 0x21, HDA_INPUT, 0 },
  4881. { 0x21, HDA_INPUT, 1 },
  4882. { 0x21, HDA_INPUT, 2 },
  4883. { } /* end */
  4884. };
  4885. #endif
  4886. /* patch for vt2002P */
  4887. static int patch_vt2002P(struct hda_codec *codec)
  4888. {
  4889. struct via_spec *spec;
  4890. int err;
  4891. /* create a codec specific record */
  4892. spec = via_new_spec(codec);
  4893. if (spec == NULL)
  4894. return -ENOMEM;
  4895. /* automatic parse from the BIOS config */
  4896. err = vt2002P_parse_auto_config(codec);
  4897. if (err < 0) {
  4898. via_free(codec);
  4899. return err;
  4900. } else if (!err) {
  4901. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  4902. "from BIOS. Using genenic mode...\n");
  4903. }
  4904. spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
  4905. spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
  4906. spec->stream_name_analog = "VT2002P Analog";
  4907. spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
  4908. spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
  4909. spec->stream_name_digital = "VT2002P Digital";
  4910. spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
  4911. if (!spec->adc_nids && spec->input_mux) {
  4912. spec->adc_nids = vt2002P_adc_nids;
  4913. spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
  4914. get_mux_nids(codec);
  4915. override_mic_boost(codec, 0x2b, 0, 3, 40);
  4916. override_mic_boost(codec, 0x29, 0, 3, 40);
  4917. spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
  4918. spec->num_mixers++;
  4919. }
  4920. codec->patch_ops = via_patch_ops;
  4921. codec->patch_ops.init = via_auto_init;
  4922. codec->patch_ops.unsol_event = via_unsol_event;
  4923. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4924. spec->loopback.amplist = vt2002P_loopbacks;
  4925. #endif
  4926. return 0;
  4927. }
  4928. /* for vt1812 */
  4929. /* capture mixer elements */
  4930. static struct snd_kcontrol_new vt1812_capture_mixer[] = {
  4931. HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
  4932. HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
  4933. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
  4934. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
  4935. HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
  4936. HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
  4937. HDA_INPUT),
  4938. {
  4939. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4940. /* The multiple "Capture Source" controls confuse alsamixer
  4941. * So call somewhat different..
  4942. */
  4943. .name = "Input Source",
  4944. .count = 2,
  4945. .info = via_mux_enum_info,
  4946. .get = via_mux_enum_get,
  4947. .put = via_mux_enum_put,
  4948. },
  4949. { } /* end */
  4950. };
  4951. static struct hda_verb vt1812_volume_init_verbs[] = {
  4952. /*
  4953. * Unmute ADC0-1 and set the default input to mic-in
  4954. */
  4955. {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4956. {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4957. /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  4958. * mixer widget
  4959. */
  4960. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  4961. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4962. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4963. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  4964. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  4965. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  4966. /* MUX Indices: Mic = 0 */
  4967. {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
  4968. {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
  4969. /* PW9 Output enable */
  4970. {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
  4971. /* Enable Boost Volume backdoor */
  4972. {0x1, 0xfb9, 0x24},
  4973. /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
  4974. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4975. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4976. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4977. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4978. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4979. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4980. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4981. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4982. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4983. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4984. /* set MUX0/1/4/13/15 = 0 (AOW0) */
  4985. {0x34, AC_VERB_SET_CONNECT_SEL, 0},
  4986. {0x35, AC_VERB_SET_CONNECT_SEL, 0},
  4987. {0x38, AC_VERB_SET_CONNECT_SEL, 0},
  4988. {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
  4989. {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
  4990. /* Enable AOW0 to MW9 */
  4991. {0x1, 0xfb8, 0xa8},
  4992. { }
  4993. };
  4994. static struct hda_verb vt1812_uniwill_init_verbs[] = {
  4995. {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
  4996. AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
  4997. {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
  4998. {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
  4999. AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
  5000. {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  5001. {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  5002. {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  5003. { }
  5004. };
  5005. static struct hda_pcm_stream vt1812_pcm_analog_playback = {
  5006. .substreams = 2,
  5007. .channels_min = 2,
  5008. .channels_max = 2,
  5009. .nid = 0x8, /* NID to query formats and rates */
  5010. .ops = {
  5011. .open = via_playback_pcm_open,
  5012. .prepare = via_playback_multi_pcm_prepare,
  5013. .cleanup = via_playback_multi_pcm_cleanup,
  5014. .close = via_pcm_open_close,
  5015. },
  5016. };
  5017. static struct hda_pcm_stream vt1812_pcm_analog_capture = {
  5018. .substreams = 2,
  5019. .channels_min = 2,
  5020. .channels_max = 2,
  5021. .nid = 0x10, /* NID to query formats and rates */
  5022. .ops = {
  5023. .open = via_pcm_open_close,
  5024. .prepare = via_capture_pcm_prepare,
  5025. .cleanup = via_capture_pcm_cleanup,
  5026. .close = via_pcm_open_close,
  5027. },
  5028. };
  5029. static struct hda_pcm_stream vt1812_pcm_digital_playback = {
  5030. .substreams = 1,
  5031. .channels_min = 2,
  5032. .channels_max = 2,
  5033. /* NID is set in via_build_pcms */
  5034. .ops = {
  5035. .open = via_dig_playback_pcm_open,
  5036. .close = via_dig_playback_pcm_close,
  5037. .prepare = via_dig_playback_pcm_prepare,
  5038. .cleanup = via_dig_playback_pcm_cleanup
  5039. },
  5040. };
  5041. /* fill in the dac_nids table from the parsed pin configuration */
  5042. static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
  5043. const struct auto_pin_cfg *cfg)
  5044. {
  5045. spec->multiout.num_dacs = 1;
  5046. spec->multiout.dac_nids = spec->private_dac_nids;
  5047. if (cfg->line_out_pins[0])
  5048. spec->multiout.dac_nids[0] = 0x8;
  5049. return 0;
  5050. }
  5051. /* add playback controls from the parsed DAC table */
  5052. static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
  5053. const struct auto_pin_cfg *cfg)
  5054. {
  5055. int err;
  5056. if (!cfg->line_out_pins[0])
  5057. return -1;
  5058. /* Line-Out: PortE */
  5059. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  5060. "Front Playback Volume",
  5061. HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
  5062. if (err < 0)
  5063. return err;
  5064. err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
  5065. "Front Playback Switch",
  5066. HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
  5067. if (err < 0)
  5068. return err;
  5069. return 0;
  5070. }
  5071. static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  5072. {
  5073. int err;
  5074. if (!pin)
  5075. return 0;
  5076. spec->multiout.hp_nid = 0x9;
  5077. spec->hp_independent_mode_index = 1;
  5078. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  5079. "Headphone Playback Volume",
  5080. HDA_COMPOSE_AMP_VAL(
  5081. spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
  5082. if (err < 0)
  5083. return err;
  5084. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  5085. "Headphone Playback Switch",
  5086. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  5087. if (err < 0)
  5088. return err;
  5089. create_hp_imux(spec);
  5090. return 0;
  5091. }
  5092. /* create playback/capture controls for input pins */
  5093. static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
  5094. const struct auto_pin_cfg *cfg)
  5095. {
  5096. struct via_spec *spec = codec->spec;
  5097. struct hda_input_mux *imux = &spec->private_imux[0];
  5098. static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
  5099. int err;
  5100. err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
  5101. ARRAY_SIZE(pin_idxs));
  5102. if (err < 0)
  5103. return err;
  5104. /* build volume/mute control of loopback */
  5105. err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
  5106. if (err < 0)
  5107. return err;
  5108. /* for digital mic select */
  5109. snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
  5110. return 0;
  5111. }
  5112. static int vt1812_parse_auto_config(struct hda_codec *codec)
  5113. {
  5114. struct via_spec *spec = codec->spec;
  5115. int err;
  5116. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  5117. if (err < 0)
  5118. return err;
  5119. fill_dig_outs(codec);
  5120. err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
  5121. if (err < 0)
  5122. return err;
  5123. if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
  5124. return 0; /* can't find valid BIOS pin config */
  5125. err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
  5126. if (err < 0)
  5127. return err;
  5128. err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  5129. if (err < 0)
  5130. return err;
  5131. err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
  5132. if (err < 0)
  5133. return err;
  5134. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  5135. fill_dig_outs(codec);
  5136. if (spec->kctls.list)
  5137. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  5138. spec->input_mux = &spec->private_imux[0];
  5139. if (spec->hp_mux)
  5140. via_hp_build(codec);
  5141. return 1;
  5142. }
  5143. #ifdef CONFIG_SND_HDA_POWER_SAVE
  5144. static struct hda_amp_list vt1812_loopbacks[] = {
  5145. { 0x21, HDA_INPUT, 0 },
  5146. { 0x21, HDA_INPUT, 1 },
  5147. { 0x21, HDA_INPUT, 2 },
  5148. { } /* end */
  5149. };
  5150. #endif
  5151. /* patch for vt1812 */
  5152. static int patch_vt1812(struct hda_codec *codec)
  5153. {
  5154. struct via_spec *spec;
  5155. int err;
  5156. /* create a codec specific record */
  5157. spec = via_new_spec(codec);
  5158. if (spec == NULL)
  5159. return -ENOMEM;
  5160. /* automatic parse from the BIOS config */
  5161. err = vt1812_parse_auto_config(codec);
  5162. if (err < 0) {
  5163. via_free(codec);
  5164. return err;
  5165. } else if (!err) {
  5166. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  5167. "from BIOS. Using genenic mode...\n");
  5168. }
  5169. spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
  5170. spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
  5171. spec->stream_name_analog = "VT1812 Analog";
  5172. spec->stream_analog_playback = &vt1812_pcm_analog_playback;
  5173. spec->stream_analog_capture = &vt1812_pcm_analog_capture;
  5174. spec->stream_name_digital = "VT1812 Digital";
  5175. spec->stream_digital_playback = &vt1812_pcm_digital_playback;
  5176. if (!spec->adc_nids && spec->input_mux) {
  5177. spec->adc_nids = vt1812_adc_nids;
  5178. spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
  5179. get_mux_nids(codec);
  5180. override_mic_boost(codec, 0x2b, 0, 3, 40);
  5181. override_mic_boost(codec, 0x29, 0, 3, 40);
  5182. spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
  5183. spec->num_mixers++;
  5184. }
  5185. codec->patch_ops = via_patch_ops;
  5186. codec->patch_ops.init = via_auto_init;
  5187. codec->patch_ops.unsol_event = via_unsol_event;
  5188. #ifdef CONFIG_SND_HDA_POWER_SAVE
  5189. spec->loopback.amplist = vt1812_loopbacks;
  5190. #endif
  5191. return 0;
  5192. }
  5193. /*
  5194. * patch entries
  5195. */
  5196. static struct hda_codec_preset snd_hda_preset_via[] = {
  5197. { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
  5198. { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
  5199. { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
  5200. { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
  5201. { .id = 0x1106e710, .name = "VT1709 10-Ch",
  5202. .patch = patch_vt1709_10ch},
  5203. { .id = 0x1106e711, .name = "VT1709 10-Ch",
  5204. .patch = patch_vt1709_10ch},
  5205. { .id = 0x1106e712, .name = "VT1709 10-Ch",
  5206. .patch = patch_vt1709_10ch},
  5207. { .id = 0x1106e713, .name = "VT1709 10-Ch",
  5208. .patch = patch_vt1709_10ch},
  5209. { .id = 0x1106e714, .name = "VT1709 6-Ch",
  5210. .patch = patch_vt1709_6ch},
  5211. { .id = 0x1106e715, .name = "VT1709 6-Ch",
  5212. .patch = patch_vt1709_6ch},
  5213. { .id = 0x1106e716, .name = "VT1709 6-Ch",
  5214. .patch = patch_vt1709_6ch},
  5215. { .id = 0x1106e717, .name = "VT1709 6-Ch",
  5216. .patch = patch_vt1709_6ch},
  5217. { .id = 0x1106e720, .name = "VT1708B 8-Ch",
  5218. .patch = patch_vt1708B_8ch},
  5219. { .id = 0x1106e721, .name = "VT1708B 8-Ch",
  5220. .patch = patch_vt1708B_8ch},
  5221. { .id = 0x1106e722, .name = "VT1708B 8-Ch",
  5222. .patch = patch_vt1708B_8ch},
  5223. { .id = 0x1106e723, .name = "VT1708B 8-Ch",
  5224. .patch = patch_vt1708B_8ch},
  5225. { .id = 0x1106e724, .name = "VT1708B 4-Ch",
  5226. .patch = patch_vt1708B_4ch},
  5227. { .id = 0x1106e725, .name = "VT1708B 4-Ch",
  5228. .patch = patch_vt1708B_4ch},
  5229. { .id = 0x1106e726, .name = "VT1708B 4-Ch",
  5230. .patch = patch_vt1708B_4ch},
  5231. { .id = 0x1106e727, .name = "VT1708B 4-Ch",
  5232. .patch = patch_vt1708B_4ch},
  5233. { .id = 0x11060397, .name = "VT1708S",
  5234. .patch = patch_vt1708S},
  5235. { .id = 0x11061397, .name = "VT1708S",
  5236. .patch = patch_vt1708S},
  5237. { .id = 0x11062397, .name = "VT1708S",
  5238. .patch = patch_vt1708S},
  5239. { .id = 0x11063397, .name = "VT1708S",
  5240. .patch = patch_vt1708S},
  5241. { .id = 0x11064397, .name = "VT1708S",
  5242. .patch = patch_vt1708S},
  5243. { .id = 0x11065397, .name = "VT1708S",
  5244. .patch = patch_vt1708S},
  5245. { .id = 0x11066397, .name = "VT1708S",
  5246. .patch = patch_vt1708S},
  5247. { .id = 0x11067397, .name = "VT1708S",
  5248. .patch = patch_vt1708S},
  5249. { .id = 0x11060398, .name = "VT1702",
  5250. .patch = patch_vt1702},
  5251. { .id = 0x11061398, .name = "VT1702",
  5252. .patch = patch_vt1702},
  5253. { .id = 0x11062398, .name = "VT1702",
  5254. .patch = patch_vt1702},
  5255. { .id = 0x11063398, .name = "VT1702",
  5256. .patch = patch_vt1702},
  5257. { .id = 0x11064398, .name = "VT1702",
  5258. .patch = patch_vt1702},
  5259. { .id = 0x11065398, .name = "VT1702",
  5260. .patch = patch_vt1702},
  5261. { .id = 0x11066398, .name = "VT1702",
  5262. .patch = patch_vt1702},
  5263. { .id = 0x11067398, .name = "VT1702",
  5264. .patch = patch_vt1702},
  5265. { .id = 0x11060428, .name = "VT1718S",
  5266. .patch = patch_vt1718S},
  5267. { .id = 0x11064428, .name = "VT1718S",
  5268. .patch = patch_vt1718S},
  5269. { .id = 0x11060441, .name = "VT2020",
  5270. .patch = patch_vt1718S},
  5271. { .id = 0x11064441, .name = "VT1828S",
  5272. .patch = patch_vt1718S},
  5273. { .id = 0x11060433, .name = "VT1716S",
  5274. .patch = patch_vt1716S},
  5275. { .id = 0x1106a721, .name = "VT1716S",
  5276. .patch = patch_vt1716S},
  5277. { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
  5278. { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
  5279. { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
  5280. { .id = 0x11060440, .name = "VT1818S",
  5281. .patch = patch_vt1708S},
  5282. {} /* terminator */
  5283. };
  5284. MODULE_ALIAS("snd-hda-codec-id:1106*");
  5285. static struct hda_codec_preset_list via_list = {
  5286. .preset = snd_hda_preset_via,
  5287. .owner = THIS_MODULE,
  5288. };
  5289. MODULE_LICENSE("GPL");
  5290. MODULE_DESCRIPTION("VIA HD-audio codec");
  5291. static int __init patch_via_init(void)
  5292. {
  5293. return snd_hda_add_codec_preset(&via_list);
  5294. }
  5295. static void __exit patch_via_exit(void)
  5296. {
  5297. snd_hda_delete_codec_preset(&via_list);
  5298. }
  5299. module_init(patch_via_init)
  5300. module_exit(patch_via_exit)