patch_via.c 170 KB

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