patch_via.c 173 KB

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