patch_via.c 175 KB

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