patch_realtek.c 190 KB

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