patch_via.c 174 KB

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