patch_realtek.c 196 KB

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