patch_realtek.c 191 KB

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