patch_realtek.c 199 KB

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