patch_realtek.c 192 KB

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