patch_realtek.c 203 KB

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