patch_via.c 173 KB

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