patch_via.c 170 KB

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