patch_via.c 169 KB

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