patch_via.c 166 KB

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