patch_via.c 170 KB

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