patch_via.c 168 KB

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