patch_via.c 174 KB

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