patch_via.c 166 KB

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