patch_realtek.c 197 KB

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