patch_via.c 173 KB

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