patch_realtek.c 195 KB

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