patch_realtek.c 188 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819
  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. alc_init_special_input_src(codec);
  1697. alc_auto_init_std(codec);
  1698. alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
  1699. snd_hda_jack_report_sync(codec);
  1700. hda_call_check_power_status(codec, 0x01);
  1701. return 0;
  1702. }
  1703. static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
  1704. {
  1705. struct alc_spec *spec = codec->spec;
  1706. if (spec->unsol_event)
  1707. spec->unsol_event(codec, res);
  1708. }
  1709. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1710. static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  1711. {
  1712. struct alc_spec *spec = codec->spec;
  1713. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  1714. }
  1715. #endif
  1716. /*
  1717. * Analog playback callbacks
  1718. */
  1719. static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1720. struct hda_codec *codec,
  1721. struct snd_pcm_substream *substream)
  1722. {
  1723. struct alc_spec *spec = codec->spec;
  1724. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  1725. hinfo);
  1726. }
  1727. static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1728. struct hda_codec *codec,
  1729. unsigned int stream_tag,
  1730. unsigned int format,
  1731. struct snd_pcm_substream *substream)
  1732. {
  1733. struct alc_spec *spec = codec->spec;
  1734. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  1735. stream_tag, format, substream);
  1736. }
  1737. static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1738. struct hda_codec *codec,
  1739. struct snd_pcm_substream *substream)
  1740. {
  1741. struct alc_spec *spec = codec->spec;
  1742. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  1743. }
  1744. /*
  1745. * Digital out
  1746. */
  1747. static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1748. struct hda_codec *codec,
  1749. struct snd_pcm_substream *substream)
  1750. {
  1751. struct alc_spec *spec = codec->spec;
  1752. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1753. }
  1754. static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1755. struct hda_codec *codec,
  1756. unsigned int stream_tag,
  1757. unsigned int format,
  1758. struct snd_pcm_substream *substream)
  1759. {
  1760. struct alc_spec *spec = codec->spec;
  1761. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1762. stream_tag, format, substream);
  1763. }
  1764. static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1765. struct hda_codec *codec,
  1766. struct snd_pcm_substream *substream)
  1767. {
  1768. struct alc_spec *spec = codec->spec;
  1769. return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  1770. }
  1771. static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1772. struct hda_codec *codec,
  1773. struct snd_pcm_substream *substream)
  1774. {
  1775. struct alc_spec *spec = codec->spec;
  1776. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1777. }
  1778. /*
  1779. * Analog capture
  1780. */
  1781. static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1782. struct hda_codec *codec,
  1783. unsigned int stream_tag,
  1784. unsigned int format,
  1785. struct snd_pcm_substream *substream)
  1786. {
  1787. struct alc_spec *spec = codec->spec;
  1788. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
  1789. stream_tag, 0, format);
  1790. return 0;
  1791. }
  1792. static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1793. struct hda_codec *codec,
  1794. struct snd_pcm_substream *substream)
  1795. {
  1796. struct alc_spec *spec = codec->spec;
  1797. snd_hda_codec_cleanup_stream(codec,
  1798. spec->adc_nids[substream->number + 1]);
  1799. return 0;
  1800. }
  1801. /* analog capture with dynamic dual-adc changes */
  1802. static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1803. struct hda_codec *codec,
  1804. unsigned int stream_tag,
  1805. unsigned int format,
  1806. struct snd_pcm_substream *substream)
  1807. {
  1808. struct alc_spec *spec = codec->spec;
  1809. spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
  1810. spec->cur_adc_stream_tag = stream_tag;
  1811. spec->cur_adc_format = format;
  1812. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  1813. return 0;
  1814. }
  1815. static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1816. struct hda_codec *codec,
  1817. struct snd_pcm_substream *substream)
  1818. {
  1819. struct alc_spec *spec = codec->spec;
  1820. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1821. spec->cur_adc = 0;
  1822. return 0;
  1823. }
  1824. static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
  1825. .substreams = 1,
  1826. .channels_min = 2,
  1827. .channels_max = 2,
  1828. .nid = 0, /* fill later */
  1829. .ops = {
  1830. .prepare = dyn_adc_capture_pcm_prepare,
  1831. .cleanup = dyn_adc_capture_pcm_cleanup
  1832. },
  1833. };
  1834. /*
  1835. */
  1836. static const struct hda_pcm_stream alc_pcm_analog_playback = {
  1837. .substreams = 1,
  1838. .channels_min = 2,
  1839. .channels_max = 8,
  1840. /* NID is set in alc_build_pcms */
  1841. .ops = {
  1842. .open = alc_playback_pcm_open,
  1843. .prepare = alc_playback_pcm_prepare,
  1844. .cleanup = alc_playback_pcm_cleanup
  1845. },
  1846. };
  1847. static const struct hda_pcm_stream alc_pcm_analog_capture = {
  1848. .substreams = 1,
  1849. .channels_min = 2,
  1850. .channels_max = 2,
  1851. /* NID is set in alc_build_pcms */
  1852. };
  1853. static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
  1854. .substreams = 1,
  1855. .channels_min = 2,
  1856. .channels_max = 2,
  1857. /* NID is set in alc_build_pcms */
  1858. };
  1859. static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
  1860. .substreams = 2, /* can be overridden */
  1861. .channels_min = 2,
  1862. .channels_max = 2,
  1863. /* NID is set in alc_build_pcms */
  1864. .ops = {
  1865. .prepare = alc_alt_capture_pcm_prepare,
  1866. .cleanup = alc_alt_capture_pcm_cleanup
  1867. },
  1868. };
  1869. static const struct hda_pcm_stream alc_pcm_digital_playback = {
  1870. .substreams = 1,
  1871. .channels_min = 2,
  1872. .channels_max = 2,
  1873. /* NID is set in alc_build_pcms */
  1874. .ops = {
  1875. .open = alc_dig_playback_pcm_open,
  1876. .close = alc_dig_playback_pcm_close,
  1877. .prepare = alc_dig_playback_pcm_prepare,
  1878. .cleanup = alc_dig_playback_pcm_cleanup
  1879. },
  1880. };
  1881. static const struct hda_pcm_stream alc_pcm_digital_capture = {
  1882. .substreams = 1,
  1883. .channels_min = 2,
  1884. .channels_max = 2,
  1885. /* NID is set in alc_build_pcms */
  1886. };
  1887. /* Used by alc_build_pcms to flag that a PCM has no playback stream */
  1888. static const struct hda_pcm_stream alc_pcm_null_stream = {
  1889. .substreams = 0,
  1890. .channels_min = 0,
  1891. .channels_max = 0,
  1892. };
  1893. static int alc_build_pcms(struct hda_codec *codec)
  1894. {
  1895. struct alc_spec *spec = codec->spec;
  1896. struct hda_pcm *info = spec->pcm_rec;
  1897. const struct hda_pcm_stream *p;
  1898. bool have_multi_adcs;
  1899. int i;
  1900. codec->num_pcms = 1;
  1901. codec->pcm_info = info;
  1902. if (spec->no_analog)
  1903. goto skip_analog;
  1904. snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
  1905. "%s Analog", codec->chip_name);
  1906. info->name = spec->stream_name_analog;
  1907. if (spec->multiout.num_dacs > 0) {
  1908. p = spec->stream_analog_playback;
  1909. if (!p)
  1910. p = &alc_pcm_analog_playback;
  1911. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
  1912. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  1913. }
  1914. if (spec->adc_nids) {
  1915. p = spec->stream_analog_capture;
  1916. if (!p) {
  1917. if (spec->dyn_adc_switch)
  1918. p = &dyn_adc_pcm_analog_capture;
  1919. else
  1920. p = &alc_pcm_analog_capture;
  1921. }
  1922. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
  1923. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  1924. }
  1925. if (spec->channel_mode) {
  1926. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
  1927. for (i = 0; i < spec->num_channel_mode; i++) {
  1928. if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
  1929. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
  1930. }
  1931. }
  1932. }
  1933. skip_analog:
  1934. /* SPDIF for stream index #1 */
  1935. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  1936. snprintf(spec->stream_name_digital,
  1937. sizeof(spec->stream_name_digital),
  1938. "%s Digital", codec->chip_name);
  1939. codec->num_pcms = 2;
  1940. codec->slave_dig_outs = spec->multiout.slave_dig_outs;
  1941. info = spec->pcm_rec + 1;
  1942. info->name = spec->stream_name_digital;
  1943. if (spec->dig_out_type)
  1944. info->pcm_type = spec->dig_out_type;
  1945. else
  1946. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  1947. if (spec->multiout.dig_out_nid) {
  1948. p = spec->stream_digital_playback;
  1949. if (!p)
  1950. p = &alc_pcm_digital_playback;
  1951. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
  1952. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  1953. }
  1954. if (spec->dig_in_nid) {
  1955. p = spec->stream_digital_capture;
  1956. if (!p)
  1957. p = &alc_pcm_digital_capture;
  1958. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
  1959. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  1960. }
  1961. /* FIXME: do we need this for all Realtek codec models? */
  1962. codec->spdif_status_reset = 1;
  1963. }
  1964. if (spec->no_analog)
  1965. return 0;
  1966. /* If the use of more than one ADC is requested for the current
  1967. * model, configure a second analog capture-only PCM.
  1968. */
  1969. have_multi_adcs = (spec->num_adc_nids > 1) &&
  1970. !spec->dyn_adc_switch && !spec->auto_mic &&
  1971. (!spec->input_mux || spec->input_mux->num_items > 1);
  1972. /* Additional Analaog capture for index #2 */
  1973. if (spec->alt_dac_nid || have_multi_adcs) {
  1974. codec->num_pcms = 3;
  1975. info = spec->pcm_rec + 2;
  1976. info->name = spec->stream_name_analog;
  1977. if (spec->alt_dac_nid) {
  1978. p = spec->stream_analog_alt_playback;
  1979. if (!p)
  1980. p = &alc_pcm_analog_alt_playback;
  1981. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
  1982. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  1983. spec->alt_dac_nid;
  1984. } else {
  1985. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  1986. alc_pcm_null_stream;
  1987. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
  1988. }
  1989. if (have_multi_adcs) {
  1990. p = spec->stream_analog_alt_capture;
  1991. if (!p)
  1992. p = &alc_pcm_analog_alt_capture;
  1993. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
  1994. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  1995. spec->adc_nids[1];
  1996. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  1997. spec->num_adc_nids - 1;
  1998. } else {
  1999. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  2000. alc_pcm_null_stream;
  2001. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
  2002. }
  2003. }
  2004. return 0;
  2005. }
  2006. static inline void alc_shutup(struct hda_codec *codec)
  2007. {
  2008. struct alc_spec *spec = codec->spec;
  2009. if (spec && spec->shutup)
  2010. spec->shutup(codec);
  2011. snd_hda_shutup_pins(codec);
  2012. }
  2013. static void alc_free_kctls(struct hda_codec *codec)
  2014. {
  2015. struct alc_spec *spec = codec->spec;
  2016. if (spec->kctls.list) {
  2017. struct snd_kcontrol_new *kctl = spec->kctls.list;
  2018. int i;
  2019. for (i = 0; i < spec->kctls.used; i++)
  2020. kfree(kctl[i].name);
  2021. }
  2022. snd_array_free(&spec->kctls);
  2023. }
  2024. static void alc_free_bind_ctls(struct hda_codec *codec)
  2025. {
  2026. struct alc_spec *spec = codec->spec;
  2027. if (spec->bind_ctls.list) {
  2028. struct hda_bind_ctls **ctl = spec->bind_ctls.list;
  2029. int i;
  2030. for (i = 0; i < spec->bind_ctls.used; i++)
  2031. kfree(ctl[i]);
  2032. }
  2033. snd_array_free(&spec->bind_ctls);
  2034. }
  2035. static void alc_free(struct hda_codec *codec)
  2036. {
  2037. struct alc_spec *spec = codec->spec;
  2038. if (!spec)
  2039. return;
  2040. alc_shutup(codec);
  2041. alc_free_kctls(codec);
  2042. alc_free_bind_ctls(codec);
  2043. kfree(spec);
  2044. snd_hda_detach_beep_device(codec);
  2045. }
  2046. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2047. static void alc_power_eapd(struct hda_codec *codec)
  2048. {
  2049. alc_auto_setup_eapd(codec, false);
  2050. }
  2051. static int alc_suspend(struct hda_codec *codec, pm_message_t state)
  2052. {
  2053. struct alc_spec *spec = codec->spec;
  2054. alc_shutup(codec);
  2055. if (spec && spec->power_hook)
  2056. spec->power_hook(codec);
  2057. return 0;
  2058. }
  2059. #endif
  2060. #ifdef CONFIG_PM
  2061. static int alc_resume(struct hda_codec *codec)
  2062. {
  2063. msleep(150); /* to avoid pop noise */
  2064. codec->patch_ops.init(codec);
  2065. snd_hda_codec_resume_amp(codec);
  2066. snd_hda_codec_resume_cache(codec);
  2067. hda_call_check_power_status(codec, 0x01);
  2068. return 0;
  2069. }
  2070. #endif
  2071. /*
  2072. */
  2073. static const struct hda_codec_ops alc_patch_ops = {
  2074. .build_controls = alc_build_controls,
  2075. .build_pcms = alc_build_pcms,
  2076. .init = alc_init,
  2077. .free = alc_free,
  2078. .unsol_event = alc_unsol_event,
  2079. #ifdef CONFIG_PM
  2080. .resume = alc_resume,
  2081. #endif
  2082. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2083. .suspend = alc_suspend,
  2084. .check_power_status = alc_check_power_status,
  2085. #endif
  2086. .reboot_notify = alc_shutup,
  2087. };
  2088. /* replace the codec chip_name with the given string */
  2089. static int alc_codec_rename(struct hda_codec *codec, const char *name)
  2090. {
  2091. kfree(codec->chip_name);
  2092. codec->chip_name = kstrdup(name, GFP_KERNEL);
  2093. if (!codec->chip_name) {
  2094. alc_free(codec);
  2095. return -ENOMEM;
  2096. }
  2097. return 0;
  2098. }
  2099. /*
  2100. * Rename codecs appropriately from COEF value
  2101. */
  2102. struct alc_codec_rename_table {
  2103. unsigned int vendor_id;
  2104. unsigned short coef_mask;
  2105. unsigned short coef_bits;
  2106. const char *name;
  2107. };
  2108. static struct alc_codec_rename_table rename_tbl[] = {
  2109. { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
  2110. { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
  2111. { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
  2112. { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
  2113. { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
  2114. { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
  2115. { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
  2116. { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
  2117. { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
  2118. { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
  2119. { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
  2120. { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
  2121. { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
  2122. { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
  2123. { } /* terminator */
  2124. };
  2125. static int alc_codec_rename_from_preset(struct hda_codec *codec)
  2126. {
  2127. const struct alc_codec_rename_table *p;
  2128. for (p = rename_tbl; p->vendor_id; p++) {
  2129. if (p->vendor_id != codec->vendor_id)
  2130. continue;
  2131. if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
  2132. return alc_codec_rename(codec, p->name);
  2133. }
  2134. return 0;
  2135. }
  2136. /*
  2137. * Automatic parse of I/O pins from the BIOS configuration
  2138. */
  2139. enum {
  2140. ALC_CTL_WIDGET_VOL,
  2141. ALC_CTL_WIDGET_MUTE,
  2142. ALC_CTL_BIND_MUTE,
  2143. ALC_CTL_BIND_VOL,
  2144. ALC_CTL_BIND_SW,
  2145. };
  2146. static const struct snd_kcontrol_new alc_control_templates[] = {
  2147. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  2148. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  2149. HDA_BIND_MUTE(NULL, 0, 0, 0),
  2150. HDA_BIND_VOL(NULL, 0),
  2151. HDA_BIND_SW(NULL, 0),
  2152. };
  2153. /* add dynamic controls */
  2154. static int add_control(struct alc_spec *spec, int type, const char *name,
  2155. int cidx, unsigned long val)
  2156. {
  2157. struct snd_kcontrol_new *knew;
  2158. knew = alc_kcontrol_new(spec);
  2159. if (!knew)
  2160. return -ENOMEM;
  2161. *knew = alc_control_templates[type];
  2162. knew->name = kstrdup(name, GFP_KERNEL);
  2163. if (!knew->name)
  2164. return -ENOMEM;
  2165. knew->index = cidx;
  2166. if (get_amp_nid_(val))
  2167. knew->subdevice = HDA_SUBDEV_AMP_FLAG;
  2168. knew->private_value = val;
  2169. return 0;
  2170. }
  2171. static int add_control_with_pfx(struct alc_spec *spec, int type,
  2172. const char *pfx, const char *dir,
  2173. const char *sfx, int cidx, unsigned long val)
  2174. {
  2175. char name[32];
  2176. snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
  2177. return add_control(spec, type, name, cidx, val);
  2178. }
  2179. #define add_pb_vol_ctrl(spec, type, pfx, val) \
  2180. add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
  2181. #define add_pb_sw_ctrl(spec, type, pfx, val) \
  2182. add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
  2183. #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
  2184. add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
  2185. #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
  2186. add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
  2187. static const char * const channel_name[4] = {
  2188. "Front", "Surround", "CLFE", "Side"
  2189. };
  2190. static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
  2191. bool can_be_master, int *index)
  2192. {
  2193. struct auto_pin_cfg *cfg = &spec->autocfg;
  2194. *index = 0;
  2195. if (cfg->line_outs == 1 && !spec->multi_ios &&
  2196. !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
  2197. return "Master";
  2198. switch (cfg->line_out_type) {
  2199. case AUTO_PIN_SPEAKER_OUT:
  2200. if (cfg->line_outs == 1)
  2201. return "Speaker";
  2202. if (cfg->line_outs == 2)
  2203. return ch ? "Bass Speaker" : "Speaker";
  2204. break;
  2205. case AUTO_PIN_HP_OUT:
  2206. /* for multi-io case, only the primary out */
  2207. if (ch && spec->multi_ios)
  2208. break;
  2209. *index = ch;
  2210. return "Headphone";
  2211. default:
  2212. if (cfg->line_outs == 1 && !spec->multi_ios)
  2213. return "PCM";
  2214. break;
  2215. }
  2216. if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
  2217. return "PCM";
  2218. return channel_name[ch];
  2219. }
  2220. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2221. /* add the powersave loopback-list entry */
  2222. static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
  2223. {
  2224. struct hda_amp_list *list;
  2225. if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
  2226. return;
  2227. list = spec->loopback_list + spec->num_loopbacks;
  2228. list->nid = mix;
  2229. list->dir = HDA_INPUT;
  2230. list->idx = idx;
  2231. spec->num_loopbacks++;
  2232. spec->loopback.amplist = spec->loopback_list;
  2233. }
  2234. #else
  2235. #define add_loopback_list(spec, mix, idx) /* NOP */
  2236. #endif
  2237. /* create input playback/capture controls for the given pin */
  2238. static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
  2239. const char *ctlname, int ctlidx,
  2240. int idx, hda_nid_t mix_nid)
  2241. {
  2242. int err;
  2243. err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
  2244. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  2245. if (err < 0)
  2246. return err;
  2247. err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
  2248. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  2249. if (err < 0)
  2250. return err;
  2251. add_loopback_list(spec, mix_nid, idx);
  2252. return 0;
  2253. }
  2254. static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
  2255. {
  2256. unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
  2257. return (pincap & AC_PINCAP_IN) != 0;
  2258. }
  2259. /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
  2260. static int alc_auto_fill_adc_caps(struct hda_codec *codec)
  2261. {
  2262. struct alc_spec *spec = codec->spec;
  2263. hda_nid_t nid;
  2264. hda_nid_t *adc_nids = spec->private_adc_nids;
  2265. hda_nid_t *cap_nids = spec->private_capsrc_nids;
  2266. int max_nums = ARRAY_SIZE(spec->private_adc_nids);
  2267. int i, nums = 0;
  2268. nid = codec->start_nid;
  2269. for (i = 0; i < codec->num_nodes; i++, nid++) {
  2270. hda_nid_t src;
  2271. unsigned int caps = get_wcaps(codec, nid);
  2272. int type = get_wcaps_type(caps);
  2273. if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
  2274. continue;
  2275. adc_nids[nums] = nid;
  2276. cap_nids[nums] = nid;
  2277. src = nid;
  2278. for (;;) {
  2279. int n;
  2280. type = get_wcaps_type(get_wcaps(codec, src));
  2281. if (type == AC_WID_PIN)
  2282. break;
  2283. if (type == AC_WID_AUD_SEL) {
  2284. cap_nids[nums] = src;
  2285. break;
  2286. }
  2287. n = snd_hda_get_num_conns(codec, src);
  2288. if (n > 1) {
  2289. cap_nids[nums] = src;
  2290. break;
  2291. } else if (n != 1)
  2292. break;
  2293. if (snd_hda_get_connections(codec, src, &src, 1) != 1)
  2294. break;
  2295. }
  2296. if (++nums >= max_nums)
  2297. break;
  2298. }
  2299. spec->adc_nids = spec->private_adc_nids;
  2300. spec->capsrc_nids = spec->private_capsrc_nids;
  2301. spec->num_adc_nids = nums;
  2302. return nums;
  2303. }
  2304. /* create playback/capture controls for input pins */
  2305. static int alc_auto_create_input_ctls(struct hda_codec *codec)
  2306. {
  2307. struct alc_spec *spec = codec->spec;
  2308. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2309. hda_nid_t mixer = spec->mixer_nid;
  2310. struct hda_input_mux *imux = &spec->private_imux[0];
  2311. int num_adcs;
  2312. int i, c, err, idx, type_idx = 0;
  2313. const char *prev_label = NULL;
  2314. num_adcs = alc_auto_fill_adc_caps(codec);
  2315. if (num_adcs < 0)
  2316. return 0;
  2317. for (i = 0; i < cfg->num_inputs; i++) {
  2318. hda_nid_t pin;
  2319. const char *label;
  2320. pin = cfg->inputs[i].pin;
  2321. if (!alc_is_input_pin(codec, pin))
  2322. continue;
  2323. label = hda_get_autocfg_input_label(codec, cfg, i);
  2324. if (spec->shared_mic_hp && !strcmp(label, "Misc"))
  2325. label = "Headphone Mic";
  2326. if (prev_label && !strcmp(label, prev_label))
  2327. type_idx++;
  2328. else
  2329. type_idx = 0;
  2330. prev_label = label;
  2331. if (mixer) {
  2332. idx = get_connection_index(codec, mixer, pin);
  2333. if (idx >= 0) {
  2334. err = new_analog_input(spec, pin,
  2335. label, type_idx,
  2336. idx, mixer);
  2337. if (err < 0)
  2338. return err;
  2339. }
  2340. }
  2341. for (c = 0; c < num_adcs; c++) {
  2342. hda_nid_t cap = get_capsrc(spec, c);
  2343. idx = get_connection_index(codec, cap, pin);
  2344. if (idx >= 0) {
  2345. spec->imux_pins[imux->num_items] = pin;
  2346. snd_hda_add_imux_item(imux, label, idx, NULL);
  2347. break;
  2348. }
  2349. }
  2350. }
  2351. spec->num_mux_defs = 1;
  2352. spec->input_mux = imux;
  2353. return 0;
  2354. }
  2355. /* create a shared input with the headphone out */
  2356. static int alc_auto_create_shared_input(struct hda_codec *codec)
  2357. {
  2358. struct alc_spec *spec = codec->spec;
  2359. struct auto_pin_cfg *cfg = &spec->autocfg;
  2360. unsigned int defcfg;
  2361. hda_nid_t nid;
  2362. /* only one internal input pin? */
  2363. if (cfg->num_inputs != 1)
  2364. return 0;
  2365. defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
  2366. if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
  2367. return 0;
  2368. if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
  2369. nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
  2370. else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
  2371. nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
  2372. else
  2373. return 0; /* both not available */
  2374. if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
  2375. return 0; /* no input */
  2376. cfg->inputs[1].pin = nid;
  2377. cfg->inputs[1].type = AUTO_PIN_MIC;
  2378. cfg->num_inputs = 2;
  2379. spec->shared_mic_hp = 1;
  2380. snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
  2381. return 0;
  2382. }
  2383. static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
  2384. unsigned int pin_type)
  2385. {
  2386. snd_hda_set_pin_ctl(codec, nid, pin_type);
  2387. /* unmute pin */
  2388. if (nid_has_mute(codec, nid, HDA_OUTPUT))
  2389. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2390. AMP_OUT_UNMUTE);
  2391. }
  2392. static int get_pin_type(int line_out_type)
  2393. {
  2394. if (line_out_type == AUTO_PIN_HP_OUT)
  2395. return PIN_HP;
  2396. else
  2397. return PIN_OUT;
  2398. }
  2399. static void alc_auto_init_analog_input(struct hda_codec *codec)
  2400. {
  2401. struct alc_spec *spec = codec->spec;
  2402. struct auto_pin_cfg *cfg = &spec->autocfg;
  2403. int i;
  2404. for (i = 0; i < cfg->num_inputs; i++) {
  2405. hda_nid_t nid = cfg->inputs[i].pin;
  2406. if (alc_is_input_pin(codec, nid)) {
  2407. alc_set_input_pin(codec, nid, cfg->inputs[i].type);
  2408. if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
  2409. snd_hda_codec_write(codec, nid, 0,
  2410. AC_VERB_SET_AMP_GAIN_MUTE,
  2411. AMP_OUT_MUTE);
  2412. }
  2413. }
  2414. /* mute all loopback inputs */
  2415. if (spec->mixer_nid) {
  2416. int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
  2417. for (i = 0; i < nums; i++)
  2418. snd_hda_codec_write(codec, spec->mixer_nid, 0,
  2419. AC_VERB_SET_AMP_GAIN_MUTE,
  2420. AMP_IN_MUTE(i));
  2421. }
  2422. }
  2423. /* convert from MIX nid to DAC */
  2424. static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
  2425. {
  2426. hda_nid_t list[5];
  2427. int i, num;
  2428. if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
  2429. return nid;
  2430. num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
  2431. for (i = 0; i < num; i++) {
  2432. if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
  2433. return list[i];
  2434. }
  2435. return 0;
  2436. }
  2437. /* go down to the selector widget before the mixer */
  2438. static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
  2439. {
  2440. hda_nid_t srcs[5];
  2441. int num = snd_hda_get_connections(codec, pin, srcs,
  2442. ARRAY_SIZE(srcs));
  2443. if (num != 1 ||
  2444. get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
  2445. return pin;
  2446. return srcs[0];
  2447. }
  2448. /* get MIX nid connected to the given pin targeted to DAC */
  2449. static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
  2450. hda_nid_t dac)
  2451. {
  2452. hda_nid_t mix[5];
  2453. int i, num;
  2454. pin = alc_go_down_to_selector(codec, pin);
  2455. num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
  2456. for (i = 0; i < num; i++) {
  2457. if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
  2458. return mix[i];
  2459. }
  2460. return 0;
  2461. }
  2462. /* select the connection from pin to DAC if needed */
  2463. static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
  2464. hda_nid_t dac)
  2465. {
  2466. hda_nid_t mix[5];
  2467. int i, num;
  2468. pin = alc_go_down_to_selector(codec, pin);
  2469. num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
  2470. if (num < 2)
  2471. return 0;
  2472. for (i = 0; i < num; i++) {
  2473. if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
  2474. snd_hda_codec_update_cache(codec, pin, 0,
  2475. AC_VERB_SET_CONNECT_SEL, i);
  2476. return 0;
  2477. }
  2478. }
  2479. return 0;
  2480. }
  2481. static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
  2482. {
  2483. struct alc_spec *spec = codec->spec;
  2484. int i;
  2485. if (found_in_nid_list(nid, spec->multiout.dac_nids,
  2486. ARRAY_SIZE(spec->private_dac_nids)) ||
  2487. found_in_nid_list(nid, spec->multiout.hp_out_nid,
  2488. ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
  2489. found_in_nid_list(nid, spec->multiout.extra_out_nid,
  2490. ARRAY_SIZE(spec->multiout.extra_out_nid)))
  2491. return true;
  2492. for (i = 0; i < spec->multi_ios; i++) {
  2493. if (spec->multi_io[i].dac == nid)
  2494. return true;
  2495. }
  2496. return false;
  2497. }
  2498. /* look for an empty DAC slot */
  2499. static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
  2500. {
  2501. hda_nid_t srcs[5];
  2502. int i, num;
  2503. pin = alc_go_down_to_selector(codec, pin);
  2504. num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
  2505. for (i = 0; i < num; i++) {
  2506. hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
  2507. if (!nid)
  2508. continue;
  2509. if (!alc_is_dac_already_used(codec, nid))
  2510. return nid;
  2511. }
  2512. return 0;
  2513. }
  2514. /* check whether the DAC is reachable from the pin */
  2515. static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
  2516. hda_nid_t pin, hda_nid_t dac)
  2517. {
  2518. hda_nid_t srcs[5];
  2519. int i, num;
  2520. if (!pin || !dac)
  2521. return false;
  2522. pin = alc_go_down_to_selector(codec, pin);
  2523. num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
  2524. for (i = 0; i < num; i++) {
  2525. hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
  2526. if (nid == dac)
  2527. return true;
  2528. }
  2529. return false;
  2530. }
  2531. static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
  2532. {
  2533. struct alc_spec *spec = codec->spec;
  2534. hda_nid_t sel = alc_go_down_to_selector(codec, pin);
  2535. hda_nid_t nid, nid_found, srcs[5];
  2536. int i, num = snd_hda_get_connections(codec, sel, srcs,
  2537. ARRAY_SIZE(srcs));
  2538. if (num == 1)
  2539. return alc_auto_look_for_dac(codec, pin);
  2540. nid_found = 0;
  2541. for (i = 0; i < num; i++) {
  2542. if (srcs[i] == spec->mixer_nid)
  2543. continue;
  2544. nid = alc_auto_mix_to_dac(codec, srcs[i]);
  2545. if (nid && !alc_is_dac_already_used(codec, nid)) {
  2546. if (nid_found)
  2547. return 0;
  2548. nid_found = nid;
  2549. }
  2550. }
  2551. return nid_found;
  2552. }
  2553. /* mark up volume and mute control NIDs: used during badness parsing and
  2554. * at creating actual controls
  2555. */
  2556. static inline unsigned int get_ctl_pos(unsigned int data)
  2557. {
  2558. hda_nid_t nid = get_amp_nid_(data);
  2559. unsigned int dir;
  2560. if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
  2561. return 0;
  2562. dir = get_amp_direction_(data);
  2563. return (nid << 1) | dir;
  2564. }
  2565. #define is_ctl_used(bits, data) \
  2566. test_bit(get_ctl_pos(data), bits)
  2567. #define mark_ctl_usage(bits, data) \
  2568. set_bit(get_ctl_pos(data), bits)
  2569. static void clear_vol_marks(struct hda_codec *codec)
  2570. {
  2571. struct alc_spec *spec = codec->spec;
  2572. memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
  2573. memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
  2574. }
  2575. /* badness definition */
  2576. enum {
  2577. /* No primary DAC is found for the main output */
  2578. BAD_NO_PRIMARY_DAC = 0x10000,
  2579. /* No DAC is found for the extra output */
  2580. BAD_NO_DAC = 0x4000,
  2581. /* No possible multi-ios */
  2582. BAD_MULTI_IO = 0x103,
  2583. /* No individual DAC for extra output */
  2584. BAD_NO_EXTRA_DAC = 0x102,
  2585. /* No individual DAC for extra surrounds */
  2586. BAD_NO_EXTRA_SURR_DAC = 0x101,
  2587. /* Primary DAC shared with main surrounds */
  2588. BAD_SHARED_SURROUND = 0x100,
  2589. /* Primary DAC shared with main CLFE */
  2590. BAD_SHARED_CLFE = 0x10,
  2591. /* Primary DAC shared with extra surrounds */
  2592. BAD_SHARED_EXTRA_SURROUND = 0x10,
  2593. /* Volume widget is shared */
  2594. BAD_SHARED_VOL = 0x10,
  2595. };
  2596. static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
  2597. hda_nid_t pin, hda_nid_t dac);
  2598. static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
  2599. hda_nid_t pin, hda_nid_t dac);
  2600. static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
  2601. hda_nid_t dac)
  2602. {
  2603. struct alc_spec *spec = codec->spec;
  2604. hda_nid_t nid;
  2605. unsigned int val;
  2606. int badness = 0;
  2607. nid = alc_look_for_out_vol_nid(codec, pin, dac);
  2608. if (nid) {
  2609. val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
  2610. if (is_ctl_used(spec->vol_ctls, nid))
  2611. badness += BAD_SHARED_VOL;
  2612. else
  2613. mark_ctl_usage(spec->vol_ctls, val);
  2614. } else
  2615. badness += BAD_SHARED_VOL;
  2616. nid = alc_look_for_out_mute_nid(codec, pin, dac);
  2617. if (nid) {
  2618. unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
  2619. if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
  2620. val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
  2621. else
  2622. val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
  2623. if (is_ctl_used(spec->sw_ctls, val))
  2624. badness += BAD_SHARED_VOL;
  2625. else
  2626. mark_ctl_usage(spec->sw_ctls, val);
  2627. } else
  2628. badness += BAD_SHARED_VOL;
  2629. return badness;
  2630. }
  2631. struct badness_table {
  2632. int no_primary_dac; /* no primary DAC */
  2633. int no_dac; /* no secondary DACs */
  2634. int shared_primary; /* primary DAC is shared with main output */
  2635. int shared_surr; /* secondary DAC shared with main or primary */
  2636. int shared_clfe; /* third DAC shared with main or primary */
  2637. int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
  2638. };
  2639. static struct badness_table main_out_badness = {
  2640. .no_primary_dac = BAD_NO_PRIMARY_DAC,
  2641. .no_dac = BAD_NO_DAC,
  2642. .shared_primary = BAD_NO_PRIMARY_DAC,
  2643. .shared_surr = BAD_SHARED_SURROUND,
  2644. .shared_clfe = BAD_SHARED_CLFE,
  2645. .shared_surr_main = BAD_SHARED_SURROUND,
  2646. };
  2647. static struct badness_table extra_out_badness = {
  2648. .no_primary_dac = BAD_NO_DAC,
  2649. .no_dac = BAD_NO_DAC,
  2650. .shared_primary = BAD_NO_EXTRA_DAC,
  2651. .shared_surr = BAD_SHARED_EXTRA_SURROUND,
  2652. .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
  2653. .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
  2654. };
  2655. /* try to assign DACs to pins and return the resultant badness */
  2656. static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
  2657. const hda_nid_t *pins, hda_nid_t *dacs,
  2658. const struct badness_table *bad)
  2659. {
  2660. struct alc_spec *spec = codec->spec;
  2661. struct auto_pin_cfg *cfg = &spec->autocfg;
  2662. int i, j;
  2663. int badness = 0;
  2664. hda_nid_t dac;
  2665. if (!num_outs)
  2666. return 0;
  2667. for (i = 0; i < num_outs; i++) {
  2668. hda_nid_t pin = pins[i];
  2669. if (!dacs[i])
  2670. dacs[i] = alc_auto_look_for_dac(codec, pin);
  2671. if (!dacs[i] && !i) {
  2672. for (j = 1; j < num_outs; j++) {
  2673. if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
  2674. dacs[0] = dacs[j];
  2675. dacs[j] = 0;
  2676. break;
  2677. }
  2678. }
  2679. }
  2680. dac = dacs[i];
  2681. if (!dac) {
  2682. if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
  2683. dac = dacs[0];
  2684. else if (cfg->line_outs > i &&
  2685. alc_auto_is_dac_reachable(codec, pin,
  2686. spec->private_dac_nids[i]))
  2687. dac = spec->private_dac_nids[i];
  2688. if (dac) {
  2689. if (!i)
  2690. badness += bad->shared_primary;
  2691. else if (i == 1)
  2692. badness += bad->shared_surr;
  2693. else
  2694. badness += bad->shared_clfe;
  2695. } else if (alc_auto_is_dac_reachable(codec, pin,
  2696. spec->private_dac_nids[0])) {
  2697. dac = spec->private_dac_nids[0];
  2698. badness += bad->shared_surr_main;
  2699. } else if (!i)
  2700. badness += bad->no_primary_dac;
  2701. else
  2702. badness += bad->no_dac;
  2703. }
  2704. if (dac)
  2705. badness += eval_shared_vol_badness(codec, pin, dac);
  2706. }
  2707. return badness;
  2708. }
  2709. static int alc_auto_fill_multi_ios(struct hda_codec *codec,
  2710. hda_nid_t reference_pin,
  2711. bool hardwired, int offset);
  2712. static bool alc_map_singles(struct hda_codec *codec, int outs,
  2713. const hda_nid_t *pins, hda_nid_t *dacs)
  2714. {
  2715. int i;
  2716. bool found = false;
  2717. for (i = 0; i < outs; i++) {
  2718. if (dacs[i])
  2719. continue;
  2720. dacs[i] = get_dac_if_single(codec, pins[i]);
  2721. if (dacs[i])
  2722. found = true;
  2723. }
  2724. return found;
  2725. }
  2726. /* fill in the dac_nids table from the parsed pin configuration */
  2727. static int fill_and_eval_dacs(struct hda_codec *codec,
  2728. bool fill_hardwired,
  2729. bool fill_mio_first)
  2730. {
  2731. struct alc_spec *spec = codec->spec;
  2732. struct auto_pin_cfg *cfg = &spec->autocfg;
  2733. int i, err, badness;
  2734. /* set num_dacs once to full for alc_auto_look_for_dac() */
  2735. spec->multiout.num_dacs = cfg->line_outs;
  2736. spec->multiout.dac_nids = spec->private_dac_nids;
  2737. memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
  2738. memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
  2739. memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
  2740. spec->multi_ios = 0;
  2741. clear_vol_marks(codec);
  2742. badness = 0;
  2743. /* fill hard-wired DACs first */
  2744. if (fill_hardwired) {
  2745. bool mapped;
  2746. do {
  2747. mapped = alc_map_singles(codec, cfg->line_outs,
  2748. cfg->line_out_pins,
  2749. spec->private_dac_nids);
  2750. mapped |= alc_map_singles(codec, cfg->hp_outs,
  2751. cfg->hp_pins,
  2752. spec->multiout.hp_out_nid);
  2753. mapped |= alc_map_singles(codec, cfg->speaker_outs,
  2754. cfg->speaker_pins,
  2755. spec->multiout.extra_out_nid);
  2756. if (fill_mio_first && cfg->line_outs == 1 &&
  2757. cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
  2758. err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
  2759. if (!err)
  2760. mapped = true;
  2761. }
  2762. } while (mapped);
  2763. }
  2764. badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
  2765. spec->private_dac_nids,
  2766. &main_out_badness);
  2767. /* re-count num_dacs and squash invalid entries */
  2768. spec->multiout.num_dacs = 0;
  2769. for (i = 0; i < cfg->line_outs; i++) {
  2770. if (spec->private_dac_nids[i])
  2771. spec->multiout.num_dacs++;
  2772. else {
  2773. memmove(spec->private_dac_nids + i,
  2774. spec->private_dac_nids + i + 1,
  2775. sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
  2776. spec->private_dac_nids[cfg->line_outs - 1] = 0;
  2777. }
  2778. }
  2779. if (fill_mio_first &&
  2780. cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
  2781. /* try to fill multi-io first */
  2782. err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
  2783. if (err < 0)
  2784. return err;
  2785. /* we don't count badness at this stage yet */
  2786. }
  2787. if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
  2788. err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
  2789. spec->multiout.hp_out_nid,
  2790. &extra_out_badness);
  2791. if (err < 0)
  2792. return err;
  2793. badness += err;
  2794. }
  2795. if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
  2796. err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
  2797. cfg->speaker_pins,
  2798. spec->multiout.extra_out_nid,
  2799. &extra_out_badness);
  2800. if (err < 0)
  2801. return err;
  2802. badness += err;
  2803. }
  2804. if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
  2805. err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
  2806. if (err < 0)
  2807. return err;
  2808. badness += err;
  2809. }
  2810. if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
  2811. /* try multi-ios with HP + inputs */
  2812. int offset = 0;
  2813. if (cfg->line_outs >= 3)
  2814. offset = 1;
  2815. err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
  2816. offset);
  2817. if (err < 0)
  2818. return err;
  2819. badness += err;
  2820. }
  2821. if (spec->multi_ios == 2) {
  2822. for (i = 0; i < 2; i++)
  2823. spec->private_dac_nids[spec->multiout.num_dacs++] =
  2824. spec->multi_io[i].dac;
  2825. spec->ext_channel_count = 2;
  2826. } else if (spec->multi_ios) {
  2827. spec->multi_ios = 0;
  2828. badness += BAD_MULTI_IO;
  2829. }
  2830. return badness;
  2831. }
  2832. #define DEBUG_BADNESS
  2833. #ifdef DEBUG_BADNESS
  2834. #define debug_badness snd_printdd
  2835. #else
  2836. #define debug_badness(...)
  2837. #endif
  2838. static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
  2839. {
  2840. debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
  2841. cfg->line_out_pins[0], cfg->line_out_pins[1],
  2842. cfg->line_out_pins[2], cfg->line_out_pins[2],
  2843. spec->multiout.dac_nids[0],
  2844. spec->multiout.dac_nids[1],
  2845. spec->multiout.dac_nids[2],
  2846. spec->multiout.dac_nids[3]);
  2847. if (spec->multi_ios > 0)
  2848. debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
  2849. spec->multi_ios,
  2850. spec->multi_io[0].pin, spec->multi_io[1].pin,
  2851. spec->multi_io[0].dac, spec->multi_io[1].dac);
  2852. debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
  2853. cfg->hp_pins[0], cfg->hp_pins[1],
  2854. cfg->hp_pins[2], cfg->hp_pins[2],
  2855. spec->multiout.hp_out_nid[0],
  2856. spec->multiout.hp_out_nid[1],
  2857. spec->multiout.hp_out_nid[2],
  2858. spec->multiout.hp_out_nid[3]);
  2859. debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
  2860. cfg->speaker_pins[0], cfg->speaker_pins[1],
  2861. cfg->speaker_pins[2], cfg->speaker_pins[3],
  2862. spec->multiout.extra_out_nid[0],
  2863. spec->multiout.extra_out_nid[1],
  2864. spec->multiout.extra_out_nid[2],
  2865. spec->multiout.extra_out_nid[3]);
  2866. }
  2867. static int alc_auto_fill_dac_nids(struct hda_codec *codec)
  2868. {
  2869. struct alc_spec *spec = codec->spec;
  2870. struct auto_pin_cfg *cfg = &spec->autocfg;
  2871. struct auto_pin_cfg *best_cfg;
  2872. int best_badness = INT_MAX;
  2873. int badness;
  2874. bool fill_hardwired = true, fill_mio_first = true;
  2875. bool best_wired = true, best_mio = true;
  2876. bool hp_spk_swapped = false;
  2877. best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
  2878. if (!best_cfg)
  2879. return -ENOMEM;
  2880. *best_cfg = *cfg;
  2881. for (;;) {
  2882. badness = fill_and_eval_dacs(codec, fill_hardwired,
  2883. fill_mio_first);
  2884. if (badness < 0) {
  2885. kfree(best_cfg);
  2886. return badness;
  2887. }
  2888. debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
  2889. cfg->line_out_type, fill_hardwired, fill_mio_first,
  2890. badness);
  2891. debug_show_configs(spec, cfg);
  2892. if (badness < best_badness) {
  2893. best_badness = badness;
  2894. *best_cfg = *cfg;
  2895. best_wired = fill_hardwired;
  2896. best_mio = fill_mio_first;
  2897. }
  2898. if (!badness)
  2899. break;
  2900. fill_mio_first = !fill_mio_first;
  2901. if (!fill_mio_first)
  2902. continue;
  2903. fill_hardwired = !fill_hardwired;
  2904. if (!fill_hardwired)
  2905. continue;
  2906. if (hp_spk_swapped)
  2907. break;
  2908. hp_spk_swapped = true;
  2909. if (cfg->speaker_outs > 0 &&
  2910. cfg->line_out_type == AUTO_PIN_HP_OUT) {
  2911. cfg->hp_outs = cfg->line_outs;
  2912. memcpy(cfg->hp_pins, cfg->line_out_pins,
  2913. sizeof(cfg->hp_pins));
  2914. cfg->line_outs = cfg->speaker_outs;
  2915. memcpy(cfg->line_out_pins, cfg->speaker_pins,
  2916. sizeof(cfg->speaker_pins));
  2917. cfg->speaker_outs = 0;
  2918. memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
  2919. cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
  2920. fill_hardwired = true;
  2921. continue;
  2922. }
  2923. if (cfg->hp_outs > 0 &&
  2924. cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
  2925. cfg->speaker_outs = cfg->line_outs;
  2926. memcpy(cfg->speaker_pins, cfg->line_out_pins,
  2927. sizeof(cfg->speaker_pins));
  2928. cfg->line_outs = cfg->hp_outs;
  2929. memcpy(cfg->line_out_pins, cfg->hp_pins,
  2930. sizeof(cfg->hp_pins));
  2931. cfg->hp_outs = 0;
  2932. memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
  2933. cfg->line_out_type = AUTO_PIN_HP_OUT;
  2934. fill_hardwired = true;
  2935. continue;
  2936. }
  2937. break;
  2938. }
  2939. if (badness) {
  2940. *cfg = *best_cfg;
  2941. fill_and_eval_dacs(codec, best_wired, best_mio);
  2942. }
  2943. debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
  2944. cfg->line_out_type, best_wired, best_mio);
  2945. debug_show_configs(spec, cfg);
  2946. if (cfg->line_out_pins[0])
  2947. spec->vmaster_nid =
  2948. alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
  2949. spec->multiout.dac_nids[0]);
  2950. /* clear the bitmap flags for creating controls */
  2951. clear_vol_marks(codec);
  2952. kfree(best_cfg);
  2953. return 0;
  2954. }
  2955. static int alc_auto_add_vol_ctl(struct hda_codec *codec,
  2956. const char *pfx, int cidx,
  2957. hda_nid_t nid, unsigned int chs)
  2958. {
  2959. struct alc_spec *spec = codec->spec;
  2960. unsigned int val;
  2961. if (!nid)
  2962. return 0;
  2963. val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
  2964. if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
  2965. return 0;
  2966. mark_ctl_usage(spec->vol_ctls, val);
  2967. return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
  2968. val);
  2969. }
  2970. static int alc_auto_add_stereo_vol(struct hda_codec *codec,
  2971. const char *pfx, int cidx,
  2972. hda_nid_t nid)
  2973. {
  2974. int chs = 1;
  2975. if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
  2976. chs = 3;
  2977. return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
  2978. }
  2979. /* create a mute-switch for the given mixer widget;
  2980. * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
  2981. */
  2982. static int alc_auto_add_sw_ctl(struct hda_codec *codec,
  2983. const char *pfx, int cidx,
  2984. hda_nid_t nid, unsigned int chs)
  2985. {
  2986. struct alc_spec *spec = codec->spec;
  2987. int wid_type;
  2988. int type;
  2989. unsigned long val;
  2990. if (!nid)
  2991. return 0;
  2992. wid_type = get_wcaps_type(get_wcaps(codec, nid));
  2993. if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
  2994. type = ALC_CTL_WIDGET_MUTE;
  2995. val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
  2996. } else if (snd_hda_get_num_conns(codec, nid) == 1) {
  2997. type = ALC_CTL_WIDGET_MUTE;
  2998. val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
  2999. } else {
  3000. type = ALC_CTL_BIND_MUTE;
  3001. val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
  3002. }
  3003. if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
  3004. return 0;
  3005. mark_ctl_usage(spec->sw_ctls, val);
  3006. return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
  3007. }
  3008. static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
  3009. int cidx, hda_nid_t nid)
  3010. {
  3011. int chs = 1;
  3012. if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
  3013. chs = 3;
  3014. return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
  3015. }
  3016. static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
  3017. hda_nid_t pin, hda_nid_t dac)
  3018. {
  3019. hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
  3020. if (nid_has_mute(codec, pin, HDA_OUTPUT))
  3021. return pin;
  3022. else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
  3023. return mix;
  3024. else if (nid_has_mute(codec, dac, HDA_OUTPUT))
  3025. return dac;
  3026. return 0;
  3027. }
  3028. static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
  3029. hda_nid_t pin, hda_nid_t dac)
  3030. {
  3031. hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
  3032. if (nid_has_volume(codec, dac, HDA_OUTPUT))
  3033. return dac;
  3034. else if (nid_has_volume(codec, mix, HDA_OUTPUT))
  3035. return mix;
  3036. else if (nid_has_volume(codec, pin, HDA_OUTPUT))
  3037. return pin;
  3038. return 0;
  3039. }
  3040. /* add playback controls from the parsed DAC table */
  3041. static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
  3042. const struct auto_pin_cfg *cfg)
  3043. {
  3044. struct alc_spec *spec = codec->spec;
  3045. int i, err, noutputs;
  3046. noutputs = cfg->line_outs;
  3047. if (spec->multi_ios > 0 && cfg->line_outs < 3)
  3048. noutputs += spec->multi_ios;
  3049. for (i = 0; i < noutputs; i++) {
  3050. const char *name;
  3051. int index;
  3052. hda_nid_t dac, pin;
  3053. hda_nid_t sw, vol;
  3054. dac = spec->multiout.dac_nids[i];
  3055. if (!dac)
  3056. continue;
  3057. if (i >= cfg->line_outs) {
  3058. pin = spec->multi_io[i - 1].pin;
  3059. index = 0;
  3060. name = channel_name[i];
  3061. } else {
  3062. pin = cfg->line_out_pins[i];
  3063. name = alc_get_line_out_pfx(spec, i, true, &index);
  3064. }
  3065. sw = alc_look_for_out_mute_nid(codec, pin, dac);
  3066. vol = alc_look_for_out_vol_nid(codec, pin, dac);
  3067. if (!name || !strcmp(name, "CLFE")) {
  3068. /* Center/LFE */
  3069. err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
  3070. if (err < 0)
  3071. return err;
  3072. err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
  3073. if (err < 0)
  3074. return err;
  3075. err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
  3076. if (err < 0)
  3077. return err;
  3078. err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
  3079. if (err < 0)
  3080. return err;
  3081. } else {
  3082. err = alc_auto_add_stereo_vol(codec, name, index, vol);
  3083. if (err < 0)
  3084. return err;
  3085. err = alc_auto_add_stereo_sw(codec, name, index, sw);
  3086. if (err < 0)
  3087. return err;
  3088. }
  3089. }
  3090. return 0;
  3091. }
  3092. static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
  3093. hda_nid_t dac, const char *pfx,
  3094. int cidx)
  3095. {
  3096. struct alc_spec *spec = codec->spec;
  3097. hda_nid_t sw, vol;
  3098. int err;
  3099. if (!dac) {
  3100. unsigned int val;
  3101. /* the corresponding DAC is already occupied */
  3102. if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
  3103. return 0; /* no way */
  3104. /* create a switch only */
  3105. val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
  3106. if (is_ctl_used(spec->sw_ctls, val))
  3107. return 0; /* already created */
  3108. mark_ctl_usage(spec->sw_ctls, val);
  3109. return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
  3110. }
  3111. sw = alc_look_for_out_mute_nid(codec, pin, dac);
  3112. vol = alc_look_for_out_vol_nid(codec, pin, dac);
  3113. err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
  3114. if (err < 0)
  3115. return err;
  3116. err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
  3117. if (err < 0)
  3118. return err;
  3119. return 0;
  3120. }
  3121. static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
  3122. unsigned int nums,
  3123. struct hda_ctl_ops *ops)
  3124. {
  3125. struct alc_spec *spec = codec->spec;
  3126. struct hda_bind_ctls **ctlp, *ctl;
  3127. snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
  3128. ctlp = snd_array_new(&spec->bind_ctls);
  3129. if (!ctlp)
  3130. return NULL;
  3131. ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
  3132. *ctlp = ctl;
  3133. if (ctl)
  3134. ctl->ops = ops;
  3135. return ctl;
  3136. }
  3137. /* add playback controls for speaker and HP outputs */
  3138. static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
  3139. const hda_nid_t *pins,
  3140. const hda_nid_t *dacs,
  3141. const char *pfx)
  3142. {
  3143. struct alc_spec *spec = codec->spec;
  3144. struct hda_bind_ctls *ctl;
  3145. char name[32];
  3146. int i, n, err;
  3147. if (!num_pins || !pins[0])
  3148. return 0;
  3149. if (num_pins == 1) {
  3150. hda_nid_t dac = *dacs;
  3151. if (!dac)
  3152. dac = spec->multiout.dac_nids[0];
  3153. return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
  3154. }
  3155. for (i = 0; i < num_pins; i++) {
  3156. hda_nid_t dac;
  3157. if (dacs[num_pins - 1])
  3158. dac = dacs[i]; /* with individual volumes */
  3159. else
  3160. dac = 0;
  3161. if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
  3162. err = alc_auto_create_extra_out(codec, pins[i], dac,
  3163. "Bass Speaker", 0);
  3164. } else if (num_pins >= 3) {
  3165. snprintf(name, sizeof(name), "%s %s",
  3166. pfx, channel_name[i]);
  3167. err = alc_auto_create_extra_out(codec, pins[i], dac,
  3168. name, 0);
  3169. } else {
  3170. err = alc_auto_create_extra_out(codec, pins[i], dac,
  3171. pfx, i);
  3172. }
  3173. if (err < 0)
  3174. return err;
  3175. }
  3176. if (dacs[num_pins - 1])
  3177. return 0;
  3178. /* Let's create a bind-controls for volumes */
  3179. ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
  3180. if (!ctl)
  3181. return -ENOMEM;
  3182. n = 0;
  3183. for (i = 0; i < num_pins; i++) {
  3184. hda_nid_t vol;
  3185. if (!pins[i] || !dacs[i])
  3186. continue;
  3187. vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
  3188. if (vol)
  3189. ctl->values[n++] =
  3190. HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
  3191. }
  3192. if (n) {
  3193. snprintf(name, sizeof(name), "%s Playback Volume", pfx);
  3194. err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
  3195. if (err < 0)
  3196. return err;
  3197. }
  3198. return 0;
  3199. }
  3200. static int alc_auto_create_hp_out(struct hda_codec *codec)
  3201. {
  3202. struct alc_spec *spec = codec->spec;
  3203. return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
  3204. spec->autocfg.hp_pins,
  3205. spec->multiout.hp_out_nid,
  3206. "Headphone");
  3207. }
  3208. static int alc_auto_create_speaker_out(struct hda_codec *codec)
  3209. {
  3210. struct alc_spec *spec = codec->spec;
  3211. return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
  3212. spec->autocfg.speaker_pins,
  3213. spec->multiout.extra_out_nid,
  3214. "Speaker");
  3215. }
  3216. static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
  3217. hda_nid_t pin, int pin_type,
  3218. hda_nid_t dac)
  3219. {
  3220. int i, num;
  3221. hda_nid_t nid, mix = 0;
  3222. hda_nid_t srcs[HDA_MAX_CONNECTIONS];
  3223. alc_set_pin_output(codec, pin, pin_type);
  3224. nid = alc_go_down_to_selector(codec, pin);
  3225. num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
  3226. for (i = 0; i < num; i++) {
  3227. if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
  3228. continue;
  3229. mix = srcs[i];
  3230. break;
  3231. }
  3232. if (!mix)
  3233. return;
  3234. /* need the manual connection? */
  3235. if (num > 1)
  3236. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
  3237. /* unmute mixer widget inputs */
  3238. if (nid_has_mute(codec, mix, HDA_INPUT)) {
  3239. snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3240. AMP_IN_UNMUTE(0));
  3241. snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3242. AMP_IN_UNMUTE(1));
  3243. }
  3244. /* initialize volume */
  3245. nid = alc_look_for_out_vol_nid(codec, pin, dac);
  3246. if (nid)
  3247. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3248. AMP_OUT_ZERO);
  3249. /* unmute DAC if it's not assigned to a mixer */
  3250. nid = alc_look_for_out_mute_nid(codec, pin, dac);
  3251. if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
  3252. snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3253. AMP_OUT_ZERO);
  3254. }
  3255. static void alc_auto_init_multi_out(struct hda_codec *codec)
  3256. {
  3257. struct alc_spec *spec = codec->spec;
  3258. int pin_type = get_pin_type(spec->autocfg.line_out_type);
  3259. int i;
  3260. for (i = 0; i <= HDA_SIDE; i++) {
  3261. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  3262. if (nid)
  3263. alc_auto_set_output_and_unmute(codec, nid, pin_type,
  3264. spec->multiout.dac_nids[i]);
  3265. }
  3266. }
  3267. static void alc_auto_init_extra_out(struct hda_codec *codec)
  3268. {
  3269. struct alc_spec *spec = codec->spec;
  3270. int i;
  3271. hda_nid_t pin, dac;
  3272. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  3273. if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
  3274. break;
  3275. pin = spec->autocfg.hp_pins[i];
  3276. if (!pin)
  3277. break;
  3278. dac = spec->multiout.hp_out_nid[i];
  3279. if (!dac) {
  3280. if (i > 0 && spec->multiout.hp_out_nid[0])
  3281. dac = spec->multiout.hp_out_nid[0];
  3282. else
  3283. dac = spec->multiout.dac_nids[0];
  3284. }
  3285. alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
  3286. }
  3287. for (i = 0; i < spec->autocfg.speaker_outs; i++) {
  3288. if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
  3289. break;
  3290. pin = spec->autocfg.speaker_pins[i];
  3291. if (!pin)
  3292. break;
  3293. dac = spec->multiout.extra_out_nid[i];
  3294. if (!dac) {
  3295. if (i > 0 && spec->multiout.extra_out_nid[0])
  3296. dac = spec->multiout.extra_out_nid[0];
  3297. else
  3298. dac = spec->multiout.dac_nids[0];
  3299. }
  3300. alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
  3301. }
  3302. }
  3303. /* check whether the given pin can be a multi-io pin */
  3304. static bool can_be_multiio_pin(struct hda_codec *codec,
  3305. unsigned int location, hda_nid_t nid)
  3306. {
  3307. unsigned int defcfg, caps;
  3308. defcfg = snd_hda_codec_get_pincfg(codec, nid);
  3309. if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
  3310. return false;
  3311. if (location && get_defcfg_location(defcfg) != location)
  3312. return false;
  3313. caps = snd_hda_query_pin_caps(codec, nid);
  3314. if (!(caps & AC_PINCAP_OUT))
  3315. return false;
  3316. return true;
  3317. }
  3318. /*
  3319. * multi-io helper
  3320. *
  3321. * When hardwired is set, try to fill ony hardwired pins, and returns
  3322. * zero if any pins are filled, non-zero if nothing found.
  3323. * When hardwired is off, try to fill possible input pins, and returns
  3324. * the badness value.
  3325. */
  3326. static int alc_auto_fill_multi_ios(struct hda_codec *codec,
  3327. hda_nid_t reference_pin,
  3328. bool hardwired, int offset)
  3329. {
  3330. struct alc_spec *spec = codec->spec;
  3331. struct auto_pin_cfg *cfg = &spec->autocfg;
  3332. int type, i, j, dacs, num_pins, old_pins;
  3333. unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
  3334. unsigned int location = get_defcfg_location(defcfg);
  3335. int badness = 0;
  3336. old_pins = spec->multi_ios;
  3337. if (old_pins >= 2)
  3338. goto end_fill;
  3339. num_pins = 0;
  3340. for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
  3341. for (i = 0; i < cfg->num_inputs; i++) {
  3342. if (cfg->inputs[i].type != type)
  3343. continue;
  3344. if (can_be_multiio_pin(codec, location,
  3345. cfg->inputs[i].pin))
  3346. num_pins++;
  3347. }
  3348. }
  3349. if (num_pins < 2)
  3350. goto end_fill;
  3351. dacs = spec->multiout.num_dacs;
  3352. for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
  3353. for (i = 0; i < cfg->num_inputs; i++) {
  3354. hda_nid_t nid = cfg->inputs[i].pin;
  3355. hda_nid_t dac = 0;
  3356. if (cfg->inputs[i].type != type)
  3357. continue;
  3358. if (!can_be_multiio_pin(codec, location, nid))
  3359. continue;
  3360. for (j = 0; j < spec->multi_ios; j++) {
  3361. if (nid == spec->multi_io[j].pin)
  3362. break;
  3363. }
  3364. if (j < spec->multi_ios)
  3365. continue;
  3366. if (offset && offset + spec->multi_ios < dacs) {
  3367. dac = spec->private_dac_nids[offset + spec->multi_ios];
  3368. if (!alc_auto_is_dac_reachable(codec, nid, dac))
  3369. dac = 0;
  3370. }
  3371. if (hardwired)
  3372. dac = get_dac_if_single(codec, nid);
  3373. else if (!dac)
  3374. dac = alc_auto_look_for_dac(codec, nid);
  3375. if (!dac) {
  3376. badness++;
  3377. continue;
  3378. }
  3379. spec->multi_io[spec->multi_ios].pin = nid;
  3380. spec->multi_io[spec->multi_ios].dac = dac;
  3381. spec->multi_ios++;
  3382. if (spec->multi_ios >= 2)
  3383. break;
  3384. }
  3385. }
  3386. end_fill:
  3387. if (badness)
  3388. badness = BAD_MULTI_IO;
  3389. if (old_pins == spec->multi_ios) {
  3390. if (hardwired)
  3391. return 1; /* nothing found */
  3392. else
  3393. return badness; /* no badness if nothing found */
  3394. }
  3395. if (!hardwired && spec->multi_ios < 2) {
  3396. spec->multi_ios = old_pins;
  3397. return badness;
  3398. }
  3399. return 0;
  3400. }
  3401. static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
  3402. struct snd_ctl_elem_info *uinfo)
  3403. {
  3404. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3405. struct alc_spec *spec = codec->spec;
  3406. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  3407. uinfo->count = 1;
  3408. uinfo->value.enumerated.items = spec->multi_ios + 1;
  3409. if (uinfo->value.enumerated.item > spec->multi_ios)
  3410. uinfo->value.enumerated.item = spec->multi_ios;
  3411. sprintf(uinfo->value.enumerated.name, "%dch",
  3412. (uinfo->value.enumerated.item + 1) * 2);
  3413. return 0;
  3414. }
  3415. static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
  3416. struct snd_ctl_elem_value *ucontrol)
  3417. {
  3418. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3419. struct alc_spec *spec = codec->spec;
  3420. ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
  3421. return 0;
  3422. }
  3423. static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
  3424. {
  3425. struct alc_spec *spec = codec->spec;
  3426. hda_nid_t nid = spec->multi_io[idx].pin;
  3427. if (!spec->multi_io[idx].ctl_in)
  3428. spec->multi_io[idx].ctl_in =
  3429. snd_hda_codec_read(codec, nid, 0,
  3430. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  3431. if (output) {
  3432. snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
  3433. if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
  3434. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  3435. HDA_AMP_MUTE, 0);
  3436. alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
  3437. } else {
  3438. if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
  3439. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  3440. HDA_AMP_MUTE, HDA_AMP_MUTE);
  3441. snd_hda_set_pin_ctl_cache(codec, nid,
  3442. spec->multi_io[idx].ctl_in);
  3443. }
  3444. return 0;
  3445. }
  3446. static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
  3447. struct snd_ctl_elem_value *ucontrol)
  3448. {
  3449. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3450. struct alc_spec *spec = codec->spec;
  3451. int i, ch;
  3452. ch = ucontrol->value.enumerated.item[0];
  3453. if (ch < 0 || ch > spec->multi_ios)
  3454. return -EINVAL;
  3455. if (ch == (spec->ext_channel_count - 1) / 2)
  3456. return 0;
  3457. spec->ext_channel_count = (ch + 1) * 2;
  3458. for (i = 0; i < spec->multi_ios; i++)
  3459. alc_set_multi_io(codec, i, i < ch);
  3460. spec->multiout.max_channels = spec->ext_channel_count;
  3461. if (spec->need_dac_fix && !spec->const_channel_count)
  3462. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  3463. return 1;
  3464. }
  3465. static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
  3466. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3467. .name = "Channel Mode",
  3468. .info = alc_auto_ch_mode_info,
  3469. .get = alc_auto_ch_mode_get,
  3470. .put = alc_auto_ch_mode_put,
  3471. };
  3472. static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
  3473. {
  3474. struct alc_spec *spec = codec->spec;
  3475. if (spec->multi_ios > 0) {
  3476. struct snd_kcontrol_new *knew;
  3477. knew = alc_kcontrol_new(spec);
  3478. if (!knew)
  3479. return -ENOMEM;
  3480. *knew = alc_auto_channel_mode_enum;
  3481. knew->name = kstrdup("Channel Mode", GFP_KERNEL);
  3482. if (!knew->name)
  3483. return -ENOMEM;
  3484. }
  3485. return 0;
  3486. }
  3487. /* filter out invalid adc_nids (and capsrc_nids) that don't give all
  3488. * active input pins
  3489. */
  3490. static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
  3491. {
  3492. struct alc_spec *spec = codec->spec;
  3493. const struct hda_input_mux *imux;
  3494. hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
  3495. hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
  3496. int i, n, nums;
  3497. imux = spec->input_mux;
  3498. if (!imux)
  3499. return;
  3500. if (spec->dyn_adc_switch)
  3501. return;
  3502. again:
  3503. nums = 0;
  3504. for (n = 0; n < spec->num_adc_nids; n++) {
  3505. hda_nid_t cap = spec->private_capsrc_nids[n];
  3506. int num_conns = snd_hda_get_num_conns(codec, cap);
  3507. for (i = 0; i < imux->num_items; i++) {
  3508. hda_nid_t pin = spec->imux_pins[i];
  3509. if (pin) {
  3510. if (get_connection_index(codec, cap, pin) < 0)
  3511. break;
  3512. } else if (num_conns <= imux->items[i].index)
  3513. break;
  3514. }
  3515. if (i >= imux->num_items) {
  3516. adc_nids[nums] = spec->private_adc_nids[n];
  3517. capsrc_nids[nums++] = cap;
  3518. }
  3519. }
  3520. if (!nums) {
  3521. /* check whether ADC-switch is possible */
  3522. if (!alc_check_dyn_adc_switch(codec)) {
  3523. if (spec->shared_mic_hp) {
  3524. spec->shared_mic_hp = 0;
  3525. spec->private_imux[0].num_items = 1;
  3526. goto again;
  3527. }
  3528. printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
  3529. " using fallback 0x%x\n",
  3530. codec->chip_name, spec->private_adc_nids[0]);
  3531. spec->num_adc_nids = 1;
  3532. spec->auto_mic = 0;
  3533. return;
  3534. }
  3535. } else if (nums != spec->num_adc_nids) {
  3536. memcpy(spec->private_adc_nids, adc_nids,
  3537. nums * sizeof(hda_nid_t));
  3538. memcpy(spec->private_capsrc_nids, capsrc_nids,
  3539. nums * sizeof(hda_nid_t));
  3540. spec->num_adc_nids = nums;
  3541. }
  3542. if (spec->auto_mic)
  3543. alc_auto_mic_check_imux(codec); /* check auto-mic setups */
  3544. else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
  3545. spec->num_adc_nids = 1; /* reduce to a single ADC */
  3546. }
  3547. /*
  3548. * initialize ADC paths
  3549. */
  3550. static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
  3551. {
  3552. struct alc_spec *spec = codec->spec;
  3553. hda_nid_t nid;
  3554. nid = spec->adc_nids[adc_idx];
  3555. /* mute ADC */
  3556. if (nid_has_mute(codec, nid, HDA_INPUT)) {
  3557. snd_hda_codec_write(codec, nid, 0,
  3558. AC_VERB_SET_AMP_GAIN_MUTE,
  3559. AMP_IN_MUTE(0));
  3560. return;
  3561. }
  3562. if (!spec->capsrc_nids)
  3563. return;
  3564. nid = spec->capsrc_nids[adc_idx];
  3565. if (nid_has_mute(codec, nid, HDA_OUTPUT))
  3566. snd_hda_codec_write(codec, nid, 0,
  3567. AC_VERB_SET_AMP_GAIN_MUTE,
  3568. AMP_OUT_MUTE);
  3569. }
  3570. static void alc_auto_init_input_src(struct hda_codec *codec)
  3571. {
  3572. struct alc_spec *spec = codec->spec;
  3573. int c, nums;
  3574. for (c = 0; c < spec->num_adc_nids; c++)
  3575. alc_auto_init_adc(codec, c);
  3576. if (spec->dyn_adc_switch)
  3577. nums = 1;
  3578. else
  3579. nums = spec->num_adc_nids;
  3580. for (c = 0; c < nums; c++)
  3581. alc_mux_select(codec, c, spec->cur_mux[c], true);
  3582. }
  3583. /* add mic boosts if needed */
  3584. static int alc_auto_add_mic_boost(struct hda_codec *codec)
  3585. {
  3586. struct alc_spec *spec = codec->spec;
  3587. struct auto_pin_cfg *cfg = &spec->autocfg;
  3588. int i, err;
  3589. int type_idx = 0;
  3590. hda_nid_t nid;
  3591. const char *prev_label = NULL;
  3592. for (i = 0; i < cfg->num_inputs; i++) {
  3593. if (cfg->inputs[i].type > AUTO_PIN_MIC)
  3594. break;
  3595. nid = cfg->inputs[i].pin;
  3596. if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
  3597. const char *label;
  3598. char boost_label[32];
  3599. label = hda_get_autocfg_input_label(codec, cfg, i);
  3600. if (spec->shared_mic_hp && !strcmp(label, "Misc"))
  3601. label = "Headphone Mic";
  3602. if (prev_label && !strcmp(label, prev_label))
  3603. type_idx++;
  3604. else
  3605. type_idx = 0;
  3606. prev_label = label;
  3607. snprintf(boost_label, sizeof(boost_label),
  3608. "%s Boost Volume", label);
  3609. err = add_control(spec, ALC_CTL_WIDGET_VOL,
  3610. boost_label, type_idx,
  3611. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
  3612. if (err < 0)
  3613. return err;
  3614. }
  3615. }
  3616. return 0;
  3617. }
  3618. /* select or unmute the given capsrc route */
  3619. static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
  3620. int idx)
  3621. {
  3622. if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
  3623. snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
  3624. HDA_AMP_MUTE, 0);
  3625. } else if (snd_hda_get_num_conns(codec, cap) > 1) {
  3626. snd_hda_codec_write_cache(codec, cap, 0,
  3627. AC_VERB_SET_CONNECT_SEL, idx);
  3628. }
  3629. }
  3630. /* set the default connection to that pin */
  3631. static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
  3632. {
  3633. struct alc_spec *spec = codec->spec;
  3634. int i;
  3635. if (!pin)
  3636. return 0;
  3637. for (i = 0; i < spec->num_adc_nids; i++) {
  3638. hda_nid_t cap = get_capsrc(spec, i);
  3639. int idx;
  3640. idx = get_connection_index(codec, cap, pin);
  3641. if (idx < 0)
  3642. continue;
  3643. select_or_unmute_capsrc(codec, cap, idx);
  3644. return i; /* return the found index */
  3645. }
  3646. return -1; /* not found */
  3647. }
  3648. /* initialize some special cases for input sources */
  3649. static void alc_init_special_input_src(struct hda_codec *codec)
  3650. {
  3651. struct alc_spec *spec = codec->spec;
  3652. int i;
  3653. for (i = 0; i < spec->autocfg.num_inputs; i++)
  3654. init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
  3655. }
  3656. /* assign appropriate capture mixers */
  3657. static void set_capture_mixer(struct hda_codec *codec)
  3658. {
  3659. struct alc_spec *spec = codec->spec;
  3660. static const struct snd_kcontrol_new *caps[2][3] = {
  3661. { alc_capture_mixer_nosrc1,
  3662. alc_capture_mixer_nosrc2,
  3663. alc_capture_mixer_nosrc3 },
  3664. { alc_capture_mixer1,
  3665. alc_capture_mixer2,
  3666. alc_capture_mixer3 },
  3667. };
  3668. /* check whether either of ADC or MUX has a volume control */
  3669. if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
  3670. if (!spec->capsrc_nids)
  3671. return; /* no volume */
  3672. if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
  3673. return; /* no volume in capsrc, too */
  3674. spec->vol_in_capsrc = 1;
  3675. }
  3676. if (spec->num_adc_nids > 0) {
  3677. int mux = 0;
  3678. int num_adcs = 0;
  3679. if (spec->input_mux && spec->input_mux->num_items > 1)
  3680. mux = 1;
  3681. if (spec->auto_mic) {
  3682. num_adcs = 1;
  3683. mux = 0;
  3684. } else if (spec->dyn_adc_switch)
  3685. num_adcs = 1;
  3686. if (!num_adcs) {
  3687. if (spec->num_adc_nids > 3)
  3688. spec->num_adc_nids = 3;
  3689. else if (!spec->num_adc_nids)
  3690. return;
  3691. num_adcs = spec->num_adc_nids;
  3692. }
  3693. spec->cap_mixer = caps[mux][num_adcs - 1];
  3694. }
  3695. }
  3696. /*
  3697. * standard auto-parser initializations
  3698. */
  3699. static void alc_auto_init_std(struct hda_codec *codec)
  3700. {
  3701. struct alc_spec *spec = codec->spec;
  3702. alc_auto_init_multi_out(codec);
  3703. alc_auto_init_extra_out(codec);
  3704. alc_auto_init_analog_input(codec);
  3705. alc_auto_init_input_src(codec);
  3706. alc_auto_init_digital(codec);
  3707. if (spec->unsol_event)
  3708. alc_inithook(codec);
  3709. }
  3710. /*
  3711. * Digital-beep handlers
  3712. */
  3713. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  3714. #define set_beep_amp(spec, nid, idx, dir) \
  3715. ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
  3716. static const struct snd_pci_quirk beep_white_list[] = {
  3717. SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
  3718. SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
  3719. SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
  3720. SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
  3721. SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
  3722. SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
  3723. {}
  3724. };
  3725. static inline int has_cdefine_beep(struct hda_codec *codec)
  3726. {
  3727. struct alc_spec *spec = codec->spec;
  3728. const struct snd_pci_quirk *q;
  3729. q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
  3730. if (q)
  3731. return q->value;
  3732. return spec->cdefine.enable_pcbeep;
  3733. }
  3734. #else
  3735. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  3736. #define has_cdefine_beep(codec) 0
  3737. #endif
  3738. /* parse the BIOS configuration and set up the alc_spec */
  3739. /* return 1 if successful, 0 if the proper config is not found,
  3740. * or a negative error code
  3741. */
  3742. static int alc_parse_auto_config(struct hda_codec *codec,
  3743. const hda_nid_t *ignore_nids,
  3744. const hda_nid_t *ssid_nids)
  3745. {
  3746. struct alc_spec *spec = codec->spec;
  3747. struct auto_pin_cfg *cfg = &spec->autocfg;
  3748. int err;
  3749. err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
  3750. spec->parse_flags);
  3751. if (err < 0)
  3752. return err;
  3753. if (!cfg->line_outs) {
  3754. if (cfg->dig_outs || cfg->dig_in_pin) {
  3755. spec->multiout.max_channels = 2;
  3756. spec->no_analog = 1;
  3757. goto dig_only;
  3758. }
  3759. return 0; /* can't find valid BIOS pin config */
  3760. }
  3761. if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
  3762. cfg->line_outs <= cfg->hp_outs) {
  3763. /* use HP as primary out */
  3764. cfg->speaker_outs = cfg->line_outs;
  3765. memcpy(cfg->speaker_pins, cfg->line_out_pins,
  3766. sizeof(cfg->speaker_pins));
  3767. cfg->line_outs = cfg->hp_outs;
  3768. memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
  3769. cfg->hp_outs = 0;
  3770. memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
  3771. cfg->line_out_type = AUTO_PIN_HP_OUT;
  3772. }
  3773. err = alc_auto_fill_dac_nids(codec);
  3774. if (err < 0)
  3775. return err;
  3776. err = alc_auto_add_multi_channel_mode(codec);
  3777. if (err < 0)
  3778. return err;
  3779. err = alc_auto_create_multi_out_ctls(codec, cfg);
  3780. if (err < 0)
  3781. return err;
  3782. err = alc_auto_create_hp_out(codec);
  3783. if (err < 0)
  3784. return err;
  3785. err = alc_auto_create_speaker_out(codec);
  3786. if (err < 0)
  3787. return err;
  3788. err = alc_auto_create_shared_input(codec);
  3789. if (err < 0)
  3790. return err;
  3791. err = alc_auto_create_input_ctls(codec);
  3792. if (err < 0)
  3793. return err;
  3794. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3795. dig_only:
  3796. alc_auto_parse_digital(codec);
  3797. if (!spec->no_analog)
  3798. alc_remove_invalid_adc_nids(codec);
  3799. if (ssid_nids)
  3800. alc_ssid_check(codec, ssid_nids);
  3801. if (!spec->no_analog) {
  3802. alc_auto_check_switches(codec);
  3803. err = alc_auto_add_mic_boost(codec);
  3804. if (err < 0)
  3805. return err;
  3806. }
  3807. if (spec->kctls.list)
  3808. add_mixer(spec, spec->kctls.list);
  3809. if (!spec->no_analog && !spec->cap_mixer)
  3810. set_capture_mixer(codec);
  3811. return 1;
  3812. }
  3813. /* common preparation job for alc_spec */
  3814. static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
  3815. {
  3816. struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3817. int err;
  3818. if (!spec)
  3819. return -ENOMEM;
  3820. codec->spec = spec;
  3821. spec->mixer_nid = mixer_nid;
  3822. err = alc_codec_rename_from_preset(codec);
  3823. if (err < 0) {
  3824. kfree(spec);
  3825. return err;
  3826. }
  3827. return 0;
  3828. }
  3829. static int alc880_parse_auto_config(struct hda_codec *codec)
  3830. {
  3831. static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
  3832. static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  3833. return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
  3834. }
  3835. /*
  3836. * ALC880 fix-ups
  3837. */
  3838. enum {
  3839. ALC880_FIXUP_GPIO1,
  3840. ALC880_FIXUP_GPIO2,
  3841. ALC880_FIXUP_MEDION_RIM,
  3842. ALC880_FIXUP_LG,
  3843. ALC880_FIXUP_W810,
  3844. ALC880_FIXUP_EAPD_COEF,
  3845. ALC880_FIXUP_TCL_S700,
  3846. ALC880_FIXUP_VOL_KNOB,
  3847. ALC880_FIXUP_FUJITSU,
  3848. ALC880_FIXUP_F1734,
  3849. ALC880_FIXUP_UNIWILL,
  3850. ALC880_FIXUP_UNIWILL_DIG,
  3851. ALC880_FIXUP_Z71V,
  3852. ALC880_FIXUP_3ST_BASE,
  3853. ALC880_FIXUP_3ST,
  3854. ALC880_FIXUP_3ST_DIG,
  3855. ALC880_FIXUP_5ST_BASE,
  3856. ALC880_FIXUP_5ST,
  3857. ALC880_FIXUP_5ST_DIG,
  3858. ALC880_FIXUP_6ST_BASE,
  3859. ALC880_FIXUP_6ST,
  3860. ALC880_FIXUP_6ST_DIG,
  3861. };
  3862. /* enable the volume-knob widget support on NID 0x21 */
  3863. static void alc880_fixup_vol_knob(struct hda_codec *codec,
  3864. const struct alc_fixup *fix, int action)
  3865. {
  3866. if (action == ALC_FIXUP_ACT_PROBE)
  3867. snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
  3868. }
  3869. static const struct alc_fixup alc880_fixups[] = {
  3870. [ALC880_FIXUP_GPIO1] = {
  3871. .type = ALC_FIXUP_VERBS,
  3872. .v.verbs = alc_gpio1_init_verbs,
  3873. },
  3874. [ALC880_FIXUP_GPIO2] = {
  3875. .type = ALC_FIXUP_VERBS,
  3876. .v.verbs = alc_gpio2_init_verbs,
  3877. },
  3878. [ALC880_FIXUP_MEDION_RIM] = {
  3879. .type = ALC_FIXUP_VERBS,
  3880. .v.verbs = (const struct hda_verb[]) {
  3881. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  3882. { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
  3883. { }
  3884. },
  3885. .chained = true,
  3886. .chain_id = ALC880_FIXUP_GPIO2,
  3887. },
  3888. [ALC880_FIXUP_LG] = {
  3889. .type = ALC_FIXUP_PINS,
  3890. .v.pins = (const struct alc_pincfg[]) {
  3891. /* disable bogus unused pins */
  3892. { 0x16, 0x411111f0 },
  3893. { 0x18, 0x411111f0 },
  3894. { 0x1a, 0x411111f0 },
  3895. { }
  3896. }
  3897. },
  3898. [ALC880_FIXUP_W810] = {
  3899. .type = ALC_FIXUP_PINS,
  3900. .v.pins = (const struct alc_pincfg[]) {
  3901. /* disable bogus unused pins */
  3902. { 0x17, 0x411111f0 },
  3903. { }
  3904. },
  3905. .chained = true,
  3906. .chain_id = ALC880_FIXUP_GPIO2,
  3907. },
  3908. [ALC880_FIXUP_EAPD_COEF] = {
  3909. .type = ALC_FIXUP_VERBS,
  3910. .v.verbs = (const struct hda_verb[]) {
  3911. /* change to EAPD mode */
  3912. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  3913. { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
  3914. {}
  3915. },
  3916. },
  3917. [ALC880_FIXUP_TCL_S700] = {
  3918. .type = ALC_FIXUP_VERBS,
  3919. .v.verbs = (const struct hda_verb[]) {
  3920. /* change to EAPD mode */
  3921. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  3922. { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
  3923. {}
  3924. },
  3925. .chained = true,
  3926. .chain_id = ALC880_FIXUP_GPIO2,
  3927. },
  3928. [ALC880_FIXUP_VOL_KNOB] = {
  3929. .type = ALC_FIXUP_FUNC,
  3930. .v.func = alc880_fixup_vol_knob,
  3931. },
  3932. [ALC880_FIXUP_FUJITSU] = {
  3933. /* override all pins as BIOS on old Amilo is broken */
  3934. .type = ALC_FIXUP_PINS,
  3935. .v.pins = (const struct alc_pincfg[]) {
  3936. { 0x14, 0x0121411f }, /* HP */
  3937. { 0x15, 0x99030120 }, /* speaker */
  3938. { 0x16, 0x99030130 }, /* bass speaker */
  3939. { 0x17, 0x411111f0 }, /* N/A */
  3940. { 0x18, 0x411111f0 }, /* N/A */
  3941. { 0x19, 0x01a19950 }, /* mic-in */
  3942. { 0x1a, 0x411111f0 }, /* N/A */
  3943. { 0x1b, 0x411111f0 }, /* N/A */
  3944. { 0x1c, 0x411111f0 }, /* N/A */
  3945. { 0x1d, 0x411111f0 }, /* N/A */
  3946. { 0x1e, 0x01454140 }, /* SPDIF out */
  3947. { }
  3948. },
  3949. .chained = true,
  3950. .chain_id = ALC880_FIXUP_VOL_KNOB,
  3951. },
  3952. [ALC880_FIXUP_F1734] = {
  3953. /* almost compatible with FUJITSU, but no bass and SPDIF */
  3954. .type = ALC_FIXUP_PINS,
  3955. .v.pins = (const struct alc_pincfg[]) {
  3956. { 0x14, 0x0121411f }, /* HP */
  3957. { 0x15, 0x99030120 }, /* speaker */
  3958. { 0x16, 0x411111f0 }, /* N/A */
  3959. { 0x17, 0x411111f0 }, /* N/A */
  3960. { 0x18, 0x411111f0 }, /* N/A */
  3961. { 0x19, 0x01a19950 }, /* mic-in */
  3962. { 0x1a, 0x411111f0 }, /* N/A */
  3963. { 0x1b, 0x411111f0 }, /* N/A */
  3964. { 0x1c, 0x411111f0 }, /* N/A */
  3965. { 0x1d, 0x411111f0 }, /* N/A */
  3966. { 0x1e, 0x411111f0 }, /* N/A */
  3967. { }
  3968. },
  3969. .chained = true,
  3970. .chain_id = ALC880_FIXUP_VOL_KNOB,
  3971. },
  3972. [ALC880_FIXUP_UNIWILL] = {
  3973. /* need to fix HP and speaker pins to be parsed correctly */
  3974. .type = ALC_FIXUP_PINS,
  3975. .v.pins = (const struct alc_pincfg[]) {
  3976. { 0x14, 0x0121411f }, /* HP */
  3977. { 0x15, 0x99030120 }, /* speaker */
  3978. { 0x16, 0x99030130 }, /* bass speaker */
  3979. { }
  3980. },
  3981. },
  3982. [ALC880_FIXUP_UNIWILL_DIG] = {
  3983. .type = ALC_FIXUP_PINS,
  3984. .v.pins = (const struct alc_pincfg[]) {
  3985. /* disable bogus unused pins */
  3986. { 0x17, 0x411111f0 },
  3987. { 0x19, 0x411111f0 },
  3988. { 0x1b, 0x411111f0 },
  3989. { 0x1f, 0x411111f0 },
  3990. { }
  3991. }
  3992. },
  3993. [ALC880_FIXUP_Z71V] = {
  3994. .type = ALC_FIXUP_PINS,
  3995. .v.pins = (const struct alc_pincfg[]) {
  3996. /* set up the whole pins as BIOS is utterly broken */
  3997. { 0x14, 0x99030120 }, /* speaker */
  3998. { 0x15, 0x0121411f }, /* HP */
  3999. { 0x16, 0x411111f0 }, /* N/A */
  4000. { 0x17, 0x411111f0 }, /* N/A */
  4001. { 0x18, 0x01a19950 }, /* mic-in */
  4002. { 0x19, 0x411111f0 }, /* N/A */
  4003. { 0x1a, 0x01813031 }, /* line-in */
  4004. { 0x1b, 0x411111f0 }, /* N/A */
  4005. { 0x1c, 0x411111f0 }, /* N/A */
  4006. { 0x1d, 0x411111f0 }, /* N/A */
  4007. { 0x1e, 0x0144111e }, /* SPDIF */
  4008. { }
  4009. }
  4010. },
  4011. [ALC880_FIXUP_3ST_BASE] = {
  4012. .type = ALC_FIXUP_PINS,
  4013. .v.pins = (const struct alc_pincfg[]) {
  4014. { 0x14, 0x01014010 }, /* line-out */
  4015. { 0x15, 0x411111f0 }, /* N/A */
  4016. { 0x16, 0x411111f0 }, /* N/A */
  4017. { 0x17, 0x411111f0 }, /* N/A */
  4018. { 0x18, 0x01a19c30 }, /* mic-in */
  4019. { 0x19, 0x0121411f }, /* HP */
  4020. { 0x1a, 0x01813031 }, /* line-in */
  4021. { 0x1b, 0x02a19c40 }, /* front-mic */
  4022. { 0x1c, 0x411111f0 }, /* N/A */
  4023. { 0x1d, 0x411111f0 }, /* N/A */
  4024. /* 0x1e is filled in below */
  4025. { 0x1f, 0x411111f0 }, /* N/A */
  4026. { }
  4027. }
  4028. },
  4029. [ALC880_FIXUP_3ST] = {
  4030. .type = ALC_FIXUP_PINS,
  4031. .v.pins = (const struct alc_pincfg[]) {
  4032. { 0x1e, 0x411111f0 }, /* N/A */
  4033. { }
  4034. },
  4035. .chained = true,
  4036. .chain_id = ALC880_FIXUP_3ST_BASE,
  4037. },
  4038. [ALC880_FIXUP_3ST_DIG] = {
  4039. .type = ALC_FIXUP_PINS,
  4040. .v.pins = (const struct alc_pincfg[]) {
  4041. { 0x1e, 0x0144111e }, /* SPDIF */
  4042. { }
  4043. },
  4044. .chained = true,
  4045. .chain_id = ALC880_FIXUP_3ST_BASE,
  4046. },
  4047. [ALC880_FIXUP_5ST_BASE] = {
  4048. .type = ALC_FIXUP_PINS,
  4049. .v.pins = (const struct alc_pincfg[]) {
  4050. { 0x14, 0x01014010 }, /* front */
  4051. { 0x15, 0x411111f0 }, /* N/A */
  4052. { 0x16, 0x01011411 }, /* CLFE */
  4053. { 0x17, 0x01016412 }, /* surr */
  4054. { 0x18, 0x01a19c30 }, /* mic-in */
  4055. { 0x19, 0x0121411f }, /* HP */
  4056. { 0x1a, 0x01813031 }, /* line-in */
  4057. { 0x1b, 0x02a19c40 }, /* front-mic */
  4058. { 0x1c, 0x411111f0 }, /* N/A */
  4059. { 0x1d, 0x411111f0 }, /* N/A */
  4060. /* 0x1e is filled in below */
  4061. { 0x1f, 0x411111f0 }, /* N/A */
  4062. { }
  4063. }
  4064. },
  4065. [ALC880_FIXUP_5ST] = {
  4066. .type = ALC_FIXUP_PINS,
  4067. .v.pins = (const struct alc_pincfg[]) {
  4068. { 0x1e, 0x411111f0 }, /* N/A */
  4069. { }
  4070. },
  4071. .chained = true,
  4072. .chain_id = ALC880_FIXUP_5ST_BASE,
  4073. },
  4074. [ALC880_FIXUP_5ST_DIG] = {
  4075. .type = ALC_FIXUP_PINS,
  4076. .v.pins = (const struct alc_pincfg[]) {
  4077. { 0x1e, 0x0144111e }, /* SPDIF */
  4078. { }
  4079. },
  4080. .chained = true,
  4081. .chain_id = ALC880_FIXUP_5ST_BASE,
  4082. },
  4083. [ALC880_FIXUP_6ST_BASE] = {
  4084. .type = ALC_FIXUP_PINS,
  4085. .v.pins = (const struct alc_pincfg[]) {
  4086. { 0x14, 0x01014010 }, /* front */
  4087. { 0x15, 0x01016412 }, /* surr */
  4088. { 0x16, 0x01011411 }, /* CLFE */
  4089. { 0x17, 0x01012414 }, /* side */
  4090. { 0x18, 0x01a19c30 }, /* mic-in */
  4091. { 0x19, 0x02a19c40 }, /* front-mic */
  4092. { 0x1a, 0x01813031 }, /* line-in */
  4093. { 0x1b, 0x0121411f }, /* HP */
  4094. { 0x1c, 0x411111f0 }, /* N/A */
  4095. { 0x1d, 0x411111f0 }, /* N/A */
  4096. /* 0x1e is filled in below */
  4097. { 0x1f, 0x411111f0 }, /* N/A */
  4098. { }
  4099. }
  4100. },
  4101. [ALC880_FIXUP_6ST] = {
  4102. .type = ALC_FIXUP_PINS,
  4103. .v.pins = (const struct alc_pincfg[]) {
  4104. { 0x1e, 0x411111f0 }, /* N/A */
  4105. { }
  4106. },
  4107. .chained = true,
  4108. .chain_id = ALC880_FIXUP_6ST_BASE,
  4109. },
  4110. [ALC880_FIXUP_6ST_DIG] = {
  4111. .type = ALC_FIXUP_PINS,
  4112. .v.pins = (const struct alc_pincfg[]) {
  4113. { 0x1e, 0x0144111e }, /* SPDIF */
  4114. { }
  4115. },
  4116. .chained = true,
  4117. .chain_id = ALC880_FIXUP_6ST_BASE,
  4118. },
  4119. };
  4120. static const struct snd_pci_quirk alc880_fixup_tbl[] = {
  4121. SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
  4122. SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
  4123. SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
  4124. SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
  4125. SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
  4126. SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
  4127. SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
  4128. SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
  4129. SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
  4130. SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
  4131. SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
  4132. SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
  4133. SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
  4134. SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
  4135. SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
  4136. SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
  4137. SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
  4138. SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
  4139. SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
  4140. /* Below is the copied entries from alc880_quirks.c.
  4141. * It's not quite sure whether BIOS sets the correct pin-config table
  4142. * on these machines, thus they are kept to be compatible with
  4143. * the old static quirks. Once when it's confirmed to work without
  4144. * these overrides, it'd be better to remove.
  4145. */
  4146. SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
  4147. SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
  4148. SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
  4149. SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
  4150. SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
  4151. SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
  4152. SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
  4153. SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
  4154. SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
  4155. SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
  4156. SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
  4157. SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
  4158. SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
  4159. SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
  4160. SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
  4161. SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
  4162. SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
  4163. SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
  4164. SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
  4165. SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
  4166. SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
  4167. SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
  4168. SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
  4169. SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4170. SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4171. SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4172. SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
  4173. SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4174. SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
  4175. SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
  4176. SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4177. SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4178. SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4179. /* default Intel */
  4180. SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
  4181. SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
  4182. SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
  4183. {}
  4184. };
  4185. static const struct alc_model_fixup alc880_fixup_models[] = {
  4186. {.id = ALC880_FIXUP_3ST, .name = "3stack"},
  4187. {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
  4188. {.id = ALC880_FIXUP_5ST, .name = "5stack"},
  4189. {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
  4190. {.id = ALC880_FIXUP_6ST, .name = "6stack"},
  4191. {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
  4192. {}
  4193. };
  4194. /*
  4195. * OK, here we have finally the patch for ALC880
  4196. */
  4197. static int patch_alc880(struct hda_codec *codec)
  4198. {
  4199. struct alc_spec *spec;
  4200. int err;
  4201. err = alc_alloc_spec(codec, 0x0b);
  4202. if (err < 0)
  4203. return err;
  4204. spec = codec->spec;
  4205. spec->need_dac_fix = 1;
  4206. alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
  4207. alc880_fixups);
  4208. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4209. /* automatic parse from the BIOS config */
  4210. err = alc880_parse_auto_config(codec);
  4211. if (err < 0)
  4212. goto error;
  4213. if (!spec->no_analog) {
  4214. err = snd_hda_attach_beep_device(codec, 0x1);
  4215. if (err < 0)
  4216. goto error;
  4217. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  4218. }
  4219. codec->patch_ops = alc_patch_ops;
  4220. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4221. return 0;
  4222. error:
  4223. alc_free(codec);
  4224. return err;
  4225. }
  4226. /*
  4227. * ALC260 support
  4228. */
  4229. static int alc260_parse_auto_config(struct hda_codec *codec)
  4230. {
  4231. static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
  4232. static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
  4233. return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
  4234. }
  4235. /*
  4236. * Pin config fixes
  4237. */
  4238. enum {
  4239. ALC260_FIXUP_HP_DC5750,
  4240. ALC260_FIXUP_HP_PIN_0F,
  4241. ALC260_FIXUP_COEF,
  4242. ALC260_FIXUP_GPIO1,
  4243. ALC260_FIXUP_GPIO1_TOGGLE,
  4244. ALC260_FIXUP_REPLACER,
  4245. ALC260_FIXUP_HP_B1900,
  4246. ALC260_FIXUP_KN1,
  4247. };
  4248. static void alc260_gpio1_automute(struct hda_codec *codec)
  4249. {
  4250. struct alc_spec *spec = codec->spec;
  4251. snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
  4252. spec->hp_jack_present);
  4253. }
  4254. static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
  4255. const struct alc_fixup *fix, int action)
  4256. {
  4257. struct alc_spec *spec = codec->spec;
  4258. if (action == ALC_FIXUP_ACT_PROBE) {
  4259. /* although the machine has only one output pin, we need to
  4260. * toggle GPIO1 according to the jack state
  4261. */
  4262. spec->automute_hook = alc260_gpio1_automute;
  4263. spec->detect_hp = 1;
  4264. spec->automute_speaker = 1;
  4265. spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
  4266. snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
  4267. spec->unsol_event = alc_sku_unsol_event;
  4268. snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
  4269. }
  4270. }
  4271. static void alc260_fixup_kn1(struct hda_codec *codec,
  4272. const struct alc_fixup *fix, int action)
  4273. {
  4274. struct alc_spec *spec = codec->spec;
  4275. static const struct alc_pincfg pincfgs[] = {
  4276. { 0x0f, 0x02214000 }, /* HP/speaker */
  4277. { 0x12, 0x90a60160 }, /* int mic */
  4278. { 0x13, 0x02a19000 }, /* ext mic */
  4279. { 0x18, 0x01446000 }, /* SPDIF out */
  4280. /* disable bogus I/O pins */
  4281. { 0x10, 0x411111f0 },
  4282. { 0x11, 0x411111f0 },
  4283. { 0x14, 0x411111f0 },
  4284. { 0x15, 0x411111f0 },
  4285. { 0x16, 0x411111f0 },
  4286. { 0x17, 0x411111f0 },
  4287. { 0x19, 0x411111f0 },
  4288. { }
  4289. };
  4290. switch (action) {
  4291. case ALC_FIXUP_ACT_PRE_PROBE:
  4292. alc_apply_pincfgs(codec, pincfgs);
  4293. break;
  4294. case ALC_FIXUP_ACT_PROBE:
  4295. spec->init_amp = ALC_INIT_NONE;
  4296. break;
  4297. }
  4298. }
  4299. static const struct alc_fixup alc260_fixups[] = {
  4300. [ALC260_FIXUP_HP_DC5750] = {
  4301. .type = ALC_FIXUP_PINS,
  4302. .v.pins = (const struct alc_pincfg[]) {
  4303. { 0x11, 0x90130110 }, /* speaker */
  4304. { }
  4305. }
  4306. },
  4307. [ALC260_FIXUP_HP_PIN_0F] = {
  4308. .type = ALC_FIXUP_PINS,
  4309. .v.pins = (const struct alc_pincfg[]) {
  4310. { 0x0f, 0x01214000 }, /* HP */
  4311. { }
  4312. }
  4313. },
  4314. [ALC260_FIXUP_COEF] = {
  4315. .type = ALC_FIXUP_VERBS,
  4316. .v.verbs = (const struct hda_verb[]) {
  4317. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4318. { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
  4319. { }
  4320. },
  4321. .chained = true,
  4322. .chain_id = ALC260_FIXUP_HP_PIN_0F,
  4323. },
  4324. [ALC260_FIXUP_GPIO1] = {
  4325. .type = ALC_FIXUP_VERBS,
  4326. .v.verbs = alc_gpio1_init_verbs,
  4327. },
  4328. [ALC260_FIXUP_GPIO1_TOGGLE] = {
  4329. .type = ALC_FIXUP_FUNC,
  4330. .v.func = alc260_fixup_gpio1_toggle,
  4331. .chained = true,
  4332. .chain_id = ALC260_FIXUP_HP_PIN_0F,
  4333. },
  4334. [ALC260_FIXUP_REPLACER] = {
  4335. .type = ALC_FIXUP_VERBS,
  4336. .v.verbs = (const struct hda_verb[]) {
  4337. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4338. { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
  4339. { }
  4340. },
  4341. .chained = true,
  4342. .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
  4343. },
  4344. [ALC260_FIXUP_HP_B1900] = {
  4345. .type = ALC_FIXUP_FUNC,
  4346. .v.func = alc260_fixup_gpio1_toggle,
  4347. .chained = true,
  4348. .chain_id = ALC260_FIXUP_COEF,
  4349. },
  4350. [ALC260_FIXUP_KN1] = {
  4351. .type = ALC_FIXUP_FUNC,
  4352. .v.func = alc260_fixup_kn1,
  4353. },
  4354. };
  4355. static const struct snd_pci_quirk alc260_fixup_tbl[] = {
  4356. SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
  4357. SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
  4358. SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
  4359. SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
  4360. SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
  4361. SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
  4362. SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
  4363. SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
  4364. SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
  4365. {}
  4366. };
  4367. /*
  4368. */
  4369. static int patch_alc260(struct hda_codec *codec)
  4370. {
  4371. struct alc_spec *spec;
  4372. int err;
  4373. err = alc_alloc_spec(codec, 0x07);
  4374. if (err < 0)
  4375. return err;
  4376. spec = codec->spec;
  4377. alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
  4378. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4379. /* automatic parse from the BIOS config */
  4380. err = alc260_parse_auto_config(codec);
  4381. if (err < 0)
  4382. goto error;
  4383. if (!spec->no_analog) {
  4384. err = snd_hda_attach_beep_device(codec, 0x1);
  4385. if (err < 0)
  4386. goto error;
  4387. set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
  4388. }
  4389. codec->patch_ops = alc_patch_ops;
  4390. spec->shutup = alc_eapd_shutup;
  4391. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4392. return 0;
  4393. error:
  4394. alc_free(codec);
  4395. return err;
  4396. }
  4397. /*
  4398. * ALC882/883/885/888/889 support
  4399. *
  4400. * ALC882 is almost identical with ALC880 but has cleaner and more flexible
  4401. * configuration. Each pin widget can choose any input DACs and a mixer.
  4402. * Each ADC is connected from a mixer of all inputs. This makes possible
  4403. * 6-channel independent captures.
  4404. *
  4405. * In addition, an independent DAC for the multi-playback (not used in this
  4406. * driver yet).
  4407. */
  4408. /*
  4409. * Pin config fixes
  4410. */
  4411. enum {
  4412. ALC882_FIXUP_ABIT_AW9D_MAX,
  4413. ALC882_FIXUP_LENOVO_Y530,
  4414. ALC882_FIXUP_PB_M5210,
  4415. ALC882_FIXUP_ACER_ASPIRE_7736,
  4416. ALC882_FIXUP_ASUS_W90V,
  4417. ALC889_FIXUP_CD,
  4418. ALC889_FIXUP_VAIO_TT,
  4419. ALC888_FIXUP_EEE1601,
  4420. ALC882_FIXUP_EAPD,
  4421. ALC883_FIXUP_EAPD,
  4422. ALC883_FIXUP_ACER_EAPD,
  4423. ALC882_FIXUP_GPIO1,
  4424. ALC882_FIXUP_GPIO2,
  4425. ALC882_FIXUP_GPIO3,
  4426. ALC889_FIXUP_COEF,
  4427. ALC882_FIXUP_ASUS_W2JC,
  4428. ALC882_FIXUP_ACER_ASPIRE_4930G,
  4429. ALC882_FIXUP_ACER_ASPIRE_8930G,
  4430. ALC882_FIXUP_ASPIRE_8930G_VERBS,
  4431. ALC885_FIXUP_MACPRO_GPIO,
  4432. ALC889_FIXUP_DAC_ROUTE,
  4433. ALC889_FIXUP_MBP_VREF,
  4434. ALC889_FIXUP_IMAC91_VREF,
  4435. };
  4436. static void alc889_fixup_coef(struct hda_codec *codec,
  4437. const struct alc_fixup *fix, int action)
  4438. {
  4439. if (action != ALC_FIXUP_ACT_INIT)
  4440. return;
  4441. alc889_coef_init(codec);
  4442. }
  4443. /* toggle speaker-output according to the hp-jack state */
  4444. static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
  4445. {
  4446. unsigned int gpiostate, gpiomask, gpiodir;
  4447. gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
  4448. AC_VERB_GET_GPIO_DATA, 0);
  4449. if (!muted)
  4450. gpiostate |= (1 << pin);
  4451. else
  4452. gpiostate &= ~(1 << pin);
  4453. gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
  4454. AC_VERB_GET_GPIO_MASK, 0);
  4455. gpiomask |= (1 << pin);
  4456. gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
  4457. AC_VERB_GET_GPIO_DIRECTION, 0);
  4458. gpiodir |= (1 << pin);
  4459. snd_hda_codec_write(codec, codec->afg, 0,
  4460. AC_VERB_SET_GPIO_MASK, gpiomask);
  4461. snd_hda_codec_write(codec, codec->afg, 0,
  4462. AC_VERB_SET_GPIO_DIRECTION, gpiodir);
  4463. msleep(1);
  4464. snd_hda_codec_write(codec, codec->afg, 0,
  4465. AC_VERB_SET_GPIO_DATA, gpiostate);
  4466. }
  4467. /* set up GPIO at initialization */
  4468. static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
  4469. const struct alc_fixup *fix, int action)
  4470. {
  4471. if (action != ALC_FIXUP_ACT_INIT)
  4472. return;
  4473. alc882_gpio_mute(codec, 0, 0);
  4474. alc882_gpio_mute(codec, 1, 0);
  4475. }
  4476. /* Fix the connection of some pins for ALC889:
  4477. * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
  4478. * work correctly (bko#42740)
  4479. */
  4480. static void alc889_fixup_dac_route(struct hda_codec *codec,
  4481. const struct alc_fixup *fix, int action)
  4482. {
  4483. if (action == ALC_FIXUP_ACT_PRE_PROBE) {
  4484. /* fake the connections during parsing the tree */
  4485. hda_nid_t conn1[2] = { 0x0c, 0x0d };
  4486. hda_nid_t conn2[2] = { 0x0e, 0x0f };
  4487. snd_hda_override_conn_list(codec, 0x14, 2, conn1);
  4488. snd_hda_override_conn_list(codec, 0x15, 2, conn1);
  4489. snd_hda_override_conn_list(codec, 0x18, 2, conn2);
  4490. snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
  4491. } else if (action == ALC_FIXUP_ACT_PROBE) {
  4492. /* restore the connections */
  4493. hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
  4494. snd_hda_override_conn_list(codec, 0x14, 5, conn);
  4495. snd_hda_override_conn_list(codec, 0x15, 5, conn);
  4496. snd_hda_override_conn_list(codec, 0x18, 5, conn);
  4497. snd_hda_override_conn_list(codec, 0x1a, 5, conn);
  4498. }
  4499. }
  4500. /* Set VREF on HP pin */
  4501. static void alc889_fixup_mbp_vref(struct hda_codec *codec,
  4502. const struct alc_fixup *fix, int action)
  4503. {
  4504. struct alc_spec *spec = codec->spec;
  4505. static hda_nid_t nids[2] = { 0x14, 0x15 };
  4506. int i;
  4507. if (action != ALC_FIXUP_ACT_INIT)
  4508. return;
  4509. for (i = 0; i < ARRAY_SIZE(nids); i++) {
  4510. unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
  4511. if (get_defcfg_device(val) != AC_JACK_HP_OUT)
  4512. continue;
  4513. val = snd_hda_codec_read(codec, nids[i], 0,
  4514. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  4515. val |= AC_PINCTL_VREF_80;
  4516. snd_hda_set_pin_ctl(codec, nids[i], val);
  4517. spec->keep_vref_in_automute = 1;
  4518. break;
  4519. }
  4520. }
  4521. /* Set VREF on speaker pins on imac91 */
  4522. static void alc889_fixup_imac91_vref(struct hda_codec *codec,
  4523. const struct alc_fixup *fix, int action)
  4524. {
  4525. struct alc_spec *spec = codec->spec;
  4526. static hda_nid_t nids[2] = { 0x18, 0x1a };
  4527. int i;
  4528. if (action != ALC_FIXUP_ACT_INIT)
  4529. return;
  4530. for (i = 0; i < ARRAY_SIZE(nids); i++) {
  4531. unsigned int val;
  4532. val = snd_hda_codec_read(codec, nids[i], 0,
  4533. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  4534. val |= AC_PINCTL_VREF_50;
  4535. snd_hda_set_pin_ctl(codec, nids[i], val);
  4536. }
  4537. spec->keep_vref_in_automute = 1;
  4538. }
  4539. static const struct alc_fixup alc882_fixups[] = {
  4540. [ALC882_FIXUP_ABIT_AW9D_MAX] = {
  4541. .type = ALC_FIXUP_PINS,
  4542. .v.pins = (const struct alc_pincfg[]) {
  4543. { 0x15, 0x01080104 }, /* side */
  4544. { 0x16, 0x01011012 }, /* rear */
  4545. { 0x17, 0x01016011 }, /* clfe */
  4546. { }
  4547. }
  4548. },
  4549. [ALC882_FIXUP_LENOVO_Y530] = {
  4550. .type = ALC_FIXUP_PINS,
  4551. .v.pins = (const struct alc_pincfg[]) {
  4552. { 0x15, 0x99130112 }, /* rear int speakers */
  4553. { 0x16, 0x99130111 }, /* subwoofer */
  4554. { }
  4555. }
  4556. },
  4557. [ALC882_FIXUP_PB_M5210] = {
  4558. .type = ALC_FIXUP_VERBS,
  4559. .v.verbs = (const struct hda_verb[]) {
  4560. { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
  4561. {}
  4562. }
  4563. },
  4564. [ALC882_FIXUP_ACER_ASPIRE_7736] = {
  4565. .type = ALC_FIXUP_FUNC,
  4566. .v.func = alc_fixup_sku_ignore,
  4567. },
  4568. [ALC882_FIXUP_ASUS_W90V] = {
  4569. .type = ALC_FIXUP_PINS,
  4570. .v.pins = (const struct alc_pincfg[]) {
  4571. { 0x16, 0x99130110 }, /* fix sequence for CLFE */
  4572. { }
  4573. }
  4574. },
  4575. [ALC889_FIXUP_CD] = {
  4576. .type = ALC_FIXUP_PINS,
  4577. .v.pins = (const struct alc_pincfg[]) {
  4578. { 0x1c, 0x993301f0 }, /* CD */
  4579. { }
  4580. }
  4581. },
  4582. [ALC889_FIXUP_VAIO_TT] = {
  4583. .type = ALC_FIXUP_PINS,
  4584. .v.pins = (const struct alc_pincfg[]) {
  4585. { 0x17, 0x90170111 }, /* hidden surround speaker */
  4586. { }
  4587. }
  4588. },
  4589. [ALC888_FIXUP_EEE1601] = {
  4590. .type = ALC_FIXUP_VERBS,
  4591. .v.verbs = (const struct hda_verb[]) {
  4592. { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
  4593. { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
  4594. { }
  4595. }
  4596. },
  4597. [ALC882_FIXUP_EAPD] = {
  4598. .type = ALC_FIXUP_VERBS,
  4599. .v.verbs = (const struct hda_verb[]) {
  4600. /* change to EAPD mode */
  4601. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4602. { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
  4603. { }
  4604. }
  4605. },
  4606. [ALC883_FIXUP_EAPD] = {
  4607. .type = ALC_FIXUP_VERBS,
  4608. .v.verbs = (const struct hda_verb[]) {
  4609. /* change to EAPD mode */
  4610. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4611. { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
  4612. { }
  4613. }
  4614. },
  4615. [ALC883_FIXUP_ACER_EAPD] = {
  4616. .type = ALC_FIXUP_VERBS,
  4617. .v.verbs = (const struct hda_verb[]) {
  4618. /* eanable EAPD on Acer laptops */
  4619. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4620. { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
  4621. { }
  4622. }
  4623. },
  4624. [ALC882_FIXUP_GPIO1] = {
  4625. .type = ALC_FIXUP_VERBS,
  4626. .v.verbs = alc_gpio1_init_verbs,
  4627. },
  4628. [ALC882_FIXUP_GPIO2] = {
  4629. .type = ALC_FIXUP_VERBS,
  4630. .v.verbs = alc_gpio2_init_verbs,
  4631. },
  4632. [ALC882_FIXUP_GPIO3] = {
  4633. .type = ALC_FIXUP_VERBS,
  4634. .v.verbs = alc_gpio3_init_verbs,
  4635. },
  4636. [ALC882_FIXUP_ASUS_W2JC] = {
  4637. .type = ALC_FIXUP_VERBS,
  4638. .v.verbs = alc_gpio1_init_verbs,
  4639. .chained = true,
  4640. .chain_id = ALC882_FIXUP_EAPD,
  4641. },
  4642. [ALC889_FIXUP_COEF] = {
  4643. .type = ALC_FIXUP_FUNC,
  4644. .v.func = alc889_fixup_coef,
  4645. },
  4646. [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
  4647. .type = ALC_FIXUP_PINS,
  4648. .v.pins = (const struct alc_pincfg[]) {
  4649. { 0x16, 0x99130111 }, /* CLFE speaker */
  4650. { 0x17, 0x99130112 }, /* surround speaker */
  4651. { }
  4652. },
  4653. .chained = true,
  4654. .chain_id = ALC882_FIXUP_GPIO1,
  4655. },
  4656. [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
  4657. .type = ALC_FIXUP_PINS,
  4658. .v.pins = (const struct alc_pincfg[]) {
  4659. { 0x16, 0x99130111 }, /* CLFE speaker */
  4660. { 0x1b, 0x99130112 }, /* surround speaker */
  4661. { }
  4662. },
  4663. .chained = true,
  4664. .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
  4665. },
  4666. [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
  4667. /* additional init verbs for Acer Aspire 8930G */
  4668. .type = ALC_FIXUP_VERBS,
  4669. .v.verbs = (const struct hda_verb[]) {
  4670. /* Enable all DACs */
  4671. /* DAC DISABLE/MUTE 1? */
  4672. /* setting bits 1-5 disables DAC nids 0x02-0x06
  4673. * apparently. Init=0x38 */
  4674. { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
  4675. { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
  4676. /* DAC DISABLE/MUTE 2? */
  4677. /* some bit here disables the other DACs.
  4678. * Init=0x4900 */
  4679. { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
  4680. { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
  4681. /* DMIC fix
  4682. * This laptop has a stereo digital microphone.
  4683. * The mics are only 1cm apart which makes the stereo
  4684. * useless. However, either the mic or the ALC889
  4685. * makes the signal become a difference/sum signal
  4686. * instead of standard stereo, which is annoying.
  4687. * So instead we flip this bit which makes the
  4688. * codec replicate the sum signal to both channels,
  4689. * turning it into a normal mono mic.
  4690. */
  4691. /* DMIC_CONTROL? Init value = 0x0001 */
  4692. { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
  4693. { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
  4694. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4695. { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
  4696. { }
  4697. },
  4698. .chained = true,
  4699. .chain_id = ALC882_FIXUP_GPIO1,
  4700. },
  4701. [ALC885_FIXUP_MACPRO_GPIO] = {
  4702. .type = ALC_FIXUP_FUNC,
  4703. .v.func = alc885_fixup_macpro_gpio,
  4704. },
  4705. [ALC889_FIXUP_DAC_ROUTE] = {
  4706. .type = ALC_FIXUP_FUNC,
  4707. .v.func = alc889_fixup_dac_route,
  4708. },
  4709. [ALC889_FIXUP_MBP_VREF] = {
  4710. .type = ALC_FIXUP_FUNC,
  4711. .v.func = alc889_fixup_mbp_vref,
  4712. .chained = true,
  4713. .chain_id = ALC882_FIXUP_GPIO1,
  4714. },
  4715. [ALC889_FIXUP_IMAC91_VREF] = {
  4716. .type = ALC_FIXUP_FUNC,
  4717. .v.func = alc889_fixup_imac91_vref,
  4718. .chained = true,
  4719. .chain_id = ALC882_FIXUP_GPIO1,
  4720. },
  4721. };
  4722. static const struct snd_pci_quirk alc882_fixup_tbl[] = {
  4723. SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
  4724. SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
  4725. SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
  4726. SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
  4727. SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
  4728. SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
  4729. SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
  4730. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4731. SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
  4732. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4733. SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
  4734. ALC882_FIXUP_ACER_ASPIRE_8930G),
  4735. SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
  4736. ALC882_FIXUP_ACER_ASPIRE_8930G),
  4737. SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
  4738. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4739. SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
  4740. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4741. SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
  4742. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4743. SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
  4744. SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
  4745. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4746. SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
  4747. SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
  4748. SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
  4749. SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
  4750. SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
  4751. SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
  4752. SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
  4753. SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
  4754. /* All Apple entries are in codec SSIDs */
  4755. SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
  4756. SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
  4757. SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
  4758. SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
  4759. SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
  4760. SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
  4761. SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
  4762. SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
  4763. SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
  4764. SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
  4765. SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
  4766. SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
  4767. SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
  4768. SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
  4769. SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
  4770. SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
  4771. SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
  4772. SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
  4773. SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
  4774. SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
  4775. SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
  4776. SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
  4777. SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
  4778. SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
  4779. SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
  4780. SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
  4781. SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
  4782. SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
  4783. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
  4784. SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
  4785. {}
  4786. };
  4787. static const struct alc_model_fixup alc882_fixup_models[] = {
  4788. {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
  4789. {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
  4790. {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
  4791. {}
  4792. };
  4793. /*
  4794. * BIOS auto configuration
  4795. */
  4796. /* almost identical with ALC880 parser... */
  4797. static int alc882_parse_auto_config(struct hda_codec *codec)
  4798. {
  4799. static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
  4800. static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  4801. return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
  4802. }
  4803. /*
  4804. */
  4805. static int patch_alc882(struct hda_codec *codec)
  4806. {
  4807. struct alc_spec *spec;
  4808. int err;
  4809. err = alc_alloc_spec(codec, 0x0b);
  4810. if (err < 0)
  4811. return err;
  4812. spec = codec->spec;
  4813. switch (codec->vendor_id) {
  4814. case 0x10ec0882:
  4815. case 0x10ec0885:
  4816. break;
  4817. default:
  4818. /* ALC883 and variants */
  4819. alc_fix_pll_init(codec, 0x20, 0x0a, 10);
  4820. break;
  4821. }
  4822. alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
  4823. alc882_fixups);
  4824. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4825. alc_auto_parse_customize_define(codec);
  4826. /* automatic parse from the BIOS config */
  4827. err = alc882_parse_auto_config(codec);
  4828. if (err < 0)
  4829. goto error;
  4830. if (!spec->no_analog && has_cdefine_beep(codec)) {
  4831. err = snd_hda_attach_beep_device(codec, 0x1);
  4832. if (err < 0)
  4833. goto error;
  4834. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  4835. }
  4836. codec->patch_ops = alc_patch_ops;
  4837. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4838. return 0;
  4839. error:
  4840. alc_free(codec);
  4841. return err;
  4842. }
  4843. /*
  4844. * ALC262 support
  4845. */
  4846. static int alc262_parse_auto_config(struct hda_codec *codec)
  4847. {
  4848. static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
  4849. static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  4850. return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
  4851. }
  4852. /*
  4853. * Pin config fixes
  4854. */
  4855. enum {
  4856. ALC262_FIXUP_FSC_H270,
  4857. ALC262_FIXUP_HP_Z200,
  4858. ALC262_FIXUP_TYAN,
  4859. ALC262_FIXUP_LENOVO_3000,
  4860. ALC262_FIXUP_BENQ,
  4861. ALC262_FIXUP_BENQ_T31,
  4862. };
  4863. static const struct alc_fixup alc262_fixups[] = {
  4864. [ALC262_FIXUP_FSC_H270] = {
  4865. .type = ALC_FIXUP_PINS,
  4866. .v.pins = (const struct alc_pincfg[]) {
  4867. { 0x14, 0x99130110 }, /* speaker */
  4868. { 0x15, 0x0221142f }, /* front HP */
  4869. { 0x1b, 0x0121141f }, /* rear HP */
  4870. { }
  4871. }
  4872. },
  4873. [ALC262_FIXUP_HP_Z200] = {
  4874. .type = ALC_FIXUP_PINS,
  4875. .v.pins = (const struct alc_pincfg[]) {
  4876. { 0x16, 0x99130120 }, /* internal speaker */
  4877. { }
  4878. }
  4879. },
  4880. [ALC262_FIXUP_TYAN] = {
  4881. .type = ALC_FIXUP_PINS,
  4882. .v.pins = (const struct alc_pincfg[]) {
  4883. { 0x14, 0x1993e1f0 }, /* int AUX */
  4884. { }
  4885. }
  4886. },
  4887. [ALC262_FIXUP_LENOVO_3000] = {
  4888. .type = ALC_FIXUP_VERBS,
  4889. .v.verbs = (const struct hda_verb[]) {
  4890. { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
  4891. {}
  4892. },
  4893. .chained = true,
  4894. .chain_id = ALC262_FIXUP_BENQ,
  4895. },
  4896. [ALC262_FIXUP_BENQ] = {
  4897. .type = ALC_FIXUP_VERBS,
  4898. .v.verbs = (const struct hda_verb[]) {
  4899. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4900. { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
  4901. {}
  4902. }
  4903. },
  4904. [ALC262_FIXUP_BENQ_T31] = {
  4905. .type = ALC_FIXUP_VERBS,
  4906. .v.verbs = (const struct hda_verb[]) {
  4907. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4908. { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
  4909. {}
  4910. }
  4911. },
  4912. };
  4913. static const struct snd_pci_quirk alc262_fixup_tbl[] = {
  4914. SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
  4915. SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
  4916. SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
  4917. SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
  4918. SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
  4919. SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
  4920. SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
  4921. SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
  4922. {}
  4923. };
  4924. /*
  4925. */
  4926. static int patch_alc262(struct hda_codec *codec)
  4927. {
  4928. struct alc_spec *spec;
  4929. int err;
  4930. err = alc_alloc_spec(codec, 0x0b);
  4931. if (err < 0)
  4932. return err;
  4933. spec = codec->spec;
  4934. #if 0
  4935. /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
  4936. * under-run
  4937. */
  4938. {
  4939. int tmp;
  4940. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
  4941. tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
  4942. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
  4943. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
  4944. }
  4945. #endif
  4946. alc_fix_pll_init(codec, 0x20, 0x0a, 10);
  4947. alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
  4948. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4949. alc_auto_parse_customize_define(codec);
  4950. /* automatic parse from the BIOS config */
  4951. err = alc262_parse_auto_config(codec);
  4952. if (err < 0)
  4953. goto error;
  4954. if (!spec->no_analog && has_cdefine_beep(codec)) {
  4955. err = snd_hda_attach_beep_device(codec, 0x1);
  4956. if (err < 0)
  4957. goto error;
  4958. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  4959. }
  4960. codec->patch_ops = alc_patch_ops;
  4961. spec->shutup = alc_eapd_shutup;
  4962. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4963. return 0;
  4964. error:
  4965. alc_free(codec);
  4966. return err;
  4967. }
  4968. /*
  4969. * ALC268
  4970. */
  4971. /* bind Beep switches of both NID 0x0f and 0x10 */
  4972. static const struct hda_bind_ctls alc268_bind_beep_sw = {
  4973. .ops = &snd_hda_bind_sw,
  4974. .values = {
  4975. HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
  4976. HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
  4977. 0
  4978. },
  4979. };
  4980. static const struct snd_kcontrol_new alc268_beep_mixer[] = {
  4981. HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
  4982. HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
  4983. { }
  4984. };
  4985. /* set PCBEEP vol = 0, mute connections */
  4986. static const struct hda_verb alc268_beep_init_verbs[] = {
  4987. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4988. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4989. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4990. { }
  4991. };
  4992. /*
  4993. * BIOS auto configuration
  4994. */
  4995. static int alc268_parse_auto_config(struct hda_codec *codec)
  4996. {
  4997. static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  4998. struct alc_spec *spec = codec->spec;
  4999. int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
  5000. if (err > 0) {
  5001. if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
  5002. add_mixer(spec, alc268_beep_mixer);
  5003. snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
  5004. }
  5005. }
  5006. return err;
  5007. }
  5008. /*
  5009. */
  5010. static int patch_alc268(struct hda_codec *codec)
  5011. {
  5012. struct alc_spec *spec;
  5013. int i, has_beep, err;
  5014. /* ALC268 has no aa-loopback mixer */
  5015. err = alc_alloc_spec(codec, 0);
  5016. if (err < 0)
  5017. return err;
  5018. spec = codec->spec;
  5019. /* automatic parse from the BIOS config */
  5020. err = alc268_parse_auto_config(codec);
  5021. if (err < 0)
  5022. goto error;
  5023. has_beep = 0;
  5024. for (i = 0; i < spec->num_mixers; i++) {
  5025. if (spec->mixers[i] == alc268_beep_mixer) {
  5026. has_beep = 1;
  5027. break;
  5028. }
  5029. }
  5030. if (has_beep) {
  5031. err = snd_hda_attach_beep_device(codec, 0x1);
  5032. if (err < 0)
  5033. goto error;
  5034. if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
  5035. /* override the amp caps for beep generator */
  5036. snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
  5037. (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
  5038. (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
  5039. (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  5040. (0 << AC_AMPCAP_MUTE_SHIFT));
  5041. }
  5042. codec->patch_ops = alc_patch_ops;
  5043. spec->shutup = alc_eapd_shutup;
  5044. return 0;
  5045. error:
  5046. alc_free(codec);
  5047. return err;
  5048. }
  5049. /*
  5050. * ALC269
  5051. */
  5052. static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
  5053. .substreams = 1,
  5054. .channels_min = 2,
  5055. .channels_max = 8,
  5056. .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
  5057. /* NID is set in alc_build_pcms */
  5058. .ops = {
  5059. .open = alc_playback_pcm_open,
  5060. .prepare = alc_playback_pcm_prepare,
  5061. .cleanup = alc_playback_pcm_cleanup
  5062. },
  5063. };
  5064. static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
  5065. .substreams = 1,
  5066. .channels_min = 2,
  5067. .channels_max = 2,
  5068. .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
  5069. /* NID is set in alc_build_pcms */
  5070. };
  5071. /* different alc269-variants */
  5072. enum {
  5073. ALC269_TYPE_ALC269VA,
  5074. ALC269_TYPE_ALC269VB,
  5075. ALC269_TYPE_ALC269VC,
  5076. };
  5077. /*
  5078. * BIOS auto configuration
  5079. */
  5080. static int alc269_parse_auto_config(struct hda_codec *codec)
  5081. {
  5082. static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
  5083. static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
  5084. static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  5085. struct alc_spec *spec = codec->spec;
  5086. const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
  5087. alc269va_ssids : alc269_ssids;
  5088. return alc_parse_auto_config(codec, alc269_ignore, ssids);
  5089. }
  5090. static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
  5091. {
  5092. int val = alc_read_coef_idx(codec, 0x04);
  5093. if (power_up)
  5094. val |= 1 << 11;
  5095. else
  5096. val &= ~(1 << 11);
  5097. alc_write_coef_idx(codec, 0x04, val);
  5098. }
  5099. static void alc269_shutup(struct hda_codec *codec)
  5100. {
  5101. if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
  5102. alc269_toggle_power_output(codec, 0);
  5103. if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
  5104. alc269_toggle_power_output(codec, 0);
  5105. msleep(150);
  5106. }
  5107. }
  5108. #ifdef CONFIG_PM
  5109. static int alc269_resume(struct hda_codec *codec)
  5110. {
  5111. if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
  5112. alc269_toggle_power_output(codec, 0);
  5113. msleep(150);
  5114. }
  5115. codec->patch_ops.init(codec);
  5116. if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
  5117. alc269_toggle_power_output(codec, 1);
  5118. msleep(200);
  5119. }
  5120. if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
  5121. alc269_toggle_power_output(codec, 1);
  5122. snd_hda_codec_resume_amp(codec);
  5123. snd_hda_codec_resume_cache(codec);
  5124. hda_call_check_power_status(codec, 0x01);
  5125. return 0;
  5126. }
  5127. #endif /* CONFIG_PM */
  5128. static void alc269_fixup_hweq(struct hda_codec *codec,
  5129. const struct alc_fixup *fix, int action)
  5130. {
  5131. int coef;
  5132. if (action != ALC_FIXUP_ACT_INIT)
  5133. return;
  5134. coef = alc_read_coef_idx(codec, 0x1e);
  5135. alc_write_coef_idx(codec, 0x1e, coef | 0x80);
  5136. }
  5137. static void alc271_fixup_dmic(struct hda_codec *codec,
  5138. const struct alc_fixup *fix, int action)
  5139. {
  5140. static const struct hda_verb verbs[] = {
  5141. {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
  5142. {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
  5143. {}
  5144. };
  5145. unsigned int cfg;
  5146. if (strcmp(codec->chip_name, "ALC271X"))
  5147. return;
  5148. cfg = snd_hda_codec_get_pincfg(codec, 0x12);
  5149. if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
  5150. snd_hda_sequence_write(codec, verbs);
  5151. }
  5152. static void alc269_fixup_pcm_44k(struct hda_codec *codec,
  5153. const struct alc_fixup *fix, int action)
  5154. {
  5155. struct alc_spec *spec = codec->spec;
  5156. if (action != ALC_FIXUP_ACT_PROBE)
  5157. return;
  5158. /* Due to a hardware problem on Lenovo Ideadpad, we need to
  5159. * fix the sample rate of analog I/O to 44.1kHz
  5160. */
  5161. spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
  5162. spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
  5163. }
  5164. static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
  5165. const struct alc_fixup *fix, int action)
  5166. {
  5167. int coef;
  5168. if (action != ALC_FIXUP_ACT_INIT)
  5169. return;
  5170. /* The digital-mic unit sends PDM (differential signal) instead of
  5171. * the standard PCM, thus you can't record a valid mono stream as is.
  5172. * Below is a workaround specific to ALC269 to control the dmic
  5173. * signal source as mono.
  5174. */
  5175. coef = alc_read_coef_idx(codec, 0x07);
  5176. alc_write_coef_idx(codec, 0x07, coef | 0x80);
  5177. }
  5178. static void alc269_quanta_automute(struct hda_codec *codec)
  5179. {
  5180. update_outputs(codec);
  5181. snd_hda_codec_write(codec, 0x20, 0,
  5182. AC_VERB_SET_COEF_INDEX, 0x0c);
  5183. snd_hda_codec_write(codec, 0x20, 0,
  5184. AC_VERB_SET_PROC_COEF, 0x680);
  5185. snd_hda_codec_write(codec, 0x20, 0,
  5186. AC_VERB_SET_COEF_INDEX, 0x0c);
  5187. snd_hda_codec_write(codec, 0x20, 0,
  5188. AC_VERB_SET_PROC_COEF, 0x480);
  5189. }
  5190. static void alc269_fixup_quanta_mute(struct hda_codec *codec,
  5191. const struct alc_fixup *fix, int action)
  5192. {
  5193. struct alc_spec *spec = codec->spec;
  5194. if (action != ALC_FIXUP_ACT_PROBE)
  5195. return;
  5196. spec->automute_hook = alc269_quanta_automute;
  5197. }
  5198. /* update mute-LED according to the speaker mute state via mic2 VREF pin */
  5199. static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
  5200. {
  5201. struct hda_codec *codec = private_data;
  5202. unsigned int pinval = enabled ? 0x20 : 0x24;
  5203. snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
  5204. }
  5205. static void alc269_fixup_mic2_mute(struct hda_codec *codec,
  5206. const struct alc_fixup *fix, int action)
  5207. {
  5208. struct alc_spec *spec = codec->spec;
  5209. switch (action) {
  5210. case ALC_FIXUP_ACT_BUILD:
  5211. spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
  5212. snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
  5213. /* fallthru */
  5214. case ALC_FIXUP_ACT_INIT:
  5215. snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
  5216. break;
  5217. }
  5218. }
  5219. enum {
  5220. ALC269_FIXUP_SONY_VAIO,
  5221. ALC275_FIXUP_SONY_VAIO_GPIO2,
  5222. ALC269_FIXUP_DELL_M101Z,
  5223. ALC269_FIXUP_SKU_IGNORE,
  5224. ALC269_FIXUP_ASUS_G73JW,
  5225. ALC269_FIXUP_LENOVO_EAPD,
  5226. ALC275_FIXUP_SONY_HWEQ,
  5227. ALC271_FIXUP_DMIC,
  5228. ALC269_FIXUP_PCM_44K,
  5229. ALC269_FIXUP_STEREO_DMIC,
  5230. ALC269_FIXUP_QUANTA_MUTE,
  5231. ALC269_FIXUP_LIFEBOOK,
  5232. ALC269_FIXUP_AMIC,
  5233. ALC269_FIXUP_DMIC,
  5234. ALC269VB_FIXUP_AMIC,
  5235. ALC269VB_FIXUP_DMIC,
  5236. ALC269_FIXUP_MIC2_MUTE_LED,
  5237. };
  5238. static const struct alc_fixup alc269_fixups[] = {
  5239. [ALC269_FIXUP_SONY_VAIO] = {
  5240. .type = ALC_FIXUP_VERBS,
  5241. .v.verbs = (const struct hda_verb[]) {
  5242. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
  5243. {}
  5244. }
  5245. },
  5246. [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
  5247. .type = ALC_FIXUP_VERBS,
  5248. .v.verbs = (const struct hda_verb[]) {
  5249. {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
  5250. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
  5251. {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
  5252. { }
  5253. },
  5254. .chained = true,
  5255. .chain_id = ALC269_FIXUP_SONY_VAIO
  5256. },
  5257. [ALC269_FIXUP_DELL_M101Z] = {
  5258. .type = ALC_FIXUP_VERBS,
  5259. .v.verbs = (const struct hda_verb[]) {
  5260. /* Enables internal speaker */
  5261. {0x20, AC_VERB_SET_COEF_INDEX, 13},
  5262. {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
  5263. {}
  5264. }
  5265. },
  5266. [ALC269_FIXUP_SKU_IGNORE] = {
  5267. .type = ALC_FIXUP_FUNC,
  5268. .v.func = alc_fixup_sku_ignore,
  5269. },
  5270. [ALC269_FIXUP_ASUS_G73JW] = {
  5271. .type = ALC_FIXUP_PINS,
  5272. .v.pins = (const struct alc_pincfg[]) {
  5273. { 0x17, 0x99130111 }, /* subwoofer */
  5274. { }
  5275. }
  5276. },
  5277. [ALC269_FIXUP_LENOVO_EAPD] = {
  5278. .type = ALC_FIXUP_VERBS,
  5279. .v.verbs = (const struct hda_verb[]) {
  5280. {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
  5281. {}
  5282. }
  5283. },
  5284. [ALC275_FIXUP_SONY_HWEQ] = {
  5285. .type = ALC_FIXUP_FUNC,
  5286. .v.func = alc269_fixup_hweq,
  5287. .chained = true,
  5288. .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
  5289. },
  5290. [ALC271_FIXUP_DMIC] = {
  5291. .type = ALC_FIXUP_FUNC,
  5292. .v.func = alc271_fixup_dmic,
  5293. },
  5294. [ALC269_FIXUP_PCM_44K] = {
  5295. .type = ALC_FIXUP_FUNC,
  5296. .v.func = alc269_fixup_pcm_44k,
  5297. },
  5298. [ALC269_FIXUP_STEREO_DMIC] = {
  5299. .type = ALC_FIXUP_FUNC,
  5300. .v.func = alc269_fixup_stereo_dmic,
  5301. },
  5302. [ALC269_FIXUP_QUANTA_MUTE] = {
  5303. .type = ALC_FIXUP_FUNC,
  5304. .v.func = alc269_fixup_quanta_mute,
  5305. },
  5306. [ALC269_FIXUP_LIFEBOOK] = {
  5307. .type = ALC_FIXUP_PINS,
  5308. .v.pins = (const struct alc_pincfg[]) {
  5309. { 0x1a, 0x2101103f }, /* dock line-out */
  5310. { 0x1b, 0x23a11040 }, /* dock mic-in */
  5311. { }
  5312. },
  5313. .chained = true,
  5314. .chain_id = ALC269_FIXUP_QUANTA_MUTE
  5315. },
  5316. [ALC269_FIXUP_AMIC] = {
  5317. .type = ALC_FIXUP_PINS,
  5318. .v.pins = (const struct alc_pincfg[]) {
  5319. { 0x14, 0x99130110 }, /* speaker */
  5320. { 0x15, 0x0121401f }, /* HP out */
  5321. { 0x18, 0x01a19c20 }, /* mic */
  5322. { 0x19, 0x99a3092f }, /* int-mic */
  5323. { }
  5324. },
  5325. },
  5326. [ALC269_FIXUP_DMIC] = {
  5327. .type = ALC_FIXUP_PINS,
  5328. .v.pins = (const struct alc_pincfg[]) {
  5329. { 0x12, 0x99a3092f }, /* int-mic */
  5330. { 0x14, 0x99130110 }, /* speaker */
  5331. { 0x15, 0x0121401f }, /* HP out */
  5332. { 0x18, 0x01a19c20 }, /* mic */
  5333. { }
  5334. },
  5335. },
  5336. [ALC269VB_FIXUP_AMIC] = {
  5337. .type = ALC_FIXUP_PINS,
  5338. .v.pins = (const struct alc_pincfg[]) {
  5339. { 0x14, 0x99130110 }, /* speaker */
  5340. { 0x18, 0x01a19c20 }, /* mic */
  5341. { 0x19, 0x99a3092f }, /* int-mic */
  5342. { 0x21, 0x0121401f }, /* HP out */
  5343. { }
  5344. },
  5345. },
  5346. [ALC269VB_FIXUP_DMIC] = {
  5347. .type = ALC_FIXUP_PINS,
  5348. .v.pins = (const struct alc_pincfg[]) {
  5349. { 0x12, 0x99a3092f }, /* int-mic */
  5350. { 0x14, 0x99130110 }, /* speaker */
  5351. { 0x18, 0x01a19c20 }, /* mic */
  5352. { 0x21, 0x0121401f }, /* HP out */
  5353. { }
  5354. },
  5355. },
  5356. [ALC269_FIXUP_MIC2_MUTE_LED] = {
  5357. .type = ALC_FIXUP_FUNC,
  5358. .v.func = alc269_fixup_mic2_mute,
  5359. },
  5360. };
  5361. static const struct snd_pci_quirk alc269_fixup_tbl[] = {
  5362. SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
  5363. SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
  5364. SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
  5365. SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
  5366. SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
  5367. SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
  5368. SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
  5369. SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
  5370. SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
  5371. SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
  5372. SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
  5373. SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
  5374. SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
  5375. SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
  5376. SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
  5377. SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
  5378. SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
  5379. SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
  5380. SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
  5381. SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
  5382. SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
  5383. SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
  5384. SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
  5385. #if 0
  5386. /* Below is a quirk table taken from the old code.
  5387. * Basically the device should work as is without the fixup table.
  5388. * If BIOS doesn't give a proper info, enable the corresponding
  5389. * fixup entry.
  5390. */
  5391. SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
  5392. ALC269_FIXUP_AMIC),
  5393. SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
  5394. SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
  5395. SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
  5396. SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
  5397. SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
  5398. SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
  5399. SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
  5400. SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
  5401. SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
  5402. SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
  5403. SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
  5404. SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
  5405. SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
  5406. SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
  5407. SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
  5408. SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
  5409. SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
  5410. SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
  5411. SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
  5412. SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
  5413. SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
  5414. SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
  5415. SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
  5416. SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
  5417. SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
  5418. SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
  5419. SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
  5420. SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
  5421. SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
  5422. SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
  5423. SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
  5424. SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
  5425. SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
  5426. SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
  5427. SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
  5428. SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
  5429. SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
  5430. SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
  5431. SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
  5432. #endif
  5433. {}
  5434. };
  5435. static const struct alc_model_fixup alc269_fixup_models[] = {
  5436. {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
  5437. {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
  5438. {}
  5439. };
  5440. static void alc269_fill_coef(struct hda_codec *codec)
  5441. {
  5442. struct alc_spec *spec = codec->spec;
  5443. int val;
  5444. if (spec->codec_variant != ALC269_TYPE_ALC269VB)
  5445. return;
  5446. if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
  5447. alc_write_coef_idx(codec, 0xf, 0x960b);
  5448. alc_write_coef_idx(codec, 0xe, 0x8817);
  5449. }
  5450. if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
  5451. alc_write_coef_idx(codec, 0xf, 0x960b);
  5452. alc_write_coef_idx(codec, 0xe, 0x8814);
  5453. }
  5454. if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
  5455. val = alc_read_coef_idx(codec, 0x04);
  5456. /* Power up output pin */
  5457. alc_write_coef_idx(codec, 0x04, val | (1<<11));
  5458. }
  5459. if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
  5460. val = alc_read_coef_idx(codec, 0xd);
  5461. if ((val & 0x0c00) >> 10 != 0x1) {
  5462. /* Capless ramp up clock control */
  5463. alc_write_coef_idx(codec, 0xd, val | (1<<10));
  5464. }
  5465. val = alc_read_coef_idx(codec, 0x17);
  5466. if ((val & 0x01c0) >> 6 != 0x4) {
  5467. /* Class D power on reset */
  5468. alc_write_coef_idx(codec, 0x17, val | (1<<7));
  5469. }
  5470. }
  5471. val = alc_read_coef_idx(codec, 0xd); /* Class D */
  5472. alc_write_coef_idx(codec, 0xd, val | (1<<14));
  5473. val = alc_read_coef_idx(codec, 0x4); /* HP */
  5474. alc_write_coef_idx(codec, 0x4, val | (1<<11));
  5475. }
  5476. /*
  5477. */
  5478. static int patch_alc269(struct hda_codec *codec)
  5479. {
  5480. struct alc_spec *spec;
  5481. int err;
  5482. err = alc_alloc_spec(codec, 0x0b);
  5483. if (err < 0)
  5484. return err;
  5485. spec = codec->spec;
  5486. if (codec->vendor_id == 0x10ec0269) {
  5487. spec->codec_variant = ALC269_TYPE_ALC269VA;
  5488. switch (alc_get_coef0(codec) & 0x00f0) {
  5489. case 0x0010:
  5490. if (codec->bus->pci->subsystem_vendor == 0x1025 &&
  5491. spec->cdefine.platform_type == 1)
  5492. err = alc_codec_rename(codec, "ALC271X");
  5493. spec->codec_variant = ALC269_TYPE_ALC269VB;
  5494. break;
  5495. case 0x0020:
  5496. if (codec->bus->pci->subsystem_vendor == 0x17aa &&
  5497. codec->bus->pci->subsystem_device == 0x21f3)
  5498. err = alc_codec_rename(codec, "ALC3202");
  5499. spec->codec_variant = ALC269_TYPE_ALC269VC;
  5500. break;
  5501. default:
  5502. alc_fix_pll_init(codec, 0x20, 0x04, 15);
  5503. }
  5504. if (err < 0)
  5505. goto error;
  5506. spec->init_hook = alc269_fill_coef;
  5507. alc269_fill_coef(codec);
  5508. }
  5509. alc_pick_fixup(codec, alc269_fixup_models,
  5510. alc269_fixup_tbl, alc269_fixups);
  5511. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5512. alc_auto_parse_customize_define(codec);
  5513. /* automatic parse from the BIOS config */
  5514. err = alc269_parse_auto_config(codec);
  5515. if (err < 0)
  5516. goto error;
  5517. if (!spec->no_analog && has_cdefine_beep(codec)) {
  5518. err = snd_hda_attach_beep_device(codec, 0x1);
  5519. if (err < 0)
  5520. goto error;
  5521. set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
  5522. }
  5523. codec->patch_ops = alc_patch_ops;
  5524. #ifdef CONFIG_PM
  5525. codec->patch_ops.resume = alc269_resume;
  5526. #endif
  5527. spec->shutup = alc269_shutup;
  5528. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5529. return 0;
  5530. error:
  5531. alc_free(codec);
  5532. return err;
  5533. }
  5534. /*
  5535. * ALC861
  5536. */
  5537. static int alc861_parse_auto_config(struct hda_codec *codec)
  5538. {
  5539. static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
  5540. static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
  5541. return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
  5542. }
  5543. /* Pin config fixes */
  5544. enum {
  5545. ALC861_FIXUP_FSC_AMILO_PI1505,
  5546. ALC861_FIXUP_AMP_VREF_0F,
  5547. ALC861_FIXUP_NO_JACK_DETECT,
  5548. ALC861_FIXUP_ASUS_A6RP,
  5549. };
  5550. /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
  5551. static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
  5552. const struct alc_fixup *fix, int action)
  5553. {
  5554. struct alc_spec *spec = codec->spec;
  5555. unsigned int val;
  5556. if (action != ALC_FIXUP_ACT_INIT)
  5557. return;
  5558. val = snd_hda_codec_read(codec, 0x0f, 0,
  5559. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  5560. if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
  5561. val |= AC_PINCTL_IN_EN;
  5562. val |= AC_PINCTL_VREF_50;
  5563. snd_hda_set_pin_ctl(codec, 0x0f, val);
  5564. spec->keep_vref_in_automute = 1;
  5565. }
  5566. /* suppress the jack-detection */
  5567. static void alc_fixup_no_jack_detect(struct hda_codec *codec,
  5568. const struct alc_fixup *fix, int action)
  5569. {
  5570. if (action == ALC_FIXUP_ACT_PRE_PROBE)
  5571. codec->no_jack_detect = 1;
  5572. }
  5573. static const struct alc_fixup alc861_fixups[] = {
  5574. [ALC861_FIXUP_FSC_AMILO_PI1505] = {
  5575. .type = ALC_FIXUP_PINS,
  5576. .v.pins = (const struct alc_pincfg[]) {
  5577. { 0x0b, 0x0221101f }, /* HP */
  5578. { 0x0f, 0x90170310 }, /* speaker */
  5579. { }
  5580. }
  5581. },
  5582. [ALC861_FIXUP_AMP_VREF_0F] = {
  5583. .type = ALC_FIXUP_FUNC,
  5584. .v.func = alc861_fixup_asus_amp_vref_0f,
  5585. },
  5586. [ALC861_FIXUP_NO_JACK_DETECT] = {
  5587. .type = ALC_FIXUP_FUNC,
  5588. .v.func = alc_fixup_no_jack_detect,
  5589. },
  5590. [ALC861_FIXUP_ASUS_A6RP] = {
  5591. .type = ALC_FIXUP_FUNC,
  5592. .v.func = alc861_fixup_asus_amp_vref_0f,
  5593. .chained = true,
  5594. .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
  5595. }
  5596. };
  5597. static const struct snd_pci_quirk alc861_fixup_tbl[] = {
  5598. SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
  5599. SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
  5600. SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
  5601. SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
  5602. SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
  5603. SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
  5604. {}
  5605. };
  5606. /*
  5607. */
  5608. static int patch_alc861(struct hda_codec *codec)
  5609. {
  5610. struct alc_spec *spec;
  5611. int err;
  5612. err = alc_alloc_spec(codec, 0x15);
  5613. if (err < 0)
  5614. return err;
  5615. spec = codec->spec;
  5616. alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
  5617. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5618. /* automatic parse from the BIOS config */
  5619. err = alc861_parse_auto_config(codec);
  5620. if (err < 0)
  5621. goto error;
  5622. if (!spec->no_analog) {
  5623. err = snd_hda_attach_beep_device(codec, 0x23);
  5624. if (err < 0)
  5625. goto error;
  5626. set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
  5627. }
  5628. codec->patch_ops = alc_patch_ops;
  5629. #ifdef CONFIG_SND_HDA_POWER_SAVE
  5630. spec->power_hook = alc_power_eapd;
  5631. #endif
  5632. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5633. return 0;
  5634. error:
  5635. alc_free(codec);
  5636. return err;
  5637. }
  5638. /*
  5639. * ALC861-VD support
  5640. *
  5641. * Based on ALC882
  5642. *
  5643. * In addition, an independent DAC
  5644. */
  5645. static int alc861vd_parse_auto_config(struct hda_codec *codec)
  5646. {
  5647. static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
  5648. static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  5649. return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
  5650. }
  5651. enum {
  5652. ALC660VD_FIX_ASUS_GPIO1,
  5653. ALC861VD_FIX_DALLAS,
  5654. };
  5655. /* exclude VREF80 */
  5656. static void alc861vd_fixup_dallas(struct hda_codec *codec,
  5657. const struct alc_fixup *fix, int action)
  5658. {
  5659. if (action == ALC_FIXUP_ACT_PRE_PROBE) {
  5660. snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
  5661. snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
  5662. }
  5663. }
  5664. static const struct alc_fixup alc861vd_fixups[] = {
  5665. [ALC660VD_FIX_ASUS_GPIO1] = {
  5666. .type = ALC_FIXUP_VERBS,
  5667. .v.verbs = (const struct hda_verb[]) {
  5668. /* reset GPIO1 */
  5669. {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
  5670. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
  5671. {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
  5672. { }
  5673. }
  5674. },
  5675. [ALC861VD_FIX_DALLAS] = {
  5676. .type = ALC_FIXUP_FUNC,
  5677. .v.func = alc861vd_fixup_dallas,
  5678. },
  5679. };
  5680. static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
  5681. SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
  5682. SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
  5683. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
  5684. {}
  5685. };
  5686. static const struct hda_verb alc660vd_eapd_verbs[] = {
  5687. {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
  5688. {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
  5689. { }
  5690. };
  5691. /*
  5692. */
  5693. static int patch_alc861vd(struct hda_codec *codec)
  5694. {
  5695. struct alc_spec *spec;
  5696. int err;
  5697. err = alc_alloc_spec(codec, 0x0b);
  5698. if (err < 0)
  5699. return err;
  5700. spec = codec->spec;
  5701. alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
  5702. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5703. /* automatic parse from the BIOS config */
  5704. err = alc861vd_parse_auto_config(codec);
  5705. if (err < 0)
  5706. goto error;
  5707. if (codec->vendor_id == 0x10ec0660) {
  5708. /* always turn on EAPD */
  5709. snd_hda_gen_add_verbs(&spec->gen, alc660vd_eapd_verbs);
  5710. }
  5711. if (!spec->no_analog) {
  5712. err = snd_hda_attach_beep_device(codec, 0x23);
  5713. if (err < 0)
  5714. goto error;
  5715. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  5716. }
  5717. codec->patch_ops = alc_patch_ops;
  5718. spec->shutup = alc_eapd_shutup;
  5719. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5720. return 0;
  5721. error:
  5722. alc_free(codec);
  5723. return err;
  5724. }
  5725. /*
  5726. * ALC662 support
  5727. *
  5728. * ALC662 is almost identical with ALC880 but has cleaner and more flexible
  5729. * configuration. Each pin widget can choose any input DACs and a mixer.
  5730. * Each ADC is connected from a mixer of all inputs. This makes possible
  5731. * 6-channel independent captures.
  5732. *
  5733. * In addition, an independent DAC for the multi-playback (not used in this
  5734. * driver yet).
  5735. */
  5736. /*
  5737. * BIOS auto configuration
  5738. */
  5739. static int alc662_parse_auto_config(struct hda_codec *codec)
  5740. {
  5741. static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
  5742. static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
  5743. static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  5744. const hda_nid_t *ssids;
  5745. if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
  5746. codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
  5747. ssids = alc663_ssids;
  5748. else
  5749. ssids = alc662_ssids;
  5750. return alc_parse_auto_config(codec, alc662_ignore, ssids);
  5751. }
  5752. static void alc272_fixup_mario(struct hda_codec *codec,
  5753. const struct alc_fixup *fix, int action)
  5754. {
  5755. if (action != ALC_FIXUP_ACT_PROBE)
  5756. return;
  5757. if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
  5758. (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
  5759. (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
  5760. (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  5761. (0 << AC_AMPCAP_MUTE_SHIFT)))
  5762. printk(KERN_WARNING
  5763. "hda_codec: failed to override amp caps for NID 0x2\n");
  5764. }
  5765. enum {
  5766. ALC662_FIXUP_ASPIRE,
  5767. ALC662_FIXUP_IDEAPAD,
  5768. ALC272_FIXUP_MARIO,
  5769. ALC662_FIXUP_CZC_P10T,
  5770. ALC662_FIXUP_SKU_IGNORE,
  5771. ALC662_FIXUP_HP_RP5800,
  5772. ALC662_FIXUP_ASUS_MODE1,
  5773. ALC662_FIXUP_ASUS_MODE2,
  5774. ALC662_FIXUP_ASUS_MODE3,
  5775. ALC662_FIXUP_ASUS_MODE4,
  5776. ALC662_FIXUP_ASUS_MODE5,
  5777. ALC662_FIXUP_ASUS_MODE6,
  5778. ALC662_FIXUP_ASUS_MODE7,
  5779. ALC662_FIXUP_ASUS_MODE8,
  5780. ALC662_FIXUP_NO_JACK_DETECT,
  5781. };
  5782. static const struct alc_fixup alc662_fixups[] = {
  5783. [ALC662_FIXUP_ASPIRE] = {
  5784. .type = ALC_FIXUP_PINS,
  5785. .v.pins = (const struct alc_pincfg[]) {
  5786. { 0x15, 0x99130112 }, /* subwoofer */
  5787. { }
  5788. }
  5789. },
  5790. [ALC662_FIXUP_IDEAPAD] = {
  5791. .type = ALC_FIXUP_PINS,
  5792. .v.pins = (const struct alc_pincfg[]) {
  5793. { 0x17, 0x99130112 }, /* subwoofer */
  5794. { }
  5795. }
  5796. },
  5797. [ALC272_FIXUP_MARIO] = {
  5798. .type = ALC_FIXUP_FUNC,
  5799. .v.func = alc272_fixup_mario,
  5800. },
  5801. [ALC662_FIXUP_CZC_P10T] = {
  5802. .type = ALC_FIXUP_VERBS,
  5803. .v.verbs = (const struct hda_verb[]) {
  5804. {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
  5805. {}
  5806. }
  5807. },
  5808. [ALC662_FIXUP_SKU_IGNORE] = {
  5809. .type = ALC_FIXUP_FUNC,
  5810. .v.func = alc_fixup_sku_ignore,
  5811. },
  5812. [ALC662_FIXUP_HP_RP5800] = {
  5813. .type = ALC_FIXUP_PINS,
  5814. .v.pins = (const struct alc_pincfg[]) {
  5815. { 0x14, 0x0221201f }, /* HP out */
  5816. { }
  5817. },
  5818. .chained = true,
  5819. .chain_id = ALC662_FIXUP_SKU_IGNORE
  5820. },
  5821. [ALC662_FIXUP_ASUS_MODE1] = {
  5822. .type = ALC_FIXUP_PINS,
  5823. .v.pins = (const struct alc_pincfg[]) {
  5824. { 0x14, 0x99130110 }, /* speaker */
  5825. { 0x18, 0x01a19c20 }, /* mic */
  5826. { 0x19, 0x99a3092f }, /* int-mic */
  5827. { 0x21, 0x0121401f }, /* HP out */
  5828. { }
  5829. },
  5830. .chained = true,
  5831. .chain_id = ALC662_FIXUP_SKU_IGNORE
  5832. },
  5833. [ALC662_FIXUP_ASUS_MODE2] = {
  5834. .type = ALC_FIXUP_PINS,
  5835. .v.pins = (const struct alc_pincfg[]) {
  5836. { 0x14, 0x99130110 }, /* speaker */
  5837. { 0x18, 0x01a19820 }, /* mic */
  5838. { 0x19, 0x99a3092f }, /* int-mic */
  5839. { 0x1b, 0x0121401f }, /* HP out */
  5840. { }
  5841. },
  5842. .chained = true,
  5843. .chain_id = ALC662_FIXUP_SKU_IGNORE
  5844. },
  5845. [ALC662_FIXUP_ASUS_MODE3] = {
  5846. .type = ALC_FIXUP_PINS,
  5847. .v.pins = (const struct alc_pincfg[]) {
  5848. { 0x14, 0x99130110 }, /* speaker */
  5849. { 0x15, 0x0121441f }, /* HP */
  5850. { 0x18, 0x01a19840 }, /* mic */
  5851. { 0x19, 0x99a3094f }, /* int-mic */
  5852. { 0x21, 0x01211420 }, /* HP2 */
  5853. { }
  5854. },
  5855. .chained = true,
  5856. .chain_id = ALC662_FIXUP_SKU_IGNORE
  5857. },
  5858. [ALC662_FIXUP_ASUS_MODE4] = {
  5859. .type = ALC_FIXUP_PINS,
  5860. .v.pins = (const struct alc_pincfg[]) {
  5861. { 0x14, 0x99130110 }, /* speaker */
  5862. { 0x16, 0x99130111 }, /* speaker */
  5863. { 0x18, 0x01a19840 }, /* mic */
  5864. { 0x19, 0x99a3094f }, /* int-mic */
  5865. { 0x21, 0x0121441f }, /* HP */
  5866. { }
  5867. },
  5868. .chained = true,
  5869. .chain_id = ALC662_FIXUP_SKU_IGNORE
  5870. },
  5871. [ALC662_FIXUP_ASUS_MODE5] = {
  5872. .type = ALC_FIXUP_PINS,
  5873. .v.pins = (const struct alc_pincfg[]) {
  5874. { 0x14, 0x99130110 }, /* speaker */
  5875. { 0x15, 0x0121441f }, /* HP */
  5876. { 0x16, 0x99130111 }, /* speaker */
  5877. { 0x18, 0x01a19840 }, /* mic */
  5878. { 0x19, 0x99a3094f }, /* int-mic */
  5879. { }
  5880. },
  5881. .chained = true,
  5882. .chain_id = ALC662_FIXUP_SKU_IGNORE
  5883. },
  5884. [ALC662_FIXUP_ASUS_MODE6] = {
  5885. .type = ALC_FIXUP_PINS,
  5886. .v.pins = (const struct alc_pincfg[]) {
  5887. { 0x14, 0x99130110 }, /* speaker */
  5888. { 0x15, 0x01211420 }, /* HP2 */
  5889. { 0x18, 0x01a19840 }, /* mic */
  5890. { 0x19, 0x99a3094f }, /* int-mic */
  5891. { 0x1b, 0x0121441f }, /* HP */
  5892. { }
  5893. },
  5894. .chained = true,
  5895. .chain_id = ALC662_FIXUP_SKU_IGNORE
  5896. },
  5897. [ALC662_FIXUP_ASUS_MODE7] = {
  5898. .type = ALC_FIXUP_PINS,
  5899. .v.pins = (const struct alc_pincfg[]) {
  5900. { 0x14, 0x99130110 }, /* speaker */
  5901. { 0x17, 0x99130111 }, /* speaker */
  5902. { 0x18, 0x01a19840 }, /* mic */
  5903. { 0x19, 0x99a3094f }, /* int-mic */
  5904. { 0x1b, 0x01214020 }, /* HP */
  5905. { 0x21, 0x0121401f }, /* HP */
  5906. { }
  5907. },
  5908. .chained = true,
  5909. .chain_id = ALC662_FIXUP_SKU_IGNORE
  5910. },
  5911. [ALC662_FIXUP_ASUS_MODE8] = {
  5912. .type = ALC_FIXUP_PINS,
  5913. .v.pins = (const struct alc_pincfg[]) {
  5914. { 0x14, 0x99130110 }, /* speaker */
  5915. { 0x12, 0x99a30970 }, /* int-mic */
  5916. { 0x15, 0x01214020 }, /* HP */
  5917. { 0x17, 0x99130111 }, /* speaker */
  5918. { 0x18, 0x01a19840 }, /* mic */
  5919. { 0x21, 0x0121401f }, /* HP */
  5920. { }
  5921. },
  5922. .chained = true,
  5923. .chain_id = ALC662_FIXUP_SKU_IGNORE
  5924. },
  5925. [ALC662_FIXUP_NO_JACK_DETECT] = {
  5926. .type = ALC_FIXUP_FUNC,
  5927. .v.func = alc_fixup_no_jack_detect,
  5928. },
  5929. };
  5930. static const struct snd_pci_quirk alc662_fixup_tbl[] = {
  5931. SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
  5932. SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
  5933. SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
  5934. SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
  5935. SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
  5936. SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
  5937. SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
  5938. SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
  5939. SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
  5940. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
  5941. SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
  5942. #if 0
  5943. /* Below is a quirk table taken from the old code.
  5944. * Basically the device should work as is without the fixup table.
  5945. * If BIOS doesn't give a proper info, enable the corresponding
  5946. * fixup entry.
  5947. */
  5948. SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
  5949. SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
  5950. SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
  5951. SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
  5952. SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
  5953. SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  5954. SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
  5955. SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
  5956. SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
  5957. SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  5958. SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
  5959. SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
  5960. SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
  5961. SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
  5962. SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
  5963. SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  5964. SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
  5965. SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
  5966. SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  5967. SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
  5968. SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
  5969. SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  5970. SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
  5971. SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
  5972. SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
  5973. SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  5974. SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
  5975. SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
  5976. SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  5977. SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
  5978. SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  5979. SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  5980. SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
  5981. SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
  5982. SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
  5983. SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
  5984. SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
  5985. SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
  5986. SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
  5987. SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  5988. SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
  5989. SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
  5990. SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
  5991. SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
  5992. SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
  5993. SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
  5994. SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
  5995. SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
  5996. SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
  5997. SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
  5998. #endif
  5999. {}
  6000. };
  6001. static const struct alc_model_fixup alc662_fixup_models[] = {
  6002. {.id = ALC272_FIXUP_MARIO, .name = "mario"},
  6003. {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
  6004. {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
  6005. {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
  6006. {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
  6007. {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
  6008. {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
  6009. {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
  6010. {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
  6011. {}
  6012. };
  6013. /*
  6014. */
  6015. static int patch_alc662(struct hda_codec *codec)
  6016. {
  6017. struct alc_spec *spec;
  6018. int err;
  6019. err = alc_alloc_spec(codec, 0x0b);
  6020. if (err < 0)
  6021. return err;
  6022. spec = codec->spec;
  6023. /* handle multiple HPs as is */
  6024. spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
  6025. alc_fix_pll_init(codec, 0x20, 0x04, 15);
  6026. if ((alc_get_coef0(codec) & (1 << 14)) &&
  6027. codec->bus->pci->subsystem_vendor == 0x1025 &&
  6028. spec->cdefine.platform_type == 1) {
  6029. if (alc_codec_rename(codec, "ALC272X") < 0)
  6030. goto error;
  6031. }
  6032. alc_pick_fixup(codec, alc662_fixup_models,
  6033. alc662_fixup_tbl, alc662_fixups);
  6034. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  6035. alc_auto_parse_customize_define(codec);
  6036. /* automatic parse from the BIOS config */
  6037. err = alc662_parse_auto_config(codec);
  6038. if (err < 0)
  6039. goto error;
  6040. if (!spec->no_analog && has_cdefine_beep(codec)) {
  6041. err = snd_hda_attach_beep_device(codec, 0x1);
  6042. if (err < 0)
  6043. goto error;
  6044. switch (codec->vendor_id) {
  6045. case 0x10ec0662:
  6046. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  6047. break;
  6048. case 0x10ec0272:
  6049. case 0x10ec0663:
  6050. case 0x10ec0665:
  6051. set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
  6052. break;
  6053. case 0x10ec0273:
  6054. set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
  6055. break;
  6056. }
  6057. }
  6058. codec->patch_ops = alc_patch_ops;
  6059. spec->shutup = alc_eapd_shutup;
  6060. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  6061. return 0;
  6062. error:
  6063. alc_free(codec);
  6064. return err;
  6065. }
  6066. /*
  6067. * ALC680 support
  6068. */
  6069. static int alc680_parse_auto_config(struct hda_codec *codec)
  6070. {
  6071. return alc_parse_auto_config(codec, NULL, NULL);
  6072. }
  6073. /*
  6074. */
  6075. static int patch_alc680(struct hda_codec *codec)
  6076. {
  6077. int err;
  6078. /* ALC680 has no aa-loopback mixer */
  6079. err = alc_alloc_spec(codec, 0);
  6080. if (err < 0)
  6081. return err;
  6082. /* automatic parse from the BIOS config */
  6083. err = alc680_parse_auto_config(codec);
  6084. if (err < 0) {
  6085. alc_free(codec);
  6086. return err;
  6087. }
  6088. codec->patch_ops = alc_patch_ops;
  6089. return 0;
  6090. }
  6091. /*
  6092. * patch entries
  6093. */
  6094. static const struct hda_codec_preset snd_hda_preset_realtek[] = {
  6095. { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
  6096. { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
  6097. { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
  6098. { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
  6099. { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
  6100. { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
  6101. { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
  6102. { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
  6103. { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
  6104. { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
  6105. { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
  6106. .patch = patch_alc861 },
  6107. { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
  6108. { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
  6109. { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
  6110. { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
  6111. .patch = patch_alc882 },
  6112. { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
  6113. .patch = patch_alc662 },
  6114. { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
  6115. .patch = patch_alc662 },
  6116. { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
  6117. { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
  6118. { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
  6119. { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
  6120. { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
  6121. { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
  6122. { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
  6123. { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
  6124. .patch = patch_alc882 },
  6125. { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
  6126. .patch = patch_alc882 },
  6127. { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
  6128. { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
  6129. { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
  6130. .patch = patch_alc882 },
  6131. { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
  6132. { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
  6133. { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
  6134. { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
  6135. {} /* terminator */
  6136. };
  6137. MODULE_ALIAS("snd-hda-codec-id:10ec*");
  6138. MODULE_LICENSE("GPL");
  6139. MODULE_DESCRIPTION("Realtek HD-audio codec");
  6140. static struct hda_codec_preset_list realtek_list = {
  6141. .preset = snd_hda_preset_realtek,
  6142. .owner = THIS_MODULE,
  6143. };
  6144. static int __init patch_realtek_init(void)
  6145. {
  6146. return snd_hda_add_codec_preset(&realtek_list);
  6147. }
  6148. static void __exit patch_realtek_exit(void)
  6149. {
  6150. snd_hda_delete_codec_preset(&realtek_list);
  6151. }
  6152. module_init(patch_realtek_init)
  6153. module_exit(patch_realtek_exit)