patch_realtek.c 207 KB

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