patch_via.c 168 KB

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