patch_realtek.c 205 KB

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