patch_realtek.c 194 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for Realtek ALC codecs
  5. *
  6. * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
  7. * PeiSen Hou <pshou@realtek.com.tw>
  8. * Takashi Iwai <tiwai@suse.de>
  9. * Jonathan Woithe <jwoithe@just42.net>
  10. *
  11. * This driver is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This driver is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. #include <linux/init.h>
  26. #include <linux/delay.h>
  27. #include <linux/slab.h>
  28. #include <linux/pci.h>
  29. #include <linux/module.h>
  30. #include <sound/core.h>
  31. #include <sound/jack.h>
  32. #include "hda_codec.h"
  33. #include "hda_local.h"
  34. #include "hda_auto_parser.h"
  35. #include "hda_beep.h"
  36. #include "hda_jack.h"
  37. /* unsol event tags */
  38. #define ALC_FRONT_EVENT 0x01
  39. #define ALC_DCVOL_EVENT 0x02
  40. #define ALC_HP_EVENT 0x04
  41. #define ALC_MIC_EVENT 0x08
  42. /* for GPIO Poll */
  43. #define GPIO_MASK 0x03
  44. /* extra amp-initialization sequence types */
  45. enum {
  46. ALC_INIT_NONE,
  47. ALC_INIT_DEFAULT,
  48. ALC_INIT_GPIO1,
  49. ALC_INIT_GPIO2,
  50. ALC_INIT_GPIO3,
  51. };
  52. struct alc_customize_define {
  53. unsigned int sku_cfg;
  54. unsigned char port_connectivity;
  55. unsigned char check_sum;
  56. unsigned char customization;
  57. unsigned char external_amp;
  58. unsigned int enable_pcbeep:1;
  59. unsigned int platform_type:1;
  60. unsigned int swap:1;
  61. unsigned int override:1;
  62. unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
  63. };
  64. struct alc_multi_io {
  65. hda_nid_t pin; /* multi-io widget pin NID */
  66. hda_nid_t dac; /* DAC to be connected */
  67. unsigned int ctl_in; /* cached input-pin control value */
  68. };
  69. enum {
  70. ALC_AUTOMUTE_PIN, /* change the pin control */
  71. ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
  72. ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
  73. };
  74. #define MAX_VOL_NIDS 0x40
  75. /* make compatible with old code */
  76. #define alc_apply_pincfgs snd_hda_apply_pincfgs
  77. #define alc_apply_fixup snd_hda_apply_fixup
  78. #define alc_pick_fixup snd_hda_pick_fixup
  79. #define alc_fixup hda_fixup
  80. #define alc_pincfg hda_pintbl
  81. #define alc_model_fixup hda_model_fixup
  82. #define ALC_FIXUP_PINS HDA_FIXUP_PINS
  83. #define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
  84. #define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
  85. #define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
  86. #define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
  87. #define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
  88. #define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
  89. struct alc_spec {
  90. struct hda_gen_spec gen;
  91. /* codec parameterization */
  92. const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
  93. unsigned int num_mixers;
  94. const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
  95. unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
  96. char stream_name_analog[32]; /* analog PCM stream */
  97. const struct hda_pcm_stream *stream_analog_playback;
  98. const struct hda_pcm_stream *stream_analog_capture;
  99. const struct hda_pcm_stream *stream_analog_alt_playback;
  100. const struct hda_pcm_stream *stream_analog_alt_capture;
  101. char stream_name_digital[32]; /* digital PCM stream */
  102. const struct hda_pcm_stream *stream_digital_playback;
  103. const struct hda_pcm_stream *stream_digital_capture;
  104. /* playback */
  105. struct hda_multi_out multiout; /* playback set-up
  106. * max_channels, dacs must be set
  107. * dig_out_nid and hp_nid are optional
  108. */
  109. hda_nid_t alt_dac_nid;
  110. hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
  111. int dig_out_type;
  112. /* capture */
  113. unsigned int num_adc_nids;
  114. const hda_nid_t *adc_nids;
  115. const hda_nid_t *capsrc_nids;
  116. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  117. hda_nid_t mixer_nid; /* analog-mixer NID */
  118. DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
  119. DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
  120. /* capture setup for dynamic dual-adc switch */
  121. hda_nid_t cur_adc;
  122. unsigned int cur_adc_stream_tag;
  123. unsigned int cur_adc_format;
  124. /* capture source */
  125. unsigned int num_mux_defs;
  126. const struct hda_input_mux *input_mux;
  127. unsigned int cur_mux[3];
  128. hda_nid_t ext_mic_pin;
  129. hda_nid_t dock_mic_pin;
  130. hda_nid_t int_mic_pin;
  131. /* channel model */
  132. const struct hda_channel_mode *channel_mode;
  133. int num_channel_mode;
  134. int need_dac_fix;
  135. int const_channel_count;
  136. int ext_channel_count;
  137. /* PCM information */
  138. struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
  139. /* dynamic controls, init_verbs and input_mux */
  140. struct auto_pin_cfg autocfg;
  141. struct alc_customize_define cdefine;
  142. struct snd_array kctls;
  143. struct hda_input_mux private_imux[3];
  144. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  145. hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
  146. hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
  147. hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
  148. unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
  149. int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
  150. hda_nid_t inv_dmic_pin;
  151. /* hooks */
  152. void (*init_hook)(struct hda_codec *codec);
  153. void (*unsol_event)(struct hda_codec *codec, unsigned int res);
  154. #ifdef CONFIG_SND_HDA_POWER_SAVE
  155. void (*power_hook)(struct hda_codec *codec);
  156. #endif
  157. void (*shutup)(struct hda_codec *codec);
  158. void (*automute_hook)(struct hda_codec *codec);
  159. /* for pin sensing */
  160. unsigned int hp_jack_present:1;
  161. unsigned int line_jack_present:1;
  162. unsigned int master_mute:1;
  163. unsigned int auto_mic:1;
  164. unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
  165. unsigned int automute_speaker:1; /* automute speaker outputs */
  166. unsigned int automute_lo:1; /* automute LO outputs */
  167. unsigned int detect_hp:1; /* Headphone detection enabled */
  168. unsigned int detect_lo:1; /* Line-out detection enabled */
  169. unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
  170. unsigned int automute_lo_possible:1; /* there are line outs and HP */
  171. unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
  172. /* other flags */
  173. unsigned int no_analog :1; /* digital I/O only */
  174. unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
  175. unsigned int single_input_src:1;
  176. unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
  177. unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
  178. unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
  179. unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
  180. unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
  181. /* auto-mute control */
  182. int automute_mode;
  183. hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
  184. int init_amp;
  185. int codec_variant; /* flag for other variants */
  186. /* for virtual master */
  187. hda_nid_t vmaster_nid;
  188. struct hda_vmaster_mute_hook vmaster_mute;
  189. #ifdef CONFIG_SND_HDA_POWER_SAVE
  190. struct hda_loopback_check loopback;
  191. int num_loopbacks;
  192. struct hda_amp_list loopback_list[8];
  193. #endif
  194. /* for PLL fix */
  195. hda_nid_t pll_nid;
  196. unsigned int pll_coef_idx, pll_coef_bit;
  197. unsigned int coef0;
  198. /* multi-io */
  199. int multi_ios;
  200. struct alc_multi_io multi_io[4];
  201. /* bind volumes */
  202. struct snd_array bind_ctls;
  203. };
  204. static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
  205. int dir, unsigned int bits)
  206. {
  207. if (!nid)
  208. return false;
  209. if (get_wcaps(codec, nid) & (1 << (dir + 1)))
  210. if (query_amp_caps(codec, nid, dir) & bits)
  211. return true;
  212. return false;
  213. }
  214. #define nid_has_mute(codec, nid, dir) \
  215. check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
  216. #define nid_has_volume(codec, nid, dir) \
  217. check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
  218. /*
  219. * input MUX handling
  220. */
  221. static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
  222. struct snd_ctl_elem_info *uinfo)
  223. {
  224. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  225. struct alc_spec *spec = codec->spec;
  226. unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
  227. if (mux_idx >= spec->num_mux_defs)
  228. mux_idx = 0;
  229. if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
  230. mux_idx = 0;
  231. return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
  232. }
  233. static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
  234. struct snd_ctl_elem_value *ucontrol)
  235. {
  236. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  237. struct alc_spec *spec = codec->spec;
  238. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  239. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  240. return 0;
  241. }
  242. static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
  243. {
  244. struct alc_spec *spec = codec->spec;
  245. hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
  246. if (spec->cur_adc && spec->cur_adc != new_adc) {
  247. /* stream is running, let's swap the current ADC */
  248. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  249. spec->cur_adc = new_adc;
  250. snd_hda_codec_setup_stream(codec, new_adc,
  251. spec->cur_adc_stream_tag, 0,
  252. spec->cur_adc_format);
  253. return true;
  254. }
  255. return false;
  256. }
  257. static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
  258. {
  259. return spec->capsrc_nids ?
  260. spec->capsrc_nids[idx] : spec->adc_nids[idx];
  261. }
  262. static void call_update_outputs(struct hda_codec *codec);
  263. static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
  264. /* select the given imux item; either unmute exclusively or select the route */
  265. static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
  266. unsigned int idx, bool force)
  267. {
  268. struct alc_spec *spec = codec->spec;
  269. const struct hda_input_mux *imux;
  270. unsigned int mux_idx;
  271. int i, type, num_conns;
  272. hda_nid_t nid;
  273. if (!spec->input_mux)
  274. return 0;
  275. mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
  276. imux = &spec->input_mux[mux_idx];
  277. if (!imux->num_items && mux_idx > 0)
  278. imux = &spec->input_mux[0];
  279. if (!imux->num_items)
  280. return 0;
  281. if (idx >= imux->num_items)
  282. idx = imux->num_items - 1;
  283. if (spec->cur_mux[adc_idx] == idx && !force)
  284. return 0;
  285. spec->cur_mux[adc_idx] = idx;
  286. /* for shared I/O, change the pin-control accordingly */
  287. if (spec->shared_mic_hp) {
  288. unsigned int val;
  289. hda_nid_t pin = spec->autocfg.inputs[1].pin;
  290. /* NOTE: this assumes that there are only two inputs, the
  291. * first is the real internal mic and the second is HP jack.
  292. */
  293. if (spec->cur_mux[adc_idx])
  294. val = snd_hda_get_default_vref(codec, pin) | PIN_IN;
  295. else
  296. val = PIN_HP;
  297. snd_hda_set_pin_ctl(codec, pin, val);
  298. spec->automute_speaker = !spec->cur_mux[adc_idx];
  299. call_update_outputs(codec);
  300. }
  301. if (spec->dyn_adc_switch) {
  302. alc_dyn_adc_pcm_resetup(codec, idx);
  303. adc_idx = spec->dyn_adc_idx[idx];
  304. }
  305. nid = get_capsrc(spec, adc_idx);
  306. /* no selection? */
  307. num_conns = snd_hda_get_num_conns(codec, nid);
  308. if (num_conns <= 1)
  309. return 1;
  310. type = get_wcaps_type(get_wcaps(codec, nid));
  311. if (type == AC_WID_AUD_MIX) {
  312. /* Matrix-mixer style (e.g. ALC882) */
  313. int active = imux->items[idx].index;
  314. for (i = 0; i < num_conns; i++) {
  315. unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
  316. snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
  317. HDA_AMP_MUTE, v);
  318. }
  319. } else {
  320. /* MUX style (e.g. ALC880) */
  321. snd_hda_codec_write_cache(codec, nid, 0,
  322. AC_VERB_SET_CONNECT_SEL,
  323. imux->items[idx].index);
  324. }
  325. alc_inv_dmic_sync(codec, true);
  326. return 1;
  327. }
  328. static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
  329. struct snd_ctl_elem_value *ucontrol)
  330. {
  331. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  332. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  333. return alc_mux_select(codec, adc_idx,
  334. ucontrol->value.enumerated.item[0], false);
  335. }
  336. /*
  337. * set up the input pin config (depending on the given auto-pin type)
  338. */
  339. static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
  340. int auto_pin_type)
  341. {
  342. unsigned int val = PIN_IN;
  343. if (auto_pin_type == AUTO_PIN_MIC)
  344. val |= snd_hda_get_default_vref(codec, nid);
  345. snd_hda_set_pin_ctl(codec, nid, val);
  346. }
  347. /*
  348. * Append the given mixer and verb elements for the later use
  349. * The mixer array is referred in build_controls(), and init_verbs are
  350. * called in init().
  351. */
  352. static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
  353. {
  354. if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
  355. return;
  356. spec->mixers[spec->num_mixers++] = mix;
  357. }
  358. /*
  359. * GPIO setup tables, used in initialization
  360. */
  361. /* Enable GPIO mask and set output */
  362. static const struct hda_verb alc_gpio1_init_verbs[] = {
  363. {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
  364. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
  365. {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
  366. { }
  367. };
  368. static const struct hda_verb alc_gpio2_init_verbs[] = {
  369. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  370. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  371. {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
  372. { }
  373. };
  374. static const struct hda_verb alc_gpio3_init_verbs[] = {
  375. {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
  376. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
  377. {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
  378. { }
  379. };
  380. /*
  381. * Fix hardware PLL issue
  382. * On some codecs, the analog PLL gating control must be off while
  383. * the default value is 1.
  384. */
  385. static void alc_fix_pll(struct hda_codec *codec)
  386. {
  387. struct alc_spec *spec = codec->spec;
  388. unsigned int val;
  389. if (!spec->pll_nid)
  390. return;
  391. snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
  392. spec->pll_coef_idx);
  393. val = snd_hda_codec_read(codec, spec->pll_nid, 0,
  394. AC_VERB_GET_PROC_COEF, 0);
  395. snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
  396. spec->pll_coef_idx);
  397. snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
  398. val & ~(1 << spec->pll_coef_bit));
  399. }
  400. static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
  401. unsigned int coef_idx, unsigned int coef_bit)
  402. {
  403. struct alc_spec *spec = codec->spec;
  404. spec->pll_nid = nid;
  405. spec->pll_coef_idx = coef_idx;
  406. spec->pll_coef_bit = coef_bit;
  407. alc_fix_pll(codec);
  408. }
  409. /*
  410. * Jack detections for HP auto-mute and mic-switch
  411. */
  412. /* check each pin in the given array; returns true if any of them is plugged */
  413. static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
  414. {
  415. int i, present = 0;
  416. for (i = 0; i < num_pins; i++) {
  417. hda_nid_t nid = pins[i];
  418. if (!nid)
  419. break;
  420. present |= snd_hda_jack_detect(codec, nid);
  421. }
  422. return present;
  423. }
  424. /* standard HP/line-out auto-mute helper */
  425. static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
  426. bool mute, bool hp_out)
  427. {
  428. struct alc_spec *spec = codec->spec;
  429. unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
  430. unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
  431. int i;
  432. for (i = 0; i < num_pins; i++) {
  433. hda_nid_t nid = pins[i];
  434. unsigned int val;
  435. if (!nid)
  436. break;
  437. switch (spec->automute_mode) {
  438. case ALC_AUTOMUTE_PIN:
  439. /* don't reset VREF value in case it's controlling
  440. * the amp (see alc861_fixup_asus_amp_vref_0f())
  441. */
  442. if (spec->keep_vref_in_automute) {
  443. val = snd_hda_codec_read(codec, nid, 0,
  444. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  445. val &= ~PIN_HP;
  446. } else
  447. val = 0;
  448. val |= pin_bits;
  449. snd_hda_set_pin_ctl(codec, nid, val);
  450. break;
  451. case ALC_AUTOMUTE_AMP:
  452. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  453. HDA_AMP_MUTE, mute_bits);
  454. break;
  455. case ALC_AUTOMUTE_MIXER:
  456. nid = spec->automute_mixer_nid[i];
  457. if (!nid)
  458. break;
  459. snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
  460. HDA_AMP_MUTE, mute_bits);
  461. snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
  462. HDA_AMP_MUTE, mute_bits);
  463. break;
  464. }
  465. }
  466. }
  467. /* Toggle outputs muting */
  468. static void update_outputs(struct hda_codec *codec)
  469. {
  470. struct alc_spec *spec = codec->spec;
  471. int on;
  472. /* Control HP pins/amps depending on master_mute state;
  473. * in general, HP pins/amps control should be enabled in all cases,
  474. * but currently set only for master_mute, just to be safe
  475. */
  476. if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
  477. do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
  478. spec->autocfg.hp_pins, spec->master_mute, true);
  479. if (!spec->automute_speaker)
  480. on = 0;
  481. else
  482. on = spec->hp_jack_present | spec->line_jack_present;
  483. on |= spec->master_mute;
  484. do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
  485. spec->autocfg.speaker_pins, on, false);
  486. /* toggle line-out mutes if needed, too */
  487. /* if LO is a copy of either HP or Speaker, don't need to handle it */
  488. if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
  489. spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
  490. return;
  491. if (!spec->automute_lo)
  492. on = 0;
  493. else
  494. on = spec->hp_jack_present;
  495. on |= spec->master_mute;
  496. do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
  497. spec->autocfg.line_out_pins, on, false);
  498. }
  499. static void call_update_outputs(struct hda_codec *codec)
  500. {
  501. struct alc_spec *spec = codec->spec;
  502. if (spec->automute_hook)
  503. spec->automute_hook(codec);
  504. else
  505. update_outputs(codec);
  506. }
  507. /* standard HP-automute helper */
  508. static void alc_hp_automute(struct hda_codec *codec)
  509. {
  510. struct alc_spec *spec = codec->spec;
  511. spec->hp_jack_present =
  512. detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
  513. spec->autocfg.hp_pins);
  514. if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
  515. return;
  516. call_update_outputs(codec);
  517. }
  518. /* standard line-out-automute helper */
  519. static void alc_line_automute(struct hda_codec *codec)
  520. {
  521. struct alc_spec *spec = codec->spec;
  522. /* check LO jack only when it's different from HP */
  523. if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
  524. return;
  525. spec->line_jack_present =
  526. detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
  527. spec->autocfg.line_out_pins);
  528. if (!spec->automute_speaker || !spec->detect_lo)
  529. return;
  530. call_update_outputs(codec);
  531. }
  532. #define get_connection_index(codec, mux, nid) \
  533. snd_hda_get_conn_index(codec, mux, nid, 0)
  534. /* standard mic auto-switch helper */
  535. static void alc_mic_automute(struct hda_codec *codec)
  536. {
  537. struct alc_spec *spec = codec->spec;
  538. hda_nid_t *pins = spec->imux_pins;
  539. if (!spec->auto_mic || !spec->auto_mic_valid_imux)
  540. return;
  541. if (snd_BUG_ON(!spec->adc_nids))
  542. return;
  543. if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
  544. return;
  545. if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
  546. alc_mux_select(codec, 0, spec->ext_mic_idx, false);
  547. else if (spec->dock_mic_idx >= 0 &&
  548. snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
  549. alc_mux_select(codec, 0, spec->dock_mic_idx, false);
  550. else
  551. alc_mux_select(codec, 0, spec->int_mic_idx, false);
  552. }
  553. /* handle the specified unsol action (ALC_XXX_EVENT) */
  554. static void alc_exec_unsol_event(struct hda_codec *codec, int action)
  555. {
  556. switch (action) {
  557. case ALC_HP_EVENT:
  558. alc_hp_automute(codec);
  559. break;
  560. case ALC_FRONT_EVENT:
  561. alc_line_automute(codec);
  562. break;
  563. case ALC_MIC_EVENT:
  564. alc_mic_automute(codec);
  565. break;
  566. }
  567. snd_hda_jack_report_sync(codec);
  568. }
  569. /* update the master volume per volume-knob's unsol event */
  570. static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
  571. {
  572. unsigned int val;
  573. struct snd_kcontrol *kctl;
  574. struct snd_ctl_elem_value *uctl;
  575. kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
  576. if (!kctl)
  577. return;
  578. uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
  579. if (!uctl)
  580. return;
  581. val = snd_hda_codec_read(codec, nid, 0,
  582. AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
  583. val &= HDA_AMP_VOLMASK;
  584. uctl->value.integer.value[0] = val;
  585. uctl->value.integer.value[1] = val;
  586. kctl->put(kctl, uctl);
  587. kfree(uctl);
  588. }
  589. /* unsolicited event for HP jack sensing */
  590. static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
  591. {
  592. int action;
  593. if (codec->vendor_id == 0x10ec0880)
  594. res >>= 28;
  595. else
  596. res >>= 26;
  597. action = snd_hda_jack_get_action(codec, res);
  598. if (action == ALC_DCVOL_EVENT) {
  599. /* Execute the dc-vol event here as it requires the NID
  600. * but we don't pass NID to alc_exec_unsol_event().
  601. * Once when we convert all static quirks to the auto-parser,
  602. * this can be integerated into there.
  603. */
  604. struct hda_jack_tbl *jack;
  605. jack = snd_hda_jack_tbl_get_from_tag(codec, res);
  606. if (jack)
  607. alc_update_knob_master(codec, jack->nid);
  608. return;
  609. }
  610. alc_exec_unsol_event(codec, action);
  611. }
  612. /* call init functions of standard auto-mute helpers */
  613. static void alc_inithook(struct hda_codec *codec)
  614. {
  615. alc_hp_automute(codec);
  616. alc_line_automute(codec);
  617. alc_mic_automute(codec);
  618. }
  619. /* additional initialization for ALC888 variants */
  620. static void alc888_coef_init(struct hda_codec *codec)
  621. {
  622. unsigned int tmp;
  623. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
  624. tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
  625. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
  626. if ((tmp & 0xf0) == 0x20)
  627. /* alc888S-VC */
  628. snd_hda_codec_read(codec, 0x20, 0,
  629. AC_VERB_SET_PROC_COEF, 0x830);
  630. else
  631. /* alc888-VB */
  632. snd_hda_codec_read(codec, 0x20, 0,
  633. AC_VERB_SET_PROC_COEF, 0x3030);
  634. }
  635. /* additional initialization for ALC889 variants */
  636. static void alc889_coef_init(struct hda_codec *codec)
  637. {
  638. unsigned int tmp;
  639. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
  640. tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
  641. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
  642. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
  643. }
  644. /* turn on/off EAPD control (only if available) */
  645. static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
  646. {
  647. if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
  648. return;
  649. if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
  650. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
  651. on ? 2 : 0);
  652. }
  653. /* turn on/off EAPD controls of the codec */
  654. static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
  655. {
  656. /* We currently only handle front, HP */
  657. static hda_nid_t pins[] = {
  658. 0x0f, 0x10, 0x14, 0x15, 0
  659. };
  660. hda_nid_t *p;
  661. for (p = pins; *p; p++)
  662. set_eapd(codec, *p, on);
  663. }
  664. /* generic shutup callback;
  665. * just turning off EPAD and a little pause for avoiding pop-noise
  666. */
  667. static void alc_eapd_shutup(struct hda_codec *codec)
  668. {
  669. alc_auto_setup_eapd(codec, false);
  670. msleep(200);
  671. }
  672. /* generic EAPD initialization */
  673. static void alc_auto_init_amp(struct hda_codec *codec, int type)
  674. {
  675. unsigned int tmp;
  676. alc_auto_setup_eapd(codec, true);
  677. switch (type) {
  678. case ALC_INIT_GPIO1:
  679. snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
  680. break;
  681. case ALC_INIT_GPIO2:
  682. snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
  683. break;
  684. case ALC_INIT_GPIO3:
  685. snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
  686. break;
  687. case ALC_INIT_DEFAULT:
  688. switch (codec->vendor_id) {
  689. case 0x10ec0260:
  690. snd_hda_codec_write(codec, 0x1a, 0,
  691. AC_VERB_SET_COEF_INDEX, 7);
  692. tmp = snd_hda_codec_read(codec, 0x1a, 0,
  693. AC_VERB_GET_PROC_COEF, 0);
  694. snd_hda_codec_write(codec, 0x1a, 0,
  695. AC_VERB_SET_COEF_INDEX, 7);
  696. snd_hda_codec_write(codec, 0x1a, 0,
  697. AC_VERB_SET_PROC_COEF,
  698. tmp | 0x2010);
  699. break;
  700. case 0x10ec0262:
  701. case 0x10ec0880:
  702. case 0x10ec0882:
  703. case 0x10ec0883:
  704. case 0x10ec0885:
  705. case 0x10ec0887:
  706. /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
  707. alc889_coef_init(codec);
  708. break;
  709. case 0x10ec0888:
  710. alc888_coef_init(codec);
  711. break;
  712. #if 0 /* XXX: This may cause the silent output on speaker on some machines */
  713. case 0x10ec0267:
  714. case 0x10ec0268:
  715. snd_hda_codec_write(codec, 0x20, 0,
  716. AC_VERB_SET_COEF_INDEX, 7);
  717. tmp = snd_hda_codec_read(codec, 0x20, 0,
  718. AC_VERB_GET_PROC_COEF, 0);
  719. snd_hda_codec_write(codec, 0x20, 0,
  720. AC_VERB_SET_COEF_INDEX, 7);
  721. snd_hda_codec_write(codec, 0x20, 0,
  722. AC_VERB_SET_PROC_COEF,
  723. tmp | 0x3000);
  724. break;
  725. #endif /* XXX */
  726. }
  727. break;
  728. }
  729. }
  730. /*
  731. * Auto-Mute mode mixer enum support
  732. */
  733. static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
  734. struct snd_ctl_elem_info *uinfo)
  735. {
  736. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  737. struct alc_spec *spec = codec->spec;
  738. static const char * const texts2[] = {
  739. "Disabled", "Enabled"
  740. };
  741. static const char * const texts3[] = {
  742. "Disabled", "Speaker Only", "Line Out+Speaker"
  743. };
  744. const char * const *texts;
  745. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  746. uinfo->count = 1;
  747. if (spec->automute_speaker_possible && spec->automute_lo_possible) {
  748. uinfo->value.enumerated.items = 3;
  749. texts = texts3;
  750. } else {
  751. uinfo->value.enumerated.items = 2;
  752. texts = texts2;
  753. }
  754. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  755. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  756. strcpy(uinfo->value.enumerated.name,
  757. texts[uinfo->value.enumerated.item]);
  758. return 0;
  759. }
  760. static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
  761. struct snd_ctl_elem_value *ucontrol)
  762. {
  763. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  764. struct alc_spec *spec = codec->spec;
  765. unsigned int val = 0;
  766. if (spec->automute_speaker)
  767. val++;
  768. if (spec->automute_lo)
  769. val++;
  770. ucontrol->value.enumerated.item[0] = val;
  771. return 0;
  772. }
  773. static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
  774. struct snd_ctl_elem_value *ucontrol)
  775. {
  776. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  777. struct alc_spec *spec = codec->spec;
  778. switch (ucontrol->value.enumerated.item[0]) {
  779. case 0:
  780. if (!spec->automute_speaker && !spec->automute_lo)
  781. return 0;
  782. spec->automute_speaker = 0;
  783. spec->automute_lo = 0;
  784. break;
  785. case 1:
  786. if (spec->automute_speaker_possible) {
  787. if (!spec->automute_lo && spec->automute_speaker)
  788. return 0;
  789. spec->automute_speaker = 1;
  790. spec->automute_lo = 0;
  791. } else if (spec->automute_lo_possible) {
  792. if (spec->automute_lo)
  793. return 0;
  794. spec->automute_lo = 1;
  795. } else
  796. return -EINVAL;
  797. break;
  798. case 2:
  799. if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
  800. return -EINVAL;
  801. if (spec->automute_speaker && spec->automute_lo)
  802. return 0;
  803. spec->automute_speaker = 1;
  804. spec->automute_lo = 1;
  805. break;
  806. default:
  807. return -EINVAL;
  808. }
  809. call_update_outputs(codec);
  810. return 1;
  811. }
  812. static const struct snd_kcontrol_new alc_automute_mode_enum = {
  813. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  814. .name = "Auto-Mute Mode",
  815. .info = alc_automute_mode_info,
  816. .get = alc_automute_mode_get,
  817. .put = alc_automute_mode_put,
  818. };
  819. static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
  820. {
  821. snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
  822. return snd_array_new(&spec->kctls);
  823. }
  824. static int alc_add_automute_mode_enum(struct hda_codec *codec)
  825. {
  826. struct alc_spec *spec = codec->spec;
  827. struct snd_kcontrol_new *knew;
  828. knew = alc_kcontrol_new(spec);
  829. if (!knew)
  830. return -ENOMEM;
  831. *knew = alc_automute_mode_enum;
  832. knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
  833. if (!knew->name)
  834. return -ENOMEM;
  835. return 0;
  836. }
  837. /*
  838. * Check the availability of HP/line-out auto-mute;
  839. * Set up appropriately if really supported
  840. */
  841. static void alc_init_automute(struct hda_codec *codec)
  842. {
  843. struct alc_spec *spec = codec->spec;
  844. struct auto_pin_cfg *cfg = &spec->autocfg;
  845. int present = 0;
  846. int i;
  847. if (cfg->hp_pins[0])
  848. present++;
  849. if (cfg->line_out_pins[0])
  850. present++;
  851. if (cfg->speaker_pins[0])
  852. present++;
  853. if (present < 2) /* need two different output types */
  854. return;
  855. if (!cfg->speaker_pins[0] &&
  856. cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
  857. memcpy(cfg->speaker_pins, cfg->line_out_pins,
  858. sizeof(cfg->speaker_pins));
  859. cfg->speaker_outs = cfg->line_outs;
  860. }
  861. if (!cfg->hp_pins[0] &&
  862. cfg->line_out_type == AUTO_PIN_HP_OUT) {
  863. memcpy(cfg->hp_pins, cfg->line_out_pins,
  864. sizeof(cfg->hp_pins));
  865. cfg->hp_outs = cfg->line_outs;
  866. }
  867. spec->automute_mode = ALC_AUTOMUTE_PIN;
  868. for (i = 0; i < cfg->hp_outs; i++) {
  869. hda_nid_t nid = cfg->hp_pins[i];
  870. if (!is_jack_detectable(codec, nid))
  871. continue;
  872. snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
  873. nid);
  874. snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
  875. spec->detect_hp = 1;
  876. }
  877. if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
  878. if (cfg->speaker_outs)
  879. for (i = 0; i < cfg->line_outs; i++) {
  880. hda_nid_t nid = cfg->line_out_pins[i];
  881. if (!is_jack_detectable(codec, nid))
  882. continue;
  883. snd_printdd("realtek: Enable Line-Out "
  884. "auto-muting on NID 0x%x\n", nid);
  885. snd_hda_jack_detect_enable(codec, nid,
  886. ALC_FRONT_EVENT);
  887. spec->detect_lo = 1;
  888. }
  889. spec->automute_lo_possible = spec->detect_hp;
  890. }
  891. spec->automute_speaker_possible = cfg->speaker_outs &&
  892. (spec->detect_hp || spec->detect_lo);
  893. spec->automute_lo = spec->automute_lo_possible;
  894. spec->automute_speaker = spec->automute_speaker_possible;
  895. if (spec->automute_speaker_possible || spec->automute_lo_possible) {
  896. /* create a control for automute mode */
  897. alc_add_automute_mode_enum(codec);
  898. spec->unsol_event = alc_sku_unsol_event;
  899. }
  900. }
  901. /* return the position of NID in the list, or -1 if not found */
  902. static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
  903. {
  904. int i;
  905. for (i = 0; i < nums; i++)
  906. if (list[i] == nid)
  907. return i;
  908. return -1;
  909. }
  910. /* check whether dynamic ADC-switching is available */
  911. static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
  912. {
  913. struct alc_spec *spec = codec->spec;
  914. struct hda_input_mux *imux = &spec->private_imux[0];
  915. int i, n, idx;
  916. hda_nid_t cap, pin;
  917. if (imux != spec->input_mux) /* no dynamic imux? */
  918. return false;
  919. for (n = 0; n < spec->num_adc_nids; n++) {
  920. cap = spec->private_capsrc_nids[n];
  921. for (i = 0; i < imux->num_items; i++) {
  922. pin = spec->imux_pins[i];
  923. if (!pin)
  924. return false;
  925. if (get_connection_index(codec, cap, pin) < 0)
  926. break;
  927. }
  928. if (i >= imux->num_items)
  929. return true; /* no ADC-switch is needed */
  930. }
  931. for (i = 0; i < imux->num_items; i++) {
  932. pin = spec->imux_pins[i];
  933. for (n = 0; n < spec->num_adc_nids; n++) {
  934. cap = spec->private_capsrc_nids[n];
  935. idx = get_connection_index(codec, cap, pin);
  936. if (idx >= 0) {
  937. imux->items[i].index = idx;
  938. spec->dyn_adc_idx[i] = n;
  939. break;
  940. }
  941. }
  942. }
  943. snd_printdd("realtek: enabling ADC switching\n");
  944. spec->dyn_adc_switch = 1;
  945. return true;
  946. }
  947. /* check whether all auto-mic pins are valid; setup indices if OK */
  948. static bool alc_auto_mic_check_imux(struct hda_codec *codec)
  949. {
  950. struct alc_spec *spec = codec->spec;
  951. const struct hda_input_mux *imux;
  952. if (!spec->auto_mic)
  953. return false;
  954. if (spec->auto_mic_valid_imux)
  955. return true; /* already checked */
  956. /* fill up imux indices */
  957. if (!alc_check_dyn_adc_switch(codec)) {
  958. spec->auto_mic = 0;
  959. return false;
  960. }
  961. imux = spec->input_mux;
  962. spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
  963. spec->imux_pins, imux->num_items);
  964. spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
  965. spec->imux_pins, imux->num_items);
  966. spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
  967. spec->imux_pins, imux->num_items);
  968. if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
  969. spec->auto_mic = 0;
  970. return false; /* no corresponding imux */
  971. }
  972. snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
  973. if (spec->dock_mic_pin)
  974. snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
  975. ALC_MIC_EVENT);
  976. spec->auto_mic_valid_imux = 1;
  977. spec->auto_mic = 1;
  978. return true;
  979. }
  980. /*
  981. * Check the availability of auto-mic switch;
  982. * Set up if really supported
  983. */
  984. static void alc_init_auto_mic(struct hda_codec *codec)
  985. {
  986. struct alc_spec *spec = codec->spec;
  987. struct auto_pin_cfg *cfg = &spec->autocfg;
  988. hda_nid_t fixed, ext, dock;
  989. int i;
  990. if (spec->shared_mic_hp)
  991. return; /* no auto-mic for the shared I/O */
  992. spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
  993. fixed = ext = dock = 0;
  994. for (i = 0; i < cfg->num_inputs; i++) {
  995. hda_nid_t nid = cfg->inputs[i].pin;
  996. unsigned int defcfg;
  997. defcfg = snd_hda_codec_get_pincfg(codec, nid);
  998. switch (snd_hda_get_input_pin_attr(defcfg)) {
  999. case INPUT_PIN_ATTR_INT:
  1000. if (fixed)
  1001. return; /* already occupied */
  1002. if (cfg->inputs[i].type != AUTO_PIN_MIC)
  1003. return; /* invalid type */
  1004. fixed = nid;
  1005. break;
  1006. case INPUT_PIN_ATTR_UNUSED:
  1007. return; /* invalid entry */
  1008. case INPUT_PIN_ATTR_DOCK:
  1009. if (dock)
  1010. return; /* already occupied */
  1011. if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
  1012. return; /* invalid type */
  1013. dock = nid;
  1014. break;
  1015. default:
  1016. if (ext)
  1017. return; /* already occupied */
  1018. if (cfg->inputs[i].type != AUTO_PIN_MIC)
  1019. return; /* invalid type */
  1020. ext = nid;
  1021. break;
  1022. }
  1023. }
  1024. if (!ext && dock) {
  1025. ext = dock;
  1026. dock = 0;
  1027. }
  1028. if (!ext || !fixed)
  1029. return;
  1030. if (!is_jack_detectable(codec, ext))
  1031. return; /* no unsol support */
  1032. if (dock && !is_jack_detectable(codec, dock))
  1033. return; /* no unsol support */
  1034. /* check imux indices */
  1035. spec->ext_mic_pin = ext;
  1036. spec->int_mic_pin = fixed;
  1037. spec->dock_mic_pin = dock;
  1038. spec->auto_mic = 1;
  1039. if (!alc_auto_mic_check_imux(codec))
  1040. return;
  1041. snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
  1042. ext, fixed, dock);
  1043. spec->unsol_event = alc_sku_unsol_event;
  1044. }
  1045. /* check the availabilities of auto-mute and auto-mic switches */
  1046. static void alc_auto_check_switches(struct hda_codec *codec)
  1047. {
  1048. alc_init_automute(codec);
  1049. alc_init_auto_mic(codec);
  1050. }
  1051. /*
  1052. * Realtek SSID verification
  1053. */
  1054. /* Could be any non-zero and even value. When used as fixup, tells
  1055. * the driver to ignore any present sku defines.
  1056. */
  1057. #define ALC_FIXUP_SKU_IGNORE (2)
  1058. static void alc_fixup_sku_ignore(struct hda_codec *codec,
  1059. const struct hda_fixup *fix, int action)
  1060. {
  1061. struct alc_spec *spec = codec->spec;
  1062. if (action == HDA_FIXUP_ACT_PRE_PROBE) {
  1063. spec->cdefine.fixup = 1;
  1064. spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
  1065. }
  1066. }
  1067. static int alc_auto_parse_customize_define(struct hda_codec *codec)
  1068. {
  1069. unsigned int ass, tmp, i;
  1070. unsigned nid = 0;
  1071. struct alc_spec *spec = codec->spec;
  1072. spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
  1073. if (spec->cdefine.fixup) {
  1074. ass = spec->cdefine.sku_cfg;
  1075. if (ass == ALC_FIXUP_SKU_IGNORE)
  1076. return -1;
  1077. goto do_sku;
  1078. }
  1079. ass = codec->subsystem_id & 0xffff;
  1080. if (ass != codec->bus->pci->subsystem_device && (ass & 1))
  1081. goto do_sku;
  1082. nid = 0x1d;
  1083. if (codec->vendor_id == 0x10ec0260)
  1084. nid = 0x17;
  1085. ass = snd_hda_codec_get_pincfg(codec, nid);
  1086. if (!(ass & 1)) {
  1087. printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
  1088. codec->chip_name, ass);
  1089. return -1;
  1090. }
  1091. /* check sum */
  1092. tmp = 0;
  1093. for (i = 1; i < 16; i++) {
  1094. if ((ass >> i) & 1)
  1095. tmp++;
  1096. }
  1097. if (((ass >> 16) & 0xf) != tmp)
  1098. return -1;
  1099. spec->cdefine.port_connectivity = ass >> 30;
  1100. spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
  1101. spec->cdefine.check_sum = (ass >> 16) & 0xf;
  1102. spec->cdefine.customization = ass >> 8;
  1103. do_sku:
  1104. spec->cdefine.sku_cfg = ass;
  1105. spec->cdefine.external_amp = (ass & 0x38) >> 3;
  1106. spec->cdefine.platform_type = (ass & 0x4) >> 2;
  1107. spec->cdefine.swap = (ass & 0x2) >> 1;
  1108. spec->cdefine.override = ass & 0x1;
  1109. snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
  1110. nid, spec->cdefine.sku_cfg);
  1111. snd_printd("SKU: port_connectivity=0x%x\n",
  1112. spec->cdefine.port_connectivity);
  1113. snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
  1114. snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
  1115. snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
  1116. snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
  1117. snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
  1118. snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
  1119. snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
  1120. return 0;
  1121. }
  1122. /* return true if the given NID is found in the list */
  1123. static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
  1124. {
  1125. return find_idx_in_nid_list(nid, list, nums) >= 0;
  1126. }
  1127. /* check subsystem ID and set up device-specific initialization;
  1128. * return 1 if initialized, 0 if invalid SSID
  1129. */
  1130. /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
  1131. * 31 ~ 16 : Manufacture ID
  1132. * 15 ~ 8 : SKU ID
  1133. * 7 ~ 0 : Assembly ID
  1134. * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
  1135. */
  1136. static int alc_subsystem_id(struct hda_codec *codec,
  1137. hda_nid_t porta, hda_nid_t porte,
  1138. hda_nid_t portd, hda_nid_t porti)
  1139. {
  1140. unsigned int ass, tmp, i;
  1141. unsigned nid;
  1142. struct alc_spec *spec = codec->spec;
  1143. if (spec->cdefine.fixup) {
  1144. ass = spec->cdefine.sku_cfg;
  1145. if (ass == ALC_FIXUP_SKU_IGNORE)
  1146. return 0;
  1147. goto do_sku;
  1148. }
  1149. ass = codec->subsystem_id & 0xffff;
  1150. if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
  1151. goto do_sku;
  1152. /* invalid SSID, check the special NID pin defcfg instead */
  1153. /*
  1154. * 31~30 : port connectivity
  1155. * 29~21 : reserve
  1156. * 20 : PCBEEP input
  1157. * 19~16 : Check sum (15:1)
  1158. * 15~1 : Custom
  1159. * 0 : override
  1160. */
  1161. nid = 0x1d;
  1162. if (codec->vendor_id == 0x10ec0260)
  1163. nid = 0x17;
  1164. ass = snd_hda_codec_get_pincfg(codec, nid);
  1165. snd_printd("realtek: No valid SSID, "
  1166. "checking pincfg 0x%08x for NID 0x%x\n",
  1167. ass, nid);
  1168. if (!(ass & 1))
  1169. return 0;
  1170. if ((ass >> 30) != 1) /* no physical connection */
  1171. return 0;
  1172. /* check sum */
  1173. tmp = 0;
  1174. for (i = 1; i < 16; i++) {
  1175. if ((ass >> i) & 1)
  1176. tmp++;
  1177. }
  1178. if (((ass >> 16) & 0xf) != tmp)
  1179. return 0;
  1180. do_sku:
  1181. snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
  1182. ass & 0xffff, codec->vendor_id);
  1183. /*
  1184. * 0 : override
  1185. * 1 : Swap Jack
  1186. * 2 : 0 --> Desktop, 1 --> Laptop
  1187. * 3~5 : External Amplifier control
  1188. * 7~6 : Reserved
  1189. */
  1190. tmp = (ass & 0x38) >> 3; /* external Amp control */
  1191. switch (tmp) {
  1192. case 1:
  1193. spec->init_amp = ALC_INIT_GPIO1;
  1194. break;
  1195. case 3:
  1196. spec->init_amp = ALC_INIT_GPIO2;
  1197. break;
  1198. case 7:
  1199. spec->init_amp = ALC_INIT_GPIO3;
  1200. break;
  1201. case 5:
  1202. default:
  1203. spec->init_amp = ALC_INIT_DEFAULT;
  1204. break;
  1205. }
  1206. /* is laptop or Desktop and enable the function "Mute internal speaker
  1207. * when the external headphone out jack is plugged"
  1208. */
  1209. if (!(ass & 0x8000))
  1210. return 1;
  1211. /*
  1212. * 10~8 : Jack location
  1213. * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
  1214. * 14~13: Resvered
  1215. * 15 : 1 --> enable the function "Mute internal speaker
  1216. * when the external headphone out jack is plugged"
  1217. */
  1218. if (!spec->autocfg.hp_pins[0] &&
  1219. !(spec->autocfg.line_out_pins[0] &&
  1220. spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
  1221. hda_nid_t nid;
  1222. tmp = (ass >> 11) & 0x3; /* HP to chassis */
  1223. if (tmp == 0)
  1224. nid = porta;
  1225. else if (tmp == 1)
  1226. nid = porte;
  1227. else if (tmp == 2)
  1228. nid = portd;
  1229. else if (tmp == 3)
  1230. nid = porti;
  1231. else
  1232. return 1;
  1233. if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
  1234. spec->autocfg.line_outs))
  1235. return 1;
  1236. spec->autocfg.hp_pins[0] = nid;
  1237. }
  1238. return 1;
  1239. }
  1240. /* Check the validity of ALC subsystem-id
  1241. * ports contains an array of 4 pin NIDs for port-A, E, D and I */
  1242. static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
  1243. {
  1244. if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
  1245. struct alc_spec *spec = codec->spec;
  1246. snd_printd("realtek: "
  1247. "Enable default setup for auto mode as fallback\n");
  1248. spec->init_amp = ALC_INIT_DEFAULT;
  1249. }
  1250. }
  1251. /*
  1252. * COEF access helper functions
  1253. */
  1254. static int alc_read_coef_idx(struct hda_codec *codec,
  1255. unsigned int coef_idx)
  1256. {
  1257. unsigned int val;
  1258. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
  1259. coef_idx);
  1260. val = snd_hda_codec_read(codec, 0x20, 0,
  1261. AC_VERB_GET_PROC_COEF, 0);
  1262. return val;
  1263. }
  1264. static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
  1265. unsigned int coef_val)
  1266. {
  1267. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
  1268. coef_idx);
  1269. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
  1270. coef_val);
  1271. }
  1272. /* a special bypass for COEF 0; read the cached value at the second time */
  1273. static unsigned int alc_get_coef0(struct hda_codec *codec)
  1274. {
  1275. struct alc_spec *spec = codec->spec;
  1276. if (!spec->coef0)
  1277. spec->coef0 = alc_read_coef_idx(codec, 0);
  1278. return spec->coef0;
  1279. }
  1280. /*
  1281. * Digital I/O handling
  1282. */
  1283. /* set right pin controls for digital I/O */
  1284. static void alc_auto_init_digital(struct hda_codec *codec)
  1285. {
  1286. struct alc_spec *spec = codec->spec;
  1287. int i;
  1288. hda_nid_t pin, dac;
  1289. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  1290. pin = spec->autocfg.dig_out_pins[i];
  1291. if (!pin)
  1292. continue;
  1293. snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
  1294. if (!i)
  1295. dac = spec->multiout.dig_out_nid;
  1296. else
  1297. dac = spec->slave_dig_outs[i - 1];
  1298. if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
  1299. continue;
  1300. snd_hda_codec_write(codec, dac, 0,
  1301. AC_VERB_SET_AMP_GAIN_MUTE,
  1302. AMP_OUT_UNMUTE);
  1303. }
  1304. pin = spec->autocfg.dig_in_pin;
  1305. if (pin)
  1306. snd_hda_set_pin_ctl(codec, pin, PIN_IN);
  1307. }
  1308. /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
  1309. static void alc_auto_parse_digital(struct hda_codec *codec)
  1310. {
  1311. struct alc_spec *spec = codec->spec;
  1312. int i, err, nums;
  1313. hda_nid_t dig_nid;
  1314. /* support multiple SPDIFs; the secondary is set up as a slave */
  1315. nums = 0;
  1316. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  1317. hda_nid_t conn[4];
  1318. err = snd_hda_get_connections(codec,
  1319. spec->autocfg.dig_out_pins[i],
  1320. conn, ARRAY_SIZE(conn));
  1321. if (err <= 0)
  1322. continue;
  1323. dig_nid = conn[0]; /* assume the first element is audio-out */
  1324. if (!nums) {
  1325. spec->multiout.dig_out_nid = dig_nid;
  1326. spec->dig_out_type = spec->autocfg.dig_out_type[0];
  1327. } else {
  1328. spec->multiout.slave_dig_outs = spec->slave_dig_outs;
  1329. if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
  1330. break;
  1331. spec->slave_dig_outs[nums - 1] = dig_nid;
  1332. }
  1333. nums++;
  1334. }
  1335. if (spec->autocfg.dig_in_pin) {
  1336. dig_nid = codec->start_nid;
  1337. for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
  1338. unsigned int wcaps = get_wcaps(codec, dig_nid);
  1339. if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
  1340. continue;
  1341. if (!(wcaps & AC_WCAP_DIGITAL))
  1342. continue;
  1343. if (!(wcaps & AC_WCAP_CONN_LIST))
  1344. continue;
  1345. err = get_connection_index(codec, dig_nid,
  1346. spec->autocfg.dig_in_pin);
  1347. if (err >= 0) {
  1348. spec->dig_in_nid = dig_nid;
  1349. break;
  1350. }
  1351. }
  1352. }
  1353. }
  1354. /*
  1355. * capture mixer elements
  1356. */
  1357. static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
  1358. struct snd_ctl_elem_info *uinfo)
  1359. {
  1360. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1361. struct alc_spec *spec = codec->spec;
  1362. unsigned long val;
  1363. int err;
  1364. mutex_lock(&codec->control_mutex);
  1365. if (spec->vol_in_capsrc)
  1366. val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
  1367. else
  1368. val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
  1369. kcontrol->private_value = val;
  1370. err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
  1371. mutex_unlock(&codec->control_mutex);
  1372. return err;
  1373. }
  1374. static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
  1375. unsigned int size, unsigned int __user *tlv)
  1376. {
  1377. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1378. struct alc_spec *spec = codec->spec;
  1379. unsigned long val;
  1380. int err;
  1381. mutex_lock(&codec->control_mutex);
  1382. if (spec->vol_in_capsrc)
  1383. val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
  1384. else
  1385. val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
  1386. kcontrol->private_value = val;
  1387. err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
  1388. mutex_unlock(&codec->control_mutex);
  1389. return err;
  1390. }
  1391. typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
  1392. struct snd_ctl_elem_value *ucontrol);
  1393. static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
  1394. struct snd_ctl_elem_value *ucontrol,
  1395. getput_call_t func, bool is_put)
  1396. {
  1397. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1398. struct alc_spec *spec = codec->spec;
  1399. int i, err = 0;
  1400. mutex_lock(&codec->control_mutex);
  1401. if (is_put && spec->dyn_adc_switch) {
  1402. for (i = 0; i < spec->num_adc_nids; i++) {
  1403. kcontrol->private_value =
  1404. HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
  1405. 3, 0, HDA_INPUT);
  1406. err = func(kcontrol, ucontrol);
  1407. if (err < 0)
  1408. goto error;
  1409. }
  1410. } else {
  1411. i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1412. if (spec->vol_in_capsrc)
  1413. kcontrol->private_value =
  1414. HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
  1415. 3, 0, HDA_OUTPUT);
  1416. else
  1417. kcontrol->private_value =
  1418. HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
  1419. 3, 0, HDA_INPUT);
  1420. err = func(kcontrol, ucontrol);
  1421. }
  1422. if (err >= 0 && is_put)
  1423. alc_inv_dmic_sync(codec, false);
  1424. error:
  1425. mutex_unlock(&codec->control_mutex);
  1426. return err;
  1427. }
  1428. static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
  1429. struct snd_ctl_elem_value *ucontrol)
  1430. {
  1431. return alc_cap_getput_caller(kcontrol, ucontrol,
  1432. snd_hda_mixer_amp_volume_get, false);
  1433. }
  1434. static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
  1435. struct snd_ctl_elem_value *ucontrol)
  1436. {
  1437. return alc_cap_getput_caller(kcontrol, ucontrol,
  1438. snd_hda_mixer_amp_volume_put, true);
  1439. }
  1440. /* capture mixer elements */
  1441. #define alc_cap_sw_info snd_ctl_boolean_stereo_info
  1442. static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
  1443. struct snd_ctl_elem_value *ucontrol)
  1444. {
  1445. return alc_cap_getput_caller(kcontrol, ucontrol,
  1446. snd_hda_mixer_amp_switch_get, false);
  1447. }
  1448. static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
  1449. struct snd_ctl_elem_value *ucontrol)
  1450. {
  1451. return alc_cap_getput_caller(kcontrol, ucontrol,
  1452. snd_hda_mixer_amp_switch_put, true);
  1453. }
  1454. #define _DEFINE_CAPMIX(num) \
  1455. { \
  1456. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1457. .name = "Capture Switch", \
  1458. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  1459. .count = num, \
  1460. .info = alc_cap_sw_info, \
  1461. .get = alc_cap_sw_get, \
  1462. .put = alc_cap_sw_put, \
  1463. }, \
  1464. { \
  1465. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1466. .name = "Capture Volume", \
  1467. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
  1468. SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  1469. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
  1470. .count = num, \
  1471. .info = alc_cap_vol_info, \
  1472. .get = alc_cap_vol_get, \
  1473. .put = alc_cap_vol_put, \
  1474. .tlv = { .c = alc_cap_vol_tlv }, \
  1475. }
  1476. #define _DEFINE_CAPSRC(num) \
  1477. { \
  1478. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1479. /* .name = "Capture Source", */ \
  1480. .name = "Input Source", \
  1481. .count = num, \
  1482. .info = alc_mux_enum_info, \
  1483. .get = alc_mux_enum_get, \
  1484. .put = alc_mux_enum_put, \
  1485. }
  1486. #define DEFINE_CAPMIX(num) \
  1487. static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
  1488. _DEFINE_CAPMIX(num), \
  1489. _DEFINE_CAPSRC(num), \
  1490. { } /* end */ \
  1491. }
  1492. #define DEFINE_CAPMIX_NOSRC(num) \
  1493. static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
  1494. _DEFINE_CAPMIX(num), \
  1495. { } /* end */ \
  1496. }
  1497. /* up to three ADCs */
  1498. DEFINE_CAPMIX(1);
  1499. DEFINE_CAPMIX(2);
  1500. DEFINE_CAPMIX(3);
  1501. DEFINE_CAPMIX_NOSRC(1);
  1502. DEFINE_CAPMIX_NOSRC(2);
  1503. DEFINE_CAPMIX_NOSRC(3);
  1504. /*
  1505. * Inverted digital-mic handling
  1506. *
  1507. * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
  1508. * gives the additional mute only to the right channel of the digital mic
  1509. * capture stream. This is a workaround for avoiding the almost silence
  1510. * by summing the stereo stream from some (known to be ForteMedia)
  1511. * digital mic unit.
  1512. *
  1513. * The logic is to call alc_inv_dmic_sync() after each action (possibly)
  1514. * modifying ADC amp. When the mute flag is set, it mutes the R-channel
  1515. * without caching so that the cache can still keep the original value.
  1516. * The cached value is then restored when the flag is set off or any other
  1517. * than d-mic is used as the current input source.
  1518. */
  1519. static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
  1520. {
  1521. struct alc_spec *spec = codec->spec;
  1522. int i;
  1523. if (!spec->inv_dmic_fixup)
  1524. return;
  1525. if (!spec->inv_dmic_muted && !force)
  1526. return;
  1527. for (i = 0; i < spec->num_adc_nids; i++) {
  1528. int src = spec->dyn_adc_switch ? 0 : i;
  1529. bool dmic_fixup = false;
  1530. hda_nid_t nid;
  1531. int parm, dir, v;
  1532. if (spec->inv_dmic_muted &&
  1533. spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
  1534. dmic_fixup = true;
  1535. if (!dmic_fixup && !force)
  1536. continue;
  1537. if (spec->vol_in_capsrc) {
  1538. nid = spec->capsrc_nids[i];
  1539. parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
  1540. dir = HDA_OUTPUT;
  1541. } else {
  1542. nid = spec->adc_nids[i];
  1543. parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
  1544. dir = HDA_INPUT;
  1545. }
  1546. /* we care only right channel */
  1547. v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
  1548. if (v & 0x80) /* if already muted, we don't need to touch */
  1549. continue;
  1550. if (dmic_fixup) /* add mute for d-mic */
  1551. v |= 0x80;
  1552. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  1553. parm | v);
  1554. }
  1555. }
  1556. static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
  1557. struct snd_ctl_elem_value *ucontrol)
  1558. {
  1559. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1560. struct alc_spec *spec = codec->spec;
  1561. ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
  1562. return 0;
  1563. }
  1564. static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
  1565. struct snd_ctl_elem_value *ucontrol)
  1566. {
  1567. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1568. struct alc_spec *spec = codec->spec;
  1569. unsigned int val = !ucontrol->value.integer.value[0];
  1570. if (val == spec->inv_dmic_muted)
  1571. return 0;
  1572. spec->inv_dmic_muted = val;
  1573. alc_inv_dmic_sync(codec, true);
  1574. return 0;
  1575. }
  1576. static const struct snd_kcontrol_new alc_inv_dmic_sw = {
  1577. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1578. .info = snd_ctl_boolean_mono_info,
  1579. .get = alc_inv_dmic_sw_get,
  1580. .put = alc_inv_dmic_sw_put,
  1581. };
  1582. static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
  1583. {
  1584. struct alc_spec *spec = codec->spec;
  1585. struct snd_kcontrol_new *knew = alc_kcontrol_new(spec);
  1586. if (!knew)
  1587. return -ENOMEM;
  1588. *knew = alc_inv_dmic_sw;
  1589. knew->name = kstrdup("Inverted Internal Mic Capture Switch", GFP_KERNEL);
  1590. if (!knew->name)
  1591. return -ENOMEM;
  1592. spec->inv_dmic_fixup = 1;
  1593. spec->inv_dmic_muted = 0;
  1594. spec->inv_dmic_pin = nid;
  1595. return 0;
  1596. }
  1597. /* typically the digital mic is put at node 0x12 */
  1598. static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
  1599. const struct alc_fixup *fix, int action)
  1600. {
  1601. if (action == ALC_FIXUP_ACT_PROBE)
  1602. alc_add_inv_dmic_mixer(codec, 0x12);
  1603. }
  1604. /*
  1605. * virtual master controls
  1606. */
  1607. /*
  1608. * slave controls for virtual master
  1609. */
  1610. static const char * const alc_slave_pfxs[] = {
  1611. "Front", "Surround", "Center", "LFE", "Side",
  1612. "Headphone", "Speaker", "Mono", "Line Out",
  1613. "CLFE", "Bass Speaker", "PCM",
  1614. NULL,
  1615. };
  1616. /*
  1617. * build control elements
  1618. */
  1619. #define NID_MAPPING (-1)
  1620. #define SUBDEV_SPEAKER_ (0 << 6)
  1621. #define SUBDEV_HP_ (1 << 6)
  1622. #define SUBDEV_LINE_ (2 << 6)
  1623. #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
  1624. #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
  1625. #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
  1626. static void alc_free_kctls(struct hda_codec *codec);
  1627. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  1628. /* additional beep mixers; the actual parameters are overwritten at build */
  1629. static const struct snd_kcontrol_new alc_beep_mixer[] = {
  1630. HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
  1631. HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
  1632. { } /* end */
  1633. };
  1634. #endif
  1635. static int __alc_build_controls(struct hda_codec *codec)
  1636. {
  1637. struct alc_spec *spec = codec->spec;
  1638. struct snd_kcontrol *kctl = NULL;
  1639. const struct snd_kcontrol_new *knew;
  1640. int i, j, err;
  1641. unsigned int u;
  1642. hda_nid_t nid;
  1643. for (i = 0; i < spec->num_mixers; i++) {
  1644. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  1645. if (err < 0)
  1646. return err;
  1647. }
  1648. if (spec->cap_mixer) {
  1649. err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
  1650. if (err < 0)
  1651. return err;
  1652. }
  1653. if (spec->multiout.dig_out_nid) {
  1654. err = snd_hda_create_spdif_out_ctls(codec,
  1655. spec->multiout.dig_out_nid,
  1656. spec->multiout.dig_out_nid);
  1657. if (err < 0)
  1658. return err;
  1659. if (!spec->no_analog) {
  1660. err = snd_hda_create_spdif_share_sw(codec,
  1661. &spec->multiout);
  1662. if (err < 0)
  1663. return err;
  1664. spec->multiout.share_spdif = 1;
  1665. }
  1666. }
  1667. if (spec->dig_in_nid) {
  1668. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  1669. if (err < 0)
  1670. return err;
  1671. }
  1672. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  1673. /* create beep controls if needed */
  1674. if (spec->beep_amp) {
  1675. const struct snd_kcontrol_new *knew;
  1676. for (knew = alc_beep_mixer; knew->name; knew++) {
  1677. struct snd_kcontrol *kctl;
  1678. kctl = snd_ctl_new1(knew, codec);
  1679. if (!kctl)
  1680. return -ENOMEM;
  1681. kctl->private_value = spec->beep_amp;
  1682. err = snd_hda_ctl_add(codec, 0, kctl);
  1683. if (err < 0)
  1684. return err;
  1685. }
  1686. }
  1687. #endif
  1688. /* if we have no master control, let's create it */
  1689. if (!spec->no_analog &&
  1690. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  1691. unsigned int vmaster_tlv[4];
  1692. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  1693. HDA_OUTPUT, vmaster_tlv);
  1694. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  1695. vmaster_tlv, alc_slave_pfxs,
  1696. "Playback Volume");
  1697. if (err < 0)
  1698. return err;
  1699. }
  1700. if (!spec->no_analog &&
  1701. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  1702. err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
  1703. NULL, alc_slave_pfxs,
  1704. "Playback Switch",
  1705. true, &spec->vmaster_mute.sw_kctl);
  1706. if (err < 0)
  1707. return err;
  1708. }
  1709. /* assign Capture Source enums to NID */
  1710. if (spec->capsrc_nids || spec->adc_nids) {
  1711. kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
  1712. if (!kctl)
  1713. kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
  1714. for (i = 0; kctl && i < kctl->count; i++) {
  1715. err = snd_hda_add_nid(codec, kctl, i,
  1716. get_capsrc(spec, i));
  1717. if (err < 0)
  1718. return err;
  1719. }
  1720. }
  1721. if (spec->cap_mixer && spec->adc_nids) {
  1722. const char *kname = kctl ? kctl->id.name : NULL;
  1723. for (knew = spec->cap_mixer; knew->name; knew++) {
  1724. if (kname && strcmp(knew->name, kname) == 0)
  1725. continue;
  1726. kctl = snd_hda_find_mixer_ctl(codec, knew->name);
  1727. for (i = 0; kctl && i < kctl->count; i++) {
  1728. err = snd_hda_add_nid(codec, kctl, i,
  1729. spec->adc_nids[i]);
  1730. if (err < 0)
  1731. return err;
  1732. }
  1733. }
  1734. }
  1735. /* other nid->control mapping */
  1736. for (i = 0; i < spec->num_mixers; i++) {
  1737. for (knew = spec->mixers[i]; knew->name; knew++) {
  1738. if (knew->iface != NID_MAPPING)
  1739. continue;
  1740. kctl = snd_hda_find_mixer_ctl(codec, knew->name);
  1741. if (kctl == NULL)
  1742. continue;
  1743. u = knew->subdevice;
  1744. for (j = 0; j < 4; j++, u >>= 8) {
  1745. nid = u & 0x3f;
  1746. if (nid == 0)
  1747. continue;
  1748. switch (u & 0xc0) {
  1749. case SUBDEV_SPEAKER_:
  1750. nid = spec->autocfg.speaker_pins[nid];
  1751. break;
  1752. case SUBDEV_LINE_:
  1753. nid = spec->autocfg.line_out_pins[nid];
  1754. break;
  1755. case SUBDEV_HP_:
  1756. nid = spec->autocfg.hp_pins[nid];
  1757. break;
  1758. default:
  1759. continue;
  1760. }
  1761. err = snd_hda_add_nid(codec, kctl, 0, nid);
  1762. if (err < 0)
  1763. return err;
  1764. }
  1765. u = knew->private_value;
  1766. for (j = 0; j < 4; j++, u >>= 8) {
  1767. nid = u & 0xff;
  1768. if (nid == 0)
  1769. continue;
  1770. err = snd_hda_add_nid(codec, kctl, 0, nid);
  1771. if (err < 0)
  1772. return err;
  1773. }
  1774. }
  1775. }
  1776. alc_free_kctls(codec); /* no longer needed */
  1777. return 0;
  1778. }
  1779. static int alc_build_controls(struct hda_codec *codec)
  1780. {
  1781. struct alc_spec *spec = codec->spec;
  1782. int err = __alc_build_controls(codec);
  1783. if (err < 0)
  1784. return err;
  1785. err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
  1786. if (err < 0)
  1787. return err;
  1788. alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
  1789. return 0;
  1790. }
  1791. /*
  1792. * Common callbacks
  1793. */
  1794. static void alc_init_special_input_src(struct hda_codec *codec);
  1795. static void alc_auto_init_std(struct hda_codec *codec);
  1796. static int alc_init(struct hda_codec *codec)
  1797. {
  1798. struct alc_spec *spec = codec->spec;
  1799. if (spec->init_hook)
  1800. spec->init_hook(codec);
  1801. alc_fix_pll(codec);
  1802. alc_auto_init_amp(codec, spec->init_amp);
  1803. snd_hda_gen_apply_verbs(codec);
  1804. alc_init_special_input_src(codec);
  1805. alc_auto_init_std(codec);
  1806. alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
  1807. snd_hda_jack_report_sync(codec);
  1808. hda_call_check_power_status(codec, 0x01);
  1809. return 0;
  1810. }
  1811. static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
  1812. {
  1813. struct alc_spec *spec = codec->spec;
  1814. if (spec->unsol_event)
  1815. spec->unsol_event(codec, res);
  1816. }
  1817. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1818. static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  1819. {
  1820. struct alc_spec *spec = codec->spec;
  1821. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  1822. }
  1823. #endif
  1824. /*
  1825. * Analog playback callbacks
  1826. */
  1827. static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1828. struct hda_codec *codec,
  1829. struct snd_pcm_substream *substream)
  1830. {
  1831. struct alc_spec *spec = codec->spec;
  1832. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  1833. hinfo);
  1834. }
  1835. static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1836. struct hda_codec *codec,
  1837. unsigned int stream_tag,
  1838. unsigned int format,
  1839. struct snd_pcm_substream *substream)
  1840. {
  1841. struct alc_spec *spec = codec->spec;
  1842. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  1843. stream_tag, format, substream);
  1844. }
  1845. static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1846. struct hda_codec *codec,
  1847. struct snd_pcm_substream *substream)
  1848. {
  1849. struct alc_spec *spec = codec->spec;
  1850. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  1851. }
  1852. /*
  1853. * Digital out
  1854. */
  1855. static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1856. struct hda_codec *codec,
  1857. struct snd_pcm_substream *substream)
  1858. {
  1859. struct alc_spec *spec = codec->spec;
  1860. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1861. }
  1862. static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1863. struct hda_codec *codec,
  1864. unsigned int stream_tag,
  1865. unsigned int format,
  1866. struct snd_pcm_substream *substream)
  1867. {
  1868. struct alc_spec *spec = codec->spec;
  1869. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1870. stream_tag, format, substream);
  1871. }
  1872. static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1873. struct hda_codec *codec,
  1874. struct snd_pcm_substream *substream)
  1875. {
  1876. struct alc_spec *spec = codec->spec;
  1877. return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  1878. }
  1879. static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1880. struct hda_codec *codec,
  1881. struct snd_pcm_substream *substream)
  1882. {
  1883. struct alc_spec *spec = codec->spec;
  1884. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1885. }
  1886. /*
  1887. * Analog capture
  1888. */
  1889. static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1890. struct hda_codec *codec,
  1891. unsigned int stream_tag,
  1892. unsigned int format,
  1893. struct snd_pcm_substream *substream)
  1894. {
  1895. struct alc_spec *spec = codec->spec;
  1896. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
  1897. stream_tag, 0, format);
  1898. return 0;
  1899. }
  1900. static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1901. struct hda_codec *codec,
  1902. struct snd_pcm_substream *substream)
  1903. {
  1904. struct alc_spec *spec = codec->spec;
  1905. snd_hda_codec_cleanup_stream(codec,
  1906. spec->adc_nids[substream->number + 1]);
  1907. return 0;
  1908. }
  1909. /* analog capture with dynamic dual-adc changes */
  1910. static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1911. struct hda_codec *codec,
  1912. unsigned int stream_tag,
  1913. unsigned int format,
  1914. struct snd_pcm_substream *substream)
  1915. {
  1916. struct alc_spec *spec = codec->spec;
  1917. spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
  1918. spec->cur_adc_stream_tag = stream_tag;
  1919. spec->cur_adc_format = format;
  1920. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  1921. return 0;
  1922. }
  1923. static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1924. struct hda_codec *codec,
  1925. struct snd_pcm_substream *substream)
  1926. {
  1927. struct alc_spec *spec = codec->spec;
  1928. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1929. spec->cur_adc = 0;
  1930. return 0;
  1931. }
  1932. static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
  1933. .substreams = 1,
  1934. .channels_min = 2,
  1935. .channels_max = 2,
  1936. .nid = 0, /* fill later */
  1937. .ops = {
  1938. .prepare = dyn_adc_capture_pcm_prepare,
  1939. .cleanup = dyn_adc_capture_pcm_cleanup
  1940. },
  1941. };
  1942. /*
  1943. */
  1944. static const struct hda_pcm_stream alc_pcm_analog_playback = {
  1945. .substreams = 1,
  1946. .channels_min = 2,
  1947. .channels_max = 8,
  1948. /* NID is set in alc_build_pcms */
  1949. .ops = {
  1950. .open = alc_playback_pcm_open,
  1951. .prepare = alc_playback_pcm_prepare,
  1952. .cleanup = alc_playback_pcm_cleanup
  1953. },
  1954. };
  1955. static const struct hda_pcm_stream alc_pcm_analog_capture = {
  1956. .substreams = 1,
  1957. .channels_min = 2,
  1958. .channels_max = 2,
  1959. /* NID is set in alc_build_pcms */
  1960. };
  1961. static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
  1962. .substreams = 1,
  1963. .channels_min = 2,
  1964. .channels_max = 2,
  1965. /* NID is set in alc_build_pcms */
  1966. };
  1967. static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
  1968. .substreams = 2, /* can be overridden */
  1969. .channels_min = 2,
  1970. .channels_max = 2,
  1971. /* NID is set in alc_build_pcms */
  1972. .ops = {
  1973. .prepare = alc_alt_capture_pcm_prepare,
  1974. .cleanup = alc_alt_capture_pcm_cleanup
  1975. },
  1976. };
  1977. static const struct hda_pcm_stream alc_pcm_digital_playback = {
  1978. .substreams = 1,
  1979. .channels_min = 2,
  1980. .channels_max = 2,
  1981. /* NID is set in alc_build_pcms */
  1982. .ops = {
  1983. .open = alc_dig_playback_pcm_open,
  1984. .close = alc_dig_playback_pcm_close,
  1985. .prepare = alc_dig_playback_pcm_prepare,
  1986. .cleanup = alc_dig_playback_pcm_cleanup
  1987. },
  1988. };
  1989. static const struct hda_pcm_stream alc_pcm_digital_capture = {
  1990. .substreams = 1,
  1991. .channels_min = 2,
  1992. .channels_max = 2,
  1993. /* NID is set in alc_build_pcms */
  1994. };
  1995. /* Used by alc_build_pcms to flag that a PCM has no playback stream */
  1996. static const struct hda_pcm_stream alc_pcm_null_stream = {
  1997. .substreams = 0,
  1998. .channels_min = 0,
  1999. .channels_max = 0,
  2000. };
  2001. static int alc_build_pcms(struct hda_codec *codec)
  2002. {
  2003. struct alc_spec *spec = codec->spec;
  2004. struct hda_pcm *info = spec->pcm_rec;
  2005. const struct hda_pcm_stream *p;
  2006. bool have_multi_adcs;
  2007. int i;
  2008. codec->num_pcms = 1;
  2009. codec->pcm_info = info;
  2010. if (spec->no_analog)
  2011. goto skip_analog;
  2012. snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
  2013. "%s Analog", codec->chip_name);
  2014. info->name = spec->stream_name_analog;
  2015. if (spec->multiout.num_dacs > 0) {
  2016. p = spec->stream_analog_playback;
  2017. if (!p)
  2018. p = &alc_pcm_analog_playback;
  2019. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
  2020. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  2021. }
  2022. if (spec->adc_nids) {
  2023. p = spec->stream_analog_capture;
  2024. if (!p) {
  2025. if (spec->dyn_adc_switch)
  2026. p = &dyn_adc_pcm_analog_capture;
  2027. else
  2028. p = &alc_pcm_analog_capture;
  2029. }
  2030. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
  2031. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  2032. }
  2033. if (spec->channel_mode) {
  2034. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
  2035. for (i = 0; i < spec->num_channel_mode; i++) {
  2036. if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
  2037. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
  2038. }
  2039. }
  2040. }
  2041. skip_analog:
  2042. /* SPDIF for stream index #1 */
  2043. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  2044. snprintf(spec->stream_name_digital,
  2045. sizeof(spec->stream_name_digital),
  2046. "%s Digital", codec->chip_name);
  2047. codec->num_pcms = 2;
  2048. codec->slave_dig_outs = spec->multiout.slave_dig_outs;
  2049. info = spec->pcm_rec + 1;
  2050. info->name = spec->stream_name_digital;
  2051. if (spec->dig_out_type)
  2052. info->pcm_type = spec->dig_out_type;
  2053. else
  2054. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  2055. if (spec->multiout.dig_out_nid) {
  2056. p = spec->stream_digital_playback;
  2057. if (!p)
  2058. p = &alc_pcm_digital_playback;
  2059. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
  2060. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  2061. }
  2062. if (spec->dig_in_nid) {
  2063. p = spec->stream_digital_capture;
  2064. if (!p)
  2065. p = &alc_pcm_digital_capture;
  2066. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
  2067. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  2068. }
  2069. /* FIXME: do we need this for all Realtek codec models? */
  2070. codec->spdif_status_reset = 1;
  2071. }
  2072. if (spec->no_analog)
  2073. return 0;
  2074. /* If the use of more than one ADC is requested for the current
  2075. * model, configure a second analog capture-only PCM.
  2076. */
  2077. have_multi_adcs = (spec->num_adc_nids > 1) &&
  2078. !spec->dyn_adc_switch && !spec->auto_mic &&
  2079. (!spec->input_mux || spec->input_mux->num_items > 1);
  2080. /* Additional Analaog capture for index #2 */
  2081. if (spec->alt_dac_nid || have_multi_adcs) {
  2082. codec->num_pcms = 3;
  2083. info = spec->pcm_rec + 2;
  2084. info->name = spec->stream_name_analog;
  2085. if (spec->alt_dac_nid) {
  2086. p = spec->stream_analog_alt_playback;
  2087. if (!p)
  2088. p = &alc_pcm_analog_alt_playback;
  2089. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
  2090. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  2091. spec->alt_dac_nid;
  2092. } else {
  2093. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  2094. alc_pcm_null_stream;
  2095. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
  2096. }
  2097. if (have_multi_adcs) {
  2098. p = spec->stream_analog_alt_capture;
  2099. if (!p)
  2100. p = &alc_pcm_analog_alt_capture;
  2101. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
  2102. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  2103. spec->adc_nids[1];
  2104. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  2105. spec->num_adc_nids - 1;
  2106. } else {
  2107. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  2108. alc_pcm_null_stream;
  2109. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
  2110. }
  2111. }
  2112. return 0;
  2113. }
  2114. static inline void alc_shutup(struct hda_codec *codec)
  2115. {
  2116. struct alc_spec *spec = codec->spec;
  2117. if (spec && spec->shutup)
  2118. spec->shutup(codec);
  2119. snd_hda_shutup_pins(codec);
  2120. }
  2121. static void alc_free_kctls(struct hda_codec *codec)
  2122. {
  2123. struct alc_spec *spec = codec->spec;
  2124. if (spec->kctls.list) {
  2125. struct snd_kcontrol_new *kctl = spec->kctls.list;
  2126. int i;
  2127. for (i = 0; i < spec->kctls.used; i++)
  2128. kfree(kctl[i].name);
  2129. }
  2130. snd_array_free(&spec->kctls);
  2131. }
  2132. static void alc_free_bind_ctls(struct hda_codec *codec)
  2133. {
  2134. struct alc_spec *spec = codec->spec;
  2135. if (spec->bind_ctls.list) {
  2136. struct hda_bind_ctls **ctl = spec->bind_ctls.list;
  2137. int i;
  2138. for (i = 0; i < spec->bind_ctls.used; i++)
  2139. kfree(ctl[i]);
  2140. }
  2141. snd_array_free(&spec->bind_ctls);
  2142. }
  2143. static void alc_free(struct hda_codec *codec)
  2144. {
  2145. struct alc_spec *spec = codec->spec;
  2146. if (!spec)
  2147. return;
  2148. alc_shutup(codec);
  2149. alc_free_kctls(codec);
  2150. alc_free_bind_ctls(codec);
  2151. kfree(spec);
  2152. snd_hda_detach_beep_device(codec);
  2153. }
  2154. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2155. static void alc_power_eapd(struct hda_codec *codec)
  2156. {
  2157. alc_auto_setup_eapd(codec, false);
  2158. }
  2159. static int alc_suspend(struct hda_codec *codec, pm_message_t state)
  2160. {
  2161. struct alc_spec *spec = codec->spec;
  2162. alc_shutup(codec);
  2163. if (spec && spec->power_hook)
  2164. spec->power_hook(codec);
  2165. return 0;
  2166. }
  2167. #endif
  2168. #ifdef CONFIG_PM
  2169. static int alc_resume(struct hda_codec *codec)
  2170. {
  2171. msleep(150); /* to avoid pop noise */
  2172. codec->patch_ops.init(codec);
  2173. snd_hda_codec_resume_amp(codec);
  2174. snd_hda_codec_resume_cache(codec);
  2175. alc_inv_dmic_sync(codec, true);
  2176. hda_call_check_power_status(codec, 0x01);
  2177. return 0;
  2178. }
  2179. #endif
  2180. /*
  2181. */
  2182. static const struct hda_codec_ops alc_patch_ops = {
  2183. .build_controls = alc_build_controls,
  2184. .build_pcms = alc_build_pcms,
  2185. .init = alc_init,
  2186. .free = alc_free,
  2187. .unsol_event = alc_unsol_event,
  2188. #ifdef CONFIG_PM
  2189. .resume = alc_resume,
  2190. #endif
  2191. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2192. .suspend = alc_suspend,
  2193. .check_power_status = alc_check_power_status,
  2194. #endif
  2195. .reboot_notify = alc_shutup,
  2196. };
  2197. /* replace the codec chip_name with the given string */
  2198. static int alc_codec_rename(struct hda_codec *codec, const char *name)
  2199. {
  2200. kfree(codec->chip_name);
  2201. codec->chip_name = kstrdup(name, GFP_KERNEL);
  2202. if (!codec->chip_name) {
  2203. alc_free(codec);
  2204. return -ENOMEM;
  2205. }
  2206. return 0;
  2207. }
  2208. /*
  2209. * Rename codecs appropriately from COEF value
  2210. */
  2211. struct alc_codec_rename_table {
  2212. unsigned int vendor_id;
  2213. unsigned short coef_mask;
  2214. unsigned short coef_bits;
  2215. const char *name;
  2216. };
  2217. static struct alc_codec_rename_table rename_tbl[] = {
  2218. { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
  2219. { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
  2220. { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
  2221. { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
  2222. { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
  2223. { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
  2224. { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
  2225. { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
  2226. { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
  2227. { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
  2228. { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
  2229. { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
  2230. { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
  2231. { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
  2232. { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
  2233. { } /* terminator */
  2234. };
  2235. static int alc_codec_rename_from_preset(struct hda_codec *codec)
  2236. {
  2237. const struct alc_codec_rename_table *p;
  2238. for (p = rename_tbl; p->vendor_id; p++) {
  2239. if (p->vendor_id != codec->vendor_id)
  2240. continue;
  2241. if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
  2242. return alc_codec_rename(codec, p->name);
  2243. }
  2244. return 0;
  2245. }
  2246. /*
  2247. * Automatic parse of I/O pins from the BIOS configuration
  2248. */
  2249. enum {
  2250. ALC_CTL_WIDGET_VOL,
  2251. ALC_CTL_WIDGET_MUTE,
  2252. ALC_CTL_BIND_MUTE,
  2253. ALC_CTL_BIND_VOL,
  2254. ALC_CTL_BIND_SW,
  2255. };
  2256. static const struct snd_kcontrol_new alc_control_templates[] = {
  2257. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  2258. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  2259. HDA_BIND_MUTE(NULL, 0, 0, 0),
  2260. HDA_BIND_VOL(NULL, 0),
  2261. HDA_BIND_SW(NULL, 0),
  2262. };
  2263. /* add dynamic controls */
  2264. static int add_control(struct alc_spec *spec, int type, const char *name,
  2265. int cidx, unsigned long val)
  2266. {
  2267. struct snd_kcontrol_new *knew;
  2268. knew = alc_kcontrol_new(spec);
  2269. if (!knew)
  2270. return -ENOMEM;
  2271. *knew = alc_control_templates[type];
  2272. knew->name = kstrdup(name, GFP_KERNEL);
  2273. if (!knew->name)
  2274. return -ENOMEM;
  2275. knew->index = cidx;
  2276. if (get_amp_nid_(val))
  2277. knew->subdevice = HDA_SUBDEV_AMP_FLAG;
  2278. knew->private_value = val;
  2279. return 0;
  2280. }
  2281. static int add_control_with_pfx(struct alc_spec *spec, int type,
  2282. const char *pfx, const char *dir,
  2283. const char *sfx, int cidx, unsigned long val)
  2284. {
  2285. char name[32];
  2286. snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
  2287. return add_control(spec, type, name, cidx, val);
  2288. }
  2289. #define add_pb_vol_ctrl(spec, type, pfx, val) \
  2290. add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
  2291. #define add_pb_sw_ctrl(spec, type, pfx, val) \
  2292. add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
  2293. #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
  2294. add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
  2295. #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
  2296. add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
  2297. static const char * const channel_name[4] = {
  2298. "Front", "Surround", "CLFE", "Side"
  2299. };
  2300. static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
  2301. bool can_be_master, int *index)
  2302. {
  2303. struct auto_pin_cfg *cfg = &spec->autocfg;
  2304. *index = 0;
  2305. if (cfg->line_outs == 1 && !spec->multi_ios &&
  2306. !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
  2307. return "Master";
  2308. switch (cfg->line_out_type) {
  2309. case AUTO_PIN_SPEAKER_OUT:
  2310. if (cfg->line_outs == 1)
  2311. return "Speaker";
  2312. if (cfg->line_outs == 2)
  2313. return ch ? "Bass Speaker" : "Speaker";
  2314. break;
  2315. case AUTO_PIN_HP_OUT:
  2316. /* for multi-io case, only the primary out */
  2317. if (ch && spec->multi_ios)
  2318. break;
  2319. *index = ch;
  2320. return "Headphone";
  2321. default:
  2322. if (cfg->line_outs == 1 && !spec->multi_ios)
  2323. return "PCM";
  2324. break;
  2325. }
  2326. if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
  2327. return "PCM";
  2328. return channel_name[ch];
  2329. }
  2330. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2331. /* add the powersave loopback-list entry */
  2332. static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
  2333. {
  2334. struct hda_amp_list *list;
  2335. if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
  2336. return;
  2337. list = spec->loopback_list + spec->num_loopbacks;
  2338. list->nid = mix;
  2339. list->dir = HDA_INPUT;
  2340. list->idx = idx;
  2341. spec->num_loopbacks++;
  2342. spec->loopback.amplist = spec->loopback_list;
  2343. }
  2344. #else
  2345. #define add_loopback_list(spec, mix, idx) /* NOP */
  2346. #endif
  2347. /* create input playback/capture controls for the given pin */
  2348. static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
  2349. const char *ctlname, int ctlidx,
  2350. int idx, hda_nid_t mix_nid)
  2351. {
  2352. int err;
  2353. err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
  2354. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  2355. if (err < 0)
  2356. return err;
  2357. err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
  2358. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  2359. if (err < 0)
  2360. return err;
  2361. add_loopback_list(spec, mix_nid, idx);
  2362. return 0;
  2363. }
  2364. static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
  2365. {
  2366. unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
  2367. return (pincap & AC_PINCAP_IN) != 0;
  2368. }
  2369. /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
  2370. static int alc_auto_fill_adc_caps(struct hda_codec *codec)
  2371. {
  2372. struct alc_spec *spec = codec->spec;
  2373. hda_nid_t nid;
  2374. hda_nid_t *adc_nids = spec->private_adc_nids;
  2375. hda_nid_t *cap_nids = spec->private_capsrc_nids;
  2376. int max_nums = ARRAY_SIZE(spec->private_adc_nids);
  2377. int i, nums = 0;
  2378. nid = codec->start_nid;
  2379. for (i = 0; i < codec->num_nodes; i++, nid++) {
  2380. hda_nid_t src;
  2381. unsigned int caps = get_wcaps(codec, nid);
  2382. int type = get_wcaps_type(caps);
  2383. if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
  2384. continue;
  2385. adc_nids[nums] = nid;
  2386. cap_nids[nums] = nid;
  2387. src = nid;
  2388. for (;;) {
  2389. int n;
  2390. type = get_wcaps_type(get_wcaps(codec, src));
  2391. if (type == AC_WID_PIN)
  2392. break;
  2393. if (type == AC_WID_AUD_SEL) {
  2394. cap_nids[nums] = src;
  2395. break;
  2396. }
  2397. n = snd_hda_get_num_conns(codec, src);
  2398. if (n > 1) {
  2399. cap_nids[nums] = src;
  2400. break;
  2401. } else if (n != 1)
  2402. break;
  2403. if (snd_hda_get_connections(codec, src, &src, 1) != 1)
  2404. break;
  2405. }
  2406. if (++nums >= max_nums)
  2407. break;
  2408. }
  2409. spec->adc_nids = spec->private_adc_nids;
  2410. spec->capsrc_nids = spec->private_capsrc_nids;
  2411. spec->num_adc_nids = nums;
  2412. return nums;
  2413. }
  2414. /* create playback/capture controls for input pins */
  2415. static int alc_auto_create_input_ctls(struct hda_codec *codec)
  2416. {
  2417. struct alc_spec *spec = codec->spec;
  2418. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2419. hda_nid_t mixer = spec->mixer_nid;
  2420. struct hda_input_mux *imux = &spec->private_imux[0];
  2421. int num_adcs;
  2422. int i, c, err, idx, type_idx = 0;
  2423. const char *prev_label = NULL;
  2424. num_adcs = alc_auto_fill_adc_caps(codec);
  2425. if (num_adcs < 0)
  2426. return 0;
  2427. for (i = 0; i < cfg->num_inputs; i++) {
  2428. hda_nid_t pin;
  2429. const char *label;
  2430. pin = cfg->inputs[i].pin;
  2431. if (!alc_is_input_pin(codec, pin))
  2432. continue;
  2433. label = hda_get_autocfg_input_label(codec, cfg, i);
  2434. if (spec->shared_mic_hp && !strcmp(label, "Misc"))
  2435. label = "Headphone Mic";
  2436. if (prev_label && !strcmp(label, prev_label))
  2437. type_idx++;
  2438. else
  2439. type_idx = 0;
  2440. prev_label = label;
  2441. if (mixer) {
  2442. idx = get_connection_index(codec, mixer, pin);
  2443. if (idx >= 0) {
  2444. err = new_analog_input(spec, pin,
  2445. label, type_idx,
  2446. idx, mixer);
  2447. if (err < 0)
  2448. return err;
  2449. }
  2450. }
  2451. for (c = 0; c < num_adcs; c++) {
  2452. hda_nid_t cap = get_capsrc(spec, c);
  2453. idx = get_connection_index(codec, cap, pin);
  2454. if (idx >= 0) {
  2455. spec->imux_pins[imux->num_items] = pin;
  2456. snd_hda_add_imux_item(imux, label, idx, NULL);
  2457. break;
  2458. }
  2459. }
  2460. }
  2461. spec->num_mux_defs = 1;
  2462. spec->input_mux = imux;
  2463. return 0;
  2464. }
  2465. /* create a shared input with the headphone out */
  2466. static int alc_auto_create_shared_input(struct hda_codec *codec)
  2467. {
  2468. struct alc_spec *spec = codec->spec;
  2469. struct auto_pin_cfg *cfg = &spec->autocfg;
  2470. unsigned int defcfg;
  2471. hda_nid_t nid;
  2472. /* only one internal input pin? */
  2473. if (cfg->num_inputs != 1)
  2474. return 0;
  2475. defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
  2476. if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
  2477. return 0;
  2478. if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
  2479. nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
  2480. else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
  2481. nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
  2482. else
  2483. return 0; /* both not available */
  2484. if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
  2485. return 0; /* no input */
  2486. cfg->inputs[1].pin = nid;
  2487. cfg->inputs[1].type = AUTO_PIN_MIC;
  2488. cfg->num_inputs = 2;
  2489. spec->shared_mic_hp = 1;
  2490. snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
  2491. return 0;
  2492. }
  2493. static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
  2494. unsigned int pin_type)
  2495. {
  2496. snd_hda_set_pin_ctl(codec, nid, pin_type);
  2497. /* unmute pin */
  2498. if (nid_has_mute(codec, nid, HDA_OUTPUT))
  2499. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2500. AMP_OUT_UNMUTE);
  2501. }
  2502. static int get_pin_type(int line_out_type)
  2503. {
  2504. if (line_out_type == AUTO_PIN_HP_OUT)
  2505. return PIN_HP;
  2506. else
  2507. return PIN_OUT;
  2508. }
  2509. static void alc_auto_init_analog_input(struct hda_codec *codec)
  2510. {
  2511. struct alc_spec *spec = codec->spec;
  2512. struct auto_pin_cfg *cfg = &spec->autocfg;
  2513. int i;
  2514. for (i = 0; i < cfg->num_inputs; i++) {
  2515. hda_nid_t nid = cfg->inputs[i].pin;
  2516. if (alc_is_input_pin(codec, nid)) {
  2517. alc_set_input_pin(codec, nid, cfg->inputs[i].type);
  2518. if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
  2519. snd_hda_codec_write(codec, nid, 0,
  2520. AC_VERB_SET_AMP_GAIN_MUTE,
  2521. AMP_OUT_MUTE);
  2522. }
  2523. }
  2524. /* mute all loopback inputs */
  2525. if (spec->mixer_nid) {
  2526. int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
  2527. for (i = 0; i < nums; i++)
  2528. snd_hda_codec_write(codec, spec->mixer_nid, 0,
  2529. AC_VERB_SET_AMP_GAIN_MUTE,
  2530. AMP_IN_MUTE(i));
  2531. }
  2532. }
  2533. /* convert from MIX nid to DAC */
  2534. static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
  2535. {
  2536. hda_nid_t list[5];
  2537. int i, num;
  2538. if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
  2539. return nid;
  2540. num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
  2541. for (i = 0; i < num; i++) {
  2542. if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
  2543. return list[i];
  2544. }
  2545. return 0;
  2546. }
  2547. /* go down to the selector widget before the mixer */
  2548. static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
  2549. {
  2550. hda_nid_t srcs[5];
  2551. int num = snd_hda_get_connections(codec, pin, srcs,
  2552. ARRAY_SIZE(srcs));
  2553. if (num != 1 ||
  2554. get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
  2555. return pin;
  2556. return srcs[0];
  2557. }
  2558. /* get MIX nid connected to the given pin targeted to DAC */
  2559. static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
  2560. hda_nid_t dac)
  2561. {
  2562. hda_nid_t mix[5];
  2563. int i, num;
  2564. pin = alc_go_down_to_selector(codec, pin);
  2565. num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
  2566. for (i = 0; i < num; i++) {
  2567. if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
  2568. return mix[i];
  2569. }
  2570. return 0;
  2571. }
  2572. /* select the connection from pin to DAC if needed */
  2573. static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
  2574. hda_nid_t dac)
  2575. {
  2576. hda_nid_t mix[5];
  2577. int i, num;
  2578. pin = alc_go_down_to_selector(codec, pin);
  2579. num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
  2580. if (num < 2)
  2581. return 0;
  2582. for (i = 0; i < num; i++) {
  2583. if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
  2584. snd_hda_codec_update_cache(codec, pin, 0,
  2585. AC_VERB_SET_CONNECT_SEL, i);
  2586. return 0;
  2587. }
  2588. }
  2589. return 0;
  2590. }
  2591. static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
  2592. {
  2593. struct alc_spec *spec = codec->spec;
  2594. int i;
  2595. if (found_in_nid_list(nid, spec->multiout.dac_nids,
  2596. ARRAY_SIZE(spec->private_dac_nids)) ||
  2597. found_in_nid_list(nid, spec->multiout.hp_out_nid,
  2598. ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
  2599. found_in_nid_list(nid, spec->multiout.extra_out_nid,
  2600. ARRAY_SIZE(spec->multiout.extra_out_nid)))
  2601. return true;
  2602. for (i = 0; i < spec->multi_ios; i++) {
  2603. if (spec->multi_io[i].dac == nid)
  2604. return true;
  2605. }
  2606. return false;
  2607. }
  2608. /* look for an empty DAC slot */
  2609. static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
  2610. {
  2611. hda_nid_t srcs[5];
  2612. int i, num;
  2613. pin = alc_go_down_to_selector(codec, pin);
  2614. num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
  2615. for (i = 0; i < num; i++) {
  2616. hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
  2617. if (!nid)
  2618. continue;
  2619. if (!alc_is_dac_already_used(codec, nid))
  2620. return nid;
  2621. }
  2622. return 0;
  2623. }
  2624. /* check whether the DAC is reachable from the pin */
  2625. static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
  2626. hda_nid_t pin, hda_nid_t dac)
  2627. {
  2628. hda_nid_t srcs[5];
  2629. int i, num;
  2630. if (!pin || !dac)
  2631. return false;
  2632. pin = alc_go_down_to_selector(codec, pin);
  2633. num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
  2634. for (i = 0; i < num; i++) {
  2635. hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
  2636. if (nid == dac)
  2637. return true;
  2638. }
  2639. return false;
  2640. }
  2641. static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
  2642. {
  2643. struct alc_spec *spec = codec->spec;
  2644. hda_nid_t sel = alc_go_down_to_selector(codec, pin);
  2645. hda_nid_t nid, nid_found, srcs[5];
  2646. int i, num = snd_hda_get_connections(codec, sel, srcs,
  2647. ARRAY_SIZE(srcs));
  2648. if (num == 1)
  2649. return alc_auto_look_for_dac(codec, pin);
  2650. nid_found = 0;
  2651. for (i = 0; i < num; i++) {
  2652. if (srcs[i] == spec->mixer_nid)
  2653. continue;
  2654. nid = alc_auto_mix_to_dac(codec, srcs[i]);
  2655. if (nid && !alc_is_dac_already_used(codec, nid)) {
  2656. if (nid_found)
  2657. return 0;
  2658. nid_found = nid;
  2659. }
  2660. }
  2661. return nid_found;
  2662. }
  2663. /* mark up volume and mute control NIDs: used during badness parsing and
  2664. * at creating actual controls
  2665. */
  2666. static inline unsigned int get_ctl_pos(unsigned int data)
  2667. {
  2668. hda_nid_t nid = get_amp_nid_(data);
  2669. unsigned int dir;
  2670. if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
  2671. return 0;
  2672. dir = get_amp_direction_(data);
  2673. return (nid << 1) | dir;
  2674. }
  2675. #define is_ctl_used(bits, data) \
  2676. test_bit(get_ctl_pos(data), bits)
  2677. #define mark_ctl_usage(bits, data) \
  2678. set_bit(get_ctl_pos(data), bits)
  2679. static void clear_vol_marks(struct hda_codec *codec)
  2680. {
  2681. struct alc_spec *spec = codec->spec;
  2682. memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
  2683. memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
  2684. }
  2685. /* badness definition */
  2686. enum {
  2687. /* No primary DAC is found for the main output */
  2688. BAD_NO_PRIMARY_DAC = 0x10000,
  2689. /* No DAC is found for the extra output */
  2690. BAD_NO_DAC = 0x4000,
  2691. /* No possible multi-ios */
  2692. BAD_MULTI_IO = 0x103,
  2693. /* No individual DAC for extra output */
  2694. BAD_NO_EXTRA_DAC = 0x102,
  2695. /* No individual DAC for extra surrounds */
  2696. BAD_NO_EXTRA_SURR_DAC = 0x101,
  2697. /* Primary DAC shared with main surrounds */
  2698. BAD_SHARED_SURROUND = 0x100,
  2699. /* Primary DAC shared with main CLFE */
  2700. BAD_SHARED_CLFE = 0x10,
  2701. /* Primary DAC shared with extra surrounds */
  2702. BAD_SHARED_EXTRA_SURROUND = 0x10,
  2703. /* Volume widget is shared */
  2704. BAD_SHARED_VOL = 0x10,
  2705. };
  2706. static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
  2707. hda_nid_t pin, hda_nid_t dac);
  2708. static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
  2709. hda_nid_t pin, hda_nid_t dac);
  2710. static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
  2711. hda_nid_t dac)
  2712. {
  2713. struct alc_spec *spec = codec->spec;
  2714. hda_nid_t nid;
  2715. unsigned int val;
  2716. int badness = 0;
  2717. nid = alc_look_for_out_vol_nid(codec, pin, dac);
  2718. if (nid) {
  2719. val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
  2720. if (is_ctl_used(spec->vol_ctls, nid))
  2721. badness += BAD_SHARED_VOL;
  2722. else
  2723. mark_ctl_usage(spec->vol_ctls, val);
  2724. } else
  2725. badness += BAD_SHARED_VOL;
  2726. nid = alc_look_for_out_mute_nid(codec, pin, dac);
  2727. if (nid) {
  2728. unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
  2729. if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
  2730. val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
  2731. else
  2732. val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
  2733. if (is_ctl_used(spec->sw_ctls, val))
  2734. badness += BAD_SHARED_VOL;
  2735. else
  2736. mark_ctl_usage(spec->sw_ctls, val);
  2737. } else
  2738. badness += BAD_SHARED_VOL;
  2739. return badness;
  2740. }
  2741. struct badness_table {
  2742. int no_primary_dac; /* no primary DAC */
  2743. int no_dac; /* no secondary DACs */
  2744. int shared_primary; /* primary DAC is shared with main output */
  2745. int shared_surr; /* secondary DAC shared with main or primary */
  2746. int shared_clfe; /* third DAC shared with main or primary */
  2747. int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
  2748. };
  2749. static struct badness_table main_out_badness = {
  2750. .no_primary_dac = BAD_NO_PRIMARY_DAC,
  2751. .no_dac = BAD_NO_DAC,
  2752. .shared_primary = BAD_NO_PRIMARY_DAC,
  2753. .shared_surr = BAD_SHARED_SURROUND,
  2754. .shared_clfe = BAD_SHARED_CLFE,
  2755. .shared_surr_main = BAD_SHARED_SURROUND,
  2756. };
  2757. static struct badness_table extra_out_badness = {
  2758. .no_primary_dac = BAD_NO_DAC,
  2759. .no_dac = BAD_NO_DAC,
  2760. .shared_primary = BAD_NO_EXTRA_DAC,
  2761. .shared_surr = BAD_SHARED_EXTRA_SURROUND,
  2762. .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
  2763. .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
  2764. };
  2765. /* try to assign DACs to pins and return the resultant badness */
  2766. static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
  2767. const hda_nid_t *pins, hda_nid_t *dacs,
  2768. const struct badness_table *bad)
  2769. {
  2770. struct alc_spec *spec = codec->spec;
  2771. struct auto_pin_cfg *cfg = &spec->autocfg;
  2772. int i, j;
  2773. int badness = 0;
  2774. hda_nid_t dac;
  2775. if (!num_outs)
  2776. return 0;
  2777. for (i = 0; i < num_outs; i++) {
  2778. hda_nid_t pin = pins[i];
  2779. if (!dacs[i])
  2780. dacs[i] = alc_auto_look_for_dac(codec, pin);
  2781. if (!dacs[i] && !i) {
  2782. for (j = 1; j < num_outs; j++) {
  2783. if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
  2784. dacs[0] = dacs[j];
  2785. dacs[j] = 0;
  2786. break;
  2787. }
  2788. }
  2789. }
  2790. dac = dacs[i];
  2791. if (!dac) {
  2792. if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
  2793. dac = dacs[0];
  2794. else if (cfg->line_outs > i &&
  2795. alc_auto_is_dac_reachable(codec, pin,
  2796. spec->private_dac_nids[i]))
  2797. dac = spec->private_dac_nids[i];
  2798. if (dac) {
  2799. if (!i)
  2800. badness += bad->shared_primary;
  2801. else if (i == 1)
  2802. badness += bad->shared_surr;
  2803. else
  2804. badness += bad->shared_clfe;
  2805. } else if (alc_auto_is_dac_reachable(codec, pin,
  2806. spec->private_dac_nids[0])) {
  2807. dac = spec->private_dac_nids[0];
  2808. badness += bad->shared_surr_main;
  2809. } else if (!i)
  2810. badness += bad->no_primary_dac;
  2811. else
  2812. badness += bad->no_dac;
  2813. }
  2814. if (dac)
  2815. badness += eval_shared_vol_badness(codec, pin, dac);
  2816. }
  2817. return badness;
  2818. }
  2819. static int alc_auto_fill_multi_ios(struct hda_codec *codec,
  2820. hda_nid_t reference_pin,
  2821. bool hardwired, int offset);
  2822. static bool alc_map_singles(struct hda_codec *codec, int outs,
  2823. const hda_nid_t *pins, hda_nid_t *dacs)
  2824. {
  2825. int i;
  2826. bool found = false;
  2827. for (i = 0; i < outs; i++) {
  2828. if (dacs[i])
  2829. continue;
  2830. dacs[i] = get_dac_if_single(codec, pins[i]);
  2831. if (dacs[i])
  2832. found = true;
  2833. }
  2834. return found;
  2835. }
  2836. /* fill in the dac_nids table from the parsed pin configuration */
  2837. static int fill_and_eval_dacs(struct hda_codec *codec,
  2838. bool fill_hardwired,
  2839. bool fill_mio_first)
  2840. {
  2841. struct alc_spec *spec = codec->spec;
  2842. struct auto_pin_cfg *cfg = &spec->autocfg;
  2843. int i, err, badness;
  2844. /* set num_dacs once to full for alc_auto_look_for_dac() */
  2845. spec->multiout.num_dacs = cfg->line_outs;
  2846. spec->multiout.dac_nids = spec->private_dac_nids;
  2847. memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
  2848. memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
  2849. memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
  2850. spec->multi_ios = 0;
  2851. clear_vol_marks(codec);
  2852. badness = 0;
  2853. /* fill hard-wired DACs first */
  2854. if (fill_hardwired) {
  2855. bool mapped;
  2856. do {
  2857. mapped = alc_map_singles(codec, cfg->line_outs,
  2858. cfg->line_out_pins,
  2859. spec->private_dac_nids);
  2860. mapped |= alc_map_singles(codec, cfg->hp_outs,
  2861. cfg->hp_pins,
  2862. spec->multiout.hp_out_nid);
  2863. mapped |= alc_map_singles(codec, cfg->speaker_outs,
  2864. cfg->speaker_pins,
  2865. spec->multiout.extra_out_nid);
  2866. if (fill_mio_first && cfg->line_outs == 1 &&
  2867. cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
  2868. err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
  2869. if (!err)
  2870. mapped = true;
  2871. }
  2872. } while (mapped);
  2873. }
  2874. badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
  2875. spec->private_dac_nids,
  2876. &main_out_badness);
  2877. /* re-count num_dacs and squash invalid entries */
  2878. spec->multiout.num_dacs = 0;
  2879. for (i = 0; i < cfg->line_outs; i++) {
  2880. if (spec->private_dac_nids[i])
  2881. spec->multiout.num_dacs++;
  2882. else {
  2883. memmove(spec->private_dac_nids + i,
  2884. spec->private_dac_nids + i + 1,
  2885. sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
  2886. spec->private_dac_nids[cfg->line_outs - 1] = 0;
  2887. }
  2888. }
  2889. if (fill_mio_first &&
  2890. cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
  2891. /* try to fill multi-io first */
  2892. err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
  2893. if (err < 0)
  2894. return err;
  2895. /* we don't count badness at this stage yet */
  2896. }
  2897. if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
  2898. err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
  2899. spec->multiout.hp_out_nid,
  2900. &extra_out_badness);
  2901. if (err < 0)
  2902. return err;
  2903. badness += err;
  2904. }
  2905. if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
  2906. err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
  2907. cfg->speaker_pins,
  2908. spec->multiout.extra_out_nid,
  2909. &extra_out_badness);
  2910. if (err < 0)
  2911. return err;
  2912. badness += err;
  2913. }
  2914. if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
  2915. err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
  2916. if (err < 0)
  2917. return err;
  2918. badness += err;
  2919. }
  2920. if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
  2921. /* try multi-ios with HP + inputs */
  2922. int offset = 0;
  2923. if (cfg->line_outs >= 3)
  2924. offset = 1;
  2925. err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
  2926. offset);
  2927. if (err < 0)
  2928. return err;
  2929. badness += err;
  2930. }
  2931. if (spec->multi_ios == 2) {
  2932. for (i = 0; i < 2; i++)
  2933. spec->private_dac_nids[spec->multiout.num_dacs++] =
  2934. spec->multi_io[i].dac;
  2935. spec->ext_channel_count = 2;
  2936. } else if (spec->multi_ios) {
  2937. spec->multi_ios = 0;
  2938. badness += BAD_MULTI_IO;
  2939. }
  2940. return badness;
  2941. }
  2942. #define DEBUG_BADNESS
  2943. #ifdef DEBUG_BADNESS
  2944. #define debug_badness snd_printdd
  2945. #else
  2946. #define debug_badness(...)
  2947. #endif
  2948. static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
  2949. {
  2950. debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
  2951. cfg->line_out_pins[0], cfg->line_out_pins[1],
  2952. cfg->line_out_pins[2], cfg->line_out_pins[2],
  2953. spec->multiout.dac_nids[0],
  2954. spec->multiout.dac_nids[1],
  2955. spec->multiout.dac_nids[2],
  2956. spec->multiout.dac_nids[3]);
  2957. if (spec->multi_ios > 0)
  2958. debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
  2959. spec->multi_ios,
  2960. spec->multi_io[0].pin, spec->multi_io[1].pin,
  2961. spec->multi_io[0].dac, spec->multi_io[1].dac);
  2962. debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
  2963. cfg->hp_pins[0], cfg->hp_pins[1],
  2964. cfg->hp_pins[2], cfg->hp_pins[2],
  2965. spec->multiout.hp_out_nid[0],
  2966. spec->multiout.hp_out_nid[1],
  2967. spec->multiout.hp_out_nid[2],
  2968. spec->multiout.hp_out_nid[3]);
  2969. debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
  2970. cfg->speaker_pins[0], cfg->speaker_pins[1],
  2971. cfg->speaker_pins[2], cfg->speaker_pins[3],
  2972. spec->multiout.extra_out_nid[0],
  2973. spec->multiout.extra_out_nid[1],
  2974. spec->multiout.extra_out_nid[2],
  2975. spec->multiout.extra_out_nid[3]);
  2976. }
  2977. static int alc_auto_fill_dac_nids(struct hda_codec *codec)
  2978. {
  2979. struct alc_spec *spec = codec->spec;
  2980. struct auto_pin_cfg *cfg = &spec->autocfg;
  2981. struct auto_pin_cfg *best_cfg;
  2982. int best_badness = INT_MAX;
  2983. int badness;
  2984. bool fill_hardwired = true, fill_mio_first = true;
  2985. bool best_wired = true, best_mio = true;
  2986. bool hp_spk_swapped = false;
  2987. best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
  2988. if (!best_cfg)
  2989. return -ENOMEM;
  2990. *best_cfg = *cfg;
  2991. for (;;) {
  2992. badness = fill_and_eval_dacs(codec, fill_hardwired,
  2993. fill_mio_first);
  2994. if (badness < 0) {
  2995. kfree(best_cfg);
  2996. return badness;
  2997. }
  2998. debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
  2999. cfg->line_out_type, fill_hardwired, fill_mio_first,
  3000. badness);
  3001. debug_show_configs(spec, cfg);
  3002. if (badness < best_badness) {
  3003. best_badness = badness;
  3004. *best_cfg = *cfg;
  3005. best_wired = fill_hardwired;
  3006. best_mio = fill_mio_first;
  3007. }
  3008. if (!badness)
  3009. break;
  3010. fill_mio_first = !fill_mio_first;
  3011. if (!fill_mio_first)
  3012. continue;
  3013. fill_hardwired = !fill_hardwired;
  3014. if (!fill_hardwired)
  3015. continue;
  3016. if (hp_spk_swapped)
  3017. break;
  3018. hp_spk_swapped = true;
  3019. if (cfg->speaker_outs > 0 &&
  3020. cfg->line_out_type == AUTO_PIN_HP_OUT) {
  3021. cfg->hp_outs = cfg->line_outs;
  3022. memcpy(cfg->hp_pins, cfg->line_out_pins,
  3023. sizeof(cfg->hp_pins));
  3024. cfg->line_outs = cfg->speaker_outs;
  3025. memcpy(cfg->line_out_pins, cfg->speaker_pins,
  3026. sizeof(cfg->speaker_pins));
  3027. cfg->speaker_outs = 0;
  3028. memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
  3029. cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
  3030. fill_hardwired = true;
  3031. continue;
  3032. }
  3033. if (cfg->hp_outs > 0 &&
  3034. cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
  3035. cfg->speaker_outs = cfg->line_outs;
  3036. memcpy(cfg->speaker_pins, cfg->line_out_pins,
  3037. sizeof(cfg->speaker_pins));
  3038. cfg->line_outs = cfg->hp_outs;
  3039. memcpy(cfg->line_out_pins, cfg->hp_pins,
  3040. sizeof(cfg->hp_pins));
  3041. cfg->hp_outs = 0;
  3042. memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
  3043. cfg->line_out_type = AUTO_PIN_HP_OUT;
  3044. fill_hardwired = true;
  3045. continue;
  3046. }
  3047. break;
  3048. }
  3049. if (badness) {
  3050. *cfg = *best_cfg;
  3051. fill_and_eval_dacs(codec, best_wired, best_mio);
  3052. }
  3053. debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
  3054. cfg->line_out_type, best_wired, best_mio);
  3055. debug_show_configs(spec, cfg);
  3056. if (cfg->line_out_pins[0])
  3057. spec->vmaster_nid =
  3058. alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
  3059. spec->multiout.dac_nids[0]);
  3060. /* clear the bitmap flags for creating controls */
  3061. clear_vol_marks(codec);
  3062. kfree(best_cfg);
  3063. return 0;
  3064. }
  3065. static int alc_auto_add_vol_ctl(struct hda_codec *codec,
  3066. const char *pfx, int cidx,
  3067. hda_nid_t nid, unsigned int chs)
  3068. {
  3069. struct alc_spec *spec = codec->spec;
  3070. unsigned int val;
  3071. if (!nid)
  3072. return 0;
  3073. val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
  3074. if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
  3075. return 0;
  3076. mark_ctl_usage(spec->vol_ctls, val);
  3077. return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
  3078. val);
  3079. }
  3080. static int alc_auto_add_stereo_vol(struct hda_codec *codec,
  3081. const char *pfx, int cidx,
  3082. hda_nid_t nid)
  3083. {
  3084. int chs = 1;
  3085. if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
  3086. chs = 3;
  3087. return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
  3088. }
  3089. /* create a mute-switch for the given mixer widget;
  3090. * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
  3091. */
  3092. static int alc_auto_add_sw_ctl(struct hda_codec *codec,
  3093. const char *pfx, int cidx,
  3094. hda_nid_t nid, unsigned int chs)
  3095. {
  3096. struct alc_spec *spec = codec->spec;
  3097. int wid_type;
  3098. int type;
  3099. unsigned long val;
  3100. if (!nid)
  3101. return 0;
  3102. wid_type = get_wcaps_type(get_wcaps(codec, nid));
  3103. if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
  3104. type = ALC_CTL_WIDGET_MUTE;
  3105. val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
  3106. } else if (snd_hda_get_num_conns(codec, nid) == 1) {
  3107. type = ALC_CTL_WIDGET_MUTE;
  3108. val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
  3109. } else {
  3110. type = ALC_CTL_BIND_MUTE;
  3111. val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
  3112. }
  3113. if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
  3114. return 0;
  3115. mark_ctl_usage(spec->sw_ctls, val);
  3116. return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
  3117. }
  3118. static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
  3119. int cidx, hda_nid_t nid)
  3120. {
  3121. int chs = 1;
  3122. if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
  3123. chs = 3;
  3124. return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
  3125. }
  3126. static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
  3127. hda_nid_t pin, hda_nid_t dac)
  3128. {
  3129. hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
  3130. if (nid_has_mute(codec, pin, HDA_OUTPUT))
  3131. return pin;
  3132. else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
  3133. return mix;
  3134. else if (nid_has_mute(codec, dac, HDA_OUTPUT))
  3135. return dac;
  3136. return 0;
  3137. }
  3138. static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
  3139. hda_nid_t pin, hda_nid_t dac)
  3140. {
  3141. hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
  3142. if (nid_has_volume(codec, dac, HDA_OUTPUT))
  3143. return dac;
  3144. else if (nid_has_volume(codec, mix, HDA_OUTPUT))
  3145. return mix;
  3146. else if (nid_has_volume(codec, pin, HDA_OUTPUT))
  3147. return pin;
  3148. return 0;
  3149. }
  3150. /* add playback controls from the parsed DAC table */
  3151. static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
  3152. const struct auto_pin_cfg *cfg)
  3153. {
  3154. struct alc_spec *spec = codec->spec;
  3155. int i, err, noutputs;
  3156. noutputs = cfg->line_outs;
  3157. if (spec->multi_ios > 0 && cfg->line_outs < 3)
  3158. noutputs += spec->multi_ios;
  3159. for (i = 0; i < noutputs; i++) {
  3160. const char *name;
  3161. int index;
  3162. hda_nid_t dac, pin;
  3163. hda_nid_t sw, vol;
  3164. dac = spec->multiout.dac_nids[i];
  3165. if (!dac)
  3166. continue;
  3167. if (i >= cfg->line_outs) {
  3168. pin = spec->multi_io[i - 1].pin;
  3169. index = 0;
  3170. name = channel_name[i];
  3171. } else {
  3172. pin = cfg->line_out_pins[i];
  3173. name = alc_get_line_out_pfx(spec, i, true, &index);
  3174. }
  3175. sw = alc_look_for_out_mute_nid(codec, pin, dac);
  3176. vol = alc_look_for_out_vol_nid(codec, pin, dac);
  3177. if (!name || !strcmp(name, "CLFE")) {
  3178. /* Center/LFE */
  3179. err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
  3180. if (err < 0)
  3181. return err;
  3182. err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
  3183. if (err < 0)
  3184. return err;
  3185. err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
  3186. if (err < 0)
  3187. return err;
  3188. err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
  3189. if (err < 0)
  3190. return err;
  3191. } else {
  3192. err = alc_auto_add_stereo_vol(codec, name, index, vol);
  3193. if (err < 0)
  3194. return err;
  3195. err = alc_auto_add_stereo_sw(codec, name, index, sw);
  3196. if (err < 0)
  3197. return err;
  3198. }
  3199. }
  3200. return 0;
  3201. }
  3202. static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
  3203. hda_nid_t dac, const char *pfx,
  3204. int cidx)
  3205. {
  3206. struct alc_spec *spec = codec->spec;
  3207. hda_nid_t sw, vol;
  3208. int err;
  3209. if (!dac) {
  3210. unsigned int val;
  3211. /* the corresponding DAC is already occupied */
  3212. if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
  3213. return 0; /* no way */
  3214. /* create a switch only */
  3215. val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
  3216. if (is_ctl_used(spec->sw_ctls, val))
  3217. return 0; /* already created */
  3218. mark_ctl_usage(spec->sw_ctls, val);
  3219. return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
  3220. }
  3221. sw = alc_look_for_out_mute_nid(codec, pin, dac);
  3222. vol = alc_look_for_out_vol_nid(codec, pin, dac);
  3223. err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
  3224. if (err < 0)
  3225. return err;
  3226. err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
  3227. if (err < 0)
  3228. return err;
  3229. return 0;
  3230. }
  3231. static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
  3232. unsigned int nums,
  3233. struct hda_ctl_ops *ops)
  3234. {
  3235. struct alc_spec *spec = codec->spec;
  3236. struct hda_bind_ctls **ctlp, *ctl;
  3237. snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
  3238. ctlp = snd_array_new(&spec->bind_ctls);
  3239. if (!ctlp)
  3240. return NULL;
  3241. ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
  3242. *ctlp = ctl;
  3243. if (ctl)
  3244. ctl->ops = ops;
  3245. return ctl;
  3246. }
  3247. /* add playback controls for speaker and HP outputs */
  3248. static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
  3249. const hda_nid_t *pins,
  3250. const hda_nid_t *dacs,
  3251. const char *pfx)
  3252. {
  3253. struct alc_spec *spec = codec->spec;
  3254. struct hda_bind_ctls *ctl;
  3255. char name[32];
  3256. int i, n, err;
  3257. if (!num_pins || !pins[0])
  3258. return 0;
  3259. if (num_pins == 1) {
  3260. hda_nid_t dac = *dacs;
  3261. if (!dac)
  3262. dac = spec->multiout.dac_nids[0];
  3263. return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
  3264. }
  3265. for (i = 0; i < num_pins; i++) {
  3266. hda_nid_t dac;
  3267. if (dacs[num_pins - 1])
  3268. dac = dacs[i]; /* with individual volumes */
  3269. else
  3270. dac = 0;
  3271. if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
  3272. err = alc_auto_create_extra_out(codec, pins[i], dac,
  3273. "Bass Speaker", 0);
  3274. } else if (num_pins >= 3) {
  3275. snprintf(name, sizeof(name), "%s %s",
  3276. pfx, channel_name[i]);
  3277. err = alc_auto_create_extra_out(codec, pins[i], dac,
  3278. name, 0);
  3279. } else {
  3280. err = alc_auto_create_extra_out(codec, pins[i], dac,
  3281. pfx, i);
  3282. }
  3283. if (err < 0)
  3284. return err;
  3285. }
  3286. if (dacs[num_pins - 1])
  3287. return 0;
  3288. /* Let's create a bind-controls for volumes */
  3289. ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
  3290. if (!ctl)
  3291. return -ENOMEM;
  3292. n = 0;
  3293. for (i = 0; i < num_pins; i++) {
  3294. hda_nid_t vol;
  3295. if (!pins[i] || !dacs[i])
  3296. continue;
  3297. vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
  3298. if (vol)
  3299. ctl->values[n++] =
  3300. HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
  3301. }
  3302. if (n) {
  3303. snprintf(name, sizeof(name), "%s Playback Volume", pfx);
  3304. err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
  3305. if (err < 0)
  3306. return err;
  3307. }
  3308. return 0;
  3309. }
  3310. static int alc_auto_create_hp_out(struct hda_codec *codec)
  3311. {
  3312. struct alc_spec *spec = codec->spec;
  3313. return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
  3314. spec->autocfg.hp_pins,
  3315. spec->multiout.hp_out_nid,
  3316. "Headphone");
  3317. }
  3318. static int alc_auto_create_speaker_out(struct hda_codec *codec)
  3319. {
  3320. struct alc_spec *spec = codec->spec;
  3321. return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
  3322. spec->autocfg.speaker_pins,
  3323. spec->multiout.extra_out_nid,
  3324. "Speaker");
  3325. }
  3326. static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
  3327. hda_nid_t pin, int pin_type,
  3328. hda_nid_t dac)
  3329. {
  3330. int i, num;
  3331. hda_nid_t nid, mix = 0;
  3332. hda_nid_t srcs[HDA_MAX_CONNECTIONS];
  3333. alc_set_pin_output(codec, pin, pin_type);
  3334. nid = alc_go_down_to_selector(codec, pin);
  3335. num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
  3336. for (i = 0; i < num; i++) {
  3337. if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
  3338. continue;
  3339. mix = srcs[i];
  3340. break;
  3341. }
  3342. if (!mix)
  3343. return;
  3344. /* need the manual connection? */
  3345. if (num > 1)
  3346. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
  3347. /* unmute mixer widget inputs */
  3348. if (nid_has_mute(codec, mix, HDA_INPUT)) {
  3349. snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3350. AMP_IN_UNMUTE(0));
  3351. snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3352. AMP_IN_UNMUTE(1));
  3353. }
  3354. /* initialize volume */
  3355. nid = alc_look_for_out_vol_nid(codec, pin, dac);
  3356. if (nid)
  3357. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3358. AMP_OUT_ZERO);
  3359. /* unmute DAC if it's not assigned to a mixer */
  3360. nid = alc_look_for_out_mute_nid(codec, pin, dac);
  3361. if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
  3362. snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3363. AMP_OUT_ZERO);
  3364. }
  3365. static void alc_auto_init_multi_out(struct hda_codec *codec)
  3366. {
  3367. struct alc_spec *spec = codec->spec;
  3368. int pin_type = get_pin_type(spec->autocfg.line_out_type);
  3369. int i;
  3370. for (i = 0; i <= HDA_SIDE; i++) {
  3371. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  3372. if (nid)
  3373. alc_auto_set_output_and_unmute(codec, nid, pin_type,
  3374. spec->multiout.dac_nids[i]);
  3375. }
  3376. }
  3377. static void alc_auto_init_extra_out(struct hda_codec *codec)
  3378. {
  3379. struct alc_spec *spec = codec->spec;
  3380. int i;
  3381. hda_nid_t pin, dac;
  3382. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  3383. if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
  3384. break;
  3385. pin = spec->autocfg.hp_pins[i];
  3386. if (!pin)
  3387. break;
  3388. dac = spec->multiout.hp_out_nid[i];
  3389. if (!dac) {
  3390. if (i > 0 && spec->multiout.hp_out_nid[0])
  3391. dac = spec->multiout.hp_out_nid[0];
  3392. else
  3393. dac = spec->multiout.dac_nids[0];
  3394. }
  3395. alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
  3396. }
  3397. for (i = 0; i < spec->autocfg.speaker_outs; i++) {
  3398. if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
  3399. break;
  3400. pin = spec->autocfg.speaker_pins[i];
  3401. if (!pin)
  3402. break;
  3403. dac = spec->multiout.extra_out_nid[i];
  3404. if (!dac) {
  3405. if (i > 0 && spec->multiout.extra_out_nid[0])
  3406. dac = spec->multiout.extra_out_nid[0];
  3407. else
  3408. dac = spec->multiout.dac_nids[0];
  3409. }
  3410. alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
  3411. }
  3412. }
  3413. /* check whether the given pin can be a multi-io pin */
  3414. static bool can_be_multiio_pin(struct hda_codec *codec,
  3415. unsigned int location, hda_nid_t nid)
  3416. {
  3417. unsigned int defcfg, caps;
  3418. defcfg = snd_hda_codec_get_pincfg(codec, nid);
  3419. if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
  3420. return false;
  3421. if (location && get_defcfg_location(defcfg) != location)
  3422. return false;
  3423. caps = snd_hda_query_pin_caps(codec, nid);
  3424. if (!(caps & AC_PINCAP_OUT))
  3425. return false;
  3426. return true;
  3427. }
  3428. /*
  3429. * multi-io helper
  3430. *
  3431. * When hardwired is set, try to fill ony hardwired pins, and returns
  3432. * zero if any pins are filled, non-zero if nothing found.
  3433. * When hardwired is off, try to fill possible input pins, and returns
  3434. * the badness value.
  3435. */
  3436. static int alc_auto_fill_multi_ios(struct hda_codec *codec,
  3437. hda_nid_t reference_pin,
  3438. bool hardwired, int offset)
  3439. {
  3440. struct alc_spec *spec = codec->spec;
  3441. struct auto_pin_cfg *cfg = &spec->autocfg;
  3442. int type, i, j, dacs, num_pins, old_pins;
  3443. unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
  3444. unsigned int location = get_defcfg_location(defcfg);
  3445. int badness = 0;
  3446. old_pins = spec->multi_ios;
  3447. if (old_pins >= 2)
  3448. goto end_fill;
  3449. num_pins = 0;
  3450. for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
  3451. for (i = 0; i < cfg->num_inputs; i++) {
  3452. if (cfg->inputs[i].type != type)
  3453. continue;
  3454. if (can_be_multiio_pin(codec, location,
  3455. cfg->inputs[i].pin))
  3456. num_pins++;
  3457. }
  3458. }
  3459. if (num_pins < 2)
  3460. goto end_fill;
  3461. dacs = spec->multiout.num_dacs;
  3462. for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
  3463. for (i = 0; i < cfg->num_inputs; i++) {
  3464. hda_nid_t nid = cfg->inputs[i].pin;
  3465. hda_nid_t dac = 0;
  3466. if (cfg->inputs[i].type != type)
  3467. continue;
  3468. if (!can_be_multiio_pin(codec, location, nid))
  3469. continue;
  3470. for (j = 0; j < spec->multi_ios; j++) {
  3471. if (nid == spec->multi_io[j].pin)
  3472. break;
  3473. }
  3474. if (j < spec->multi_ios)
  3475. continue;
  3476. if (offset && offset + spec->multi_ios < dacs) {
  3477. dac = spec->private_dac_nids[offset + spec->multi_ios];
  3478. if (!alc_auto_is_dac_reachable(codec, nid, dac))
  3479. dac = 0;
  3480. }
  3481. if (hardwired)
  3482. dac = get_dac_if_single(codec, nid);
  3483. else if (!dac)
  3484. dac = alc_auto_look_for_dac(codec, nid);
  3485. if (!dac) {
  3486. badness++;
  3487. continue;
  3488. }
  3489. spec->multi_io[spec->multi_ios].pin = nid;
  3490. spec->multi_io[spec->multi_ios].dac = dac;
  3491. spec->multi_ios++;
  3492. if (spec->multi_ios >= 2)
  3493. break;
  3494. }
  3495. }
  3496. end_fill:
  3497. if (badness)
  3498. badness = BAD_MULTI_IO;
  3499. if (old_pins == spec->multi_ios) {
  3500. if (hardwired)
  3501. return 1; /* nothing found */
  3502. else
  3503. return badness; /* no badness if nothing found */
  3504. }
  3505. if (!hardwired && spec->multi_ios < 2) {
  3506. spec->multi_ios = old_pins;
  3507. return badness;
  3508. }
  3509. return 0;
  3510. }
  3511. static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
  3512. struct snd_ctl_elem_info *uinfo)
  3513. {
  3514. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3515. struct alc_spec *spec = codec->spec;
  3516. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  3517. uinfo->count = 1;
  3518. uinfo->value.enumerated.items = spec->multi_ios + 1;
  3519. if (uinfo->value.enumerated.item > spec->multi_ios)
  3520. uinfo->value.enumerated.item = spec->multi_ios;
  3521. sprintf(uinfo->value.enumerated.name, "%dch",
  3522. (uinfo->value.enumerated.item + 1) * 2);
  3523. return 0;
  3524. }
  3525. static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
  3526. struct snd_ctl_elem_value *ucontrol)
  3527. {
  3528. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3529. struct alc_spec *spec = codec->spec;
  3530. ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
  3531. return 0;
  3532. }
  3533. static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
  3534. {
  3535. struct alc_spec *spec = codec->spec;
  3536. hda_nid_t nid = spec->multi_io[idx].pin;
  3537. if (!spec->multi_io[idx].ctl_in)
  3538. spec->multi_io[idx].ctl_in =
  3539. snd_hda_codec_read(codec, nid, 0,
  3540. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  3541. if (output) {
  3542. snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
  3543. if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
  3544. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  3545. HDA_AMP_MUTE, 0);
  3546. alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
  3547. } else {
  3548. if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
  3549. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  3550. HDA_AMP_MUTE, HDA_AMP_MUTE);
  3551. snd_hda_set_pin_ctl_cache(codec, nid,
  3552. spec->multi_io[idx].ctl_in);
  3553. }
  3554. return 0;
  3555. }
  3556. static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
  3557. struct snd_ctl_elem_value *ucontrol)
  3558. {
  3559. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3560. struct alc_spec *spec = codec->spec;
  3561. int i, ch;
  3562. ch = ucontrol->value.enumerated.item[0];
  3563. if (ch < 0 || ch > spec->multi_ios)
  3564. return -EINVAL;
  3565. if (ch == (spec->ext_channel_count - 1) / 2)
  3566. return 0;
  3567. spec->ext_channel_count = (ch + 1) * 2;
  3568. for (i = 0; i < spec->multi_ios; i++)
  3569. alc_set_multi_io(codec, i, i < ch);
  3570. spec->multiout.max_channels = spec->ext_channel_count;
  3571. if (spec->need_dac_fix && !spec->const_channel_count)
  3572. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  3573. return 1;
  3574. }
  3575. static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
  3576. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3577. .name = "Channel Mode",
  3578. .info = alc_auto_ch_mode_info,
  3579. .get = alc_auto_ch_mode_get,
  3580. .put = alc_auto_ch_mode_put,
  3581. };
  3582. static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
  3583. {
  3584. struct alc_spec *spec = codec->spec;
  3585. if (spec->multi_ios > 0) {
  3586. struct snd_kcontrol_new *knew;
  3587. knew = alc_kcontrol_new(spec);
  3588. if (!knew)
  3589. return -ENOMEM;
  3590. *knew = alc_auto_channel_mode_enum;
  3591. knew->name = kstrdup("Channel Mode", GFP_KERNEL);
  3592. if (!knew->name)
  3593. return -ENOMEM;
  3594. }
  3595. return 0;
  3596. }
  3597. /* filter out invalid adc_nids (and capsrc_nids) that don't give all
  3598. * active input pins
  3599. */
  3600. static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
  3601. {
  3602. struct alc_spec *spec = codec->spec;
  3603. const struct hda_input_mux *imux;
  3604. hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
  3605. hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
  3606. int i, n, nums;
  3607. imux = spec->input_mux;
  3608. if (!imux)
  3609. return;
  3610. if (spec->dyn_adc_switch)
  3611. return;
  3612. again:
  3613. nums = 0;
  3614. for (n = 0; n < spec->num_adc_nids; n++) {
  3615. hda_nid_t cap = spec->private_capsrc_nids[n];
  3616. int num_conns = snd_hda_get_num_conns(codec, cap);
  3617. for (i = 0; i < imux->num_items; i++) {
  3618. hda_nid_t pin = spec->imux_pins[i];
  3619. if (pin) {
  3620. if (get_connection_index(codec, cap, pin) < 0)
  3621. break;
  3622. } else if (num_conns <= imux->items[i].index)
  3623. break;
  3624. }
  3625. if (i >= imux->num_items) {
  3626. adc_nids[nums] = spec->private_adc_nids[n];
  3627. capsrc_nids[nums++] = cap;
  3628. }
  3629. }
  3630. if (!nums) {
  3631. /* check whether ADC-switch is possible */
  3632. if (!alc_check_dyn_adc_switch(codec)) {
  3633. if (spec->shared_mic_hp) {
  3634. spec->shared_mic_hp = 0;
  3635. spec->private_imux[0].num_items = 1;
  3636. goto again;
  3637. }
  3638. printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
  3639. " using fallback 0x%x\n",
  3640. codec->chip_name, spec->private_adc_nids[0]);
  3641. spec->num_adc_nids = 1;
  3642. spec->auto_mic = 0;
  3643. return;
  3644. }
  3645. } else if (nums != spec->num_adc_nids) {
  3646. memcpy(spec->private_adc_nids, adc_nids,
  3647. nums * sizeof(hda_nid_t));
  3648. memcpy(spec->private_capsrc_nids, capsrc_nids,
  3649. nums * sizeof(hda_nid_t));
  3650. spec->num_adc_nids = nums;
  3651. }
  3652. if (spec->auto_mic)
  3653. alc_auto_mic_check_imux(codec); /* check auto-mic setups */
  3654. else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
  3655. spec->num_adc_nids = 1; /* reduce to a single ADC */
  3656. }
  3657. /*
  3658. * initialize ADC paths
  3659. */
  3660. static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
  3661. {
  3662. struct alc_spec *spec = codec->spec;
  3663. hda_nid_t nid;
  3664. nid = spec->adc_nids[adc_idx];
  3665. /* mute ADC */
  3666. if (nid_has_mute(codec, nid, HDA_INPUT)) {
  3667. snd_hda_codec_write(codec, nid, 0,
  3668. AC_VERB_SET_AMP_GAIN_MUTE,
  3669. AMP_IN_MUTE(0));
  3670. return;
  3671. }
  3672. if (!spec->capsrc_nids)
  3673. return;
  3674. nid = spec->capsrc_nids[adc_idx];
  3675. if (nid_has_mute(codec, nid, HDA_OUTPUT))
  3676. snd_hda_codec_write(codec, nid, 0,
  3677. AC_VERB_SET_AMP_GAIN_MUTE,
  3678. AMP_OUT_MUTE);
  3679. }
  3680. static void alc_auto_init_input_src(struct hda_codec *codec)
  3681. {
  3682. struct alc_spec *spec = codec->spec;
  3683. int c, nums;
  3684. for (c = 0; c < spec->num_adc_nids; c++)
  3685. alc_auto_init_adc(codec, c);
  3686. if (spec->dyn_adc_switch)
  3687. nums = 1;
  3688. else
  3689. nums = spec->num_adc_nids;
  3690. for (c = 0; c < nums; c++)
  3691. alc_mux_select(codec, c, spec->cur_mux[c], true);
  3692. }
  3693. /* add mic boosts if needed */
  3694. static int alc_auto_add_mic_boost(struct hda_codec *codec)
  3695. {
  3696. struct alc_spec *spec = codec->spec;
  3697. struct auto_pin_cfg *cfg = &spec->autocfg;
  3698. int i, err;
  3699. int type_idx = 0;
  3700. hda_nid_t nid;
  3701. const char *prev_label = NULL;
  3702. for (i = 0; i < cfg->num_inputs; i++) {
  3703. if (cfg->inputs[i].type > AUTO_PIN_MIC)
  3704. break;
  3705. nid = cfg->inputs[i].pin;
  3706. if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
  3707. const char *label;
  3708. char boost_label[32];
  3709. label = hda_get_autocfg_input_label(codec, cfg, i);
  3710. if (spec->shared_mic_hp && !strcmp(label, "Misc"))
  3711. label = "Headphone Mic";
  3712. if (prev_label && !strcmp(label, prev_label))
  3713. type_idx++;
  3714. else
  3715. type_idx = 0;
  3716. prev_label = label;
  3717. snprintf(boost_label, sizeof(boost_label),
  3718. "%s Boost Volume", label);
  3719. err = add_control(spec, ALC_CTL_WIDGET_VOL,
  3720. boost_label, type_idx,
  3721. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
  3722. if (err < 0)
  3723. return err;
  3724. }
  3725. }
  3726. return 0;
  3727. }
  3728. /* select or unmute the given capsrc route */
  3729. static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
  3730. int idx)
  3731. {
  3732. if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
  3733. snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
  3734. HDA_AMP_MUTE, 0);
  3735. } else if (snd_hda_get_num_conns(codec, cap) > 1) {
  3736. snd_hda_codec_write_cache(codec, cap, 0,
  3737. AC_VERB_SET_CONNECT_SEL, idx);
  3738. }
  3739. }
  3740. /* set the default connection to that pin */
  3741. static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
  3742. {
  3743. struct alc_spec *spec = codec->spec;
  3744. int i;
  3745. if (!pin)
  3746. return 0;
  3747. for (i = 0; i < spec->num_adc_nids; i++) {
  3748. hda_nid_t cap = get_capsrc(spec, i);
  3749. int idx;
  3750. idx = get_connection_index(codec, cap, pin);
  3751. if (idx < 0)
  3752. continue;
  3753. select_or_unmute_capsrc(codec, cap, idx);
  3754. return i; /* return the found index */
  3755. }
  3756. return -1; /* not found */
  3757. }
  3758. /* initialize some special cases for input sources */
  3759. static void alc_init_special_input_src(struct hda_codec *codec)
  3760. {
  3761. struct alc_spec *spec = codec->spec;
  3762. int i;
  3763. for (i = 0; i < spec->autocfg.num_inputs; i++)
  3764. init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
  3765. }
  3766. /* assign appropriate capture mixers */
  3767. static void set_capture_mixer(struct hda_codec *codec)
  3768. {
  3769. struct alc_spec *spec = codec->spec;
  3770. static const struct snd_kcontrol_new *caps[2][3] = {
  3771. { alc_capture_mixer_nosrc1,
  3772. alc_capture_mixer_nosrc2,
  3773. alc_capture_mixer_nosrc3 },
  3774. { alc_capture_mixer1,
  3775. alc_capture_mixer2,
  3776. alc_capture_mixer3 },
  3777. };
  3778. /* check whether either of ADC or MUX has a volume control */
  3779. if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
  3780. if (!spec->capsrc_nids)
  3781. return; /* no volume */
  3782. if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
  3783. return; /* no volume in capsrc, too */
  3784. spec->vol_in_capsrc = 1;
  3785. }
  3786. if (spec->num_adc_nids > 0) {
  3787. int mux = 0;
  3788. int num_adcs = 0;
  3789. if (spec->input_mux && spec->input_mux->num_items > 1)
  3790. mux = 1;
  3791. if (spec->auto_mic) {
  3792. num_adcs = 1;
  3793. mux = 0;
  3794. } else if (spec->dyn_adc_switch)
  3795. num_adcs = 1;
  3796. if (!num_adcs) {
  3797. if (spec->num_adc_nids > 3)
  3798. spec->num_adc_nids = 3;
  3799. else if (!spec->num_adc_nids)
  3800. return;
  3801. num_adcs = spec->num_adc_nids;
  3802. }
  3803. spec->cap_mixer = caps[mux][num_adcs - 1];
  3804. }
  3805. }
  3806. /*
  3807. * standard auto-parser initializations
  3808. */
  3809. static void alc_auto_init_std(struct hda_codec *codec)
  3810. {
  3811. struct alc_spec *spec = codec->spec;
  3812. alc_auto_init_multi_out(codec);
  3813. alc_auto_init_extra_out(codec);
  3814. alc_auto_init_analog_input(codec);
  3815. alc_auto_init_input_src(codec);
  3816. alc_auto_init_digital(codec);
  3817. if (spec->unsol_event)
  3818. alc_inithook(codec);
  3819. }
  3820. /*
  3821. * Digital-beep handlers
  3822. */
  3823. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  3824. #define set_beep_amp(spec, nid, idx, dir) \
  3825. ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
  3826. static const struct snd_pci_quirk beep_white_list[] = {
  3827. SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
  3828. SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
  3829. SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
  3830. SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
  3831. SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
  3832. SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
  3833. {}
  3834. };
  3835. static inline int has_cdefine_beep(struct hda_codec *codec)
  3836. {
  3837. struct alc_spec *spec = codec->spec;
  3838. const struct snd_pci_quirk *q;
  3839. q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
  3840. if (q)
  3841. return q->value;
  3842. return spec->cdefine.enable_pcbeep;
  3843. }
  3844. #else
  3845. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  3846. #define has_cdefine_beep(codec) 0
  3847. #endif
  3848. /* parse the BIOS configuration and set up the alc_spec */
  3849. /* return 1 if successful, 0 if the proper config is not found,
  3850. * or a negative error code
  3851. */
  3852. static int alc_parse_auto_config(struct hda_codec *codec,
  3853. const hda_nid_t *ignore_nids,
  3854. const hda_nid_t *ssid_nids)
  3855. {
  3856. struct alc_spec *spec = codec->spec;
  3857. struct auto_pin_cfg *cfg = &spec->autocfg;
  3858. int err;
  3859. err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
  3860. spec->parse_flags);
  3861. if (err < 0)
  3862. return err;
  3863. if (!cfg->line_outs) {
  3864. if (cfg->dig_outs || cfg->dig_in_pin) {
  3865. spec->multiout.max_channels = 2;
  3866. spec->no_analog = 1;
  3867. goto dig_only;
  3868. }
  3869. return 0; /* can't find valid BIOS pin config */
  3870. }
  3871. if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
  3872. cfg->line_outs <= cfg->hp_outs) {
  3873. /* use HP as primary out */
  3874. cfg->speaker_outs = cfg->line_outs;
  3875. memcpy(cfg->speaker_pins, cfg->line_out_pins,
  3876. sizeof(cfg->speaker_pins));
  3877. cfg->line_outs = cfg->hp_outs;
  3878. memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
  3879. cfg->hp_outs = 0;
  3880. memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
  3881. cfg->line_out_type = AUTO_PIN_HP_OUT;
  3882. }
  3883. err = alc_auto_fill_dac_nids(codec);
  3884. if (err < 0)
  3885. return err;
  3886. err = alc_auto_add_multi_channel_mode(codec);
  3887. if (err < 0)
  3888. return err;
  3889. err = alc_auto_create_multi_out_ctls(codec, cfg);
  3890. if (err < 0)
  3891. return err;
  3892. err = alc_auto_create_hp_out(codec);
  3893. if (err < 0)
  3894. return err;
  3895. err = alc_auto_create_speaker_out(codec);
  3896. if (err < 0)
  3897. return err;
  3898. err = alc_auto_create_shared_input(codec);
  3899. if (err < 0)
  3900. return err;
  3901. err = alc_auto_create_input_ctls(codec);
  3902. if (err < 0)
  3903. return err;
  3904. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3905. dig_only:
  3906. alc_auto_parse_digital(codec);
  3907. if (!spec->no_analog)
  3908. alc_remove_invalid_adc_nids(codec);
  3909. if (ssid_nids)
  3910. alc_ssid_check(codec, ssid_nids);
  3911. if (!spec->no_analog) {
  3912. alc_auto_check_switches(codec);
  3913. err = alc_auto_add_mic_boost(codec);
  3914. if (err < 0)
  3915. return err;
  3916. }
  3917. if (spec->kctls.list)
  3918. add_mixer(spec, spec->kctls.list);
  3919. if (!spec->no_analog && !spec->cap_mixer)
  3920. set_capture_mixer(codec);
  3921. return 1;
  3922. }
  3923. /* common preparation job for alc_spec */
  3924. static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
  3925. {
  3926. struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3927. int err;
  3928. if (!spec)
  3929. return -ENOMEM;
  3930. codec->spec = spec;
  3931. spec->mixer_nid = mixer_nid;
  3932. err = alc_codec_rename_from_preset(codec);
  3933. if (err < 0) {
  3934. kfree(spec);
  3935. return err;
  3936. }
  3937. return 0;
  3938. }
  3939. static int alc880_parse_auto_config(struct hda_codec *codec)
  3940. {
  3941. static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
  3942. static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  3943. return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
  3944. }
  3945. /*
  3946. * ALC880 fix-ups
  3947. */
  3948. enum {
  3949. ALC880_FIXUP_GPIO1,
  3950. ALC880_FIXUP_GPIO2,
  3951. ALC880_FIXUP_MEDION_RIM,
  3952. ALC880_FIXUP_LG,
  3953. ALC880_FIXUP_W810,
  3954. ALC880_FIXUP_EAPD_COEF,
  3955. ALC880_FIXUP_TCL_S700,
  3956. ALC880_FIXUP_VOL_KNOB,
  3957. ALC880_FIXUP_FUJITSU,
  3958. ALC880_FIXUP_F1734,
  3959. ALC880_FIXUP_UNIWILL,
  3960. ALC880_FIXUP_UNIWILL_DIG,
  3961. ALC880_FIXUP_Z71V,
  3962. ALC880_FIXUP_3ST_BASE,
  3963. ALC880_FIXUP_3ST,
  3964. ALC880_FIXUP_3ST_DIG,
  3965. ALC880_FIXUP_5ST_BASE,
  3966. ALC880_FIXUP_5ST,
  3967. ALC880_FIXUP_5ST_DIG,
  3968. ALC880_FIXUP_6ST_BASE,
  3969. ALC880_FIXUP_6ST,
  3970. ALC880_FIXUP_6ST_DIG,
  3971. };
  3972. /* enable the volume-knob widget support on NID 0x21 */
  3973. static void alc880_fixup_vol_knob(struct hda_codec *codec,
  3974. const struct alc_fixup *fix, int action)
  3975. {
  3976. if (action == ALC_FIXUP_ACT_PROBE)
  3977. snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
  3978. }
  3979. static const struct alc_fixup alc880_fixups[] = {
  3980. [ALC880_FIXUP_GPIO1] = {
  3981. .type = ALC_FIXUP_VERBS,
  3982. .v.verbs = alc_gpio1_init_verbs,
  3983. },
  3984. [ALC880_FIXUP_GPIO2] = {
  3985. .type = ALC_FIXUP_VERBS,
  3986. .v.verbs = alc_gpio2_init_verbs,
  3987. },
  3988. [ALC880_FIXUP_MEDION_RIM] = {
  3989. .type = ALC_FIXUP_VERBS,
  3990. .v.verbs = (const struct hda_verb[]) {
  3991. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  3992. { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
  3993. { }
  3994. },
  3995. .chained = true,
  3996. .chain_id = ALC880_FIXUP_GPIO2,
  3997. },
  3998. [ALC880_FIXUP_LG] = {
  3999. .type = ALC_FIXUP_PINS,
  4000. .v.pins = (const struct alc_pincfg[]) {
  4001. /* disable bogus unused pins */
  4002. { 0x16, 0x411111f0 },
  4003. { 0x18, 0x411111f0 },
  4004. { 0x1a, 0x411111f0 },
  4005. { }
  4006. }
  4007. },
  4008. [ALC880_FIXUP_W810] = {
  4009. .type = ALC_FIXUP_PINS,
  4010. .v.pins = (const struct alc_pincfg[]) {
  4011. /* disable bogus unused pins */
  4012. { 0x17, 0x411111f0 },
  4013. { }
  4014. },
  4015. .chained = true,
  4016. .chain_id = ALC880_FIXUP_GPIO2,
  4017. },
  4018. [ALC880_FIXUP_EAPD_COEF] = {
  4019. .type = ALC_FIXUP_VERBS,
  4020. .v.verbs = (const struct hda_verb[]) {
  4021. /* change to EAPD mode */
  4022. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4023. { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
  4024. {}
  4025. },
  4026. },
  4027. [ALC880_FIXUP_TCL_S700] = {
  4028. .type = ALC_FIXUP_VERBS,
  4029. .v.verbs = (const struct hda_verb[]) {
  4030. /* change to EAPD mode */
  4031. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4032. { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
  4033. {}
  4034. },
  4035. .chained = true,
  4036. .chain_id = ALC880_FIXUP_GPIO2,
  4037. },
  4038. [ALC880_FIXUP_VOL_KNOB] = {
  4039. .type = ALC_FIXUP_FUNC,
  4040. .v.func = alc880_fixup_vol_knob,
  4041. },
  4042. [ALC880_FIXUP_FUJITSU] = {
  4043. /* override all pins as BIOS on old Amilo is broken */
  4044. .type = ALC_FIXUP_PINS,
  4045. .v.pins = (const struct alc_pincfg[]) {
  4046. { 0x14, 0x0121411f }, /* HP */
  4047. { 0x15, 0x99030120 }, /* speaker */
  4048. { 0x16, 0x99030130 }, /* bass speaker */
  4049. { 0x17, 0x411111f0 }, /* N/A */
  4050. { 0x18, 0x411111f0 }, /* N/A */
  4051. { 0x19, 0x01a19950 }, /* mic-in */
  4052. { 0x1a, 0x411111f0 }, /* N/A */
  4053. { 0x1b, 0x411111f0 }, /* N/A */
  4054. { 0x1c, 0x411111f0 }, /* N/A */
  4055. { 0x1d, 0x411111f0 }, /* N/A */
  4056. { 0x1e, 0x01454140 }, /* SPDIF out */
  4057. { }
  4058. },
  4059. .chained = true,
  4060. .chain_id = ALC880_FIXUP_VOL_KNOB,
  4061. },
  4062. [ALC880_FIXUP_F1734] = {
  4063. /* almost compatible with FUJITSU, but no bass and SPDIF */
  4064. .type = ALC_FIXUP_PINS,
  4065. .v.pins = (const struct alc_pincfg[]) {
  4066. { 0x14, 0x0121411f }, /* HP */
  4067. { 0x15, 0x99030120 }, /* speaker */
  4068. { 0x16, 0x411111f0 }, /* N/A */
  4069. { 0x17, 0x411111f0 }, /* N/A */
  4070. { 0x18, 0x411111f0 }, /* N/A */
  4071. { 0x19, 0x01a19950 }, /* mic-in */
  4072. { 0x1a, 0x411111f0 }, /* N/A */
  4073. { 0x1b, 0x411111f0 }, /* N/A */
  4074. { 0x1c, 0x411111f0 }, /* N/A */
  4075. { 0x1d, 0x411111f0 }, /* N/A */
  4076. { 0x1e, 0x411111f0 }, /* N/A */
  4077. { }
  4078. },
  4079. .chained = true,
  4080. .chain_id = ALC880_FIXUP_VOL_KNOB,
  4081. },
  4082. [ALC880_FIXUP_UNIWILL] = {
  4083. /* need to fix HP and speaker pins to be parsed correctly */
  4084. .type = ALC_FIXUP_PINS,
  4085. .v.pins = (const struct alc_pincfg[]) {
  4086. { 0x14, 0x0121411f }, /* HP */
  4087. { 0x15, 0x99030120 }, /* speaker */
  4088. { 0x16, 0x99030130 }, /* bass speaker */
  4089. { }
  4090. },
  4091. },
  4092. [ALC880_FIXUP_UNIWILL_DIG] = {
  4093. .type = ALC_FIXUP_PINS,
  4094. .v.pins = (const struct alc_pincfg[]) {
  4095. /* disable bogus unused pins */
  4096. { 0x17, 0x411111f0 },
  4097. { 0x19, 0x411111f0 },
  4098. { 0x1b, 0x411111f0 },
  4099. { 0x1f, 0x411111f0 },
  4100. { }
  4101. }
  4102. },
  4103. [ALC880_FIXUP_Z71V] = {
  4104. .type = ALC_FIXUP_PINS,
  4105. .v.pins = (const struct alc_pincfg[]) {
  4106. /* set up the whole pins as BIOS is utterly broken */
  4107. { 0x14, 0x99030120 }, /* speaker */
  4108. { 0x15, 0x0121411f }, /* HP */
  4109. { 0x16, 0x411111f0 }, /* N/A */
  4110. { 0x17, 0x411111f0 }, /* N/A */
  4111. { 0x18, 0x01a19950 }, /* mic-in */
  4112. { 0x19, 0x411111f0 }, /* N/A */
  4113. { 0x1a, 0x01813031 }, /* line-in */
  4114. { 0x1b, 0x411111f0 }, /* N/A */
  4115. { 0x1c, 0x411111f0 }, /* N/A */
  4116. { 0x1d, 0x411111f0 }, /* N/A */
  4117. { 0x1e, 0x0144111e }, /* SPDIF */
  4118. { }
  4119. }
  4120. },
  4121. [ALC880_FIXUP_3ST_BASE] = {
  4122. .type = ALC_FIXUP_PINS,
  4123. .v.pins = (const struct alc_pincfg[]) {
  4124. { 0x14, 0x01014010 }, /* line-out */
  4125. { 0x15, 0x411111f0 }, /* N/A */
  4126. { 0x16, 0x411111f0 }, /* N/A */
  4127. { 0x17, 0x411111f0 }, /* N/A */
  4128. { 0x18, 0x01a19c30 }, /* mic-in */
  4129. { 0x19, 0x0121411f }, /* HP */
  4130. { 0x1a, 0x01813031 }, /* line-in */
  4131. { 0x1b, 0x02a19c40 }, /* front-mic */
  4132. { 0x1c, 0x411111f0 }, /* N/A */
  4133. { 0x1d, 0x411111f0 }, /* N/A */
  4134. /* 0x1e is filled in below */
  4135. { 0x1f, 0x411111f0 }, /* N/A */
  4136. { }
  4137. }
  4138. },
  4139. [ALC880_FIXUP_3ST] = {
  4140. .type = ALC_FIXUP_PINS,
  4141. .v.pins = (const struct alc_pincfg[]) {
  4142. { 0x1e, 0x411111f0 }, /* N/A */
  4143. { }
  4144. },
  4145. .chained = true,
  4146. .chain_id = ALC880_FIXUP_3ST_BASE,
  4147. },
  4148. [ALC880_FIXUP_3ST_DIG] = {
  4149. .type = ALC_FIXUP_PINS,
  4150. .v.pins = (const struct alc_pincfg[]) {
  4151. { 0x1e, 0x0144111e }, /* SPDIF */
  4152. { }
  4153. },
  4154. .chained = true,
  4155. .chain_id = ALC880_FIXUP_3ST_BASE,
  4156. },
  4157. [ALC880_FIXUP_5ST_BASE] = {
  4158. .type = ALC_FIXUP_PINS,
  4159. .v.pins = (const struct alc_pincfg[]) {
  4160. { 0x14, 0x01014010 }, /* front */
  4161. { 0x15, 0x411111f0 }, /* N/A */
  4162. { 0x16, 0x01011411 }, /* CLFE */
  4163. { 0x17, 0x01016412 }, /* surr */
  4164. { 0x18, 0x01a19c30 }, /* mic-in */
  4165. { 0x19, 0x0121411f }, /* HP */
  4166. { 0x1a, 0x01813031 }, /* line-in */
  4167. { 0x1b, 0x02a19c40 }, /* front-mic */
  4168. { 0x1c, 0x411111f0 }, /* N/A */
  4169. { 0x1d, 0x411111f0 }, /* N/A */
  4170. /* 0x1e is filled in below */
  4171. { 0x1f, 0x411111f0 }, /* N/A */
  4172. { }
  4173. }
  4174. },
  4175. [ALC880_FIXUP_5ST] = {
  4176. .type = ALC_FIXUP_PINS,
  4177. .v.pins = (const struct alc_pincfg[]) {
  4178. { 0x1e, 0x411111f0 }, /* N/A */
  4179. { }
  4180. },
  4181. .chained = true,
  4182. .chain_id = ALC880_FIXUP_5ST_BASE,
  4183. },
  4184. [ALC880_FIXUP_5ST_DIG] = {
  4185. .type = ALC_FIXUP_PINS,
  4186. .v.pins = (const struct alc_pincfg[]) {
  4187. { 0x1e, 0x0144111e }, /* SPDIF */
  4188. { }
  4189. },
  4190. .chained = true,
  4191. .chain_id = ALC880_FIXUP_5ST_BASE,
  4192. },
  4193. [ALC880_FIXUP_6ST_BASE] = {
  4194. .type = ALC_FIXUP_PINS,
  4195. .v.pins = (const struct alc_pincfg[]) {
  4196. { 0x14, 0x01014010 }, /* front */
  4197. { 0x15, 0x01016412 }, /* surr */
  4198. { 0x16, 0x01011411 }, /* CLFE */
  4199. { 0x17, 0x01012414 }, /* side */
  4200. { 0x18, 0x01a19c30 }, /* mic-in */
  4201. { 0x19, 0x02a19c40 }, /* front-mic */
  4202. { 0x1a, 0x01813031 }, /* line-in */
  4203. { 0x1b, 0x0121411f }, /* HP */
  4204. { 0x1c, 0x411111f0 }, /* N/A */
  4205. { 0x1d, 0x411111f0 }, /* N/A */
  4206. /* 0x1e is filled in below */
  4207. { 0x1f, 0x411111f0 }, /* N/A */
  4208. { }
  4209. }
  4210. },
  4211. [ALC880_FIXUP_6ST] = {
  4212. .type = ALC_FIXUP_PINS,
  4213. .v.pins = (const struct alc_pincfg[]) {
  4214. { 0x1e, 0x411111f0 }, /* N/A */
  4215. { }
  4216. },
  4217. .chained = true,
  4218. .chain_id = ALC880_FIXUP_6ST_BASE,
  4219. },
  4220. [ALC880_FIXUP_6ST_DIG] = {
  4221. .type = ALC_FIXUP_PINS,
  4222. .v.pins = (const struct alc_pincfg[]) {
  4223. { 0x1e, 0x0144111e }, /* SPDIF */
  4224. { }
  4225. },
  4226. .chained = true,
  4227. .chain_id = ALC880_FIXUP_6ST_BASE,
  4228. },
  4229. };
  4230. static const struct snd_pci_quirk alc880_fixup_tbl[] = {
  4231. SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
  4232. SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
  4233. SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
  4234. SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
  4235. SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
  4236. SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
  4237. SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
  4238. SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
  4239. SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
  4240. SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
  4241. SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
  4242. SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
  4243. SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
  4244. SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
  4245. SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
  4246. SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
  4247. SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
  4248. SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
  4249. SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
  4250. /* Below is the copied entries from alc880_quirks.c.
  4251. * It's not quite sure whether BIOS sets the correct pin-config table
  4252. * on these machines, thus they are kept to be compatible with
  4253. * the old static quirks. Once when it's confirmed to work without
  4254. * these overrides, it'd be better to remove.
  4255. */
  4256. SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
  4257. SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
  4258. SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
  4259. SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
  4260. SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
  4261. SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
  4262. SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
  4263. SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
  4264. SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
  4265. SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
  4266. SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
  4267. SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
  4268. SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
  4269. SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
  4270. SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
  4271. SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
  4272. SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
  4273. SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
  4274. SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
  4275. SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
  4276. SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
  4277. SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
  4278. SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
  4279. SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4280. SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4281. SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4282. SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
  4283. SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4284. SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
  4285. SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
  4286. SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4287. SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4288. SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4289. /* default Intel */
  4290. SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
  4291. SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
  4292. SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
  4293. {}
  4294. };
  4295. static const struct alc_model_fixup alc880_fixup_models[] = {
  4296. {.id = ALC880_FIXUP_3ST, .name = "3stack"},
  4297. {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
  4298. {.id = ALC880_FIXUP_5ST, .name = "5stack"},
  4299. {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
  4300. {.id = ALC880_FIXUP_6ST, .name = "6stack"},
  4301. {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
  4302. {}
  4303. };
  4304. /*
  4305. * OK, here we have finally the patch for ALC880
  4306. */
  4307. static int patch_alc880(struct hda_codec *codec)
  4308. {
  4309. struct alc_spec *spec;
  4310. int err;
  4311. err = alc_alloc_spec(codec, 0x0b);
  4312. if (err < 0)
  4313. return err;
  4314. spec = codec->spec;
  4315. spec->need_dac_fix = 1;
  4316. alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
  4317. alc880_fixups);
  4318. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4319. /* automatic parse from the BIOS config */
  4320. err = alc880_parse_auto_config(codec);
  4321. if (err < 0)
  4322. goto error;
  4323. if (!spec->no_analog) {
  4324. err = snd_hda_attach_beep_device(codec, 0x1);
  4325. if (err < 0)
  4326. goto error;
  4327. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  4328. }
  4329. codec->patch_ops = alc_patch_ops;
  4330. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4331. return 0;
  4332. error:
  4333. alc_free(codec);
  4334. return err;
  4335. }
  4336. /*
  4337. * ALC260 support
  4338. */
  4339. static int alc260_parse_auto_config(struct hda_codec *codec)
  4340. {
  4341. static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
  4342. static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
  4343. return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
  4344. }
  4345. /*
  4346. * Pin config fixes
  4347. */
  4348. enum {
  4349. ALC260_FIXUP_HP_DC5750,
  4350. ALC260_FIXUP_HP_PIN_0F,
  4351. ALC260_FIXUP_COEF,
  4352. ALC260_FIXUP_GPIO1,
  4353. ALC260_FIXUP_GPIO1_TOGGLE,
  4354. ALC260_FIXUP_REPLACER,
  4355. ALC260_FIXUP_HP_B1900,
  4356. ALC260_FIXUP_KN1,
  4357. };
  4358. static void alc260_gpio1_automute(struct hda_codec *codec)
  4359. {
  4360. struct alc_spec *spec = codec->spec;
  4361. snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
  4362. spec->hp_jack_present);
  4363. }
  4364. static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
  4365. const struct alc_fixup *fix, int action)
  4366. {
  4367. struct alc_spec *spec = codec->spec;
  4368. if (action == ALC_FIXUP_ACT_PROBE) {
  4369. /* although the machine has only one output pin, we need to
  4370. * toggle GPIO1 according to the jack state
  4371. */
  4372. spec->automute_hook = alc260_gpio1_automute;
  4373. spec->detect_hp = 1;
  4374. spec->automute_speaker = 1;
  4375. spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
  4376. snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
  4377. spec->unsol_event = alc_sku_unsol_event;
  4378. snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
  4379. }
  4380. }
  4381. static void alc260_fixup_kn1(struct hda_codec *codec,
  4382. const struct alc_fixup *fix, int action)
  4383. {
  4384. struct alc_spec *spec = codec->spec;
  4385. static const struct alc_pincfg pincfgs[] = {
  4386. { 0x0f, 0x02214000 }, /* HP/speaker */
  4387. { 0x12, 0x90a60160 }, /* int mic */
  4388. { 0x13, 0x02a19000 }, /* ext mic */
  4389. { 0x18, 0x01446000 }, /* SPDIF out */
  4390. /* disable bogus I/O pins */
  4391. { 0x10, 0x411111f0 },
  4392. { 0x11, 0x411111f0 },
  4393. { 0x14, 0x411111f0 },
  4394. { 0x15, 0x411111f0 },
  4395. { 0x16, 0x411111f0 },
  4396. { 0x17, 0x411111f0 },
  4397. { 0x19, 0x411111f0 },
  4398. { }
  4399. };
  4400. switch (action) {
  4401. case ALC_FIXUP_ACT_PRE_PROBE:
  4402. alc_apply_pincfgs(codec, pincfgs);
  4403. break;
  4404. case ALC_FIXUP_ACT_PROBE:
  4405. spec->init_amp = ALC_INIT_NONE;
  4406. break;
  4407. }
  4408. }
  4409. static const struct alc_fixup alc260_fixups[] = {
  4410. [ALC260_FIXUP_HP_DC5750] = {
  4411. .type = ALC_FIXUP_PINS,
  4412. .v.pins = (const struct alc_pincfg[]) {
  4413. { 0x11, 0x90130110 }, /* speaker */
  4414. { }
  4415. }
  4416. },
  4417. [ALC260_FIXUP_HP_PIN_0F] = {
  4418. .type = ALC_FIXUP_PINS,
  4419. .v.pins = (const struct alc_pincfg[]) {
  4420. { 0x0f, 0x01214000 }, /* HP */
  4421. { }
  4422. }
  4423. },
  4424. [ALC260_FIXUP_COEF] = {
  4425. .type = ALC_FIXUP_VERBS,
  4426. .v.verbs = (const struct hda_verb[]) {
  4427. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4428. { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
  4429. { }
  4430. },
  4431. .chained = true,
  4432. .chain_id = ALC260_FIXUP_HP_PIN_0F,
  4433. },
  4434. [ALC260_FIXUP_GPIO1] = {
  4435. .type = ALC_FIXUP_VERBS,
  4436. .v.verbs = alc_gpio1_init_verbs,
  4437. },
  4438. [ALC260_FIXUP_GPIO1_TOGGLE] = {
  4439. .type = ALC_FIXUP_FUNC,
  4440. .v.func = alc260_fixup_gpio1_toggle,
  4441. .chained = true,
  4442. .chain_id = ALC260_FIXUP_HP_PIN_0F,
  4443. },
  4444. [ALC260_FIXUP_REPLACER] = {
  4445. .type = ALC_FIXUP_VERBS,
  4446. .v.verbs = (const struct hda_verb[]) {
  4447. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4448. { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
  4449. { }
  4450. },
  4451. .chained = true,
  4452. .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
  4453. },
  4454. [ALC260_FIXUP_HP_B1900] = {
  4455. .type = ALC_FIXUP_FUNC,
  4456. .v.func = alc260_fixup_gpio1_toggle,
  4457. .chained = true,
  4458. .chain_id = ALC260_FIXUP_COEF,
  4459. },
  4460. [ALC260_FIXUP_KN1] = {
  4461. .type = ALC_FIXUP_FUNC,
  4462. .v.func = alc260_fixup_kn1,
  4463. },
  4464. };
  4465. static const struct snd_pci_quirk alc260_fixup_tbl[] = {
  4466. SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
  4467. SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
  4468. SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
  4469. SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
  4470. SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
  4471. SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
  4472. SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
  4473. SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
  4474. SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
  4475. {}
  4476. };
  4477. /*
  4478. */
  4479. static int patch_alc260(struct hda_codec *codec)
  4480. {
  4481. struct alc_spec *spec;
  4482. int err;
  4483. err = alc_alloc_spec(codec, 0x07);
  4484. if (err < 0)
  4485. return err;
  4486. spec = codec->spec;
  4487. alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
  4488. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4489. /* automatic parse from the BIOS config */
  4490. err = alc260_parse_auto_config(codec);
  4491. if (err < 0)
  4492. goto error;
  4493. if (!spec->no_analog) {
  4494. err = snd_hda_attach_beep_device(codec, 0x1);
  4495. if (err < 0)
  4496. goto error;
  4497. set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
  4498. }
  4499. codec->patch_ops = alc_patch_ops;
  4500. spec->shutup = alc_eapd_shutup;
  4501. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4502. return 0;
  4503. error:
  4504. alc_free(codec);
  4505. return err;
  4506. }
  4507. /*
  4508. * ALC882/883/885/888/889 support
  4509. *
  4510. * ALC882 is almost identical with ALC880 but has cleaner and more flexible
  4511. * configuration. Each pin widget can choose any input DACs and a mixer.
  4512. * Each ADC is connected from a mixer of all inputs. This makes possible
  4513. * 6-channel independent captures.
  4514. *
  4515. * In addition, an independent DAC for the multi-playback (not used in this
  4516. * driver yet).
  4517. */
  4518. /*
  4519. * Pin config fixes
  4520. */
  4521. enum {
  4522. ALC882_FIXUP_ABIT_AW9D_MAX,
  4523. ALC882_FIXUP_LENOVO_Y530,
  4524. ALC882_FIXUP_PB_M5210,
  4525. ALC882_FIXUP_ACER_ASPIRE_7736,
  4526. ALC882_FIXUP_ASUS_W90V,
  4527. ALC889_FIXUP_CD,
  4528. ALC889_FIXUP_VAIO_TT,
  4529. ALC888_FIXUP_EEE1601,
  4530. ALC882_FIXUP_EAPD,
  4531. ALC883_FIXUP_EAPD,
  4532. ALC883_FIXUP_ACER_EAPD,
  4533. ALC882_FIXUP_GPIO1,
  4534. ALC882_FIXUP_GPIO2,
  4535. ALC882_FIXUP_GPIO3,
  4536. ALC889_FIXUP_COEF,
  4537. ALC882_FIXUP_ASUS_W2JC,
  4538. ALC882_FIXUP_ACER_ASPIRE_4930G,
  4539. ALC882_FIXUP_ACER_ASPIRE_8930G,
  4540. ALC882_FIXUP_ASPIRE_8930G_VERBS,
  4541. ALC885_FIXUP_MACPRO_GPIO,
  4542. ALC889_FIXUP_DAC_ROUTE,
  4543. ALC889_FIXUP_MBP_VREF,
  4544. ALC889_FIXUP_IMAC91_VREF,
  4545. ALC882_FIXUP_INV_DMIC,
  4546. };
  4547. static void alc889_fixup_coef(struct hda_codec *codec,
  4548. const struct alc_fixup *fix, int action)
  4549. {
  4550. if (action != ALC_FIXUP_ACT_INIT)
  4551. return;
  4552. alc889_coef_init(codec);
  4553. }
  4554. /* toggle speaker-output according to the hp-jack state */
  4555. static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
  4556. {
  4557. unsigned int gpiostate, gpiomask, gpiodir;
  4558. gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
  4559. AC_VERB_GET_GPIO_DATA, 0);
  4560. if (!muted)
  4561. gpiostate |= (1 << pin);
  4562. else
  4563. gpiostate &= ~(1 << pin);
  4564. gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
  4565. AC_VERB_GET_GPIO_MASK, 0);
  4566. gpiomask |= (1 << pin);
  4567. gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
  4568. AC_VERB_GET_GPIO_DIRECTION, 0);
  4569. gpiodir |= (1 << pin);
  4570. snd_hda_codec_write(codec, codec->afg, 0,
  4571. AC_VERB_SET_GPIO_MASK, gpiomask);
  4572. snd_hda_codec_write(codec, codec->afg, 0,
  4573. AC_VERB_SET_GPIO_DIRECTION, gpiodir);
  4574. msleep(1);
  4575. snd_hda_codec_write(codec, codec->afg, 0,
  4576. AC_VERB_SET_GPIO_DATA, gpiostate);
  4577. }
  4578. /* set up GPIO at initialization */
  4579. static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
  4580. const struct alc_fixup *fix, int action)
  4581. {
  4582. if (action != ALC_FIXUP_ACT_INIT)
  4583. return;
  4584. alc882_gpio_mute(codec, 0, 0);
  4585. alc882_gpio_mute(codec, 1, 0);
  4586. }
  4587. /* Fix the connection of some pins for ALC889:
  4588. * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
  4589. * work correctly (bko#42740)
  4590. */
  4591. static void alc889_fixup_dac_route(struct hda_codec *codec,
  4592. const struct alc_fixup *fix, int action)
  4593. {
  4594. if (action == ALC_FIXUP_ACT_PRE_PROBE) {
  4595. /* fake the connections during parsing the tree */
  4596. hda_nid_t conn1[2] = { 0x0c, 0x0d };
  4597. hda_nid_t conn2[2] = { 0x0e, 0x0f };
  4598. snd_hda_override_conn_list(codec, 0x14, 2, conn1);
  4599. snd_hda_override_conn_list(codec, 0x15, 2, conn1);
  4600. snd_hda_override_conn_list(codec, 0x18, 2, conn2);
  4601. snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
  4602. } else if (action == ALC_FIXUP_ACT_PROBE) {
  4603. /* restore the connections */
  4604. hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
  4605. snd_hda_override_conn_list(codec, 0x14, 5, conn);
  4606. snd_hda_override_conn_list(codec, 0x15, 5, conn);
  4607. snd_hda_override_conn_list(codec, 0x18, 5, conn);
  4608. snd_hda_override_conn_list(codec, 0x1a, 5, conn);
  4609. }
  4610. }
  4611. /* Set VREF on HP pin */
  4612. static void alc889_fixup_mbp_vref(struct hda_codec *codec,
  4613. const struct alc_fixup *fix, int action)
  4614. {
  4615. struct alc_spec *spec = codec->spec;
  4616. static hda_nid_t nids[2] = { 0x14, 0x15 };
  4617. int i;
  4618. if (action != ALC_FIXUP_ACT_INIT)
  4619. return;
  4620. for (i = 0; i < ARRAY_SIZE(nids); i++) {
  4621. unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
  4622. if (get_defcfg_device(val) != AC_JACK_HP_OUT)
  4623. continue;
  4624. val = snd_hda_codec_read(codec, nids[i], 0,
  4625. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  4626. val |= AC_PINCTL_VREF_80;
  4627. snd_hda_set_pin_ctl(codec, nids[i], val);
  4628. spec->keep_vref_in_automute = 1;
  4629. break;
  4630. }
  4631. }
  4632. /* Set VREF on speaker pins on imac91 */
  4633. static void alc889_fixup_imac91_vref(struct hda_codec *codec,
  4634. const struct alc_fixup *fix, int action)
  4635. {
  4636. struct alc_spec *spec = codec->spec;
  4637. static hda_nid_t nids[2] = { 0x18, 0x1a };
  4638. int i;
  4639. if (action != ALC_FIXUP_ACT_INIT)
  4640. return;
  4641. for (i = 0; i < ARRAY_SIZE(nids); i++) {
  4642. unsigned int val;
  4643. val = snd_hda_codec_read(codec, nids[i], 0,
  4644. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  4645. val |= AC_PINCTL_VREF_50;
  4646. snd_hda_set_pin_ctl(codec, nids[i], val);
  4647. }
  4648. spec->keep_vref_in_automute = 1;
  4649. }
  4650. static const struct alc_fixup alc882_fixups[] = {
  4651. [ALC882_FIXUP_ABIT_AW9D_MAX] = {
  4652. .type = ALC_FIXUP_PINS,
  4653. .v.pins = (const struct alc_pincfg[]) {
  4654. { 0x15, 0x01080104 }, /* side */
  4655. { 0x16, 0x01011012 }, /* rear */
  4656. { 0x17, 0x01016011 }, /* clfe */
  4657. { }
  4658. }
  4659. },
  4660. [ALC882_FIXUP_LENOVO_Y530] = {
  4661. .type = ALC_FIXUP_PINS,
  4662. .v.pins = (const struct alc_pincfg[]) {
  4663. { 0x15, 0x99130112 }, /* rear int speakers */
  4664. { 0x16, 0x99130111 }, /* subwoofer */
  4665. { }
  4666. }
  4667. },
  4668. [ALC882_FIXUP_PB_M5210] = {
  4669. .type = ALC_FIXUP_VERBS,
  4670. .v.verbs = (const struct hda_verb[]) {
  4671. { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
  4672. {}
  4673. }
  4674. },
  4675. [ALC882_FIXUP_ACER_ASPIRE_7736] = {
  4676. .type = ALC_FIXUP_FUNC,
  4677. .v.func = alc_fixup_sku_ignore,
  4678. },
  4679. [ALC882_FIXUP_ASUS_W90V] = {
  4680. .type = ALC_FIXUP_PINS,
  4681. .v.pins = (const struct alc_pincfg[]) {
  4682. { 0x16, 0x99130110 }, /* fix sequence for CLFE */
  4683. { }
  4684. }
  4685. },
  4686. [ALC889_FIXUP_CD] = {
  4687. .type = ALC_FIXUP_PINS,
  4688. .v.pins = (const struct alc_pincfg[]) {
  4689. { 0x1c, 0x993301f0 }, /* CD */
  4690. { }
  4691. }
  4692. },
  4693. [ALC889_FIXUP_VAIO_TT] = {
  4694. .type = ALC_FIXUP_PINS,
  4695. .v.pins = (const struct alc_pincfg[]) {
  4696. { 0x17, 0x90170111 }, /* hidden surround speaker */
  4697. { }
  4698. }
  4699. },
  4700. [ALC888_FIXUP_EEE1601] = {
  4701. .type = ALC_FIXUP_VERBS,
  4702. .v.verbs = (const struct hda_verb[]) {
  4703. { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
  4704. { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
  4705. { }
  4706. }
  4707. },
  4708. [ALC882_FIXUP_EAPD] = {
  4709. .type = ALC_FIXUP_VERBS,
  4710. .v.verbs = (const struct hda_verb[]) {
  4711. /* change to EAPD mode */
  4712. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4713. { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
  4714. { }
  4715. }
  4716. },
  4717. [ALC883_FIXUP_EAPD] = {
  4718. .type = ALC_FIXUP_VERBS,
  4719. .v.verbs = (const struct hda_verb[]) {
  4720. /* change to EAPD mode */
  4721. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4722. { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
  4723. { }
  4724. }
  4725. },
  4726. [ALC883_FIXUP_ACER_EAPD] = {
  4727. .type = ALC_FIXUP_VERBS,
  4728. .v.verbs = (const struct hda_verb[]) {
  4729. /* eanable EAPD on Acer laptops */
  4730. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4731. { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
  4732. { }
  4733. }
  4734. },
  4735. [ALC882_FIXUP_GPIO1] = {
  4736. .type = ALC_FIXUP_VERBS,
  4737. .v.verbs = alc_gpio1_init_verbs,
  4738. },
  4739. [ALC882_FIXUP_GPIO2] = {
  4740. .type = ALC_FIXUP_VERBS,
  4741. .v.verbs = alc_gpio2_init_verbs,
  4742. },
  4743. [ALC882_FIXUP_GPIO3] = {
  4744. .type = ALC_FIXUP_VERBS,
  4745. .v.verbs = alc_gpio3_init_verbs,
  4746. },
  4747. [ALC882_FIXUP_ASUS_W2JC] = {
  4748. .type = ALC_FIXUP_VERBS,
  4749. .v.verbs = alc_gpio1_init_verbs,
  4750. .chained = true,
  4751. .chain_id = ALC882_FIXUP_EAPD,
  4752. },
  4753. [ALC889_FIXUP_COEF] = {
  4754. .type = ALC_FIXUP_FUNC,
  4755. .v.func = alc889_fixup_coef,
  4756. },
  4757. [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
  4758. .type = ALC_FIXUP_PINS,
  4759. .v.pins = (const struct alc_pincfg[]) {
  4760. { 0x16, 0x99130111 }, /* CLFE speaker */
  4761. { 0x17, 0x99130112 }, /* surround speaker */
  4762. { }
  4763. },
  4764. .chained = true,
  4765. .chain_id = ALC882_FIXUP_GPIO1,
  4766. },
  4767. [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
  4768. .type = ALC_FIXUP_PINS,
  4769. .v.pins = (const struct alc_pincfg[]) {
  4770. { 0x16, 0x99130111 }, /* CLFE speaker */
  4771. { 0x1b, 0x99130112 }, /* surround speaker */
  4772. { }
  4773. },
  4774. .chained = true,
  4775. .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
  4776. },
  4777. [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
  4778. /* additional init verbs for Acer Aspire 8930G */
  4779. .type = ALC_FIXUP_VERBS,
  4780. .v.verbs = (const struct hda_verb[]) {
  4781. /* Enable all DACs */
  4782. /* DAC DISABLE/MUTE 1? */
  4783. /* setting bits 1-5 disables DAC nids 0x02-0x06
  4784. * apparently. Init=0x38 */
  4785. { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
  4786. { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
  4787. /* DAC DISABLE/MUTE 2? */
  4788. /* some bit here disables the other DACs.
  4789. * Init=0x4900 */
  4790. { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
  4791. { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
  4792. /* DMIC fix
  4793. * This laptop has a stereo digital microphone.
  4794. * The mics are only 1cm apart which makes the stereo
  4795. * useless. However, either the mic or the ALC889
  4796. * makes the signal become a difference/sum signal
  4797. * instead of standard stereo, which is annoying.
  4798. * So instead we flip this bit which makes the
  4799. * codec replicate the sum signal to both channels,
  4800. * turning it into a normal mono mic.
  4801. */
  4802. /* DMIC_CONTROL? Init value = 0x0001 */
  4803. { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
  4804. { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
  4805. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4806. { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
  4807. { }
  4808. },
  4809. .chained = true,
  4810. .chain_id = ALC882_FIXUP_GPIO1,
  4811. },
  4812. [ALC885_FIXUP_MACPRO_GPIO] = {
  4813. .type = ALC_FIXUP_FUNC,
  4814. .v.func = alc885_fixup_macpro_gpio,
  4815. },
  4816. [ALC889_FIXUP_DAC_ROUTE] = {
  4817. .type = ALC_FIXUP_FUNC,
  4818. .v.func = alc889_fixup_dac_route,
  4819. },
  4820. [ALC889_FIXUP_MBP_VREF] = {
  4821. .type = ALC_FIXUP_FUNC,
  4822. .v.func = alc889_fixup_mbp_vref,
  4823. .chained = true,
  4824. .chain_id = ALC882_FIXUP_GPIO1,
  4825. },
  4826. [ALC889_FIXUP_IMAC91_VREF] = {
  4827. .type = ALC_FIXUP_FUNC,
  4828. .v.func = alc889_fixup_imac91_vref,
  4829. .chained = true,
  4830. .chain_id = ALC882_FIXUP_GPIO1,
  4831. },
  4832. [ALC882_FIXUP_INV_DMIC] = {
  4833. .type = ALC_FIXUP_FUNC,
  4834. .v.func = alc_fixup_inv_dmic_0x12,
  4835. },
  4836. };
  4837. static const struct snd_pci_quirk alc882_fixup_tbl[] = {
  4838. SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
  4839. SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
  4840. SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
  4841. SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
  4842. SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
  4843. SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
  4844. SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
  4845. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4846. SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
  4847. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4848. SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
  4849. ALC882_FIXUP_ACER_ASPIRE_8930G),
  4850. SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
  4851. ALC882_FIXUP_ACER_ASPIRE_8930G),
  4852. SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
  4853. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4854. SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
  4855. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4856. SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
  4857. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4858. SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
  4859. SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
  4860. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4861. SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
  4862. SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
  4863. SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
  4864. SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
  4865. SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
  4866. SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
  4867. SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
  4868. SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
  4869. /* All Apple entries are in codec SSIDs */
  4870. SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
  4871. SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
  4872. SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
  4873. SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
  4874. SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
  4875. SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
  4876. SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
  4877. SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
  4878. SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
  4879. SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
  4880. SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
  4881. SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
  4882. SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
  4883. SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
  4884. SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
  4885. SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
  4886. SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
  4887. SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
  4888. SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
  4889. SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
  4890. SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
  4891. SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
  4892. SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
  4893. SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
  4894. SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
  4895. SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
  4896. SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
  4897. SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
  4898. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
  4899. SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
  4900. {}
  4901. };
  4902. static const struct alc_model_fixup alc882_fixup_models[] = {
  4903. {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
  4904. {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
  4905. {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
  4906. {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
  4907. {}
  4908. };
  4909. /*
  4910. * BIOS auto configuration
  4911. */
  4912. /* almost identical with ALC880 parser... */
  4913. static int alc882_parse_auto_config(struct hda_codec *codec)
  4914. {
  4915. static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
  4916. static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  4917. return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
  4918. }
  4919. /*
  4920. */
  4921. static int patch_alc882(struct hda_codec *codec)
  4922. {
  4923. struct alc_spec *spec;
  4924. int err;
  4925. err = alc_alloc_spec(codec, 0x0b);
  4926. if (err < 0)
  4927. return err;
  4928. spec = codec->spec;
  4929. switch (codec->vendor_id) {
  4930. case 0x10ec0882:
  4931. case 0x10ec0885:
  4932. break;
  4933. default:
  4934. /* ALC883 and variants */
  4935. alc_fix_pll_init(codec, 0x20, 0x0a, 10);
  4936. break;
  4937. }
  4938. alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
  4939. alc882_fixups);
  4940. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4941. alc_auto_parse_customize_define(codec);
  4942. /* automatic parse from the BIOS config */
  4943. err = alc882_parse_auto_config(codec);
  4944. if (err < 0)
  4945. goto error;
  4946. if (!spec->no_analog && has_cdefine_beep(codec)) {
  4947. err = snd_hda_attach_beep_device(codec, 0x1);
  4948. if (err < 0)
  4949. goto error;
  4950. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  4951. }
  4952. codec->patch_ops = alc_patch_ops;
  4953. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4954. return 0;
  4955. error:
  4956. alc_free(codec);
  4957. return err;
  4958. }
  4959. /*
  4960. * ALC262 support
  4961. */
  4962. static int alc262_parse_auto_config(struct hda_codec *codec)
  4963. {
  4964. static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
  4965. static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  4966. return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
  4967. }
  4968. /*
  4969. * Pin config fixes
  4970. */
  4971. enum {
  4972. ALC262_FIXUP_FSC_H270,
  4973. ALC262_FIXUP_HP_Z200,
  4974. ALC262_FIXUP_TYAN,
  4975. ALC262_FIXUP_LENOVO_3000,
  4976. ALC262_FIXUP_BENQ,
  4977. ALC262_FIXUP_BENQ_T31,
  4978. ALC262_FIXUP_INV_DMIC,
  4979. };
  4980. static const struct alc_fixup alc262_fixups[] = {
  4981. [ALC262_FIXUP_FSC_H270] = {
  4982. .type = ALC_FIXUP_PINS,
  4983. .v.pins = (const struct alc_pincfg[]) {
  4984. { 0x14, 0x99130110 }, /* speaker */
  4985. { 0x15, 0x0221142f }, /* front HP */
  4986. { 0x1b, 0x0121141f }, /* rear HP */
  4987. { }
  4988. }
  4989. },
  4990. [ALC262_FIXUP_HP_Z200] = {
  4991. .type = ALC_FIXUP_PINS,
  4992. .v.pins = (const struct alc_pincfg[]) {
  4993. { 0x16, 0x99130120 }, /* internal speaker */
  4994. { }
  4995. }
  4996. },
  4997. [ALC262_FIXUP_TYAN] = {
  4998. .type = ALC_FIXUP_PINS,
  4999. .v.pins = (const struct alc_pincfg[]) {
  5000. { 0x14, 0x1993e1f0 }, /* int AUX */
  5001. { }
  5002. }
  5003. },
  5004. [ALC262_FIXUP_LENOVO_3000] = {
  5005. .type = ALC_FIXUP_VERBS,
  5006. .v.verbs = (const struct hda_verb[]) {
  5007. { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
  5008. {}
  5009. },
  5010. .chained = true,
  5011. .chain_id = ALC262_FIXUP_BENQ,
  5012. },
  5013. [ALC262_FIXUP_BENQ] = {
  5014. .type = ALC_FIXUP_VERBS,
  5015. .v.verbs = (const struct hda_verb[]) {
  5016. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  5017. { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
  5018. {}
  5019. }
  5020. },
  5021. [ALC262_FIXUP_BENQ_T31] = {
  5022. .type = ALC_FIXUP_VERBS,
  5023. .v.verbs = (const struct hda_verb[]) {
  5024. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  5025. { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
  5026. {}
  5027. }
  5028. },
  5029. [ALC262_FIXUP_INV_DMIC] = {
  5030. .type = ALC_FIXUP_FUNC,
  5031. .v.func = alc_fixup_inv_dmic_0x12,
  5032. },
  5033. };
  5034. static const struct snd_pci_quirk alc262_fixup_tbl[] = {
  5035. SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
  5036. SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
  5037. SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
  5038. SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
  5039. SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
  5040. SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
  5041. SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
  5042. SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
  5043. {}
  5044. };
  5045. static const struct alc_model_fixup alc262_fixup_models[] = {
  5046. {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
  5047. {}
  5048. };
  5049. /*
  5050. */
  5051. static int patch_alc262(struct hda_codec *codec)
  5052. {
  5053. struct alc_spec *spec;
  5054. int err;
  5055. err = alc_alloc_spec(codec, 0x0b);
  5056. if (err < 0)
  5057. return err;
  5058. spec = codec->spec;
  5059. #if 0
  5060. /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
  5061. * under-run
  5062. */
  5063. {
  5064. int tmp;
  5065. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
  5066. tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
  5067. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
  5068. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
  5069. }
  5070. #endif
  5071. alc_fix_pll_init(codec, 0x20, 0x0a, 10);
  5072. alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
  5073. alc262_fixups);
  5074. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5075. alc_auto_parse_customize_define(codec);
  5076. /* automatic parse from the BIOS config */
  5077. err = alc262_parse_auto_config(codec);
  5078. if (err < 0)
  5079. goto error;
  5080. if (!spec->no_analog && has_cdefine_beep(codec)) {
  5081. err = snd_hda_attach_beep_device(codec, 0x1);
  5082. if (err < 0)
  5083. goto error;
  5084. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  5085. }
  5086. codec->patch_ops = alc_patch_ops;
  5087. spec->shutup = alc_eapd_shutup;
  5088. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5089. return 0;
  5090. error:
  5091. alc_free(codec);
  5092. return err;
  5093. }
  5094. /*
  5095. * ALC268
  5096. */
  5097. /* bind Beep switches of both NID 0x0f and 0x10 */
  5098. static const struct hda_bind_ctls alc268_bind_beep_sw = {
  5099. .ops = &snd_hda_bind_sw,
  5100. .values = {
  5101. HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
  5102. HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
  5103. 0
  5104. },
  5105. };
  5106. static const struct snd_kcontrol_new alc268_beep_mixer[] = {
  5107. HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
  5108. HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
  5109. { }
  5110. };
  5111. /* set PCBEEP vol = 0, mute connections */
  5112. static const struct hda_verb alc268_beep_init_verbs[] = {
  5113. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  5114. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  5115. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  5116. { }
  5117. };
  5118. enum {
  5119. ALC268_FIXUP_INV_DMIC,
  5120. };
  5121. static const struct alc_fixup alc268_fixups[] = {
  5122. [ALC268_FIXUP_INV_DMIC] = {
  5123. .type = ALC_FIXUP_FUNC,
  5124. .v.func = alc_fixup_inv_dmic_0x12,
  5125. },
  5126. };
  5127. static const struct alc_model_fixup alc268_fixup_models[] = {
  5128. {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
  5129. {}
  5130. };
  5131. /*
  5132. * BIOS auto configuration
  5133. */
  5134. static int alc268_parse_auto_config(struct hda_codec *codec)
  5135. {
  5136. static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  5137. struct alc_spec *spec = codec->spec;
  5138. int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
  5139. if (err > 0) {
  5140. if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
  5141. add_mixer(spec, alc268_beep_mixer);
  5142. snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
  5143. }
  5144. }
  5145. return err;
  5146. }
  5147. /*
  5148. */
  5149. static int patch_alc268(struct hda_codec *codec)
  5150. {
  5151. struct alc_spec *spec;
  5152. int i, has_beep, err;
  5153. /* ALC268 has no aa-loopback mixer */
  5154. err = alc_alloc_spec(codec, 0);
  5155. if (err < 0)
  5156. return err;
  5157. spec = codec->spec;
  5158. alc_pick_fixup(codec, alc268_fixup_models, NULL, alc268_fixups);
  5159. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5160. /* automatic parse from the BIOS config */
  5161. err = alc268_parse_auto_config(codec);
  5162. if (err < 0)
  5163. goto error;
  5164. has_beep = 0;
  5165. for (i = 0; i < spec->num_mixers; i++) {
  5166. if (spec->mixers[i] == alc268_beep_mixer) {
  5167. has_beep = 1;
  5168. break;
  5169. }
  5170. }
  5171. if (has_beep) {
  5172. err = snd_hda_attach_beep_device(codec, 0x1);
  5173. if (err < 0)
  5174. goto error;
  5175. if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
  5176. /* override the amp caps for beep generator */
  5177. snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
  5178. (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
  5179. (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
  5180. (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  5181. (0 << AC_AMPCAP_MUTE_SHIFT));
  5182. }
  5183. codec->patch_ops = alc_patch_ops;
  5184. spec->shutup = alc_eapd_shutup;
  5185. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5186. return 0;
  5187. error:
  5188. alc_free(codec);
  5189. return err;
  5190. }
  5191. /*
  5192. * ALC269
  5193. */
  5194. static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
  5195. .substreams = 1,
  5196. .channels_min = 2,
  5197. .channels_max = 8,
  5198. .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
  5199. /* NID is set in alc_build_pcms */
  5200. .ops = {
  5201. .open = alc_playback_pcm_open,
  5202. .prepare = alc_playback_pcm_prepare,
  5203. .cleanup = alc_playback_pcm_cleanup
  5204. },
  5205. };
  5206. static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
  5207. .substreams = 1,
  5208. .channels_min = 2,
  5209. .channels_max = 2,
  5210. .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
  5211. /* NID is set in alc_build_pcms */
  5212. };
  5213. /* different alc269-variants */
  5214. enum {
  5215. ALC269_TYPE_ALC269VA,
  5216. ALC269_TYPE_ALC269VB,
  5217. ALC269_TYPE_ALC269VC,
  5218. ALC269_TYPE_ALC269VD,
  5219. };
  5220. /*
  5221. * BIOS auto configuration
  5222. */
  5223. static int alc269_parse_auto_config(struct hda_codec *codec)
  5224. {
  5225. static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
  5226. static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
  5227. static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  5228. struct alc_spec *spec = codec->spec;
  5229. const hda_nid_t *ssids;
  5230. switch (spec->codec_variant) {
  5231. case ALC269_TYPE_ALC269VA:
  5232. case ALC269_TYPE_ALC269VC:
  5233. ssids = alc269va_ssids;
  5234. break;
  5235. case ALC269_TYPE_ALC269VB:
  5236. case ALC269_TYPE_ALC269VD:
  5237. ssids = alc269_ssids;
  5238. break;
  5239. default:
  5240. ssids = alc269_ssids;
  5241. break;
  5242. }
  5243. return alc_parse_auto_config(codec, alc269_ignore, ssids);
  5244. }
  5245. static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
  5246. {
  5247. int val = alc_read_coef_idx(codec, 0x04);
  5248. if (power_up)
  5249. val |= 1 << 11;
  5250. else
  5251. val &= ~(1 << 11);
  5252. alc_write_coef_idx(codec, 0x04, val);
  5253. }
  5254. static void alc269_shutup(struct hda_codec *codec)
  5255. {
  5256. struct alc_spec *spec = codec->spec;
  5257. if (spec->codec_variant != ALC269_TYPE_ALC269VB)
  5258. return;
  5259. if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
  5260. alc269_toggle_power_output(codec, 0);
  5261. if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
  5262. alc269_toggle_power_output(codec, 0);
  5263. msleep(150);
  5264. }
  5265. }
  5266. #ifdef CONFIG_PM
  5267. static int alc269_resume(struct hda_codec *codec)
  5268. {
  5269. struct alc_spec *spec = codec->spec;
  5270. if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
  5271. (alc_get_coef0(codec) & 0x00ff) == 0x018) {
  5272. alc269_toggle_power_output(codec, 0);
  5273. msleep(150);
  5274. }
  5275. codec->patch_ops.init(codec);
  5276. if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
  5277. (alc_get_coef0(codec) & 0x00ff) == 0x017) {
  5278. alc269_toggle_power_output(codec, 1);
  5279. msleep(200);
  5280. }
  5281. if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
  5282. (alc_get_coef0(codec) & 0x00ff) == 0x018)
  5283. alc269_toggle_power_output(codec, 1);
  5284. snd_hda_codec_resume_amp(codec);
  5285. snd_hda_codec_resume_cache(codec);
  5286. hda_call_check_power_status(codec, 0x01);
  5287. return 0;
  5288. }
  5289. #endif /* CONFIG_PM */
  5290. static void alc269_fixup_hweq(struct hda_codec *codec,
  5291. const struct alc_fixup *fix, int action)
  5292. {
  5293. int coef;
  5294. if (action != ALC_FIXUP_ACT_INIT)
  5295. return;
  5296. coef = alc_read_coef_idx(codec, 0x1e);
  5297. alc_write_coef_idx(codec, 0x1e, coef | 0x80);
  5298. }
  5299. static void alc271_fixup_dmic(struct hda_codec *codec,
  5300. const struct alc_fixup *fix, int action)
  5301. {
  5302. static const struct hda_verb verbs[] = {
  5303. {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
  5304. {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
  5305. {}
  5306. };
  5307. unsigned int cfg;
  5308. if (strcmp(codec->chip_name, "ALC271X"))
  5309. return;
  5310. cfg = snd_hda_codec_get_pincfg(codec, 0x12);
  5311. if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
  5312. snd_hda_sequence_write(codec, verbs);
  5313. }
  5314. static void alc269_fixup_pcm_44k(struct hda_codec *codec,
  5315. const struct alc_fixup *fix, int action)
  5316. {
  5317. struct alc_spec *spec = codec->spec;
  5318. if (action != ALC_FIXUP_ACT_PROBE)
  5319. return;
  5320. /* Due to a hardware problem on Lenovo Ideadpad, we need to
  5321. * fix the sample rate of analog I/O to 44.1kHz
  5322. */
  5323. spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
  5324. spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
  5325. }
  5326. static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
  5327. const struct alc_fixup *fix, int action)
  5328. {
  5329. int coef;
  5330. if (action != ALC_FIXUP_ACT_INIT)
  5331. return;
  5332. /* The digital-mic unit sends PDM (differential signal) instead of
  5333. * the standard PCM, thus you can't record a valid mono stream as is.
  5334. * Below is a workaround specific to ALC269 to control the dmic
  5335. * signal source as mono.
  5336. */
  5337. coef = alc_read_coef_idx(codec, 0x07);
  5338. alc_write_coef_idx(codec, 0x07, coef | 0x80);
  5339. }
  5340. static void alc269_quanta_automute(struct hda_codec *codec)
  5341. {
  5342. update_outputs(codec);
  5343. snd_hda_codec_write(codec, 0x20, 0,
  5344. AC_VERB_SET_COEF_INDEX, 0x0c);
  5345. snd_hda_codec_write(codec, 0x20, 0,
  5346. AC_VERB_SET_PROC_COEF, 0x680);
  5347. snd_hda_codec_write(codec, 0x20, 0,
  5348. AC_VERB_SET_COEF_INDEX, 0x0c);
  5349. snd_hda_codec_write(codec, 0x20, 0,
  5350. AC_VERB_SET_PROC_COEF, 0x480);
  5351. }
  5352. static void alc269_fixup_quanta_mute(struct hda_codec *codec,
  5353. const struct alc_fixup *fix, int action)
  5354. {
  5355. struct alc_spec *spec = codec->spec;
  5356. if (action != ALC_FIXUP_ACT_PROBE)
  5357. return;
  5358. spec->automute_hook = alc269_quanta_automute;
  5359. }
  5360. /* update mute-LED according to the speaker mute state via mic2 VREF pin */
  5361. static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
  5362. {
  5363. struct hda_codec *codec = private_data;
  5364. unsigned int pinval = enabled ? 0x20 : 0x24;
  5365. snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
  5366. }
  5367. static void alc269_fixup_mic2_mute(struct hda_codec *codec,
  5368. const struct alc_fixup *fix, int action)
  5369. {
  5370. struct alc_spec *spec = codec->spec;
  5371. switch (action) {
  5372. case ALC_FIXUP_ACT_BUILD:
  5373. spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
  5374. snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
  5375. /* fallthru */
  5376. case ALC_FIXUP_ACT_INIT:
  5377. snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
  5378. break;
  5379. }
  5380. }
  5381. enum {
  5382. ALC269_FIXUP_SONY_VAIO,
  5383. ALC275_FIXUP_SONY_VAIO_GPIO2,
  5384. ALC269_FIXUP_DELL_M101Z,
  5385. ALC269_FIXUP_SKU_IGNORE,
  5386. ALC269_FIXUP_ASUS_G73JW,
  5387. ALC269_FIXUP_LENOVO_EAPD,
  5388. ALC275_FIXUP_SONY_HWEQ,
  5389. ALC271_FIXUP_DMIC,
  5390. ALC269_FIXUP_PCM_44K,
  5391. ALC269_FIXUP_STEREO_DMIC,
  5392. ALC269_FIXUP_QUANTA_MUTE,
  5393. ALC269_FIXUP_LIFEBOOK,
  5394. ALC269_FIXUP_AMIC,
  5395. ALC269_FIXUP_DMIC,
  5396. ALC269VB_FIXUP_AMIC,
  5397. ALC269VB_FIXUP_DMIC,
  5398. ALC269_FIXUP_MIC2_MUTE_LED,
  5399. ALC269_FIXUP_INV_DMIC,
  5400. };
  5401. static const struct alc_fixup alc269_fixups[] = {
  5402. [ALC269_FIXUP_SONY_VAIO] = {
  5403. .type = ALC_FIXUP_VERBS,
  5404. .v.verbs = (const struct hda_verb[]) {
  5405. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
  5406. {}
  5407. }
  5408. },
  5409. [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
  5410. .type = ALC_FIXUP_VERBS,
  5411. .v.verbs = (const struct hda_verb[]) {
  5412. {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
  5413. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
  5414. {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
  5415. { }
  5416. },
  5417. .chained = true,
  5418. .chain_id = ALC269_FIXUP_SONY_VAIO
  5419. },
  5420. [ALC269_FIXUP_DELL_M101Z] = {
  5421. .type = ALC_FIXUP_VERBS,
  5422. .v.verbs = (const struct hda_verb[]) {
  5423. /* Enables internal speaker */
  5424. {0x20, AC_VERB_SET_COEF_INDEX, 13},
  5425. {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
  5426. {}
  5427. }
  5428. },
  5429. [ALC269_FIXUP_SKU_IGNORE] = {
  5430. .type = ALC_FIXUP_FUNC,
  5431. .v.func = alc_fixup_sku_ignore,
  5432. },
  5433. [ALC269_FIXUP_ASUS_G73JW] = {
  5434. .type = ALC_FIXUP_PINS,
  5435. .v.pins = (const struct alc_pincfg[]) {
  5436. { 0x17, 0x99130111 }, /* subwoofer */
  5437. { }
  5438. }
  5439. },
  5440. [ALC269_FIXUP_LENOVO_EAPD] = {
  5441. .type = ALC_FIXUP_VERBS,
  5442. .v.verbs = (const struct hda_verb[]) {
  5443. {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
  5444. {}
  5445. }
  5446. },
  5447. [ALC275_FIXUP_SONY_HWEQ] = {
  5448. .type = ALC_FIXUP_FUNC,
  5449. .v.func = alc269_fixup_hweq,
  5450. .chained = true,
  5451. .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
  5452. },
  5453. [ALC271_FIXUP_DMIC] = {
  5454. .type = ALC_FIXUP_FUNC,
  5455. .v.func = alc271_fixup_dmic,
  5456. },
  5457. [ALC269_FIXUP_PCM_44K] = {
  5458. .type = ALC_FIXUP_FUNC,
  5459. .v.func = alc269_fixup_pcm_44k,
  5460. },
  5461. [ALC269_FIXUP_STEREO_DMIC] = {
  5462. .type = ALC_FIXUP_FUNC,
  5463. .v.func = alc269_fixup_stereo_dmic,
  5464. },
  5465. [ALC269_FIXUP_QUANTA_MUTE] = {
  5466. .type = ALC_FIXUP_FUNC,
  5467. .v.func = alc269_fixup_quanta_mute,
  5468. },
  5469. [ALC269_FIXUP_LIFEBOOK] = {
  5470. .type = ALC_FIXUP_PINS,
  5471. .v.pins = (const struct alc_pincfg[]) {
  5472. { 0x1a, 0x2101103f }, /* dock line-out */
  5473. { 0x1b, 0x23a11040 }, /* dock mic-in */
  5474. { }
  5475. },
  5476. .chained = true,
  5477. .chain_id = ALC269_FIXUP_QUANTA_MUTE
  5478. },
  5479. [ALC269_FIXUP_AMIC] = {
  5480. .type = ALC_FIXUP_PINS,
  5481. .v.pins = (const struct alc_pincfg[]) {
  5482. { 0x14, 0x99130110 }, /* speaker */
  5483. { 0x15, 0x0121401f }, /* HP out */
  5484. { 0x18, 0x01a19c20 }, /* mic */
  5485. { 0x19, 0x99a3092f }, /* int-mic */
  5486. { }
  5487. },
  5488. },
  5489. [ALC269_FIXUP_DMIC] = {
  5490. .type = ALC_FIXUP_PINS,
  5491. .v.pins = (const struct alc_pincfg[]) {
  5492. { 0x12, 0x99a3092f }, /* int-mic */
  5493. { 0x14, 0x99130110 }, /* speaker */
  5494. { 0x15, 0x0121401f }, /* HP out */
  5495. { 0x18, 0x01a19c20 }, /* mic */
  5496. { }
  5497. },
  5498. },
  5499. [ALC269VB_FIXUP_AMIC] = {
  5500. .type = ALC_FIXUP_PINS,
  5501. .v.pins = (const struct alc_pincfg[]) {
  5502. { 0x14, 0x99130110 }, /* speaker */
  5503. { 0x18, 0x01a19c20 }, /* mic */
  5504. { 0x19, 0x99a3092f }, /* int-mic */
  5505. { 0x21, 0x0121401f }, /* HP out */
  5506. { }
  5507. },
  5508. },
  5509. [ALC269VB_FIXUP_DMIC] = {
  5510. .type = ALC_FIXUP_PINS,
  5511. .v.pins = (const struct alc_pincfg[]) {
  5512. { 0x12, 0x99a3092f }, /* int-mic */
  5513. { 0x14, 0x99130110 }, /* speaker */
  5514. { 0x18, 0x01a19c20 }, /* mic */
  5515. { 0x21, 0x0121401f }, /* HP out */
  5516. { }
  5517. },
  5518. },
  5519. [ALC269_FIXUP_MIC2_MUTE_LED] = {
  5520. .type = ALC_FIXUP_FUNC,
  5521. .v.func = alc269_fixup_mic2_mute,
  5522. },
  5523. [ALC269_FIXUP_INV_DMIC] = {
  5524. .type = ALC_FIXUP_FUNC,
  5525. .v.func = alc_fixup_inv_dmic_0x12,
  5526. },
  5527. };
  5528. static const struct snd_pci_quirk alc269_fixup_tbl[] = {
  5529. SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
  5530. SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
  5531. SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
  5532. SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
  5533. SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
  5534. SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
  5535. SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
  5536. SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
  5537. SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
  5538. SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
  5539. SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
  5540. SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
  5541. SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
  5542. SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
  5543. SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
  5544. SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
  5545. SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
  5546. SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
  5547. SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
  5548. SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
  5549. SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
  5550. SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
  5551. SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
  5552. SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
  5553. SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
  5554. SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
  5555. #if 0
  5556. /* Below is a quirk table taken from the old code.
  5557. * Basically the device should work as is without the fixup table.
  5558. * If BIOS doesn't give a proper info, enable the corresponding
  5559. * fixup entry.
  5560. */
  5561. SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
  5562. ALC269_FIXUP_AMIC),
  5563. SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
  5564. SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
  5565. SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
  5566. SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
  5567. SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
  5568. SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
  5569. SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
  5570. SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
  5571. SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
  5572. SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
  5573. SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
  5574. SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
  5575. SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
  5576. SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
  5577. SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
  5578. SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
  5579. SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
  5580. SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
  5581. SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
  5582. SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
  5583. SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
  5584. SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
  5585. SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
  5586. SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
  5587. SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
  5588. SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
  5589. SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
  5590. SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
  5591. SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
  5592. SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
  5593. SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
  5594. SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
  5595. SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
  5596. SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
  5597. SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
  5598. SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
  5599. SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
  5600. SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
  5601. SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
  5602. #endif
  5603. {}
  5604. };
  5605. static const struct alc_model_fixup alc269_fixup_models[] = {
  5606. {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
  5607. {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
  5608. {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
  5609. {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
  5610. {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
  5611. {}
  5612. };
  5613. static void alc269_fill_coef(struct hda_codec *codec)
  5614. {
  5615. struct alc_spec *spec = codec->spec;
  5616. int val;
  5617. if (spec->codec_variant != ALC269_TYPE_ALC269VB)
  5618. return;
  5619. if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
  5620. alc_write_coef_idx(codec, 0xf, 0x960b);
  5621. alc_write_coef_idx(codec, 0xe, 0x8817);
  5622. }
  5623. if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
  5624. alc_write_coef_idx(codec, 0xf, 0x960b);
  5625. alc_write_coef_idx(codec, 0xe, 0x8814);
  5626. }
  5627. if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
  5628. val = alc_read_coef_idx(codec, 0x04);
  5629. /* Power up output pin */
  5630. alc_write_coef_idx(codec, 0x04, val | (1<<11));
  5631. }
  5632. if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
  5633. val = alc_read_coef_idx(codec, 0xd);
  5634. if ((val & 0x0c00) >> 10 != 0x1) {
  5635. /* Capless ramp up clock control */
  5636. alc_write_coef_idx(codec, 0xd, val | (1<<10));
  5637. }
  5638. val = alc_read_coef_idx(codec, 0x17);
  5639. if ((val & 0x01c0) >> 6 != 0x4) {
  5640. /* Class D power on reset */
  5641. alc_write_coef_idx(codec, 0x17, val | (1<<7));
  5642. }
  5643. }
  5644. val = alc_read_coef_idx(codec, 0xd); /* Class D */
  5645. alc_write_coef_idx(codec, 0xd, val | (1<<14));
  5646. val = alc_read_coef_idx(codec, 0x4); /* HP */
  5647. alc_write_coef_idx(codec, 0x4, val | (1<<11));
  5648. }
  5649. /*
  5650. */
  5651. static int patch_alc269(struct hda_codec *codec)
  5652. {
  5653. struct alc_spec *spec;
  5654. int err;
  5655. err = alc_alloc_spec(codec, 0x0b);
  5656. if (err < 0)
  5657. return err;
  5658. spec = codec->spec;
  5659. if (codec->vendor_id == 0x10ec0269) {
  5660. spec->codec_variant = ALC269_TYPE_ALC269VA;
  5661. switch (alc_get_coef0(codec) & 0x00f0) {
  5662. case 0x0010:
  5663. if (codec->bus->pci->subsystem_vendor == 0x1025 &&
  5664. spec->cdefine.platform_type == 1)
  5665. err = alc_codec_rename(codec, "ALC271X");
  5666. spec->codec_variant = ALC269_TYPE_ALC269VB;
  5667. break;
  5668. case 0x0020:
  5669. if (codec->bus->pci->subsystem_vendor == 0x17aa &&
  5670. codec->bus->pci->subsystem_device == 0x21f3)
  5671. err = alc_codec_rename(codec, "ALC3202");
  5672. spec->codec_variant = ALC269_TYPE_ALC269VC;
  5673. break;
  5674. case 0x0030:
  5675. spec->codec_variant = ALC269_TYPE_ALC269VD;
  5676. break;
  5677. default:
  5678. alc_fix_pll_init(codec, 0x20, 0x04, 15);
  5679. }
  5680. if (err < 0)
  5681. goto error;
  5682. spec->init_hook = alc269_fill_coef;
  5683. alc269_fill_coef(codec);
  5684. }
  5685. alc_pick_fixup(codec, alc269_fixup_models,
  5686. alc269_fixup_tbl, alc269_fixups);
  5687. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5688. alc_auto_parse_customize_define(codec);
  5689. /* automatic parse from the BIOS config */
  5690. err = alc269_parse_auto_config(codec);
  5691. if (err < 0)
  5692. goto error;
  5693. if (!spec->no_analog && has_cdefine_beep(codec)) {
  5694. err = snd_hda_attach_beep_device(codec, 0x1);
  5695. if (err < 0)
  5696. goto error;
  5697. set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
  5698. }
  5699. codec->patch_ops = alc_patch_ops;
  5700. #ifdef CONFIG_PM
  5701. codec->patch_ops.resume = alc269_resume;
  5702. #endif
  5703. spec->shutup = alc269_shutup;
  5704. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5705. return 0;
  5706. error:
  5707. alc_free(codec);
  5708. return err;
  5709. }
  5710. /*
  5711. * ALC861
  5712. */
  5713. static int alc861_parse_auto_config(struct hda_codec *codec)
  5714. {
  5715. static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
  5716. static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
  5717. return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
  5718. }
  5719. /* Pin config fixes */
  5720. enum {
  5721. ALC861_FIXUP_FSC_AMILO_PI1505,
  5722. ALC861_FIXUP_AMP_VREF_0F,
  5723. ALC861_FIXUP_NO_JACK_DETECT,
  5724. ALC861_FIXUP_ASUS_A6RP,
  5725. };
  5726. /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
  5727. static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
  5728. const struct alc_fixup *fix, int action)
  5729. {
  5730. struct alc_spec *spec = codec->spec;
  5731. unsigned int val;
  5732. if (action != ALC_FIXUP_ACT_INIT)
  5733. return;
  5734. val = snd_hda_codec_read(codec, 0x0f, 0,
  5735. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  5736. if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
  5737. val |= AC_PINCTL_IN_EN;
  5738. val |= AC_PINCTL_VREF_50;
  5739. snd_hda_set_pin_ctl(codec, 0x0f, val);
  5740. spec->keep_vref_in_automute = 1;
  5741. }
  5742. /* suppress the jack-detection */
  5743. static void alc_fixup_no_jack_detect(struct hda_codec *codec,
  5744. const struct alc_fixup *fix, int action)
  5745. {
  5746. if (action == ALC_FIXUP_ACT_PRE_PROBE)
  5747. codec->no_jack_detect = 1;
  5748. }
  5749. static const struct alc_fixup alc861_fixups[] = {
  5750. [ALC861_FIXUP_FSC_AMILO_PI1505] = {
  5751. .type = ALC_FIXUP_PINS,
  5752. .v.pins = (const struct alc_pincfg[]) {
  5753. { 0x0b, 0x0221101f }, /* HP */
  5754. { 0x0f, 0x90170310 }, /* speaker */
  5755. { }
  5756. }
  5757. },
  5758. [ALC861_FIXUP_AMP_VREF_0F] = {
  5759. .type = ALC_FIXUP_FUNC,
  5760. .v.func = alc861_fixup_asus_amp_vref_0f,
  5761. },
  5762. [ALC861_FIXUP_NO_JACK_DETECT] = {
  5763. .type = ALC_FIXUP_FUNC,
  5764. .v.func = alc_fixup_no_jack_detect,
  5765. },
  5766. [ALC861_FIXUP_ASUS_A6RP] = {
  5767. .type = ALC_FIXUP_FUNC,
  5768. .v.func = alc861_fixup_asus_amp_vref_0f,
  5769. .chained = true,
  5770. .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
  5771. }
  5772. };
  5773. static const struct snd_pci_quirk alc861_fixup_tbl[] = {
  5774. SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
  5775. SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
  5776. SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
  5777. SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
  5778. SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
  5779. SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
  5780. {}
  5781. };
  5782. /*
  5783. */
  5784. static int patch_alc861(struct hda_codec *codec)
  5785. {
  5786. struct alc_spec *spec;
  5787. int err;
  5788. err = alc_alloc_spec(codec, 0x15);
  5789. if (err < 0)
  5790. return err;
  5791. spec = codec->spec;
  5792. alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
  5793. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5794. /* automatic parse from the BIOS config */
  5795. err = alc861_parse_auto_config(codec);
  5796. if (err < 0)
  5797. goto error;
  5798. if (!spec->no_analog) {
  5799. err = snd_hda_attach_beep_device(codec, 0x23);
  5800. if (err < 0)
  5801. goto error;
  5802. set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
  5803. }
  5804. codec->patch_ops = alc_patch_ops;
  5805. #ifdef CONFIG_SND_HDA_POWER_SAVE
  5806. spec->power_hook = alc_power_eapd;
  5807. #endif
  5808. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5809. return 0;
  5810. error:
  5811. alc_free(codec);
  5812. return err;
  5813. }
  5814. /*
  5815. * ALC861-VD support
  5816. *
  5817. * Based on ALC882
  5818. *
  5819. * In addition, an independent DAC
  5820. */
  5821. static int alc861vd_parse_auto_config(struct hda_codec *codec)
  5822. {
  5823. static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
  5824. static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  5825. return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
  5826. }
  5827. enum {
  5828. ALC660VD_FIX_ASUS_GPIO1,
  5829. ALC861VD_FIX_DALLAS,
  5830. };
  5831. /* exclude VREF80 */
  5832. static void alc861vd_fixup_dallas(struct hda_codec *codec,
  5833. const struct alc_fixup *fix, int action)
  5834. {
  5835. if (action == ALC_FIXUP_ACT_PRE_PROBE) {
  5836. snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
  5837. snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
  5838. }
  5839. }
  5840. static const struct alc_fixup alc861vd_fixups[] = {
  5841. [ALC660VD_FIX_ASUS_GPIO1] = {
  5842. .type = ALC_FIXUP_VERBS,
  5843. .v.verbs = (const struct hda_verb[]) {
  5844. /* reset GPIO1 */
  5845. {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
  5846. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
  5847. {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
  5848. { }
  5849. }
  5850. },
  5851. [ALC861VD_FIX_DALLAS] = {
  5852. .type = ALC_FIXUP_FUNC,
  5853. .v.func = alc861vd_fixup_dallas,
  5854. },
  5855. };
  5856. static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
  5857. SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
  5858. SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
  5859. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
  5860. {}
  5861. };
  5862. static const struct hda_verb alc660vd_eapd_verbs[] = {
  5863. {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
  5864. {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
  5865. { }
  5866. };
  5867. /*
  5868. */
  5869. static int patch_alc861vd(struct hda_codec *codec)
  5870. {
  5871. struct alc_spec *spec;
  5872. int err;
  5873. err = alc_alloc_spec(codec, 0x0b);
  5874. if (err < 0)
  5875. return err;
  5876. spec = codec->spec;
  5877. alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
  5878. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5879. /* automatic parse from the BIOS config */
  5880. err = alc861vd_parse_auto_config(codec);
  5881. if (err < 0)
  5882. goto error;
  5883. if (codec->vendor_id == 0x10ec0660) {
  5884. /* always turn on EAPD */
  5885. snd_hda_gen_add_verbs(&spec->gen, alc660vd_eapd_verbs);
  5886. }
  5887. if (!spec->no_analog) {
  5888. err = snd_hda_attach_beep_device(codec, 0x23);
  5889. if (err < 0)
  5890. goto error;
  5891. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  5892. }
  5893. codec->patch_ops = alc_patch_ops;
  5894. spec->shutup = alc_eapd_shutup;
  5895. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5896. return 0;
  5897. error:
  5898. alc_free(codec);
  5899. return err;
  5900. }
  5901. /*
  5902. * ALC662 support
  5903. *
  5904. * ALC662 is almost identical with ALC880 but has cleaner and more flexible
  5905. * configuration. Each pin widget can choose any input DACs and a mixer.
  5906. * Each ADC is connected from a mixer of all inputs. This makes possible
  5907. * 6-channel independent captures.
  5908. *
  5909. * In addition, an independent DAC for the multi-playback (not used in this
  5910. * driver yet).
  5911. */
  5912. /*
  5913. * BIOS auto configuration
  5914. */
  5915. static int alc662_parse_auto_config(struct hda_codec *codec)
  5916. {
  5917. static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
  5918. static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
  5919. static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  5920. const hda_nid_t *ssids;
  5921. if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
  5922. codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
  5923. ssids = alc663_ssids;
  5924. else
  5925. ssids = alc662_ssids;
  5926. return alc_parse_auto_config(codec, alc662_ignore, ssids);
  5927. }
  5928. static void alc272_fixup_mario(struct hda_codec *codec,
  5929. const struct alc_fixup *fix, int action)
  5930. {
  5931. if (action != ALC_FIXUP_ACT_PROBE)
  5932. return;
  5933. if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
  5934. (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
  5935. (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
  5936. (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  5937. (0 << AC_AMPCAP_MUTE_SHIFT)))
  5938. printk(KERN_WARNING
  5939. "hda_codec: failed to override amp caps for NID 0x2\n");
  5940. }
  5941. enum {
  5942. ALC662_FIXUP_ASPIRE,
  5943. ALC662_FIXUP_IDEAPAD,
  5944. ALC272_FIXUP_MARIO,
  5945. ALC662_FIXUP_CZC_P10T,
  5946. ALC662_FIXUP_SKU_IGNORE,
  5947. ALC662_FIXUP_HP_RP5800,
  5948. ALC662_FIXUP_ASUS_MODE1,
  5949. ALC662_FIXUP_ASUS_MODE2,
  5950. ALC662_FIXUP_ASUS_MODE3,
  5951. ALC662_FIXUP_ASUS_MODE4,
  5952. ALC662_FIXUP_ASUS_MODE5,
  5953. ALC662_FIXUP_ASUS_MODE6,
  5954. ALC662_FIXUP_ASUS_MODE7,
  5955. ALC662_FIXUP_ASUS_MODE8,
  5956. ALC662_FIXUP_NO_JACK_DETECT,
  5957. ALC662_FIXUP_ZOTAC_Z68,
  5958. ALC662_FIXUP_INV_DMIC,
  5959. };
  5960. static const struct alc_fixup alc662_fixups[] = {
  5961. [ALC662_FIXUP_ASPIRE] = {
  5962. .type = ALC_FIXUP_PINS,
  5963. .v.pins = (const struct alc_pincfg[]) {
  5964. { 0x15, 0x99130112 }, /* subwoofer */
  5965. { }
  5966. }
  5967. },
  5968. [ALC662_FIXUP_IDEAPAD] = {
  5969. .type = ALC_FIXUP_PINS,
  5970. .v.pins = (const struct alc_pincfg[]) {
  5971. { 0x17, 0x99130112 }, /* subwoofer */
  5972. { }
  5973. }
  5974. },
  5975. [ALC272_FIXUP_MARIO] = {
  5976. .type = ALC_FIXUP_FUNC,
  5977. .v.func = alc272_fixup_mario,
  5978. },
  5979. [ALC662_FIXUP_CZC_P10T] = {
  5980. .type = ALC_FIXUP_VERBS,
  5981. .v.verbs = (const struct hda_verb[]) {
  5982. {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
  5983. {}
  5984. }
  5985. },
  5986. [ALC662_FIXUP_SKU_IGNORE] = {
  5987. .type = ALC_FIXUP_FUNC,
  5988. .v.func = alc_fixup_sku_ignore,
  5989. },
  5990. [ALC662_FIXUP_HP_RP5800] = {
  5991. .type = ALC_FIXUP_PINS,
  5992. .v.pins = (const struct alc_pincfg[]) {
  5993. { 0x14, 0x0221201f }, /* HP out */
  5994. { }
  5995. },
  5996. .chained = true,
  5997. .chain_id = ALC662_FIXUP_SKU_IGNORE
  5998. },
  5999. [ALC662_FIXUP_ASUS_MODE1] = {
  6000. .type = ALC_FIXUP_PINS,
  6001. .v.pins = (const struct alc_pincfg[]) {
  6002. { 0x14, 0x99130110 }, /* speaker */
  6003. { 0x18, 0x01a19c20 }, /* mic */
  6004. { 0x19, 0x99a3092f }, /* int-mic */
  6005. { 0x21, 0x0121401f }, /* HP out */
  6006. { }
  6007. },
  6008. .chained = true,
  6009. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6010. },
  6011. [ALC662_FIXUP_ASUS_MODE2] = {
  6012. .type = ALC_FIXUP_PINS,
  6013. .v.pins = (const struct alc_pincfg[]) {
  6014. { 0x14, 0x99130110 }, /* speaker */
  6015. { 0x18, 0x01a19820 }, /* mic */
  6016. { 0x19, 0x99a3092f }, /* int-mic */
  6017. { 0x1b, 0x0121401f }, /* HP out */
  6018. { }
  6019. },
  6020. .chained = true,
  6021. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6022. },
  6023. [ALC662_FIXUP_ASUS_MODE3] = {
  6024. .type = ALC_FIXUP_PINS,
  6025. .v.pins = (const struct alc_pincfg[]) {
  6026. { 0x14, 0x99130110 }, /* speaker */
  6027. { 0x15, 0x0121441f }, /* HP */
  6028. { 0x18, 0x01a19840 }, /* mic */
  6029. { 0x19, 0x99a3094f }, /* int-mic */
  6030. { 0x21, 0x01211420 }, /* HP2 */
  6031. { }
  6032. },
  6033. .chained = true,
  6034. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6035. },
  6036. [ALC662_FIXUP_ASUS_MODE4] = {
  6037. .type = ALC_FIXUP_PINS,
  6038. .v.pins = (const struct alc_pincfg[]) {
  6039. { 0x14, 0x99130110 }, /* speaker */
  6040. { 0x16, 0x99130111 }, /* speaker */
  6041. { 0x18, 0x01a19840 }, /* mic */
  6042. { 0x19, 0x99a3094f }, /* int-mic */
  6043. { 0x21, 0x0121441f }, /* HP */
  6044. { }
  6045. },
  6046. .chained = true,
  6047. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6048. },
  6049. [ALC662_FIXUP_ASUS_MODE5] = {
  6050. .type = ALC_FIXUP_PINS,
  6051. .v.pins = (const struct alc_pincfg[]) {
  6052. { 0x14, 0x99130110 }, /* speaker */
  6053. { 0x15, 0x0121441f }, /* HP */
  6054. { 0x16, 0x99130111 }, /* speaker */
  6055. { 0x18, 0x01a19840 }, /* mic */
  6056. { 0x19, 0x99a3094f }, /* int-mic */
  6057. { }
  6058. },
  6059. .chained = true,
  6060. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6061. },
  6062. [ALC662_FIXUP_ASUS_MODE6] = {
  6063. .type = ALC_FIXUP_PINS,
  6064. .v.pins = (const struct alc_pincfg[]) {
  6065. { 0x14, 0x99130110 }, /* speaker */
  6066. { 0x15, 0x01211420 }, /* HP2 */
  6067. { 0x18, 0x01a19840 }, /* mic */
  6068. { 0x19, 0x99a3094f }, /* int-mic */
  6069. { 0x1b, 0x0121441f }, /* HP */
  6070. { }
  6071. },
  6072. .chained = true,
  6073. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6074. },
  6075. [ALC662_FIXUP_ASUS_MODE7] = {
  6076. .type = ALC_FIXUP_PINS,
  6077. .v.pins = (const struct alc_pincfg[]) {
  6078. { 0x14, 0x99130110 }, /* speaker */
  6079. { 0x17, 0x99130111 }, /* speaker */
  6080. { 0x18, 0x01a19840 }, /* mic */
  6081. { 0x19, 0x99a3094f }, /* int-mic */
  6082. { 0x1b, 0x01214020 }, /* HP */
  6083. { 0x21, 0x0121401f }, /* HP */
  6084. { }
  6085. },
  6086. .chained = true,
  6087. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6088. },
  6089. [ALC662_FIXUP_ASUS_MODE8] = {
  6090. .type = ALC_FIXUP_PINS,
  6091. .v.pins = (const struct alc_pincfg[]) {
  6092. { 0x14, 0x99130110 }, /* speaker */
  6093. { 0x12, 0x99a30970 }, /* int-mic */
  6094. { 0x15, 0x01214020 }, /* HP */
  6095. { 0x17, 0x99130111 }, /* speaker */
  6096. { 0x18, 0x01a19840 }, /* mic */
  6097. { 0x21, 0x0121401f }, /* HP */
  6098. { }
  6099. },
  6100. .chained = true,
  6101. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6102. },
  6103. [ALC662_FIXUP_NO_JACK_DETECT] = {
  6104. .type = ALC_FIXUP_FUNC,
  6105. .v.func = alc_fixup_no_jack_detect,
  6106. },
  6107. [ALC662_FIXUP_ZOTAC_Z68] = {
  6108. .type = ALC_FIXUP_PINS,
  6109. .v.pins = (const struct alc_pincfg[]) {
  6110. { 0x1b, 0x02214020 }, /* Front HP */
  6111. { }
  6112. }
  6113. },
  6114. [ALC662_FIXUP_INV_DMIC] = {
  6115. .type = ALC_FIXUP_FUNC,
  6116. .v.func = alc_fixup_inv_dmic_0x12,
  6117. },
  6118. };
  6119. static const struct snd_pci_quirk alc662_fixup_tbl[] = {
  6120. SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
  6121. SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
  6122. SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
  6123. SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
  6124. SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
  6125. SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
  6126. SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
  6127. SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
  6128. SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
  6129. SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
  6130. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
  6131. SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
  6132. SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
  6133. #if 0
  6134. /* Below is a quirk table taken from the old code.
  6135. * Basically the device should work as is without the fixup table.
  6136. * If BIOS doesn't give a proper info, enable the corresponding
  6137. * fixup entry.
  6138. */
  6139. SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
  6140. SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
  6141. SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
  6142. SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
  6143. SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
  6144. SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6145. SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
  6146. SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
  6147. SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
  6148. SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6149. SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
  6150. SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
  6151. SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
  6152. SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
  6153. SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
  6154. SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6155. SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
  6156. SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
  6157. SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6158. SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
  6159. SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
  6160. SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6161. SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
  6162. SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
  6163. SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
  6164. SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6165. SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
  6166. SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
  6167. SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6168. SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
  6169. SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6170. SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6171. SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
  6172. SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
  6173. SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
  6174. SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
  6175. SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
  6176. SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
  6177. SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
  6178. SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6179. SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
  6180. SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
  6181. SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
  6182. SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
  6183. SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
  6184. SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
  6185. SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
  6186. SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
  6187. SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
  6188. SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
  6189. #endif
  6190. {}
  6191. };
  6192. static const struct alc_model_fixup alc662_fixup_models[] = {
  6193. {.id = ALC272_FIXUP_MARIO, .name = "mario"},
  6194. {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
  6195. {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
  6196. {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
  6197. {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
  6198. {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
  6199. {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
  6200. {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
  6201. {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
  6202. {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
  6203. {}
  6204. };
  6205. /*
  6206. */
  6207. static int patch_alc662(struct hda_codec *codec)
  6208. {
  6209. struct alc_spec *spec;
  6210. int err;
  6211. err = alc_alloc_spec(codec, 0x0b);
  6212. if (err < 0)
  6213. return err;
  6214. spec = codec->spec;
  6215. /* handle multiple HPs as is */
  6216. spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
  6217. alc_fix_pll_init(codec, 0x20, 0x04, 15);
  6218. if ((alc_get_coef0(codec) & (1 << 14)) &&
  6219. codec->bus->pci->subsystem_vendor == 0x1025 &&
  6220. spec->cdefine.platform_type == 1) {
  6221. if (alc_codec_rename(codec, "ALC272X") < 0)
  6222. goto error;
  6223. }
  6224. alc_pick_fixup(codec, alc662_fixup_models,
  6225. alc662_fixup_tbl, alc662_fixups);
  6226. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  6227. alc_auto_parse_customize_define(codec);
  6228. /* automatic parse from the BIOS config */
  6229. err = alc662_parse_auto_config(codec);
  6230. if (err < 0)
  6231. goto error;
  6232. if (!spec->no_analog && has_cdefine_beep(codec)) {
  6233. err = snd_hda_attach_beep_device(codec, 0x1);
  6234. if (err < 0)
  6235. goto error;
  6236. switch (codec->vendor_id) {
  6237. case 0x10ec0662:
  6238. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  6239. break;
  6240. case 0x10ec0272:
  6241. case 0x10ec0663:
  6242. case 0x10ec0665:
  6243. set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
  6244. break;
  6245. case 0x10ec0273:
  6246. set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
  6247. break;
  6248. }
  6249. }
  6250. codec->patch_ops = alc_patch_ops;
  6251. spec->shutup = alc_eapd_shutup;
  6252. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  6253. return 0;
  6254. error:
  6255. alc_free(codec);
  6256. return err;
  6257. }
  6258. /*
  6259. * ALC680 support
  6260. */
  6261. static int alc680_parse_auto_config(struct hda_codec *codec)
  6262. {
  6263. return alc_parse_auto_config(codec, NULL, NULL);
  6264. }
  6265. /*
  6266. */
  6267. static int patch_alc680(struct hda_codec *codec)
  6268. {
  6269. int err;
  6270. /* ALC680 has no aa-loopback mixer */
  6271. err = alc_alloc_spec(codec, 0);
  6272. if (err < 0)
  6273. return err;
  6274. /* automatic parse from the BIOS config */
  6275. err = alc680_parse_auto_config(codec);
  6276. if (err < 0) {
  6277. alc_free(codec);
  6278. return err;
  6279. }
  6280. codec->patch_ops = alc_patch_ops;
  6281. return 0;
  6282. }
  6283. /*
  6284. * patch entries
  6285. */
  6286. static const struct hda_codec_preset snd_hda_preset_realtek[] = {
  6287. { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
  6288. { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
  6289. { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
  6290. { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
  6291. { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
  6292. { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
  6293. { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
  6294. { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
  6295. { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
  6296. { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
  6297. { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
  6298. .patch = patch_alc861 },
  6299. { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
  6300. { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
  6301. { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
  6302. { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
  6303. .patch = patch_alc882 },
  6304. { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
  6305. .patch = patch_alc662 },
  6306. { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
  6307. .patch = patch_alc662 },
  6308. { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
  6309. { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
  6310. { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
  6311. { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
  6312. { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
  6313. { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
  6314. { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
  6315. { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
  6316. .patch = patch_alc882 },
  6317. { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
  6318. .patch = patch_alc882 },
  6319. { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
  6320. { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
  6321. { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
  6322. .patch = patch_alc882 },
  6323. { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
  6324. { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
  6325. { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
  6326. { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
  6327. {} /* terminator */
  6328. };
  6329. MODULE_ALIAS("snd-hda-codec-id:10ec*");
  6330. MODULE_LICENSE("GPL");
  6331. MODULE_DESCRIPTION("Realtek HD-audio codec");
  6332. static struct hda_codec_preset_list realtek_list = {
  6333. .preset = snd_hda_preset_realtek,
  6334. .owner = THIS_MODULE,
  6335. };
  6336. static int __init patch_realtek_init(void)
  6337. {
  6338. return snd_hda_add_codec_preset(&realtek_list);
  6339. }
  6340. static void __exit patch_realtek_exit(void)
  6341. {
  6342. snd_hda_delete_codec_preset(&realtek_list);
  6343. }
  6344. module_init(patch_realtek_init)
  6345. module_exit(patch_realtek_exit)