patch_via.c 175 KB

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