patch_realtek.c 187 KB

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