patch_via.c 174 KB

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