patch_via.c 169 KB

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