patch_realtek.c 198 KB

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