patch_via.c 167 KB

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