patch_realtek.c 203 KB

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