patch_realtek.c 189 KB

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