patch_via.c 175 KB

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