patch_realtek.c 169 KB

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