patch_sigmatel.c 181 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for SigmaTel STAC92xx
  5. *
  6. * Copyright (c) 2005 Embedded Alley Solutions, Inc.
  7. * Matt Porter <mporter@embeddedalley.com>
  8. *
  9. * Based on patch_cmedia.c and patch_realtek.c
  10. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  11. *
  12. * This driver is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This driver is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #include <linux/init.h>
  27. #include <linux/delay.h>
  28. #include <linux/slab.h>
  29. #include <linux/pci.h>
  30. #include <linux/dmi.h>
  31. #include <linux/module.h>
  32. #include <sound/core.h>
  33. #include <sound/asoundef.h>
  34. #include <sound/jack.h>
  35. #include <sound/tlv.h>
  36. #include "hda_codec.h"
  37. #include "hda_local.h"
  38. #include "hda_auto_parser.h"
  39. #include "hda_beep.h"
  40. #include "hda_jack.h"
  41. enum {
  42. STAC_VREF_EVENT = 1,
  43. STAC_INSERT_EVENT,
  44. STAC_PWR_EVENT,
  45. STAC_HP_EVENT,
  46. STAC_LO_EVENT,
  47. STAC_MIC_EVENT,
  48. };
  49. enum {
  50. STAC_AUTO,
  51. STAC_REF,
  52. STAC_9200_OQO,
  53. STAC_9200_DELL_D21,
  54. STAC_9200_DELL_D22,
  55. STAC_9200_DELL_D23,
  56. STAC_9200_DELL_M21,
  57. STAC_9200_DELL_M22,
  58. STAC_9200_DELL_M23,
  59. STAC_9200_DELL_M24,
  60. STAC_9200_DELL_M25,
  61. STAC_9200_DELL_M26,
  62. STAC_9200_DELL_M27,
  63. STAC_9200_M4,
  64. STAC_9200_M4_2,
  65. STAC_9200_PANASONIC,
  66. STAC_9200_MODELS
  67. };
  68. enum {
  69. STAC_9205_AUTO,
  70. STAC_9205_REF,
  71. STAC_9205_DELL_M42,
  72. STAC_9205_DELL_M43,
  73. STAC_9205_DELL_M44,
  74. STAC_9205_EAPD,
  75. STAC_9205_MODELS
  76. };
  77. enum {
  78. STAC_92HD73XX_AUTO,
  79. STAC_92HD73XX_NO_JD, /* no jack-detection */
  80. STAC_92HD73XX_REF,
  81. STAC_92HD73XX_INTEL,
  82. STAC_DELL_M6_AMIC,
  83. STAC_DELL_M6_DMIC,
  84. STAC_DELL_M6_BOTH,
  85. STAC_DELL_EQ,
  86. STAC_ALIENWARE_M17X,
  87. STAC_92HD73XX_MODELS
  88. };
  89. enum {
  90. STAC_92HD83XXX_AUTO,
  91. STAC_92HD83XXX_REF,
  92. STAC_92HD83XXX_PWR_REF,
  93. STAC_DELL_S14,
  94. STAC_DELL_VOSTRO_3500,
  95. STAC_92HD83XXX_HP_cNB11_INTQUAD,
  96. STAC_HP_DV7_4000,
  97. STAC_HP_ZEPHYR,
  98. STAC_92HD83XXX_MODELS
  99. };
  100. enum {
  101. STAC_92HD71BXX_AUTO,
  102. STAC_92HD71BXX_REF,
  103. STAC_DELL_M4_1,
  104. STAC_DELL_M4_2,
  105. STAC_DELL_M4_3,
  106. STAC_HP_M4,
  107. STAC_HP_DV4,
  108. STAC_HP_DV5,
  109. STAC_HP_HDX,
  110. STAC_HP_DV4_1222NR,
  111. STAC_92HD71BXX_MODELS
  112. };
  113. enum {
  114. STAC_925x_AUTO,
  115. STAC_925x_REF,
  116. STAC_M1,
  117. STAC_M1_2,
  118. STAC_M2,
  119. STAC_M2_2,
  120. STAC_M3,
  121. STAC_M5,
  122. STAC_M6,
  123. STAC_925x_MODELS
  124. };
  125. enum {
  126. STAC_922X_AUTO,
  127. STAC_D945_REF,
  128. STAC_D945GTP3,
  129. STAC_D945GTP5,
  130. STAC_INTEL_MAC_V1,
  131. STAC_INTEL_MAC_V2,
  132. STAC_INTEL_MAC_V3,
  133. STAC_INTEL_MAC_V4,
  134. STAC_INTEL_MAC_V5,
  135. STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
  136. * is given, one of the above models will be
  137. * chosen according to the subsystem id. */
  138. /* for backward compatibility */
  139. STAC_MACMINI,
  140. STAC_MACBOOK,
  141. STAC_MACBOOK_PRO_V1,
  142. STAC_MACBOOK_PRO_V2,
  143. STAC_IMAC_INTEL,
  144. STAC_IMAC_INTEL_20,
  145. STAC_ECS_202,
  146. STAC_922X_DELL_D81,
  147. STAC_922X_DELL_D82,
  148. STAC_922X_DELL_M81,
  149. STAC_922X_DELL_M82,
  150. STAC_922X_MODELS
  151. };
  152. enum {
  153. STAC_927X_AUTO,
  154. STAC_D965_REF_NO_JD, /* no jack-detection */
  155. STAC_D965_REF,
  156. STAC_D965_3ST,
  157. STAC_D965_5ST,
  158. STAC_D965_5ST_NO_FP,
  159. STAC_DELL_3ST,
  160. STAC_DELL_BIOS,
  161. STAC_927X_VOLKNOB,
  162. STAC_927X_MODELS
  163. };
  164. enum {
  165. STAC_9872_AUTO,
  166. STAC_9872_VAIO,
  167. STAC_9872_MODELS
  168. };
  169. struct sigmatel_mic_route {
  170. hda_nid_t pin;
  171. signed char mux_idx;
  172. signed char dmux_idx;
  173. };
  174. #define MAX_PINS_NUM 16
  175. #define MAX_ADCS_NUM 4
  176. #define MAX_DMICS_NUM 4
  177. struct sigmatel_spec {
  178. struct snd_kcontrol_new *mixers[4];
  179. unsigned int num_mixers;
  180. int board_config;
  181. unsigned int eapd_switch: 1;
  182. unsigned int surr_switch: 1;
  183. unsigned int alt_switch: 1;
  184. unsigned int hp_detect: 1;
  185. unsigned int spdif_mute: 1;
  186. unsigned int check_volume_offset:1;
  187. unsigned int auto_mic:1;
  188. unsigned int linear_tone_beep:1;
  189. /* gpio lines */
  190. unsigned int eapd_mask;
  191. unsigned int gpio_mask;
  192. unsigned int gpio_dir;
  193. unsigned int gpio_data;
  194. unsigned int gpio_mute;
  195. unsigned int gpio_led;
  196. unsigned int gpio_led_polarity;
  197. unsigned int vref_mute_led_nid; /* pin NID for mute-LED vref control */
  198. unsigned int vref_led;
  199. /* stream */
  200. unsigned int stream_delay;
  201. /* analog loopback */
  202. const struct snd_kcontrol_new *aloopback_ctl;
  203. unsigned char aloopback_mask;
  204. unsigned char aloopback_shift;
  205. /* power management */
  206. unsigned int num_pwrs;
  207. const hda_nid_t *pwr_nids;
  208. const hda_nid_t *dac_list;
  209. /* playback */
  210. struct hda_input_mux *mono_mux;
  211. unsigned int cur_mmux;
  212. struct hda_multi_out multiout;
  213. hda_nid_t dac_nids[5];
  214. hda_nid_t hp_dacs[5];
  215. hda_nid_t speaker_dacs[5];
  216. int volume_offset;
  217. /* capture */
  218. const hda_nid_t *adc_nids;
  219. unsigned int num_adcs;
  220. const hda_nid_t *mux_nids;
  221. unsigned int num_muxes;
  222. const hda_nid_t *dmic_nids;
  223. unsigned int num_dmics;
  224. const hda_nid_t *dmux_nids;
  225. unsigned int num_dmuxes;
  226. const hda_nid_t *smux_nids;
  227. unsigned int num_smuxes;
  228. unsigned int num_analog_muxes;
  229. const unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
  230. const unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
  231. unsigned int num_caps; /* number of capture volume/switch elements */
  232. struct sigmatel_mic_route ext_mic;
  233. struct sigmatel_mic_route int_mic;
  234. struct sigmatel_mic_route dock_mic;
  235. const char * const *spdif_labels;
  236. hda_nid_t dig_in_nid;
  237. hda_nid_t mono_nid;
  238. hda_nid_t anabeep_nid;
  239. hda_nid_t digbeep_nid;
  240. /* pin widgets */
  241. const hda_nid_t *pin_nids;
  242. unsigned int num_pins;
  243. /* codec specific stuff */
  244. const struct hda_verb *init;
  245. const struct snd_kcontrol_new *mixer;
  246. /* capture source */
  247. struct hda_input_mux *dinput_mux;
  248. unsigned int cur_dmux[2];
  249. struct hda_input_mux *input_mux;
  250. unsigned int cur_mux[3];
  251. struct hda_input_mux *sinput_mux;
  252. unsigned int cur_smux[2];
  253. unsigned int cur_amux;
  254. hda_nid_t *amp_nids;
  255. unsigned int powerdown_adcs;
  256. /* i/o switches */
  257. unsigned int io_switch[2];
  258. unsigned int clfe_swap;
  259. hda_nid_t line_switch; /* shared line-in for input and output */
  260. hda_nid_t mic_switch; /* shared mic-in for input and output */
  261. hda_nid_t hp_switch; /* NID of HP as line-out */
  262. unsigned int aloopback;
  263. struct hda_pcm pcm_rec[2]; /* PCM information */
  264. /* dynamic controls and input_mux */
  265. struct auto_pin_cfg autocfg;
  266. struct snd_array kctls;
  267. struct hda_input_mux private_dimux;
  268. struct hda_input_mux private_imux;
  269. struct hda_input_mux private_smux;
  270. struct hda_input_mux private_mono_mux;
  271. /* auto spec */
  272. unsigned auto_pin_cnt;
  273. hda_nid_t auto_pin_nids[MAX_PINS_NUM];
  274. unsigned auto_adc_cnt;
  275. hda_nid_t auto_adc_nids[MAX_ADCS_NUM];
  276. hda_nid_t auto_mux_nids[MAX_ADCS_NUM];
  277. hda_nid_t auto_dmux_nids[MAX_ADCS_NUM];
  278. unsigned long auto_capvols[MAX_ADCS_NUM];
  279. unsigned auto_dmic_cnt;
  280. hda_nid_t auto_dmic_nids[MAX_DMICS_NUM];
  281. struct hda_vmaster_mute_hook vmaster_mute;
  282. };
  283. static const hda_nid_t stac9200_adc_nids[1] = {
  284. 0x03,
  285. };
  286. static const hda_nid_t stac9200_mux_nids[1] = {
  287. 0x0c,
  288. };
  289. static const hda_nid_t stac9200_dac_nids[1] = {
  290. 0x02,
  291. };
  292. static const hda_nid_t stac92hd73xx_pwr_nids[8] = {
  293. 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
  294. 0x0f, 0x10, 0x11
  295. };
  296. static const hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
  297. 0x26, 0,
  298. };
  299. static const hda_nid_t stac92hd73xx_adc_nids[2] = {
  300. 0x1a, 0x1b
  301. };
  302. #define STAC92HD73XX_NUM_DMICS 2
  303. static const hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
  304. 0x13, 0x14, 0
  305. };
  306. #define STAC92HD73_DAC_COUNT 5
  307. static const hda_nid_t stac92hd73xx_mux_nids[2] = {
  308. 0x20, 0x21,
  309. };
  310. static const hda_nid_t stac92hd73xx_dmux_nids[2] = {
  311. 0x20, 0x21,
  312. };
  313. static const hda_nid_t stac92hd73xx_smux_nids[2] = {
  314. 0x22, 0x23,
  315. };
  316. #define STAC92HD73XX_NUM_CAPS 2
  317. static const unsigned long stac92hd73xx_capvols[] = {
  318. HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
  319. HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
  320. };
  321. #define stac92hd73xx_capsws stac92hd73xx_capvols
  322. #define STAC92HD83_DAC_COUNT 3
  323. static const hda_nid_t stac92hd83xxx_pwr_nids[7] = {
  324. 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
  325. 0x0f, 0x10
  326. };
  327. static const hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
  328. 0x1e, 0,
  329. };
  330. static const hda_nid_t stac92hd83xxx_dmic_nids[] = {
  331. 0x11, 0x20,
  332. };
  333. static const hda_nid_t stac92hd71bxx_pwr_nids[3] = {
  334. 0x0a, 0x0d, 0x0f
  335. };
  336. static const hda_nid_t stac92hd71bxx_adc_nids[2] = {
  337. 0x12, 0x13,
  338. };
  339. static const hda_nid_t stac92hd71bxx_mux_nids[2] = {
  340. 0x1a, 0x1b
  341. };
  342. static const hda_nid_t stac92hd71bxx_dmux_nids[2] = {
  343. 0x1c, 0x1d,
  344. };
  345. static const hda_nid_t stac92hd71bxx_smux_nids[2] = {
  346. 0x24, 0x25,
  347. };
  348. #define STAC92HD71BXX_NUM_DMICS 2
  349. static const hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
  350. 0x18, 0x19, 0
  351. };
  352. static const hda_nid_t stac92hd71bxx_dmic_5port_nids[STAC92HD71BXX_NUM_DMICS] = {
  353. 0x18, 0
  354. };
  355. static const hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
  356. 0x22, 0
  357. };
  358. #define STAC92HD71BXX_NUM_CAPS 2
  359. static const unsigned long stac92hd71bxx_capvols[] = {
  360. HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
  361. HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
  362. };
  363. #define stac92hd71bxx_capsws stac92hd71bxx_capvols
  364. static const hda_nid_t stac925x_adc_nids[1] = {
  365. 0x03,
  366. };
  367. static const hda_nid_t stac925x_mux_nids[1] = {
  368. 0x0f,
  369. };
  370. static const hda_nid_t stac925x_dac_nids[1] = {
  371. 0x02,
  372. };
  373. #define STAC925X_NUM_DMICS 1
  374. static const hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
  375. 0x15, 0
  376. };
  377. static const hda_nid_t stac925x_dmux_nids[1] = {
  378. 0x14,
  379. };
  380. static const unsigned long stac925x_capvols[] = {
  381. HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
  382. };
  383. static const unsigned long stac925x_capsws[] = {
  384. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
  385. };
  386. static const hda_nid_t stac922x_adc_nids[2] = {
  387. 0x06, 0x07,
  388. };
  389. static const hda_nid_t stac922x_mux_nids[2] = {
  390. 0x12, 0x13,
  391. };
  392. #define STAC922X_NUM_CAPS 2
  393. static const unsigned long stac922x_capvols[] = {
  394. HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
  395. HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
  396. };
  397. #define stac922x_capsws stac922x_capvols
  398. static const hda_nid_t stac927x_slave_dig_outs[2] = {
  399. 0x1f, 0,
  400. };
  401. static const hda_nid_t stac927x_adc_nids[3] = {
  402. 0x07, 0x08, 0x09
  403. };
  404. static const hda_nid_t stac927x_mux_nids[3] = {
  405. 0x15, 0x16, 0x17
  406. };
  407. static const hda_nid_t stac927x_smux_nids[1] = {
  408. 0x21,
  409. };
  410. static const hda_nid_t stac927x_dac_nids[6] = {
  411. 0x02, 0x03, 0x04, 0x05, 0x06, 0
  412. };
  413. static const hda_nid_t stac927x_dmux_nids[1] = {
  414. 0x1b,
  415. };
  416. #define STAC927X_NUM_DMICS 2
  417. static const hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
  418. 0x13, 0x14, 0
  419. };
  420. #define STAC927X_NUM_CAPS 3
  421. static const unsigned long stac927x_capvols[] = {
  422. HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
  423. HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
  424. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
  425. };
  426. static const unsigned long stac927x_capsws[] = {
  427. HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
  428. HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
  429. HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
  430. };
  431. static const char * const stac927x_spdif_labels[5] = {
  432. "Digital Playback", "ADAT", "Analog Mux 1",
  433. "Analog Mux 2", "Analog Mux 3"
  434. };
  435. static const hda_nid_t stac9205_adc_nids[2] = {
  436. 0x12, 0x13
  437. };
  438. static const hda_nid_t stac9205_mux_nids[2] = {
  439. 0x19, 0x1a
  440. };
  441. static const hda_nid_t stac9205_dmux_nids[1] = {
  442. 0x1d,
  443. };
  444. static const hda_nid_t stac9205_smux_nids[1] = {
  445. 0x21,
  446. };
  447. #define STAC9205_NUM_DMICS 2
  448. static const hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
  449. 0x17, 0x18, 0
  450. };
  451. #define STAC9205_NUM_CAPS 2
  452. static const unsigned long stac9205_capvols[] = {
  453. HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
  454. HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
  455. };
  456. static const unsigned long stac9205_capsws[] = {
  457. HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
  458. HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
  459. };
  460. static const hda_nid_t stac9200_pin_nids[8] = {
  461. 0x08, 0x09, 0x0d, 0x0e,
  462. 0x0f, 0x10, 0x11, 0x12,
  463. };
  464. static const hda_nid_t stac925x_pin_nids[8] = {
  465. 0x07, 0x08, 0x0a, 0x0b,
  466. 0x0c, 0x0d, 0x10, 0x11,
  467. };
  468. static const hda_nid_t stac922x_pin_nids[10] = {
  469. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  470. 0x0f, 0x10, 0x11, 0x15, 0x1b,
  471. };
  472. static const hda_nid_t stac92hd73xx_pin_nids[13] = {
  473. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  474. 0x0f, 0x10, 0x11, 0x12, 0x13,
  475. 0x14, 0x22, 0x23
  476. };
  477. #define STAC92HD71BXX_NUM_PINS 13
  478. static const hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
  479. 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
  480. 0x00, 0x14, 0x18, 0x19, 0x1e,
  481. 0x1f, 0x20, 0x27
  482. };
  483. static const hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
  484. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  485. 0x0f, 0x14, 0x18, 0x19, 0x1e,
  486. 0x1f, 0x20, 0x27
  487. };
  488. static const hda_nid_t stac927x_pin_nids[14] = {
  489. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  490. 0x0f, 0x10, 0x11, 0x12, 0x13,
  491. 0x14, 0x21, 0x22, 0x23,
  492. };
  493. static const hda_nid_t stac9205_pin_nids[12] = {
  494. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  495. 0x0f, 0x14, 0x16, 0x17, 0x18,
  496. 0x21, 0x22,
  497. };
  498. static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
  499. struct snd_ctl_elem_info *uinfo)
  500. {
  501. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  502. struct sigmatel_spec *spec = codec->spec;
  503. return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
  504. }
  505. static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
  506. struct snd_ctl_elem_value *ucontrol)
  507. {
  508. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  509. struct sigmatel_spec *spec = codec->spec;
  510. unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  511. ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
  512. return 0;
  513. }
  514. static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
  515. struct snd_ctl_elem_value *ucontrol)
  516. {
  517. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  518. struct sigmatel_spec *spec = codec->spec;
  519. unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  520. return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
  521. spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
  522. }
  523. static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
  524. struct snd_ctl_elem_info *uinfo)
  525. {
  526. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  527. struct sigmatel_spec *spec = codec->spec;
  528. return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
  529. }
  530. static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
  531. struct snd_ctl_elem_value *ucontrol)
  532. {
  533. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  534. struct sigmatel_spec *spec = codec->spec;
  535. unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  536. ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
  537. return 0;
  538. }
  539. static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
  540. struct snd_ctl_elem_value *ucontrol)
  541. {
  542. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  543. struct sigmatel_spec *spec = codec->spec;
  544. struct hda_input_mux *smux = &spec->private_smux;
  545. unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  546. int err, val;
  547. hda_nid_t nid;
  548. err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
  549. spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
  550. if (err < 0)
  551. return err;
  552. if (spec->spdif_mute) {
  553. if (smux_idx == 0)
  554. nid = spec->multiout.dig_out_nid;
  555. else
  556. nid = codec->slave_dig_outs[smux_idx - 1];
  557. if (spec->cur_smux[smux_idx] == smux->num_items - 1)
  558. val = HDA_AMP_MUTE;
  559. else
  560. val = 0;
  561. /* un/mute SPDIF out */
  562. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  563. HDA_AMP_MUTE, val);
  564. }
  565. return 0;
  566. }
  567. static int stac_vrefout_set(struct hda_codec *codec,
  568. hda_nid_t nid, unsigned int new_vref)
  569. {
  570. int error, pinctl;
  571. snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref);
  572. pinctl = snd_hda_codec_read(codec, nid, 0,
  573. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  574. if (pinctl < 0)
  575. return pinctl;
  576. pinctl &= 0xff;
  577. pinctl &= ~AC_PINCTL_VREFEN;
  578. pinctl |= (new_vref & AC_PINCTL_VREFEN);
  579. error = snd_hda_set_pin_ctl_cache(codec, nid, pinctl);
  580. if (error < 0)
  581. return error;
  582. return 1;
  583. }
  584. static unsigned int stac92xx_vref_set(struct hda_codec *codec,
  585. hda_nid_t nid, unsigned int new_vref)
  586. {
  587. int error;
  588. unsigned int pincfg;
  589. pincfg = snd_hda_codec_read(codec, nid, 0,
  590. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  591. pincfg &= 0xff;
  592. pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  593. pincfg |= new_vref;
  594. if (new_vref == AC_PINCTL_VREF_HIZ)
  595. pincfg |= AC_PINCTL_OUT_EN;
  596. else
  597. pincfg |= AC_PINCTL_IN_EN;
  598. error = snd_hda_set_pin_ctl_cache(codec, nid, pincfg);
  599. if (error < 0)
  600. return error;
  601. else
  602. return 1;
  603. }
  604. static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
  605. {
  606. unsigned int vref;
  607. vref = snd_hda_codec_read(codec, nid, 0,
  608. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  609. vref &= AC_PINCTL_VREFEN;
  610. return vref;
  611. }
  612. static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  613. {
  614. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  615. struct sigmatel_spec *spec = codec->spec;
  616. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  617. }
  618. static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  619. {
  620. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  621. struct sigmatel_spec *spec = codec->spec;
  622. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  623. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  624. return 0;
  625. }
  626. static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  627. {
  628. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  629. struct sigmatel_spec *spec = codec->spec;
  630. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  631. const struct hda_input_mux *imux = spec->input_mux;
  632. unsigned int idx, prev_idx, didx;
  633. idx = ucontrol->value.enumerated.item[0];
  634. if (idx >= imux->num_items)
  635. idx = imux->num_items - 1;
  636. prev_idx = spec->cur_mux[adc_idx];
  637. if (prev_idx == idx)
  638. return 0;
  639. if (idx < spec->num_analog_muxes) {
  640. snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
  641. AC_VERB_SET_CONNECT_SEL,
  642. imux->items[idx].index);
  643. if (prev_idx >= spec->num_analog_muxes &&
  644. spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) {
  645. imux = spec->dinput_mux;
  646. /* 0 = analog */
  647. snd_hda_codec_write_cache(codec,
  648. spec->dmux_nids[adc_idx], 0,
  649. AC_VERB_SET_CONNECT_SEL,
  650. imux->items[0].index);
  651. }
  652. } else {
  653. imux = spec->dinput_mux;
  654. /* first dimux item is hardcoded to select analog imux,
  655. * so lets skip it
  656. */
  657. didx = idx - spec->num_analog_muxes + 1;
  658. snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
  659. AC_VERB_SET_CONNECT_SEL,
  660. imux->items[didx].index);
  661. }
  662. spec->cur_mux[adc_idx] = idx;
  663. return 1;
  664. }
  665. static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
  666. struct snd_ctl_elem_info *uinfo)
  667. {
  668. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  669. struct sigmatel_spec *spec = codec->spec;
  670. return snd_hda_input_mux_info(spec->mono_mux, uinfo);
  671. }
  672. static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
  673. struct snd_ctl_elem_value *ucontrol)
  674. {
  675. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  676. struct sigmatel_spec *spec = codec->spec;
  677. ucontrol->value.enumerated.item[0] = spec->cur_mmux;
  678. return 0;
  679. }
  680. static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
  681. struct snd_ctl_elem_value *ucontrol)
  682. {
  683. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  684. struct sigmatel_spec *spec = codec->spec;
  685. return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
  686. spec->mono_nid, &spec->cur_mmux);
  687. }
  688. #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
  689. static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
  690. struct snd_ctl_elem_value *ucontrol)
  691. {
  692. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  693. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  694. struct sigmatel_spec *spec = codec->spec;
  695. ucontrol->value.integer.value[0] = !!(spec->aloopback &
  696. (spec->aloopback_mask << idx));
  697. return 0;
  698. }
  699. static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
  700. struct snd_ctl_elem_value *ucontrol)
  701. {
  702. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  703. struct sigmatel_spec *spec = codec->spec;
  704. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  705. unsigned int dac_mode;
  706. unsigned int val, idx_val;
  707. idx_val = spec->aloopback_mask << idx;
  708. if (ucontrol->value.integer.value[0])
  709. val = spec->aloopback | idx_val;
  710. else
  711. val = spec->aloopback & ~idx_val;
  712. if (spec->aloopback == val)
  713. return 0;
  714. spec->aloopback = val;
  715. /* Only return the bits defined by the shift value of the
  716. * first two bytes of the mask
  717. */
  718. dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
  719. kcontrol->private_value & 0xFFFF, 0x0);
  720. dac_mode >>= spec->aloopback_shift;
  721. if (spec->aloopback & idx_val) {
  722. snd_hda_power_up(codec);
  723. dac_mode |= idx_val;
  724. } else {
  725. snd_hda_power_down(codec);
  726. dac_mode &= ~idx_val;
  727. }
  728. snd_hda_codec_write_cache(codec, codec->afg, 0,
  729. kcontrol->private_value >> 16, dac_mode);
  730. return 1;
  731. }
  732. static const struct hda_verb stac9200_core_init[] = {
  733. /* set dac0mux for dac converter */
  734. { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  735. {}
  736. };
  737. static const struct hda_verb stac9200_eapd_init[] = {
  738. /* set dac0mux for dac converter */
  739. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  740. {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  741. {}
  742. };
  743. static const struct hda_verb dell_eq_core_init[] = {
  744. /* set master volume to max value without distortion
  745. * and direct control */
  746. { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
  747. {}
  748. };
  749. static const struct hda_verb stac92hd73xx_core_init[] = {
  750. /* set master volume and direct control */
  751. { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  752. {}
  753. };
  754. static const struct hda_verb stac92hd83xxx_core_init[] = {
  755. /* power state controls amps */
  756. { 0x01, AC_VERB_SET_EAPD, 1 << 2},
  757. {}
  758. };
  759. static const struct hda_verb stac92hd83xxx_hp_zephyr_init[] = {
  760. { 0x22, 0x785, 0x43 },
  761. { 0x22, 0x782, 0xe0 },
  762. { 0x22, 0x795, 0x00 },
  763. {}
  764. };
  765. static const struct hda_verb stac92hd71bxx_core_init[] = {
  766. /* set master volume and direct control */
  767. { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  768. {}
  769. };
  770. static const struct hda_verb stac92hd71bxx_unmute_core_init[] = {
  771. /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
  772. { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  773. { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  774. { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  775. {}
  776. };
  777. static const struct hda_verb stac925x_core_init[] = {
  778. /* set dac0mux for dac converter */
  779. { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
  780. /* mute the master volume */
  781. { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  782. {}
  783. };
  784. static const struct hda_verb stac922x_core_init[] = {
  785. /* set master volume and direct control */
  786. { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  787. {}
  788. };
  789. static const struct hda_verb d965_core_init[] = {
  790. /* set master volume and direct control */
  791. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  792. /* unmute node 0x1b */
  793. { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  794. /* select node 0x03 as DAC */
  795. { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
  796. {}
  797. };
  798. static const struct hda_verb dell_3st_core_init[] = {
  799. /* don't set delta bit */
  800. {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
  801. /* unmute node 0x1b */
  802. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  803. /* select node 0x03 as DAC */
  804. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
  805. {}
  806. };
  807. static const struct hda_verb stac927x_core_init[] = {
  808. /* set master volume and direct control */
  809. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  810. /* enable analog pc beep path */
  811. { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
  812. {}
  813. };
  814. static const struct hda_verb stac927x_volknob_core_init[] = {
  815. /* don't set delta bit */
  816. {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
  817. /* enable analog pc beep path */
  818. {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
  819. {}
  820. };
  821. static const struct hda_verb stac9205_core_init[] = {
  822. /* set master volume and direct control */
  823. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  824. /* enable analog pc beep path */
  825. { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
  826. {}
  827. };
  828. #define STAC_MONO_MUX \
  829. { \
  830. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  831. .name = "Mono Mux", \
  832. .count = 1, \
  833. .info = stac92xx_mono_mux_enum_info, \
  834. .get = stac92xx_mono_mux_enum_get, \
  835. .put = stac92xx_mono_mux_enum_put, \
  836. }
  837. #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
  838. { \
  839. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  840. .name = "Analog Loopback", \
  841. .count = cnt, \
  842. .info = stac92xx_aloopback_info, \
  843. .get = stac92xx_aloopback_get, \
  844. .put = stac92xx_aloopback_put, \
  845. .private_value = verb_read | (verb_write << 16), \
  846. }
  847. #define DC_BIAS(xname, idx, nid) \
  848. { \
  849. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  850. .name = xname, \
  851. .index = idx, \
  852. .info = stac92xx_dc_bias_info, \
  853. .get = stac92xx_dc_bias_get, \
  854. .put = stac92xx_dc_bias_put, \
  855. .private_value = nid, \
  856. }
  857. static const struct snd_kcontrol_new stac9200_mixer[] = {
  858. HDA_CODEC_VOLUME_MIN_MUTE("PCM Playback Volume", 0xb, 0, HDA_OUTPUT),
  859. HDA_CODEC_MUTE("PCM Playback Switch", 0xb, 0, HDA_OUTPUT),
  860. HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
  861. HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
  862. { } /* end */
  863. };
  864. static const struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
  865. STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
  866. {}
  867. };
  868. static const struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
  869. STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
  870. {}
  871. };
  872. static const struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
  873. STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
  874. {}
  875. };
  876. static const struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
  877. STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
  878. };
  879. static const struct snd_kcontrol_new stac925x_mixer[] = {
  880. HDA_CODEC_VOLUME_MIN_MUTE("PCM Playback Volume", 0xe, 0, HDA_OUTPUT),
  881. HDA_CODEC_MUTE("PCM Playback Switch", 0x0e, 0, HDA_OUTPUT),
  882. { } /* end */
  883. };
  884. static const struct snd_kcontrol_new stac9205_loopback[] = {
  885. STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
  886. {}
  887. };
  888. static const struct snd_kcontrol_new stac927x_loopback[] = {
  889. STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
  890. {}
  891. };
  892. static struct snd_kcontrol_new stac_dmux_mixer = {
  893. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  894. .name = "Digital Input Source",
  895. /* count set later */
  896. .info = stac92xx_dmux_enum_info,
  897. .get = stac92xx_dmux_enum_get,
  898. .put = stac92xx_dmux_enum_put,
  899. };
  900. static struct snd_kcontrol_new stac_smux_mixer = {
  901. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  902. .name = "IEC958 Playback Source",
  903. /* count set later */
  904. .info = stac92xx_smux_enum_info,
  905. .get = stac92xx_smux_enum_get,
  906. .put = stac92xx_smux_enum_put,
  907. };
  908. static const char * const slave_pfxs[] = {
  909. "Front", "Surround", "Center", "LFE", "Side",
  910. "Headphone", "Speaker", "IEC958",
  911. NULL
  912. };
  913. static void stac92xx_update_led_status(struct hda_codec *codec, int enabled);
  914. static void stac92xx_vmaster_hook(void *private_data, int val)
  915. {
  916. stac92xx_update_led_status(private_data, val);
  917. }
  918. static void stac92xx_free_kctls(struct hda_codec *codec);
  919. static int stac92xx_build_controls(struct hda_codec *codec)
  920. {
  921. struct sigmatel_spec *spec = codec->spec;
  922. unsigned int vmaster_tlv[4];
  923. int err;
  924. int i;
  925. if (spec->mixer) {
  926. err = snd_hda_add_new_ctls(codec, spec->mixer);
  927. if (err < 0)
  928. return err;
  929. }
  930. for (i = 0; i < spec->num_mixers; i++) {
  931. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  932. if (err < 0)
  933. return err;
  934. }
  935. if (!spec->auto_mic && spec->num_dmuxes > 0 &&
  936. snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
  937. stac_dmux_mixer.count = spec->num_dmuxes;
  938. err = snd_hda_ctl_add(codec, 0,
  939. snd_ctl_new1(&stac_dmux_mixer, codec));
  940. if (err < 0)
  941. return err;
  942. }
  943. if (spec->num_smuxes > 0) {
  944. int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
  945. struct hda_input_mux *smux = &spec->private_smux;
  946. /* check for mute support on SPDIF out */
  947. if (wcaps & AC_WCAP_OUT_AMP) {
  948. snd_hda_add_imux_item(smux, "Off", 0, NULL);
  949. spec->spdif_mute = 1;
  950. }
  951. stac_smux_mixer.count = spec->num_smuxes;
  952. err = snd_hda_ctl_add(codec, 0,
  953. snd_ctl_new1(&stac_smux_mixer, codec));
  954. if (err < 0)
  955. return err;
  956. }
  957. if (spec->multiout.dig_out_nid) {
  958. err = snd_hda_create_spdif_out_ctls(codec,
  959. spec->multiout.dig_out_nid,
  960. spec->multiout.dig_out_nid);
  961. if (err < 0)
  962. return err;
  963. err = snd_hda_create_spdif_share_sw(codec,
  964. &spec->multiout);
  965. if (err < 0)
  966. return err;
  967. spec->multiout.share_spdif = 1;
  968. }
  969. if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
  970. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  971. if (err < 0)
  972. return err;
  973. }
  974. /* if we have no master control, let's create it */
  975. snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
  976. HDA_OUTPUT, vmaster_tlv);
  977. /* correct volume offset */
  978. vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
  979. /* minimum value is actually mute */
  980. vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
  981. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  982. vmaster_tlv, slave_pfxs,
  983. "Playback Volume");
  984. if (err < 0)
  985. return err;
  986. err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
  987. NULL, slave_pfxs,
  988. "Playback Switch", true,
  989. &spec->vmaster_mute.sw_kctl);
  990. if (err < 0)
  991. return err;
  992. if (spec->gpio_led) {
  993. spec->vmaster_mute.hook = stac92xx_vmaster_hook;
  994. err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
  995. if (err < 0)
  996. return err;
  997. }
  998. if (spec->aloopback_ctl &&
  999. snd_hda_get_bool_hint(codec, "loopback") == 1) {
  1000. err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
  1001. if (err < 0)
  1002. return err;
  1003. }
  1004. stac92xx_free_kctls(codec); /* no longer needed */
  1005. err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
  1006. if (err < 0)
  1007. return err;
  1008. return 0;
  1009. }
  1010. static const unsigned int ref9200_pin_configs[8] = {
  1011. 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
  1012. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  1013. };
  1014. static const unsigned int gateway9200_m4_pin_configs[8] = {
  1015. 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
  1016. 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
  1017. };
  1018. static const unsigned int gateway9200_m4_2_pin_configs[8] = {
  1019. 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
  1020. 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
  1021. };
  1022. /*
  1023. STAC 9200 pin configs for
  1024. 102801A8
  1025. 102801DE
  1026. 102801E8
  1027. */
  1028. static const unsigned int dell9200_d21_pin_configs[8] = {
  1029. 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
  1030. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  1031. };
  1032. /*
  1033. STAC 9200 pin configs for
  1034. 102801C0
  1035. 102801C1
  1036. */
  1037. static const unsigned int dell9200_d22_pin_configs[8] = {
  1038. 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
  1039. 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
  1040. };
  1041. /*
  1042. STAC 9200 pin configs for
  1043. 102801C4 (Dell Dimension E310)
  1044. 102801C5
  1045. 102801C7
  1046. 102801D9
  1047. 102801DA
  1048. 102801E3
  1049. */
  1050. static const unsigned int dell9200_d23_pin_configs[8] = {
  1051. 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
  1052. 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
  1053. };
  1054. /*
  1055. STAC 9200-32 pin configs for
  1056. 102801B5 (Dell Inspiron 630m)
  1057. 102801D8 (Dell Inspiron 640m)
  1058. */
  1059. static const unsigned int dell9200_m21_pin_configs[8] = {
  1060. 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
  1061. 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
  1062. };
  1063. /*
  1064. STAC 9200-32 pin configs for
  1065. 102801C2 (Dell Latitude D620)
  1066. 102801C8
  1067. 102801CC (Dell Latitude D820)
  1068. 102801D4
  1069. 102801D6
  1070. */
  1071. static const unsigned int dell9200_m22_pin_configs[8] = {
  1072. 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
  1073. 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
  1074. };
  1075. /*
  1076. STAC 9200-32 pin configs for
  1077. 102801CE (Dell XPS M1710)
  1078. 102801CF (Dell Precision M90)
  1079. */
  1080. static const unsigned int dell9200_m23_pin_configs[8] = {
  1081. 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
  1082. 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
  1083. };
  1084. /*
  1085. STAC 9200-32 pin configs for
  1086. 102801C9
  1087. 102801CA
  1088. 102801CB (Dell Latitude 120L)
  1089. 102801D3
  1090. */
  1091. static const unsigned int dell9200_m24_pin_configs[8] = {
  1092. 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
  1093. 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
  1094. };
  1095. /*
  1096. STAC 9200-32 pin configs for
  1097. 102801BD (Dell Inspiron E1505n)
  1098. 102801EE
  1099. 102801EF
  1100. */
  1101. static const unsigned int dell9200_m25_pin_configs[8] = {
  1102. 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
  1103. 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
  1104. };
  1105. /*
  1106. STAC 9200-32 pin configs for
  1107. 102801F5 (Dell Inspiron 1501)
  1108. 102801F6
  1109. */
  1110. static const unsigned int dell9200_m26_pin_configs[8] = {
  1111. 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
  1112. 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
  1113. };
  1114. /*
  1115. STAC 9200-32
  1116. 102801CD (Dell Inspiron E1705/9400)
  1117. */
  1118. static const unsigned int dell9200_m27_pin_configs[8] = {
  1119. 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
  1120. 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
  1121. };
  1122. static const unsigned int oqo9200_pin_configs[8] = {
  1123. 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
  1124. 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
  1125. };
  1126. static const unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
  1127. [STAC_REF] = ref9200_pin_configs,
  1128. [STAC_9200_OQO] = oqo9200_pin_configs,
  1129. [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
  1130. [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
  1131. [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
  1132. [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
  1133. [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
  1134. [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
  1135. [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
  1136. [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
  1137. [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
  1138. [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
  1139. [STAC_9200_M4] = gateway9200_m4_pin_configs,
  1140. [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
  1141. [STAC_9200_PANASONIC] = ref9200_pin_configs,
  1142. };
  1143. static const char * const stac9200_models[STAC_9200_MODELS] = {
  1144. [STAC_AUTO] = "auto",
  1145. [STAC_REF] = "ref",
  1146. [STAC_9200_OQO] = "oqo",
  1147. [STAC_9200_DELL_D21] = "dell-d21",
  1148. [STAC_9200_DELL_D22] = "dell-d22",
  1149. [STAC_9200_DELL_D23] = "dell-d23",
  1150. [STAC_9200_DELL_M21] = "dell-m21",
  1151. [STAC_9200_DELL_M22] = "dell-m22",
  1152. [STAC_9200_DELL_M23] = "dell-m23",
  1153. [STAC_9200_DELL_M24] = "dell-m24",
  1154. [STAC_9200_DELL_M25] = "dell-m25",
  1155. [STAC_9200_DELL_M26] = "dell-m26",
  1156. [STAC_9200_DELL_M27] = "dell-m27",
  1157. [STAC_9200_M4] = "gateway-m4",
  1158. [STAC_9200_M4_2] = "gateway-m4-2",
  1159. [STAC_9200_PANASONIC] = "panasonic",
  1160. };
  1161. static const struct snd_pci_quirk stac9200_cfg_tbl[] = {
  1162. /* SigmaTel reference board */
  1163. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1164. "DFI LanParty", STAC_REF),
  1165. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1166. "DFI LanParty", STAC_REF),
  1167. /* Dell laptops have BIOS problem */
  1168. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
  1169. "unknown Dell", STAC_9200_DELL_D21),
  1170. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
  1171. "Dell Inspiron 630m", STAC_9200_DELL_M21),
  1172. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
  1173. "Dell Inspiron E1505n", STAC_9200_DELL_M25),
  1174. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
  1175. "unknown Dell", STAC_9200_DELL_D22),
  1176. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
  1177. "unknown Dell", STAC_9200_DELL_D22),
  1178. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
  1179. "Dell Latitude D620", STAC_9200_DELL_M22),
  1180. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
  1181. "unknown Dell", STAC_9200_DELL_D23),
  1182. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
  1183. "unknown Dell", STAC_9200_DELL_D23),
  1184. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
  1185. "unknown Dell", STAC_9200_DELL_M22),
  1186. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
  1187. "unknown Dell", STAC_9200_DELL_M24),
  1188. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
  1189. "unknown Dell", STAC_9200_DELL_M24),
  1190. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
  1191. "Dell Latitude 120L", STAC_9200_DELL_M24),
  1192. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
  1193. "Dell Latitude D820", STAC_9200_DELL_M22),
  1194. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
  1195. "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
  1196. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
  1197. "Dell XPS M1710", STAC_9200_DELL_M23),
  1198. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
  1199. "Dell Precision M90", STAC_9200_DELL_M23),
  1200. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
  1201. "unknown Dell", STAC_9200_DELL_M22),
  1202. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
  1203. "unknown Dell", STAC_9200_DELL_M22),
  1204. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
  1205. "unknown Dell", STAC_9200_DELL_M22),
  1206. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
  1207. "Dell Inspiron 640m", STAC_9200_DELL_M21),
  1208. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
  1209. "unknown Dell", STAC_9200_DELL_D23),
  1210. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
  1211. "unknown Dell", STAC_9200_DELL_D23),
  1212. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
  1213. "unknown Dell", STAC_9200_DELL_D21),
  1214. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
  1215. "unknown Dell", STAC_9200_DELL_D23),
  1216. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
  1217. "unknown Dell", STAC_9200_DELL_D21),
  1218. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
  1219. "unknown Dell", STAC_9200_DELL_M25),
  1220. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
  1221. "unknown Dell", STAC_9200_DELL_M25),
  1222. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
  1223. "Dell Inspiron 1501", STAC_9200_DELL_M26),
  1224. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
  1225. "unknown Dell", STAC_9200_DELL_M26),
  1226. /* Panasonic */
  1227. SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
  1228. /* Gateway machines needs EAPD to be set on resume */
  1229. SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
  1230. SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
  1231. SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
  1232. /* OQO Mobile */
  1233. SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
  1234. {} /* terminator */
  1235. };
  1236. static const unsigned int ref925x_pin_configs[8] = {
  1237. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  1238. 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
  1239. };
  1240. static const unsigned int stac925xM1_pin_configs[8] = {
  1241. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1242. 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
  1243. };
  1244. static const unsigned int stac925xM1_2_pin_configs[8] = {
  1245. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1246. 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
  1247. };
  1248. static const unsigned int stac925xM2_pin_configs[8] = {
  1249. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1250. 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
  1251. };
  1252. static const unsigned int stac925xM2_2_pin_configs[8] = {
  1253. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1254. 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
  1255. };
  1256. static const unsigned int stac925xM3_pin_configs[8] = {
  1257. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1258. 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
  1259. };
  1260. static const unsigned int stac925xM5_pin_configs[8] = {
  1261. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1262. 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
  1263. };
  1264. static const unsigned int stac925xM6_pin_configs[8] = {
  1265. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1266. 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
  1267. };
  1268. static const unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
  1269. [STAC_REF] = ref925x_pin_configs,
  1270. [STAC_M1] = stac925xM1_pin_configs,
  1271. [STAC_M1_2] = stac925xM1_2_pin_configs,
  1272. [STAC_M2] = stac925xM2_pin_configs,
  1273. [STAC_M2_2] = stac925xM2_2_pin_configs,
  1274. [STAC_M3] = stac925xM3_pin_configs,
  1275. [STAC_M5] = stac925xM5_pin_configs,
  1276. [STAC_M6] = stac925xM6_pin_configs,
  1277. };
  1278. static const char * const stac925x_models[STAC_925x_MODELS] = {
  1279. [STAC_925x_AUTO] = "auto",
  1280. [STAC_REF] = "ref",
  1281. [STAC_M1] = "m1",
  1282. [STAC_M1_2] = "m1-2",
  1283. [STAC_M2] = "m2",
  1284. [STAC_M2_2] = "m2-2",
  1285. [STAC_M3] = "m3",
  1286. [STAC_M5] = "m5",
  1287. [STAC_M6] = "m6",
  1288. };
  1289. static const struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
  1290. SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
  1291. SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
  1292. SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
  1293. SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
  1294. SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
  1295. /* Not sure about the brand name for those */
  1296. SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
  1297. SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
  1298. SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
  1299. SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
  1300. {} /* terminator */
  1301. };
  1302. static const struct snd_pci_quirk stac925x_cfg_tbl[] = {
  1303. /* SigmaTel reference board */
  1304. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
  1305. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
  1306. SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
  1307. /* Default table for unknown ID */
  1308. SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
  1309. {} /* terminator */
  1310. };
  1311. static const unsigned int ref92hd73xx_pin_configs[13] = {
  1312. 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
  1313. 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
  1314. 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
  1315. 0x01452050,
  1316. };
  1317. static const unsigned int dell_m6_pin_configs[13] = {
  1318. 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
  1319. 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
  1320. 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
  1321. 0x4f0000f0,
  1322. };
  1323. static const unsigned int alienware_m17x_pin_configs[13] = {
  1324. 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
  1325. 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
  1326. 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
  1327. 0x904601b0,
  1328. };
  1329. static const unsigned int intel_dg45id_pin_configs[13] = {
  1330. 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
  1331. 0x01A19250, 0x01011212, 0x01016211
  1332. };
  1333. static const unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
  1334. [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
  1335. [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
  1336. [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
  1337. [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
  1338. [STAC_DELL_EQ] = dell_m6_pin_configs,
  1339. [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
  1340. [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
  1341. };
  1342. static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
  1343. [STAC_92HD73XX_AUTO] = "auto",
  1344. [STAC_92HD73XX_NO_JD] = "no-jd",
  1345. [STAC_92HD73XX_REF] = "ref",
  1346. [STAC_92HD73XX_INTEL] = "intel",
  1347. [STAC_DELL_M6_AMIC] = "dell-m6-amic",
  1348. [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
  1349. [STAC_DELL_M6_BOTH] = "dell-m6",
  1350. [STAC_DELL_EQ] = "dell-eq",
  1351. [STAC_ALIENWARE_M17X] = "alienware",
  1352. };
  1353. static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
  1354. /* SigmaTel reference board */
  1355. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1356. "DFI LanParty", STAC_92HD73XX_REF),
  1357. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1358. "DFI LanParty", STAC_92HD73XX_REF),
  1359. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
  1360. "Intel DG45ID", STAC_92HD73XX_INTEL),
  1361. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
  1362. "Intel DG45FC", STAC_92HD73XX_INTEL),
  1363. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
  1364. "Dell Studio 1535", STAC_DELL_M6_DMIC),
  1365. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
  1366. "unknown Dell", STAC_DELL_M6_DMIC),
  1367. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
  1368. "unknown Dell", STAC_DELL_M6_BOTH),
  1369. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
  1370. "unknown Dell", STAC_DELL_M6_BOTH),
  1371. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
  1372. "unknown Dell", STAC_DELL_M6_AMIC),
  1373. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
  1374. "unknown Dell", STAC_DELL_M6_AMIC),
  1375. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
  1376. "unknown Dell", STAC_DELL_M6_DMIC),
  1377. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
  1378. "unknown Dell", STAC_DELL_M6_DMIC),
  1379. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
  1380. "Dell Studio 1537", STAC_DELL_M6_DMIC),
  1381. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
  1382. "Dell Studio 17", STAC_DELL_M6_DMIC),
  1383. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
  1384. "Dell Studio 1555", STAC_DELL_M6_DMIC),
  1385. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
  1386. "Dell Studio 1557", STAC_DELL_M6_DMIC),
  1387. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
  1388. "Dell Studio XPS 1645", STAC_DELL_M6_DMIC),
  1389. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
  1390. "Dell Studio 1558", STAC_DELL_M6_DMIC),
  1391. {} /* terminator */
  1392. };
  1393. static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
  1394. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
  1395. "Alienware M17x", STAC_ALIENWARE_M17X),
  1396. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
  1397. "Alienware M17x", STAC_ALIENWARE_M17X),
  1398. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0490,
  1399. "Alienware M17x R3", STAC_DELL_EQ),
  1400. {} /* terminator */
  1401. };
  1402. static const unsigned int ref92hd83xxx_pin_configs[10] = {
  1403. 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
  1404. 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
  1405. 0x01451160, 0x98560170,
  1406. };
  1407. static const unsigned int dell_s14_pin_configs[10] = {
  1408. 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
  1409. 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
  1410. 0x40f000f0, 0x40f000f0,
  1411. };
  1412. static const unsigned int dell_vostro_3500_pin_configs[10] = {
  1413. 0x02a11020, 0x0221101f, 0x400000f0, 0x90170110,
  1414. 0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160,
  1415. 0x400000f4, 0x400000f5,
  1416. };
  1417. static const unsigned int hp_dv7_4000_pin_configs[10] = {
  1418. 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
  1419. 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
  1420. 0x40f000f0, 0x40f000f0,
  1421. };
  1422. static const unsigned int hp_zephyr_pin_configs[10] = {
  1423. 0x01813050, 0x0421201f, 0x04a1205e, 0x96130310,
  1424. 0x96130310, 0x0101401f, 0x1111611f, 0xd5a30130,
  1425. 0, 0,
  1426. };
  1427. static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
  1428. 0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
  1429. 0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
  1430. 0x40f000f0, 0x40f000f0,
  1431. };
  1432. static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
  1433. [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
  1434. [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
  1435. [STAC_DELL_S14] = dell_s14_pin_configs,
  1436. [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs,
  1437. [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
  1438. [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
  1439. [STAC_HP_ZEPHYR] = hp_zephyr_pin_configs,
  1440. };
  1441. static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
  1442. [STAC_92HD83XXX_AUTO] = "auto",
  1443. [STAC_92HD83XXX_REF] = "ref",
  1444. [STAC_92HD83XXX_PWR_REF] = "mic-ref",
  1445. [STAC_DELL_S14] = "dell-s14",
  1446. [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500",
  1447. [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
  1448. [STAC_HP_DV7_4000] = "hp-dv7-4000",
  1449. [STAC_HP_ZEPHYR] = "hp-zephyr",
  1450. };
  1451. static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
  1452. /* SigmaTel reference board */
  1453. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1454. "DFI LanParty", STAC_92HD83XXX_REF),
  1455. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1456. "DFI LanParty", STAC_92HD83XXX_REF),
  1457. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
  1458. "unknown Dell", STAC_DELL_S14),
  1459. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x1028,
  1460. "Dell Vostro 3500", STAC_DELL_VOSTRO_3500),
  1461. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
  1462. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1463. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
  1464. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1465. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
  1466. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1467. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
  1468. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1469. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
  1470. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1471. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
  1472. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1473. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
  1474. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1475. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
  1476. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1477. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
  1478. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1479. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
  1480. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1481. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
  1482. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1483. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
  1484. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1485. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
  1486. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1487. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
  1488. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1489. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
  1490. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1491. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
  1492. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1493. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
  1494. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1495. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
  1496. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1497. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
  1498. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1499. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
  1500. "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
  1501. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3561,
  1502. "HP", STAC_HP_ZEPHYR),
  1503. {} /* terminator */
  1504. };
  1505. static const struct snd_pci_quirk stac92hd83xxx_codec_id_cfg_tbl[] = {
  1506. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3561,
  1507. "HP", STAC_HP_ZEPHYR),
  1508. {} /* terminator */
  1509. };
  1510. static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
  1511. 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
  1512. 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
  1513. 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
  1514. 0x00000000
  1515. };
  1516. static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
  1517. 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
  1518. 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
  1519. 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
  1520. 0x00000000
  1521. };
  1522. static const unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
  1523. 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
  1524. 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
  1525. 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
  1526. 0x00000000
  1527. };
  1528. static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
  1529. 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
  1530. 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
  1531. 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
  1532. 0x00000000
  1533. };
  1534. static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
  1535. [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
  1536. [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
  1537. [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
  1538. [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
  1539. [STAC_HP_M4] = NULL,
  1540. [STAC_HP_DV4] = NULL,
  1541. [STAC_HP_DV5] = NULL,
  1542. [STAC_HP_HDX] = NULL,
  1543. [STAC_HP_DV4_1222NR] = NULL,
  1544. };
  1545. static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
  1546. [STAC_92HD71BXX_AUTO] = "auto",
  1547. [STAC_92HD71BXX_REF] = "ref",
  1548. [STAC_DELL_M4_1] = "dell-m4-1",
  1549. [STAC_DELL_M4_2] = "dell-m4-2",
  1550. [STAC_DELL_M4_3] = "dell-m4-3",
  1551. [STAC_HP_M4] = "hp-m4",
  1552. [STAC_HP_DV4] = "hp-dv4",
  1553. [STAC_HP_DV5] = "hp-dv5",
  1554. [STAC_HP_HDX] = "hp-hdx",
  1555. [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
  1556. };
  1557. static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
  1558. /* SigmaTel reference board */
  1559. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1560. "DFI LanParty", STAC_92HD71BXX_REF),
  1561. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1562. "DFI LanParty", STAC_92HD71BXX_REF),
  1563. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
  1564. "HP dv4-1222nr", STAC_HP_DV4_1222NR),
  1565. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
  1566. "HP", STAC_HP_DV5),
  1567. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
  1568. "HP", STAC_HP_DV5),
  1569. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
  1570. "HP dv4-7", STAC_HP_DV4),
  1571. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
  1572. "HP dv4-7", STAC_HP_DV5),
  1573. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
  1574. "HP HDX", STAC_HP_HDX), /* HDX18 */
  1575. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
  1576. "HP mini 1000", STAC_HP_M4),
  1577. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
  1578. "HP HDX", STAC_HP_HDX), /* HDX16 */
  1579. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
  1580. "HP dv6", STAC_HP_DV5),
  1581. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
  1582. "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
  1583. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
  1584. "HP DV6", STAC_HP_DV5),
  1585. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
  1586. "HP", STAC_HP_DV5),
  1587. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
  1588. "unknown Dell", STAC_DELL_M4_1),
  1589. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
  1590. "unknown Dell", STAC_DELL_M4_1),
  1591. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
  1592. "unknown Dell", STAC_DELL_M4_1),
  1593. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
  1594. "unknown Dell", STAC_DELL_M4_1),
  1595. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
  1596. "unknown Dell", STAC_DELL_M4_1),
  1597. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
  1598. "unknown Dell", STAC_DELL_M4_1),
  1599. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
  1600. "unknown Dell", STAC_DELL_M4_1),
  1601. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
  1602. "unknown Dell", STAC_DELL_M4_2),
  1603. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
  1604. "unknown Dell", STAC_DELL_M4_2),
  1605. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
  1606. "unknown Dell", STAC_DELL_M4_2),
  1607. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
  1608. "unknown Dell", STAC_DELL_M4_2),
  1609. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
  1610. "unknown Dell", STAC_DELL_M4_3),
  1611. {} /* terminator */
  1612. };
  1613. static const unsigned int ref922x_pin_configs[10] = {
  1614. 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
  1615. 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
  1616. 0x40000100, 0x40000100,
  1617. };
  1618. /*
  1619. STAC 922X pin configs for
  1620. 102801A7
  1621. 102801AB
  1622. 102801A9
  1623. 102801D1
  1624. 102801D2
  1625. */
  1626. static const unsigned int dell_922x_d81_pin_configs[10] = {
  1627. 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
  1628. 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
  1629. 0x01813122, 0x400001f2,
  1630. };
  1631. /*
  1632. STAC 922X pin configs for
  1633. 102801AC
  1634. 102801D0
  1635. */
  1636. static const unsigned int dell_922x_d82_pin_configs[10] = {
  1637. 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
  1638. 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
  1639. 0x01813122, 0x400001f1,
  1640. };
  1641. /*
  1642. STAC 922X pin configs for
  1643. 102801BF
  1644. */
  1645. static const unsigned int dell_922x_m81_pin_configs[10] = {
  1646. 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
  1647. 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
  1648. 0x40C003f1, 0x405003f0,
  1649. };
  1650. /*
  1651. STAC 9221 A1 pin configs for
  1652. 102801D7 (Dell XPS M1210)
  1653. */
  1654. static const unsigned int dell_922x_m82_pin_configs[10] = {
  1655. 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
  1656. 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
  1657. 0x508003f3, 0x405003f4,
  1658. };
  1659. static const unsigned int d945gtp3_pin_configs[10] = {
  1660. 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
  1661. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  1662. 0x02a19120, 0x40000100,
  1663. };
  1664. static const unsigned int d945gtp5_pin_configs[10] = {
  1665. 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
  1666. 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
  1667. 0x02a19320, 0x40000100,
  1668. };
  1669. static const unsigned int intel_mac_v1_pin_configs[10] = {
  1670. 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
  1671. 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
  1672. 0x400000fc, 0x400000fb,
  1673. };
  1674. static const unsigned int intel_mac_v2_pin_configs[10] = {
  1675. 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
  1676. 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
  1677. 0x400000fc, 0x400000fb,
  1678. };
  1679. static const unsigned int intel_mac_v3_pin_configs[10] = {
  1680. 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
  1681. 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
  1682. 0x400000fc, 0x400000fb,
  1683. };
  1684. static const unsigned int intel_mac_v4_pin_configs[10] = {
  1685. 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
  1686. 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
  1687. 0x400000fc, 0x400000fb,
  1688. };
  1689. static const unsigned int intel_mac_v5_pin_configs[10] = {
  1690. 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
  1691. 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
  1692. 0x400000fc, 0x400000fb,
  1693. };
  1694. static const unsigned int ecs202_pin_configs[10] = {
  1695. 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
  1696. 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
  1697. 0x9037012e, 0x40e000f2,
  1698. };
  1699. static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
  1700. [STAC_D945_REF] = ref922x_pin_configs,
  1701. [STAC_D945GTP3] = d945gtp3_pin_configs,
  1702. [STAC_D945GTP5] = d945gtp5_pin_configs,
  1703. [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
  1704. [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
  1705. [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
  1706. [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
  1707. [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
  1708. [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
  1709. /* for backward compatibility */
  1710. [STAC_MACMINI] = intel_mac_v3_pin_configs,
  1711. [STAC_MACBOOK] = intel_mac_v5_pin_configs,
  1712. [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
  1713. [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
  1714. [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
  1715. [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
  1716. [STAC_ECS_202] = ecs202_pin_configs,
  1717. [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
  1718. [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
  1719. [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
  1720. [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
  1721. };
  1722. static const char * const stac922x_models[STAC_922X_MODELS] = {
  1723. [STAC_922X_AUTO] = "auto",
  1724. [STAC_D945_REF] = "ref",
  1725. [STAC_D945GTP5] = "5stack",
  1726. [STAC_D945GTP3] = "3stack",
  1727. [STAC_INTEL_MAC_V1] = "intel-mac-v1",
  1728. [STAC_INTEL_MAC_V2] = "intel-mac-v2",
  1729. [STAC_INTEL_MAC_V3] = "intel-mac-v3",
  1730. [STAC_INTEL_MAC_V4] = "intel-mac-v4",
  1731. [STAC_INTEL_MAC_V5] = "intel-mac-v5",
  1732. [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
  1733. /* for backward compatibility */
  1734. [STAC_MACMINI] = "macmini",
  1735. [STAC_MACBOOK] = "macbook",
  1736. [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
  1737. [STAC_MACBOOK_PRO_V2] = "macbook-pro",
  1738. [STAC_IMAC_INTEL] = "imac-intel",
  1739. [STAC_IMAC_INTEL_20] = "imac-intel-20",
  1740. [STAC_ECS_202] = "ecs202",
  1741. [STAC_922X_DELL_D81] = "dell-d81",
  1742. [STAC_922X_DELL_D82] = "dell-d82",
  1743. [STAC_922X_DELL_M81] = "dell-m81",
  1744. [STAC_922X_DELL_M82] = "dell-m82",
  1745. };
  1746. static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
  1747. /* SigmaTel reference board */
  1748. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1749. "DFI LanParty", STAC_D945_REF),
  1750. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1751. "DFI LanParty", STAC_D945_REF),
  1752. /* Intel 945G based systems */
  1753. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
  1754. "Intel D945G", STAC_D945GTP3),
  1755. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
  1756. "Intel D945G", STAC_D945GTP3),
  1757. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
  1758. "Intel D945G", STAC_D945GTP3),
  1759. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
  1760. "Intel D945G", STAC_D945GTP3),
  1761. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
  1762. "Intel D945G", STAC_D945GTP3),
  1763. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
  1764. "Intel D945G", STAC_D945GTP3),
  1765. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
  1766. "Intel D945G", STAC_D945GTP3),
  1767. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
  1768. "Intel D945G", STAC_D945GTP3),
  1769. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
  1770. "Intel D945G", STAC_D945GTP3),
  1771. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
  1772. "Intel D945G", STAC_D945GTP3),
  1773. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
  1774. "Intel D945G", STAC_D945GTP3),
  1775. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
  1776. "Intel D945G", STAC_D945GTP3),
  1777. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
  1778. "Intel D945G", STAC_D945GTP3),
  1779. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
  1780. "Intel D945G", STAC_D945GTP3),
  1781. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
  1782. "Intel D945G", STAC_D945GTP3),
  1783. /* Intel D945G 5-stack systems */
  1784. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
  1785. "Intel D945G", STAC_D945GTP5),
  1786. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
  1787. "Intel D945G", STAC_D945GTP5),
  1788. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
  1789. "Intel D945G", STAC_D945GTP5),
  1790. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
  1791. "Intel D945G", STAC_D945GTP5),
  1792. /* Intel 945P based systems */
  1793. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
  1794. "Intel D945P", STAC_D945GTP3),
  1795. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
  1796. "Intel D945P", STAC_D945GTP3),
  1797. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
  1798. "Intel D945P", STAC_D945GTP3),
  1799. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
  1800. "Intel D945P", STAC_D945GTP3),
  1801. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
  1802. "Intel D945P", STAC_D945GTP3),
  1803. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
  1804. "Intel D945P", STAC_D945GTP5),
  1805. /* other intel */
  1806. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
  1807. "Intel D945", STAC_D945_REF),
  1808. /* other systems */
  1809. /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
  1810. SND_PCI_QUIRK(0x8384, 0x7680,
  1811. "Mac", STAC_INTEL_MAC_AUTO),
  1812. /* Dell systems */
  1813. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
  1814. "unknown Dell", STAC_922X_DELL_D81),
  1815. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
  1816. "unknown Dell", STAC_922X_DELL_D81),
  1817. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
  1818. "unknown Dell", STAC_922X_DELL_D81),
  1819. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
  1820. "unknown Dell", STAC_922X_DELL_D82),
  1821. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
  1822. "unknown Dell", STAC_922X_DELL_M81),
  1823. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
  1824. "unknown Dell", STAC_922X_DELL_D82),
  1825. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
  1826. "unknown Dell", STAC_922X_DELL_D81),
  1827. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
  1828. "unknown Dell", STAC_922X_DELL_D81),
  1829. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
  1830. "Dell XPS M1210", STAC_922X_DELL_M82),
  1831. /* ECS/PC Chips boards */
  1832. SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
  1833. "ECS/PC chips", STAC_ECS_202),
  1834. {} /* terminator */
  1835. };
  1836. static const unsigned int ref927x_pin_configs[14] = {
  1837. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  1838. 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
  1839. 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
  1840. 0x01c42190, 0x40000100,
  1841. };
  1842. static const unsigned int d965_3st_pin_configs[14] = {
  1843. 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
  1844. 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
  1845. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  1846. 0x40000100, 0x40000100
  1847. };
  1848. static const unsigned int d965_5st_pin_configs[14] = {
  1849. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  1850. 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
  1851. 0x40000100, 0x40000100, 0x40000100, 0x01442070,
  1852. 0x40000100, 0x40000100
  1853. };
  1854. static const unsigned int d965_5st_no_fp_pin_configs[14] = {
  1855. 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
  1856. 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
  1857. 0x40000100, 0x40000100, 0x40000100, 0x01442070,
  1858. 0x40000100, 0x40000100
  1859. };
  1860. static const unsigned int dell_3st_pin_configs[14] = {
  1861. 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
  1862. 0x01111212, 0x01116211, 0x01813050, 0x01112214,
  1863. 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
  1864. 0x40c003fc, 0x40000100
  1865. };
  1866. static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
  1867. [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
  1868. [STAC_D965_REF] = ref927x_pin_configs,
  1869. [STAC_D965_3ST] = d965_3st_pin_configs,
  1870. [STAC_D965_5ST] = d965_5st_pin_configs,
  1871. [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
  1872. [STAC_DELL_3ST] = dell_3st_pin_configs,
  1873. [STAC_DELL_BIOS] = NULL,
  1874. [STAC_927X_VOLKNOB] = NULL,
  1875. };
  1876. static const char * const stac927x_models[STAC_927X_MODELS] = {
  1877. [STAC_927X_AUTO] = "auto",
  1878. [STAC_D965_REF_NO_JD] = "ref-no-jd",
  1879. [STAC_D965_REF] = "ref",
  1880. [STAC_D965_3ST] = "3stack",
  1881. [STAC_D965_5ST] = "5stack",
  1882. [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
  1883. [STAC_DELL_3ST] = "dell-3stack",
  1884. [STAC_DELL_BIOS] = "dell-bios",
  1885. [STAC_927X_VOLKNOB] = "volknob",
  1886. };
  1887. static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
  1888. /* SigmaTel reference board */
  1889. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1890. "DFI LanParty", STAC_D965_REF),
  1891. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1892. "DFI LanParty", STAC_D965_REF),
  1893. /* Intel 946 based systems */
  1894. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
  1895. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
  1896. /* 965 based 3 stack systems */
  1897. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
  1898. "Intel D965", STAC_D965_3ST),
  1899. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
  1900. "Intel D965", STAC_D965_3ST),
  1901. /* Dell 3 stack systems */
  1902. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
  1903. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
  1904. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
  1905. /* Dell 3 stack systems with verb table in BIOS */
  1906. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
  1907. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
  1908. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
  1909. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
  1910. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
  1911. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
  1912. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
  1913. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
  1914. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
  1915. /* 965 based 5 stack systems */
  1916. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
  1917. "Intel D965", STAC_D965_5ST),
  1918. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
  1919. "Intel D965", STAC_D965_5ST),
  1920. /* volume-knob fixes */
  1921. SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
  1922. {} /* terminator */
  1923. };
  1924. static const unsigned int ref9205_pin_configs[12] = {
  1925. 0x40000100, 0x40000100, 0x01016011, 0x01014010,
  1926. 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
  1927. 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
  1928. };
  1929. /*
  1930. STAC 9205 pin configs for
  1931. 102801F1
  1932. 102801F2
  1933. 102801FC
  1934. 102801FD
  1935. 10280204
  1936. 1028021F
  1937. 10280228 (Dell Vostro 1500)
  1938. 10280229 (Dell Vostro 1700)
  1939. */
  1940. static const unsigned int dell_9205_m42_pin_configs[12] = {
  1941. 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
  1942. 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
  1943. 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
  1944. };
  1945. /*
  1946. STAC 9205 pin configs for
  1947. 102801F9
  1948. 102801FA
  1949. 102801FE
  1950. 102801FF (Dell Precision M4300)
  1951. 10280206
  1952. 10280200
  1953. 10280201
  1954. */
  1955. static const unsigned int dell_9205_m43_pin_configs[12] = {
  1956. 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
  1957. 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
  1958. 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
  1959. };
  1960. static const unsigned int dell_9205_m44_pin_configs[12] = {
  1961. 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
  1962. 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
  1963. 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
  1964. };
  1965. static const unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
  1966. [STAC_9205_REF] = ref9205_pin_configs,
  1967. [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
  1968. [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
  1969. [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
  1970. [STAC_9205_EAPD] = NULL,
  1971. };
  1972. static const char * const stac9205_models[STAC_9205_MODELS] = {
  1973. [STAC_9205_AUTO] = "auto",
  1974. [STAC_9205_REF] = "ref",
  1975. [STAC_9205_DELL_M42] = "dell-m42",
  1976. [STAC_9205_DELL_M43] = "dell-m43",
  1977. [STAC_9205_DELL_M44] = "dell-m44",
  1978. [STAC_9205_EAPD] = "eapd",
  1979. };
  1980. static const struct snd_pci_quirk stac9205_cfg_tbl[] = {
  1981. /* SigmaTel reference board */
  1982. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1983. "DFI LanParty", STAC_9205_REF),
  1984. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
  1985. "SigmaTel", STAC_9205_REF),
  1986. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1987. "DFI LanParty", STAC_9205_REF),
  1988. /* Dell */
  1989. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
  1990. "unknown Dell", STAC_9205_DELL_M42),
  1991. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
  1992. "unknown Dell", STAC_9205_DELL_M42),
  1993. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
  1994. "Dell Precision", STAC_9205_DELL_M43),
  1995. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
  1996. "Dell Precision", STAC_9205_DELL_M43),
  1997. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
  1998. "Dell Precision", STAC_9205_DELL_M43),
  1999. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
  2000. "unknown Dell", STAC_9205_DELL_M42),
  2001. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
  2002. "unknown Dell", STAC_9205_DELL_M42),
  2003. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
  2004. "Dell Precision", STAC_9205_DELL_M43),
  2005. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
  2006. "Dell Precision M4300", STAC_9205_DELL_M43),
  2007. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
  2008. "unknown Dell", STAC_9205_DELL_M42),
  2009. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
  2010. "Dell Precision", STAC_9205_DELL_M43),
  2011. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
  2012. "Dell Precision", STAC_9205_DELL_M43),
  2013. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
  2014. "Dell Precision", STAC_9205_DELL_M43),
  2015. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
  2016. "Dell Inspiron", STAC_9205_DELL_M44),
  2017. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
  2018. "Dell Vostro 1500", STAC_9205_DELL_M42),
  2019. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
  2020. "Dell Vostro 1700", STAC_9205_DELL_M42),
  2021. /* Gateway */
  2022. SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
  2023. SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
  2024. {} /* terminator */
  2025. };
  2026. static void stac92xx_set_config_regs(struct hda_codec *codec,
  2027. const unsigned int *pincfgs)
  2028. {
  2029. int i;
  2030. struct sigmatel_spec *spec = codec->spec;
  2031. if (!pincfgs)
  2032. return;
  2033. for (i = 0; i < spec->num_pins; i++)
  2034. if (spec->pin_nids[i] && pincfgs[i])
  2035. snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
  2036. pincfgs[i]);
  2037. }
  2038. /*
  2039. * Analog playback callbacks
  2040. */
  2041. static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
  2042. struct hda_codec *codec,
  2043. struct snd_pcm_substream *substream)
  2044. {
  2045. struct sigmatel_spec *spec = codec->spec;
  2046. if (spec->stream_delay)
  2047. msleep(spec->stream_delay);
  2048. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  2049. hinfo);
  2050. }
  2051. static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  2052. struct hda_codec *codec,
  2053. unsigned int stream_tag,
  2054. unsigned int format,
  2055. struct snd_pcm_substream *substream)
  2056. {
  2057. struct sigmatel_spec *spec = codec->spec;
  2058. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
  2059. }
  2060. static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  2061. struct hda_codec *codec,
  2062. struct snd_pcm_substream *substream)
  2063. {
  2064. struct sigmatel_spec *spec = codec->spec;
  2065. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  2066. }
  2067. /*
  2068. * Digital playback callbacks
  2069. */
  2070. static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  2071. struct hda_codec *codec,
  2072. struct snd_pcm_substream *substream)
  2073. {
  2074. struct sigmatel_spec *spec = codec->spec;
  2075. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  2076. }
  2077. static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  2078. struct hda_codec *codec,
  2079. struct snd_pcm_substream *substream)
  2080. {
  2081. struct sigmatel_spec *spec = codec->spec;
  2082. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  2083. }
  2084. static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  2085. struct hda_codec *codec,
  2086. unsigned int stream_tag,
  2087. unsigned int format,
  2088. struct snd_pcm_substream *substream)
  2089. {
  2090. struct sigmatel_spec *spec = codec->spec;
  2091. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  2092. stream_tag, format, substream);
  2093. }
  2094. static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  2095. struct hda_codec *codec,
  2096. struct snd_pcm_substream *substream)
  2097. {
  2098. struct sigmatel_spec *spec = codec->spec;
  2099. return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  2100. }
  2101. /*
  2102. * Analog capture callbacks
  2103. */
  2104. static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  2105. struct hda_codec *codec,
  2106. unsigned int stream_tag,
  2107. unsigned int format,
  2108. struct snd_pcm_substream *substream)
  2109. {
  2110. struct sigmatel_spec *spec = codec->spec;
  2111. hda_nid_t nid = spec->adc_nids[substream->number];
  2112. if (spec->powerdown_adcs) {
  2113. msleep(40);
  2114. snd_hda_codec_write(codec, nid, 0,
  2115. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  2116. }
  2117. snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
  2118. return 0;
  2119. }
  2120. static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  2121. struct hda_codec *codec,
  2122. struct snd_pcm_substream *substream)
  2123. {
  2124. struct sigmatel_spec *spec = codec->spec;
  2125. hda_nid_t nid = spec->adc_nids[substream->number];
  2126. snd_hda_codec_cleanup_stream(codec, nid);
  2127. if (spec->powerdown_adcs)
  2128. snd_hda_codec_write(codec, nid, 0,
  2129. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  2130. return 0;
  2131. }
  2132. static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
  2133. .substreams = 1,
  2134. .channels_min = 2,
  2135. .channels_max = 2,
  2136. /* NID is set in stac92xx_build_pcms */
  2137. .ops = {
  2138. .open = stac92xx_dig_playback_pcm_open,
  2139. .close = stac92xx_dig_playback_pcm_close,
  2140. .prepare = stac92xx_dig_playback_pcm_prepare,
  2141. .cleanup = stac92xx_dig_playback_pcm_cleanup
  2142. },
  2143. };
  2144. static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
  2145. .substreams = 1,
  2146. .channels_min = 2,
  2147. .channels_max = 2,
  2148. /* NID is set in stac92xx_build_pcms */
  2149. };
  2150. static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
  2151. .substreams = 1,
  2152. .channels_min = 2,
  2153. .channels_max = 8,
  2154. .nid = 0x02, /* NID to query formats and rates */
  2155. .ops = {
  2156. .open = stac92xx_playback_pcm_open,
  2157. .prepare = stac92xx_playback_pcm_prepare,
  2158. .cleanup = stac92xx_playback_pcm_cleanup
  2159. },
  2160. };
  2161. static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
  2162. .substreams = 1,
  2163. .channels_min = 2,
  2164. .channels_max = 2,
  2165. .nid = 0x06, /* NID to query formats and rates */
  2166. .ops = {
  2167. .open = stac92xx_playback_pcm_open,
  2168. .prepare = stac92xx_playback_pcm_prepare,
  2169. .cleanup = stac92xx_playback_pcm_cleanup
  2170. },
  2171. };
  2172. static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
  2173. .channels_min = 2,
  2174. .channels_max = 2,
  2175. /* NID + .substreams is set in stac92xx_build_pcms */
  2176. .ops = {
  2177. .prepare = stac92xx_capture_pcm_prepare,
  2178. .cleanup = stac92xx_capture_pcm_cleanup
  2179. },
  2180. };
  2181. static int stac92xx_build_pcms(struct hda_codec *codec)
  2182. {
  2183. struct sigmatel_spec *spec = codec->spec;
  2184. struct hda_pcm *info = spec->pcm_rec;
  2185. codec->num_pcms = 1;
  2186. codec->pcm_info = info;
  2187. info->name = "STAC92xx Analog";
  2188. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
  2189. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  2190. spec->multiout.dac_nids[0];
  2191. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
  2192. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  2193. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
  2194. if (spec->alt_switch) {
  2195. codec->num_pcms++;
  2196. info++;
  2197. info->name = "STAC92xx Analog Alt";
  2198. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
  2199. }
  2200. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  2201. codec->num_pcms++;
  2202. info++;
  2203. info->name = "STAC92xx Digital";
  2204. info->pcm_type = spec->autocfg.dig_out_type[0];
  2205. if (spec->multiout.dig_out_nid) {
  2206. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
  2207. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  2208. }
  2209. if (spec->dig_in_nid) {
  2210. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
  2211. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  2212. }
  2213. }
  2214. return 0;
  2215. }
  2216. static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
  2217. {
  2218. snd_hda_set_pin_ctl_cache(codec, nid, pin_type);
  2219. }
  2220. #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
  2221. static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
  2222. struct snd_ctl_elem_value *ucontrol)
  2223. {
  2224. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2225. struct sigmatel_spec *spec = codec->spec;
  2226. ucontrol->value.integer.value[0] = !!spec->hp_switch;
  2227. return 0;
  2228. }
  2229. static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
  2230. static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
  2231. struct snd_ctl_elem_value *ucontrol)
  2232. {
  2233. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2234. struct sigmatel_spec *spec = codec->spec;
  2235. int nid = kcontrol->private_value;
  2236. spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
  2237. /* check to be sure that the ports are up to date with
  2238. * switch changes
  2239. */
  2240. stac_issue_unsol_event(codec, nid);
  2241. return 1;
  2242. }
  2243. static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
  2244. struct snd_ctl_elem_info *uinfo)
  2245. {
  2246. int i;
  2247. static const char * const texts[] = {
  2248. "Mic In", "Line In", "Line Out"
  2249. };
  2250. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2251. struct sigmatel_spec *spec = codec->spec;
  2252. hda_nid_t nid = kcontrol->private_value;
  2253. if (nid == spec->mic_switch || nid == spec->line_switch)
  2254. i = 3;
  2255. else
  2256. i = 2;
  2257. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2258. uinfo->value.enumerated.items = i;
  2259. uinfo->count = 1;
  2260. if (uinfo->value.enumerated.item >= i)
  2261. uinfo->value.enumerated.item = i-1;
  2262. strcpy(uinfo->value.enumerated.name,
  2263. texts[uinfo->value.enumerated.item]);
  2264. return 0;
  2265. }
  2266. static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
  2267. struct snd_ctl_elem_value *ucontrol)
  2268. {
  2269. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2270. hda_nid_t nid = kcontrol->private_value;
  2271. unsigned int vref = stac92xx_vref_get(codec, nid);
  2272. if (vref == snd_hda_get_default_vref(codec, nid))
  2273. ucontrol->value.enumerated.item[0] = 0;
  2274. else if (vref == AC_PINCTL_VREF_GRD)
  2275. ucontrol->value.enumerated.item[0] = 1;
  2276. else if (vref == AC_PINCTL_VREF_HIZ)
  2277. ucontrol->value.enumerated.item[0] = 2;
  2278. return 0;
  2279. }
  2280. static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
  2281. struct snd_ctl_elem_value *ucontrol)
  2282. {
  2283. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2284. unsigned int new_vref = 0;
  2285. int error;
  2286. hda_nid_t nid = kcontrol->private_value;
  2287. if (ucontrol->value.enumerated.item[0] == 0)
  2288. new_vref = snd_hda_get_default_vref(codec, nid);
  2289. else if (ucontrol->value.enumerated.item[0] == 1)
  2290. new_vref = AC_PINCTL_VREF_GRD;
  2291. else if (ucontrol->value.enumerated.item[0] == 2)
  2292. new_vref = AC_PINCTL_VREF_HIZ;
  2293. else
  2294. return 0;
  2295. if (new_vref != stac92xx_vref_get(codec, nid)) {
  2296. error = stac92xx_vref_set(codec, nid, new_vref);
  2297. return error;
  2298. }
  2299. return 0;
  2300. }
  2301. static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
  2302. struct snd_ctl_elem_info *uinfo)
  2303. {
  2304. char *texts[2];
  2305. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2306. struct sigmatel_spec *spec = codec->spec;
  2307. if (kcontrol->private_value == spec->line_switch)
  2308. texts[0] = "Line In";
  2309. else
  2310. texts[0] = "Mic In";
  2311. texts[1] = "Line Out";
  2312. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2313. uinfo->value.enumerated.items = 2;
  2314. uinfo->count = 1;
  2315. if (uinfo->value.enumerated.item >= 2)
  2316. uinfo->value.enumerated.item = 1;
  2317. strcpy(uinfo->value.enumerated.name,
  2318. texts[uinfo->value.enumerated.item]);
  2319. return 0;
  2320. }
  2321. static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2322. {
  2323. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2324. struct sigmatel_spec *spec = codec->spec;
  2325. hda_nid_t nid = kcontrol->private_value;
  2326. int io_idx = (nid == spec->mic_switch) ? 1 : 0;
  2327. ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
  2328. return 0;
  2329. }
  2330. static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2331. {
  2332. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2333. struct sigmatel_spec *spec = codec->spec;
  2334. hda_nid_t nid = kcontrol->private_value;
  2335. int io_idx = (nid == spec->mic_switch) ? 1 : 0;
  2336. unsigned short val = !!ucontrol->value.enumerated.item[0];
  2337. spec->io_switch[io_idx] = val;
  2338. if (val)
  2339. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  2340. else {
  2341. unsigned int pinctl = AC_PINCTL_IN_EN;
  2342. if (io_idx) /* set VREF for mic */
  2343. pinctl |= snd_hda_get_default_vref(codec, nid);
  2344. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  2345. }
  2346. /* check the auto-mute again: we need to mute/unmute the speaker
  2347. * appropriately according to the pin direction
  2348. */
  2349. if (spec->hp_detect)
  2350. stac_issue_unsol_event(codec, nid);
  2351. return 1;
  2352. }
  2353. #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
  2354. static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
  2355. struct snd_ctl_elem_value *ucontrol)
  2356. {
  2357. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2358. struct sigmatel_spec *spec = codec->spec;
  2359. ucontrol->value.integer.value[0] = spec->clfe_swap;
  2360. return 0;
  2361. }
  2362. static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
  2363. struct snd_ctl_elem_value *ucontrol)
  2364. {
  2365. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2366. struct sigmatel_spec *spec = codec->spec;
  2367. hda_nid_t nid = kcontrol->private_value & 0xff;
  2368. unsigned int val = !!ucontrol->value.integer.value[0];
  2369. if (spec->clfe_swap == val)
  2370. return 0;
  2371. spec->clfe_swap = val;
  2372. snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
  2373. spec->clfe_swap ? 0x4 : 0x0);
  2374. return 1;
  2375. }
  2376. #define STAC_CODEC_HP_SWITCH(xname) \
  2377. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2378. .name = xname, \
  2379. .index = 0, \
  2380. .info = stac92xx_hp_switch_info, \
  2381. .get = stac92xx_hp_switch_get, \
  2382. .put = stac92xx_hp_switch_put, \
  2383. }
  2384. #define STAC_CODEC_IO_SWITCH(xname, xpval) \
  2385. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2386. .name = xname, \
  2387. .index = 0, \
  2388. .info = stac92xx_io_switch_info, \
  2389. .get = stac92xx_io_switch_get, \
  2390. .put = stac92xx_io_switch_put, \
  2391. .private_value = xpval, \
  2392. }
  2393. #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
  2394. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2395. .name = xname, \
  2396. .index = 0, \
  2397. .info = stac92xx_clfe_switch_info, \
  2398. .get = stac92xx_clfe_switch_get, \
  2399. .put = stac92xx_clfe_switch_put, \
  2400. .private_value = xpval, \
  2401. }
  2402. enum {
  2403. STAC_CTL_WIDGET_VOL,
  2404. STAC_CTL_WIDGET_MUTE,
  2405. STAC_CTL_WIDGET_MUTE_BEEP,
  2406. STAC_CTL_WIDGET_MONO_MUX,
  2407. STAC_CTL_WIDGET_HP_SWITCH,
  2408. STAC_CTL_WIDGET_IO_SWITCH,
  2409. STAC_CTL_WIDGET_CLFE_SWITCH,
  2410. STAC_CTL_WIDGET_DC_BIAS
  2411. };
  2412. static const struct snd_kcontrol_new stac92xx_control_templates[] = {
  2413. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  2414. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  2415. HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
  2416. STAC_MONO_MUX,
  2417. STAC_CODEC_HP_SWITCH(NULL),
  2418. STAC_CODEC_IO_SWITCH(NULL, 0),
  2419. STAC_CODEC_CLFE_SWITCH(NULL, 0),
  2420. DC_BIAS(NULL, 0, 0),
  2421. };
  2422. /* add dynamic controls */
  2423. static struct snd_kcontrol_new *
  2424. stac_control_new(struct sigmatel_spec *spec,
  2425. const struct snd_kcontrol_new *ktemp,
  2426. const char *name,
  2427. unsigned int subdev)
  2428. {
  2429. struct snd_kcontrol_new *knew;
  2430. snd_array_init(&spec->kctls, sizeof(*knew), 32);
  2431. knew = snd_array_new(&spec->kctls);
  2432. if (!knew)
  2433. return NULL;
  2434. *knew = *ktemp;
  2435. knew->name = kstrdup(name, GFP_KERNEL);
  2436. if (!knew->name) {
  2437. /* roolback */
  2438. memset(knew, 0, sizeof(*knew));
  2439. spec->kctls.alloced--;
  2440. return NULL;
  2441. }
  2442. knew->subdevice = subdev;
  2443. return knew;
  2444. }
  2445. static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
  2446. const struct snd_kcontrol_new *ktemp,
  2447. int idx, const char *name,
  2448. unsigned long val)
  2449. {
  2450. struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
  2451. HDA_SUBDEV_AMP_FLAG);
  2452. if (!knew)
  2453. return -ENOMEM;
  2454. knew->index = idx;
  2455. knew->private_value = val;
  2456. return 0;
  2457. }
  2458. static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
  2459. int type, int idx, const char *name,
  2460. unsigned long val)
  2461. {
  2462. return stac92xx_add_control_temp(spec,
  2463. &stac92xx_control_templates[type],
  2464. idx, name, val);
  2465. }
  2466. /* add dynamic controls */
  2467. static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
  2468. const char *name, unsigned long val)
  2469. {
  2470. return stac92xx_add_control_idx(spec, type, 0, name, val);
  2471. }
  2472. static const struct snd_kcontrol_new stac_input_src_temp = {
  2473. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2474. .name = "Input Source",
  2475. .info = stac92xx_mux_enum_info,
  2476. .get = stac92xx_mux_enum_get,
  2477. .put = stac92xx_mux_enum_put,
  2478. };
  2479. static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
  2480. hda_nid_t nid, int idx)
  2481. {
  2482. int def_conf = snd_hda_codec_get_pincfg(codec, nid);
  2483. int control = 0;
  2484. struct sigmatel_spec *spec = codec->spec;
  2485. char name[22];
  2486. if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
  2487. if (snd_hda_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
  2488. && nid == spec->line_switch)
  2489. control = STAC_CTL_WIDGET_IO_SWITCH;
  2490. else if (snd_hda_query_pin_caps(codec, nid)
  2491. & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
  2492. control = STAC_CTL_WIDGET_DC_BIAS;
  2493. else if (nid == spec->mic_switch)
  2494. control = STAC_CTL_WIDGET_IO_SWITCH;
  2495. }
  2496. if (control) {
  2497. snd_hda_get_pin_label(codec, nid, &spec->autocfg,
  2498. name, sizeof(name), NULL);
  2499. return stac92xx_add_control(codec->spec, control,
  2500. strcat(name, " Jack Mode"), nid);
  2501. }
  2502. return 0;
  2503. }
  2504. static int stac92xx_add_input_source(struct sigmatel_spec *spec)
  2505. {
  2506. struct snd_kcontrol_new *knew;
  2507. struct hda_input_mux *imux = &spec->private_imux;
  2508. if (spec->auto_mic)
  2509. return 0; /* no need for input source */
  2510. if (!spec->num_adcs || imux->num_items <= 1)
  2511. return 0; /* no need for input source control */
  2512. knew = stac_control_new(spec, &stac_input_src_temp,
  2513. stac_input_src_temp.name, 0);
  2514. if (!knew)
  2515. return -ENOMEM;
  2516. knew->count = spec->num_adcs;
  2517. return 0;
  2518. }
  2519. /* check whether the line-input can be used as line-out */
  2520. static hda_nid_t check_line_out_switch(struct hda_codec *codec)
  2521. {
  2522. struct sigmatel_spec *spec = codec->spec;
  2523. struct auto_pin_cfg *cfg = &spec->autocfg;
  2524. hda_nid_t nid;
  2525. unsigned int pincap;
  2526. int i;
  2527. if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
  2528. return 0;
  2529. for (i = 0; i < cfg->num_inputs; i++) {
  2530. if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
  2531. nid = cfg->inputs[i].pin;
  2532. pincap = snd_hda_query_pin_caps(codec, nid);
  2533. if (pincap & AC_PINCAP_OUT)
  2534. return nid;
  2535. }
  2536. }
  2537. return 0;
  2538. }
  2539. static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
  2540. /* check whether the mic-input can be used as line-out */
  2541. static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
  2542. {
  2543. struct sigmatel_spec *spec = codec->spec;
  2544. struct auto_pin_cfg *cfg = &spec->autocfg;
  2545. unsigned int def_conf, pincap;
  2546. int i;
  2547. *dac = 0;
  2548. if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
  2549. return 0;
  2550. for (i = 0; i < cfg->num_inputs; i++) {
  2551. hda_nid_t nid = cfg->inputs[i].pin;
  2552. if (cfg->inputs[i].type != AUTO_PIN_MIC)
  2553. continue;
  2554. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  2555. /* some laptops have an internal analog microphone
  2556. * which can't be used as a output */
  2557. if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
  2558. pincap = snd_hda_query_pin_caps(codec, nid);
  2559. if (pincap & AC_PINCAP_OUT) {
  2560. *dac = get_unassigned_dac(codec, nid);
  2561. if (*dac)
  2562. return nid;
  2563. }
  2564. }
  2565. }
  2566. return 0;
  2567. }
  2568. static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  2569. {
  2570. int i;
  2571. for (i = 0; i < spec->multiout.num_dacs; i++) {
  2572. if (spec->multiout.dac_nids[i] == nid)
  2573. return 1;
  2574. }
  2575. return 0;
  2576. }
  2577. static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  2578. {
  2579. int i;
  2580. if (is_in_dac_nids(spec, nid))
  2581. return 1;
  2582. for (i = 0; i < spec->autocfg.hp_outs; i++)
  2583. if (spec->hp_dacs[i] == nid)
  2584. return 1;
  2585. for (i = 0; i < spec->autocfg.speaker_outs; i++)
  2586. if (spec->speaker_dacs[i] == nid)
  2587. return 1;
  2588. return 0;
  2589. }
  2590. static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
  2591. {
  2592. struct sigmatel_spec *spec = codec->spec;
  2593. struct auto_pin_cfg *cfg = &spec->autocfg;
  2594. int j, conn_len;
  2595. hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
  2596. unsigned int wcaps, wtype;
  2597. conn_len = snd_hda_get_connections(codec, nid, conn,
  2598. HDA_MAX_CONNECTIONS);
  2599. /* 92HD88: trace back up the link of nids to find the DAC */
  2600. while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
  2601. != AC_WID_AUD_OUT)) {
  2602. nid = conn[0];
  2603. conn_len = snd_hda_get_connections(codec, nid, conn,
  2604. HDA_MAX_CONNECTIONS);
  2605. }
  2606. for (j = 0; j < conn_len; j++) {
  2607. wcaps = get_wcaps(codec, conn[j]);
  2608. wtype = get_wcaps_type(wcaps);
  2609. /* we check only analog outputs */
  2610. if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
  2611. continue;
  2612. /* if this route has a free DAC, assign it */
  2613. if (!check_all_dac_nids(spec, conn[j])) {
  2614. if (conn_len > 1) {
  2615. /* select this DAC in the pin's input mux */
  2616. snd_hda_codec_write_cache(codec, nid, 0,
  2617. AC_VERB_SET_CONNECT_SEL, j);
  2618. }
  2619. return conn[j];
  2620. }
  2621. }
  2622. /* if all DACs are already assigned, connect to the primary DAC,
  2623. unless we're assigning a secondary headphone */
  2624. fallback_dac = spec->multiout.dac_nids[0];
  2625. if (spec->multiout.hp_nid) {
  2626. for (j = 0; j < cfg->hp_outs; j++)
  2627. if (cfg->hp_pins[j] == nid) {
  2628. fallback_dac = spec->multiout.hp_nid;
  2629. break;
  2630. }
  2631. }
  2632. if (conn_len > 1) {
  2633. for (j = 0; j < conn_len; j++) {
  2634. if (conn[j] == fallback_dac) {
  2635. snd_hda_codec_write_cache(codec, nid, 0,
  2636. AC_VERB_SET_CONNECT_SEL, j);
  2637. break;
  2638. }
  2639. }
  2640. }
  2641. return 0;
  2642. }
  2643. static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
  2644. static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
  2645. /*
  2646. * Fill in the dac_nids table from the parsed pin configuration
  2647. * This function only works when every pin in line_out_pins[]
  2648. * contains atleast one DAC in its connection list. Some 92xx
  2649. * codecs are not connected directly to a DAC, such as the 9200
  2650. * and 9202/925x. For those, dac_nids[] must be hard-coded.
  2651. */
  2652. static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
  2653. {
  2654. struct sigmatel_spec *spec = codec->spec;
  2655. struct auto_pin_cfg *cfg = &spec->autocfg;
  2656. int i;
  2657. hda_nid_t nid, dac;
  2658. for (i = 0; i < cfg->line_outs; i++) {
  2659. nid = cfg->line_out_pins[i];
  2660. dac = get_unassigned_dac(codec, nid);
  2661. if (!dac) {
  2662. if (spec->multiout.num_dacs > 0) {
  2663. /* we have already working output pins,
  2664. * so let's drop the broken ones again
  2665. */
  2666. cfg->line_outs = spec->multiout.num_dacs;
  2667. break;
  2668. }
  2669. /* error out, no available DAC found */
  2670. snd_printk(KERN_ERR
  2671. "%s: No available DAC for pin 0x%x\n",
  2672. __func__, nid);
  2673. return -ENODEV;
  2674. }
  2675. add_spec_dacs(spec, dac);
  2676. }
  2677. for (i = 0; i < cfg->hp_outs; i++) {
  2678. nid = cfg->hp_pins[i];
  2679. dac = get_unassigned_dac(codec, nid);
  2680. if (dac) {
  2681. if (!spec->multiout.hp_nid)
  2682. spec->multiout.hp_nid = dac;
  2683. else
  2684. add_spec_extra_dacs(spec, dac);
  2685. }
  2686. spec->hp_dacs[i] = dac;
  2687. }
  2688. for (i = 0; i < cfg->speaker_outs; i++) {
  2689. nid = cfg->speaker_pins[i];
  2690. dac = get_unassigned_dac(codec, nid);
  2691. if (dac)
  2692. add_spec_extra_dacs(spec, dac);
  2693. spec->speaker_dacs[i] = dac;
  2694. }
  2695. /* add line-in as output */
  2696. nid = check_line_out_switch(codec);
  2697. if (nid) {
  2698. dac = get_unassigned_dac(codec, nid);
  2699. if (dac) {
  2700. snd_printdd("STAC: Add line-in 0x%x as output %d\n",
  2701. nid, cfg->line_outs);
  2702. cfg->line_out_pins[cfg->line_outs] = nid;
  2703. cfg->line_outs++;
  2704. spec->line_switch = nid;
  2705. add_spec_dacs(spec, dac);
  2706. }
  2707. }
  2708. /* add mic as output */
  2709. nid = check_mic_out_switch(codec, &dac);
  2710. if (nid && dac) {
  2711. snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
  2712. nid, cfg->line_outs);
  2713. cfg->line_out_pins[cfg->line_outs] = nid;
  2714. cfg->line_outs++;
  2715. spec->mic_switch = nid;
  2716. add_spec_dacs(spec, dac);
  2717. }
  2718. snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
  2719. spec->multiout.num_dacs,
  2720. spec->multiout.dac_nids[0],
  2721. spec->multiout.dac_nids[1],
  2722. spec->multiout.dac_nids[2],
  2723. spec->multiout.dac_nids[3],
  2724. spec->multiout.dac_nids[4]);
  2725. return 0;
  2726. }
  2727. /* create volume control/switch for the given prefx type */
  2728. static int create_controls_idx(struct hda_codec *codec, const char *pfx,
  2729. int idx, hda_nid_t nid, int chs)
  2730. {
  2731. struct sigmatel_spec *spec = codec->spec;
  2732. char name[32];
  2733. int err;
  2734. if (!spec->check_volume_offset) {
  2735. unsigned int caps, step, nums, db_scale;
  2736. caps = query_amp_caps(codec, nid, HDA_OUTPUT);
  2737. step = (caps & AC_AMPCAP_STEP_SIZE) >>
  2738. AC_AMPCAP_STEP_SIZE_SHIFT;
  2739. step = (step + 1) * 25; /* in .01dB unit */
  2740. nums = (caps & AC_AMPCAP_NUM_STEPS) >>
  2741. AC_AMPCAP_NUM_STEPS_SHIFT;
  2742. db_scale = nums * step;
  2743. /* if dB scale is over -64dB, and finer enough,
  2744. * let's reduce it to half
  2745. */
  2746. if (db_scale > 6400 && nums >= 0x1f)
  2747. spec->volume_offset = nums / 2;
  2748. spec->check_volume_offset = 1;
  2749. }
  2750. sprintf(name, "%s Playback Volume", pfx);
  2751. err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
  2752. HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
  2753. spec->volume_offset));
  2754. if (err < 0)
  2755. return err;
  2756. sprintf(name, "%s Playback Switch", pfx);
  2757. err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
  2758. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  2759. if (err < 0)
  2760. return err;
  2761. return 0;
  2762. }
  2763. #define create_controls(codec, pfx, nid, chs) \
  2764. create_controls_idx(codec, pfx, 0, nid, chs)
  2765. static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
  2766. {
  2767. if (spec->multiout.num_dacs > 4) {
  2768. printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
  2769. return 1;
  2770. } else {
  2771. snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
  2772. spec->dac_nids[spec->multiout.num_dacs] = nid;
  2773. spec->multiout.num_dacs++;
  2774. }
  2775. return 0;
  2776. }
  2777. static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
  2778. {
  2779. int i;
  2780. for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
  2781. if (!spec->multiout.extra_out_nid[i]) {
  2782. spec->multiout.extra_out_nid[i] = nid;
  2783. return 0;
  2784. }
  2785. }
  2786. printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
  2787. return 1;
  2788. }
  2789. /* Create output controls
  2790. * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
  2791. */
  2792. static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
  2793. const hda_nid_t *pins,
  2794. const hda_nid_t *dac_nids,
  2795. int type)
  2796. {
  2797. struct sigmatel_spec *spec = codec->spec;
  2798. static const char * const chname[4] = {
  2799. "Front", "Surround", NULL /*CLFE*/, "Side"
  2800. };
  2801. hda_nid_t nid;
  2802. int i, err;
  2803. unsigned int wid_caps;
  2804. for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
  2805. if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
  2806. if (is_jack_detectable(codec, pins[i]))
  2807. spec->hp_detect = 1;
  2808. }
  2809. nid = dac_nids[i];
  2810. if (!nid)
  2811. continue;
  2812. if (type != AUTO_PIN_HP_OUT && i == 2) {
  2813. /* Center/LFE */
  2814. err = create_controls(codec, "Center", nid, 1);
  2815. if (err < 0)
  2816. return err;
  2817. err = create_controls(codec, "LFE", nid, 2);
  2818. if (err < 0)
  2819. return err;
  2820. wid_caps = get_wcaps(codec, nid);
  2821. if (wid_caps & AC_WCAP_LR_SWAP) {
  2822. err = stac92xx_add_control(spec,
  2823. STAC_CTL_WIDGET_CLFE_SWITCH,
  2824. "Swap Center/LFE Playback Switch", nid);
  2825. if (err < 0)
  2826. return err;
  2827. }
  2828. } else {
  2829. const char *name;
  2830. int idx;
  2831. switch (type) {
  2832. case AUTO_PIN_HP_OUT:
  2833. name = "Headphone";
  2834. idx = i;
  2835. break;
  2836. case AUTO_PIN_SPEAKER_OUT:
  2837. name = "Speaker";
  2838. idx = i;
  2839. break;
  2840. default:
  2841. name = chname[i];
  2842. idx = 0;
  2843. break;
  2844. }
  2845. err = create_controls_idx(codec, name, idx, nid, 3);
  2846. if (err < 0)
  2847. return err;
  2848. }
  2849. }
  2850. return 0;
  2851. }
  2852. static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
  2853. unsigned long sw, int idx)
  2854. {
  2855. int err;
  2856. err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
  2857. "Capture Volume", vol);
  2858. if (err < 0)
  2859. return err;
  2860. err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
  2861. "Capture Switch", sw);
  2862. if (err < 0)
  2863. return err;
  2864. return 0;
  2865. }
  2866. /* add playback controls from the parsed DAC table */
  2867. static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
  2868. const struct auto_pin_cfg *cfg)
  2869. {
  2870. struct sigmatel_spec *spec = codec->spec;
  2871. hda_nid_t nid;
  2872. int err;
  2873. int idx;
  2874. err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
  2875. spec->multiout.dac_nids,
  2876. cfg->line_out_type);
  2877. if (err < 0)
  2878. return err;
  2879. if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
  2880. err = stac92xx_add_control(spec,
  2881. STAC_CTL_WIDGET_HP_SWITCH,
  2882. "Headphone as Line Out Switch",
  2883. cfg->hp_pins[cfg->hp_outs - 1]);
  2884. if (err < 0)
  2885. return err;
  2886. }
  2887. for (idx = 0; idx < cfg->num_inputs; idx++) {
  2888. if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
  2889. break;
  2890. nid = cfg->inputs[idx].pin;
  2891. err = stac92xx_add_jack_mode_control(codec, nid, idx);
  2892. if (err < 0)
  2893. return err;
  2894. }
  2895. return 0;
  2896. }
  2897. /* add playback controls for Speaker and HP outputs */
  2898. static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
  2899. struct auto_pin_cfg *cfg)
  2900. {
  2901. struct sigmatel_spec *spec = codec->spec;
  2902. int err;
  2903. err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
  2904. spec->hp_dacs, AUTO_PIN_HP_OUT);
  2905. if (err < 0)
  2906. return err;
  2907. err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
  2908. spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
  2909. if (err < 0)
  2910. return err;
  2911. return 0;
  2912. }
  2913. /* labels for mono mux outputs */
  2914. static const char * const stac92xx_mono_labels[4] = {
  2915. "DAC0", "DAC1", "Mixer", "DAC2"
  2916. };
  2917. /* create mono mux for mono out on capable codecs */
  2918. static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
  2919. {
  2920. struct sigmatel_spec *spec = codec->spec;
  2921. struct hda_input_mux *mono_mux = &spec->private_mono_mux;
  2922. int i, num_cons;
  2923. hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
  2924. num_cons = snd_hda_get_connections(codec,
  2925. spec->mono_nid,
  2926. con_lst,
  2927. HDA_MAX_NUM_INPUTS);
  2928. if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
  2929. return -EINVAL;
  2930. for (i = 0; i < num_cons; i++)
  2931. snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
  2932. NULL);
  2933. return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
  2934. "Mono Mux", spec->mono_nid);
  2935. }
  2936. /* create PC beep volume controls */
  2937. static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
  2938. hda_nid_t nid)
  2939. {
  2940. struct sigmatel_spec *spec = codec->spec;
  2941. u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
  2942. int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
  2943. if (spec->anabeep_nid == nid)
  2944. type = STAC_CTL_WIDGET_MUTE;
  2945. /* check for mute support for the the amp */
  2946. if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
  2947. err = stac92xx_add_control(spec, type,
  2948. "Beep Playback Switch",
  2949. HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
  2950. if (err < 0)
  2951. return err;
  2952. }
  2953. /* check to see if there is volume support for the amp */
  2954. if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
  2955. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
  2956. "Beep Playback Volume",
  2957. HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
  2958. if (err < 0)
  2959. return err;
  2960. }
  2961. return 0;
  2962. }
  2963. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  2964. #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
  2965. static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
  2966. struct snd_ctl_elem_value *ucontrol)
  2967. {
  2968. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2969. ucontrol->value.integer.value[0] = codec->beep->enabled;
  2970. return 0;
  2971. }
  2972. static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
  2973. struct snd_ctl_elem_value *ucontrol)
  2974. {
  2975. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2976. return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
  2977. }
  2978. static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
  2979. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2980. .info = stac92xx_dig_beep_switch_info,
  2981. .get = stac92xx_dig_beep_switch_get,
  2982. .put = stac92xx_dig_beep_switch_put,
  2983. };
  2984. static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
  2985. {
  2986. return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
  2987. 0, "Beep Playback Switch", 0);
  2988. }
  2989. #endif
  2990. static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
  2991. {
  2992. struct sigmatel_spec *spec = codec->spec;
  2993. int i, j, err = 0;
  2994. for (i = 0; i < spec->num_muxes; i++) {
  2995. hda_nid_t nid;
  2996. unsigned int wcaps;
  2997. unsigned long val;
  2998. nid = spec->mux_nids[i];
  2999. wcaps = get_wcaps(codec, nid);
  3000. if (!(wcaps & AC_WCAP_OUT_AMP))
  3001. continue;
  3002. /* check whether already the same control was created as
  3003. * normal Capture Volume.
  3004. */
  3005. val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
  3006. for (j = 0; j < spec->num_caps; j++) {
  3007. if (spec->capvols[j] == val)
  3008. break;
  3009. }
  3010. if (j < spec->num_caps)
  3011. continue;
  3012. err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
  3013. "Mux Capture Volume", val);
  3014. if (err < 0)
  3015. return err;
  3016. }
  3017. return 0;
  3018. };
  3019. static const char * const stac92xx_spdif_labels[3] = {
  3020. "Digital Playback", "Analog Mux 1", "Analog Mux 2",
  3021. };
  3022. static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
  3023. {
  3024. struct sigmatel_spec *spec = codec->spec;
  3025. struct hda_input_mux *spdif_mux = &spec->private_smux;
  3026. const char * const *labels = spec->spdif_labels;
  3027. int i, num_cons;
  3028. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  3029. num_cons = snd_hda_get_connections(codec,
  3030. spec->smux_nids[0],
  3031. con_lst,
  3032. HDA_MAX_NUM_INPUTS);
  3033. if (num_cons <= 0)
  3034. return -EINVAL;
  3035. if (!labels)
  3036. labels = stac92xx_spdif_labels;
  3037. for (i = 0; i < num_cons; i++)
  3038. snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
  3039. return 0;
  3040. }
  3041. /* labels for dmic mux inputs */
  3042. static const char * const stac92xx_dmic_labels[5] = {
  3043. "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
  3044. "Digital Mic 3", "Digital Mic 4"
  3045. };
  3046. static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
  3047. int idx)
  3048. {
  3049. hda_nid_t conn[HDA_MAX_NUM_INPUTS];
  3050. int nums;
  3051. nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
  3052. if (idx >= 0 && idx < nums)
  3053. return conn[idx];
  3054. return 0;
  3055. }
  3056. /* look for NID recursively */
  3057. #define get_connection_index(codec, mux, nid) \
  3058. snd_hda_get_conn_index(codec, mux, nid, 1)
  3059. /* create a volume assigned to the given pin (only if supported) */
  3060. /* return 1 if the volume control is created */
  3061. static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
  3062. const char *label, int idx, int direction)
  3063. {
  3064. unsigned int caps, nums;
  3065. char name[32];
  3066. int err;
  3067. if (direction == HDA_OUTPUT)
  3068. caps = AC_WCAP_OUT_AMP;
  3069. else
  3070. caps = AC_WCAP_IN_AMP;
  3071. if (!(get_wcaps(codec, nid) & caps))
  3072. return 0;
  3073. caps = query_amp_caps(codec, nid, direction);
  3074. nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
  3075. if (!nums)
  3076. return 0;
  3077. snprintf(name, sizeof(name), "%s Capture Volume", label);
  3078. err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
  3079. HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
  3080. if (err < 0)
  3081. return err;
  3082. return 1;
  3083. }
  3084. /* create playback/capture controls for input pins on dmic capable codecs */
  3085. static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
  3086. const struct auto_pin_cfg *cfg)
  3087. {
  3088. struct sigmatel_spec *spec = codec->spec;
  3089. struct hda_input_mux *imux = &spec->private_imux;
  3090. struct hda_input_mux *dimux = &spec->private_dimux;
  3091. int err, i;
  3092. unsigned int def_conf;
  3093. snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
  3094. for (i = 0; i < spec->num_dmics; i++) {
  3095. hda_nid_t nid;
  3096. int index, type_idx;
  3097. char label[32];
  3098. nid = spec->dmic_nids[i];
  3099. if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
  3100. continue;
  3101. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  3102. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
  3103. continue;
  3104. index = get_connection_index(codec, spec->dmux_nids[0], nid);
  3105. if (index < 0)
  3106. continue;
  3107. snd_hda_get_pin_label(codec, nid, &spec->autocfg,
  3108. label, sizeof(label), NULL);
  3109. snd_hda_add_imux_item(dimux, label, index, &type_idx);
  3110. if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
  3111. snd_hda_add_imux_item(imux, label, index, &type_idx);
  3112. err = create_elem_capture_vol(codec, nid, label, type_idx,
  3113. HDA_INPUT);
  3114. if (err < 0)
  3115. return err;
  3116. if (!err) {
  3117. err = create_elem_capture_vol(codec, nid, label,
  3118. type_idx, HDA_OUTPUT);
  3119. if (err < 0)
  3120. return err;
  3121. if (!err) {
  3122. nid = get_connected_node(codec,
  3123. spec->dmux_nids[0], index);
  3124. if (nid)
  3125. err = create_elem_capture_vol(codec,
  3126. nid, label,
  3127. type_idx, HDA_INPUT);
  3128. if (err < 0)
  3129. return err;
  3130. }
  3131. }
  3132. }
  3133. return 0;
  3134. }
  3135. static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
  3136. hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
  3137. {
  3138. unsigned int cfg;
  3139. unsigned int type;
  3140. if (!nid)
  3141. return 0;
  3142. cfg = snd_hda_codec_get_pincfg(codec, nid);
  3143. type = get_defcfg_device(cfg);
  3144. switch (snd_hda_get_input_pin_attr(cfg)) {
  3145. case INPUT_PIN_ATTR_INT:
  3146. if (*fixed)
  3147. return 1; /* already occupied */
  3148. if (type != AC_JACK_MIC_IN)
  3149. return 1; /* invalid type */
  3150. *fixed = nid;
  3151. break;
  3152. case INPUT_PIN_ATTR_UNUSED:
  3153. break;
  3154. case INPUT_PIN_ATTR_DOCK:
  3155. if (*dock)
  3156. return 1; /* already occupied */
  3157. if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
  3158. return 1; /* invalid type */
  3159. *dock = nid;
  3160. break;
  3161. default:
  3162. if (*ext)
  3163. return 1; /* already occupied */
  3164. if (type != AC_JACK_MIC_IN)
  3165. return 1; /* invalid type */
  3166. *ext = nid;
  3167. break;
  3168. }
  3169. return 0;
  3170. }
  3171. static int set_mic_route(struct hda_codec *codec,
  3172. struct sigmatel_mic_route *mic,
  3173. hda_nid_t pin)
  3174. {
  3175. struct sigmatel_spec *spec = codec->spec;
  3176. struct auto_pin_cfg *cfg = &spec->autocfg;
  3177. int i;
  3178. mic->pin = pin;
  3179. if (pin == 0)
  3180. return 0;
  3181. for (i = 0; i < cfg->num_inputs; i++) {
  3182. if (pin == cfg->inputs[i].pin)
  3183. break;
  3184. }
  3185. if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
  3186. /* analog pin */
  3187. i = get_connection_index(codec, spec->mux_nids[0], pin);
  3188. if (i < 0)
  3189. return -1;
  3190. mic->mux_idx = i;
  3191. mic->dmux_idx = -1;
  3192. if (spec->dmux_nids)
  3193. mic->dmux_idx = get_connection_index(codec,
  3194. spec->dmux_nids[0],
  3195. spec->mux_nids[0]);
  3196. } else if (spec->dmux_nids) {
  3197. /* digital pin */
  3198. i = get_connection_index(codec, spec->dmux_nids[0], pin);
  3199. if (i < 0)
  3200. return -1;
  3201. mic->dmux_idx = i;
  3202. mic->mux_idx = -1;
  3203. if (spec->mux_nids)
  3204. mic->mux_idx = get_connection_index(codec,
  3205. spec->mux_nids[0],
  3206. spec->dmux_nids[0]);
  3207. }
  3208. return 0;
  3209. }
  3210. /* return non-zero if the device is for automatic mic switch */
  3211. static int stac_check_auto_mic(struct hda_codec *codec)
  3212. {
  3213. struct sigmatel_spec *spec = codec->spec;
  3214. struct auto_pin_cfg *cfg = &spec->autocfg;
  3215. hda_nid_t fixed, ext, dock;
  3216. int i;
  3217. fixed = ext = dock = 0;
  3218. for (i = 0; i < cfg->num_inputs; i++)
  3219. if (check_mic_pin(codec, cfg->inputs[i].pin,
  3220. &fixed, &ext, &dock))
  3221. return 0;
  3222. for (i = 0; i < spec->num_dmics; i++)
  3223. if (check_mic_pin(codec, spec->dmic_nids[i],
  3224. &fixed, &ext, &dock))
  3225. return 0;
  3226. if (!fixed || (!ext && !dock))
  3227. return 0; /* no input to switch */
  3228. if (!is_jack_detectable(codec, ext))
  3229. return 0; /* no unsol support */
  3230. if (set_mic_route(codec, &spec->ext_mic, ext) ||
  3231. set_mic_route(codec, &spec->int_mic, fixed) ||
  3232. set_mic_route(codec, &spec->dock_mic, dock))
  3233. return 0; /* something is wrong */
  3234. return 1;
  3235. }
  3236. /* create playback/capture controls for input pins */
  3237. static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
  3238. {
  3239. struct sigmatel_spec *spec = codec->spec;
  3240. struct hda_input_mux *imux = &spec->private_imux;
  3241. int i, j;
  3242. const char *label;
  3243. for (i = 0; i < cfg->num_inputs; i++) {
  3244. hda_nid_t nid = cfg->inputs[i].pin;
  3245. int index, err, type_idx;
  3246. index = -1;
  3247. for (j = 0; j < spec->num_muxes; j++) {
  3248. index = get_connection_index(codec, spec->mux_nids[j],
  3249. nid);
  3250. if (index >= 0)
  3251. break;
  3252. }
  3253. if (index < 0)
  3254. continue;
  3255. label = hda_get_autocfg_input_label(codec, cfg, i);
  3256. snd_hda_add_imux_item(imux, label, index, &type_idx);
  3257. err = create_elem_capture_vol(codec, nid,
  3258. label, type_idx,
  3259. HDA_INPUT);
  3260. if (err < 0)
  3261. return err;
  3262. }
  3263. spec->num_analog_muxes = imux->num_items;
  3264. if (imux->num_items) {
  3265. /*
  3266. * Set the current input for the muxes.
  3267. * The STAC9221 has two input muxes with identical source
  3268. * NID lists. Hopefully this won't get confused.
  3269. */
  3270. for (i = 0; i < spec->num_muxes; i++) {
  3271. snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
  3272. AC_VERB_SET_CONNECT_SEL,
  3273. imux->items[0].index);
  3274. }
  3275. }
  3276. return 0;
  3277. }
  3278. static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
  3279. {
  3280. struct sigmatel_spec *spec = codec->spec;
  3281. int i;
  3282. for (i = 0; i < spec->autocfg.line_outs; i++) {
  3283. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  3284. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  3285. }
  3286. }
  3287. static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
  3288. {
  3289. struct sigmatel_spec *spec = codec->spec;
  3290. int i;
  3291. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  3292. hda_nid_t pin;
  3293. pin = spec->autocfg.hp_pins[i];
  3294. if (pin) /* connect to front */
  3295. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
  3296. }
  3297. for (i = 0; i < spec->autocfg.speaker_outs; i++) {
  3298. hda_nid_t pin;
  3299. pin = spec->autocfg.speaker_pins[i];
  3300. if (pin) /* connect to front */
  3301. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
  3302. }
  3303. }
  3304. static int is_dual_headphones(struct hda_codec *codec)
  3305. {
  3306. struct sigmatel_spec *spec = codec->spec;
  3307. int i, valid_hps;
  3308. if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
  3309. spec->autocfg.hp_outs <= 1)
  3310. return 0;
  3311. valid_hps = 0;
  3312. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  3313. hda_nid_t nid = spec->autocfg.hp_pins[i];
  3314. unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
  3315. if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
  3316. continue;
  3317. valid_hps++;
  3318. }
  3319. return (valid_hps > 1);
  3320. }
  3321. static int stac92xx_parse_auto_config(struct hda_codec *codec)
  3322. {
  3323. struct sigmatel_spec *spec = codec->spec;
  3324. hda_nid_t dig_out = 0, dig_in = 0;
  3325. int hp_swap = 0;
  3326. int i, err;
  3327. if ((err = snd_hda_parse_pin_def_config(codec,
  3328. &spec->autocfg,
  3329. spec->dmic_nids)) < 0)
  3330. return err;
  3331. if (! spec->autocfg.line_outs)
  3332. return 0; /* can't find valid pin config */
  3333. /* If we have no real line-out pin and multiple hp-outs, HPs should
  3334. * be set up as multi-channel outputs.
  3335. */
  3336. if (is_dual_headphones(codec)) {
  3337. /* Copy hp_outs to line_outs, backup line_outs in
  3338. * speaker_outs so that the following routines can handle
  3339. * HP pins as primary outputs.
  3340. */
  3341. snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
  3342. memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
  3343. sizeof(spec->autocfg.line_out_pins));
  3344. spec->autocfg.speaker_outs = spec->autocfg.line_outs;
  3345. memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
  3346. sizeof(spec->autocfg.hp_pins));
  3347. spec->autocfg.line_outs = spec->autocfg.hp_outs;
  3348. spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
  3349. spec->autocfg.hp_outs = 0;
  3350. hp_swap = 1;
  3351. }
  3352. if (spec->autocfg.mono_out_pin) {
  3353. int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
  3354. (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
  3355. u32 caps = query_amp_caps(codec,
  3356. spec->autocfg.mono_out_pin, dir);
  3357. hda_nid_t conn_list[1];
  3358. /* get the mixer node and then the mono mux if it exists */
  3359. if (snd_hda_get_connections(codec,
  3360. spec->autocfg.mono_out_pin, conn_list, 1) &&
  3361. snd_hda_get_connections(codec, conn_list[0],
  3362. conn_list, 1) > 0) {
  3363. int wcaps = get_wcaps(codec, conn_list[0]);
  3364. int wid_type = get_wcaps_type(wcaps);
  3365. /* LR swap check, some stac925x have a mux that
  3366. * changes the DACs output path instead of the
  3367. * mono-mux path.
  3368. */
  3369. if (wid_type == AC_WID_AUD_SEL &&
  3370. !(wcaps & AC_WCAP_LR_SWAP))
  3371. spec->mono_nid = conn_list[0];
  3372. }
  3373. if (dir) {
  3374. hda_nid_t nid = spec->autocfg.mono_out_pin;
  3375. /* most mono outs have a least a mute/unmute switch */
  3376. dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
  3377. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
  3378. "Mono Playback Switch",
  3379. HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
  3380. if (err < 0)
  3381. return err;
  3382. /* check for volume support for the amp */
  3383. if ((caps & AC_AMPCAP_NUM_STEPS)
  3384. >> AC_AMPCAP_NUM_STEPS_SHIFT) {
  3385. err = stac92xx_add_control(spec,
  3386. STAC_CTL_WIDGET_VOL,
  3387. "Mono Playback Volume",
  3388. HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
  3389. if (err < 0)
  3390. return err;
  3391. }
  3392. }
  3393. stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
  3394. AC_PINCTL_OUT_EN);
  3395. }
  3396. if (!spec->multiout.num_dacs) {
  3397. err = stac92xx_auto_fill_dac_nids(codec);
  3398. if (err < 0)
  3399. return err;
  3400. err = stac92xx_auto_create_multi_out_ctls(codec,
  3401. &spec->autocfg);
  3402. if (err < 0)
  3403. return err;
  3404. }
  3405. /* setup analog beep controls */
  3406. if (spec->anabeep_nid > 0) {
  3407. err = stac92xx_auto_create_beep_ctls(codec,
  3408. spec->anabeep_nid);
  3409. if (err < 0)
  3410. return err;
  3411. }
  3412. /* setup digital beep controls and input device */
  3413. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  3414. if (spec->digbeep_nid > 0) {
  3415. hda_nid_t nid = spec->digbeep_nid;
  3416. unsigned int caps;
  3417. err = stac92xx_auto_create_beep_ctls(codec, nid);
  3418. if (err < 0)
  3419. return err;
  3420. err = snd_hda_attach_beep_device(codec, nid);
  3421. if (err < 0)
  3422. return err;
  3423. if (codec->beep) {
  3424. /* IDT/STAC codecs have linear beep tone parameter */
  3425. codec->beep->linear_tone = spec->linear_tone_beep;
  3426. /* if no beep switch is available, make its own one */
  3427. caps = query_amp_caps(codec, nid, HDA_OUTPUT);
  3428. if (!(caps & AC_AMPCAP_MUTE)) {
  3429. err = stac92xx_beep_switch_ctl(codec);
  3430. if (err < 0)
  3431. return err;
  3432. }
  3433. }
  3434. }
  3435. #endif
  3436. err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
  3437. if (err < 0)
  3438. return err;
  3439. /* All output parsing done, now restore the swapped hp pins */
  3440. if (hp_swap) {
  3441. memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
  3442. sizeof(spec->autocfg.hp_pins));
  3443. spec->autocfg.hp_outs = spec->autocfg.line_outs;
  3444. spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
  3445. spec->autocfg.line_outs = 0;
  3446. }
  3447. if (stac_check_auto_mic(codec)) {
  3448. spec->auto_mic = 1;
  3449. /* only one capture for auto-mic */
  3450. spec->num_adcs = 1;
  3451. spec->num_caps = 1;
  3452. spec->num_muxes = 1;
  3453. }
  3454. for (i = 0; i < spec->num_caps; i++) {
  3455. err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
  3456. spec->capsws[i], i);
  3457. if (err < 0)
  3458. return err;
  3459. }
  3460. err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
  3461. if (err < 0)
  3462. return err;
  3463. if (spec->mono_nid > 0) {
  3464. err = stac92xx_auto_create_mono_output_ctls(codec);
  3465. if (err < 0)
  3466. return err;
  3467. }
  3468. if (spec->num_dmics > 0 && !spec->dinput_mux)
  3469. if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
  3470. &spec->autocfg)) < 0)
  3471. return err;
  3472. if (spec->num_muxes > 0) {
  3473. err = stac92xx_auto_create_mux_input_ctls(codec);
  3474. if (err < 0)
  3475. return err;
  3476. }
  3477. if (spec->num_smuxes > 0) {
  3478. err = stac92xx_auto_create_spdif_mux_ctls(codec);
  3479. if (err < 0)
  3480. return err;
  3481. }
  3482. err = stac92xx_add_input_source(spec);
  3483. if (err < 0)
  3484. return err;
  3485. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3486. if (spec->multiout.max_channels > 2)
  3487. spec->surr_switch = 1;
  3488. /* find digital out and in converters */
  3489. for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
  3490. unsigned int wid_caps = get_wcaps(codec, i);
  3491. if (wid_caps & AC_WCAP_DIGITAL) {
  3492. switch (get_wcaps_type(wid_caps)) {
  3493. case AC_WID_AUD_OUT:
  3494. if (!dig_out)
  3495. dig_out = i;
  3496. break;
  3497. case AC_WID_AUD_IN:
  3498. if (!dig_in)
  3499. dig_in = i;
  3500. break;
  3501. }
  3502. }
  3503. }
  3504. if (spec->autocfg.dig_outs)
  3505. spec->multiout.dig_out_nid = dig_out;
  3506. if (dig_in && spec->autocfg.dig_in_pin)
  3507. spec->dig_in_nid = dig_in;
  3508. if (spec->kctls.list)
  3509. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  3510. spec->input_mux = &spec->private_imux;
  3511. if (!spec->dinput_mux)
  3512. spec->dinput_mux = &spec->private_dimux;
  3513. spec->sinput_mux = &spec->private_smux;
  3514. spec->mono_mux = &spec->private_mono_mux;
  3515. return 1;
  3516. }
  3517. /* add playback controls for HP output */
  3518. static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
  3519. struct auto_pin_cfg *cfg)
  3520. {
  3521. struct sigmatel_spec *spec = codec->spec;
  3522. hda_nid_t pin = cfg->hp_pins[0];
  3523. if (! pin)
  3524. return 0;
  3525. if (is_jack_detectable(codec, pin))
  3526. spec->hp_detect = 1;
  3527. return 0;
  3528. }
  3529. /* add playback controls for LFE output */
  3530. static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
  3531. struct auto_pin_cfg *cfg)
  3532. {
  3533. struct sigmatel_spec *spec = codec->spec;
  3534. int err;
  3535. hda_nid_t lfe_pin = 0x0;
  3536. int i;
  3537. /*
  3538. * search speaker outs and line outs for a mono speaker pin
  3539. * with an amp. If one is found, add LFE controls
  3540. * for it.
  3541. */
  3542. for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
  3543. hda_nid_t pin = spec->autocfg.speaker_pins[i];
  3544. unsigned int wcaps = get_wcaps(codec, pin);
  3545. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  3546. if (wcaps == AC_WCAP_OUT_AMP)
  3547. /* found a mono speaker with an amp, must be lfe */
  3548. lfe_pin = pin;
  3549. }
  3550. /* if speaker_outs is 0, then speakers may be in line_outs */
  3551. if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
  3552. for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
  3553. hda_nid_t pin = spec->autocfg.line_out_pins[i];
  3554. unsigned int defcfg;
  3555. defcfg = snd_hda_codec_get_pincfg(codec, pin);
  3556. if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
  3557. unsigned int wcaps = get_wcaps(codec, pin);
  3558. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  3559. if (wcaps == AC_WCAP_OUT_AMP)
  3560. /* found a mono speaker with an amp,
  3561. must be lfe */
  3562. lfe_pin = pin;
  3563. }
  3564. }
  3565. }
  3566. if (lfe_pin) {
  3567. err = create_controls(codec, "LFE", lfe_pin, 1);
  3568. if (err < 0)
  3569. return err;
  3570. }
  3571. return 0;
  3572. }
  3573. static int stac9200_parse_auto_config(struct hda_codec *codec)
  3574. {
  3575. struct sigmatel_spec *spec = codec->spec;
  3576. int err;
  3577. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  3578. return err;
  3579. if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  3580. return err;
  3581. if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
  3582. return err;
  3583. if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
  3584. return err;
  3585. if (spec->num_muxes > 0) {
  3586. err = stac92xx_auto_create_mux_input_ctls(codec);
  3587. if (err < 0)
  3588. return err;
  3589. }
  3590. err = stac92xx_add_input_source(spec);
  3591. if (err < 0)
  3592. return err;
  3593. if (spec->autocfg.dig_outs)
  3594. spec->multiout.dig_out_nid = 0x05;
  3595. if (spec->autocfg.dig_in_pin)
  3596. spec->dig_in_nid = 0x04;
  3597. if (spec->kctls.list)
  3598. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  3599. spec->input_mux = &spec->private_imux;
  3600. spec->dinput_mux = &spec->private_dimux;
  3601. return 1;
  3602. }
  3603. /*
  3604. * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
  3605. * funky external mute control using GPIO pins.
  3606. */
  3607. static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
  3608. unsigned int dir_mask, unsigned int data)
  3609. {
  3610. unsigned int gpiostate, gpiomask, gpiodir;
  3611. snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
  3612. gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
  3613. AC_VERB_GET_GPIO_DATA, 0);
  3614. gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
  3615. gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
  3616. AC_VERB_GET_GPIO_MASK, 0);
  3617. gpiomask |= mask;
  3618. gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
  3619. AC_VERB_GET_GPIO_DIRECTION, 0);
  3620. gpiodir |= dir_mask;
  3621. /* Configure GPIOx as CMOS */
  3622. snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
  3623. snd_hda_codec_write(codec, codec->afg, 0,
  3624. AC_VERB_SET_GPIO_MASK, gpiomask);
  3625. snd_hda_codec_read(codec, codec->afg, 0,
  3626. AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
  3627. msleep(1);
  3628. snd_hda_codec_read(codec, codec->afg, 0,
  3629. AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
  3630. }
  3631. static int stac_add_event(struct hda_codec *codec, hda_nid_t nid,
  3632. unsigned char type, int data)
  3633. {
  3634. struct hda_jack_tbl *event;
  3635. event = snd_hda_jack_tbl_new(codec, nid);
  3636. if (!event)
  3637. return -ENOMEM;
  3638. event->action = type;
  3639. event->private_data = data;
  3640. return 0;
  3641. }
  3642. /* check if given nid is a valid pin and no other events are assigned
  3643. * to it. If OK, assign the event, set the unsol flag, and returns 1.
  3644. * Otherwise, returns zero.
  3645. */
  3646. static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
  3647. unsigned int type)
  3648. {
  3649. struct hda_jack_tbl *event;
  3650. if (!is_jack_detectable(codec, nid))
  3651. return 0;
  3652. event = snd_hda_jack_tbl_new(codec, nid);
  3653. if (!event)
  3654. return -ENOMEM;
  3655. if (event->action && event->action != type)
  3656. return 0;
  3657. event->action = type;
  3658. snd_hda_jack_detect_enable(codec, nid, 0);
  3659. return 1;
  3660. }
  3661. static int is_nid_out_jack_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
  3662. {
  3663. int i;
  3664. for (i = 0; i < cfg->hp_outs; i++)
  3665. if (cfg->hp_pins[i] == nid)
  3666. return 1; /* nid is a HP-Out */
  3667. for (i = 0; i < cfg->line_outs; i++)
  3668. if (cfg->line_out_pins[i] == nid)
  3669. return 1; /* nid is a line-Out */
  3670. return 0; /* nid is not a HP-Out */
  3671. };
  3672. static void stac92xx_power_down(struct hda_codec *codec)
  3673. {
  3674. struct sigmatel_spec *spec = codec->spec;
  3675. /* power down inactive DACs */
  3676. const hda_nid_t *dac;
  3677. for (dac = spec->dac_list; *dac; dac++)
  3678. if (!check_all_dac_nids(spec, *dac))
  3679. snd_hda_codec_write(codec, *dac, 0,
  3680. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  3681. }
  3682. static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
  3683. int enable);
  3684. static inline int get_int_hint(struct hda_codec *codec, const char *key,
  3685. int *valp)
  3686. {
  3687. const char *p;
  3688. p = snd_hda_get_hint(codec, key);
  3689. if (p) {
  3690. unsigned long val;
  3691. if (!strict_strtoul(p, 0, &val)) {
  3692. *valp = val;
  3693. return 1;
  3694. }
  3695. }
  3696. return 0;
  3697. }
  3698. /* override some hints from the hwdep entry */
  3699. static void stac_store_hints(struct hda_codec *codec)
  3700. {
  3701. struct sigmatel_spec *spec = codec->spec;
  3702. int val;
  3703. val = snd_hda_get_bool_hint(codec, "hp_detect");
  3704. if (val >= 0)
  3705. spec->hp_detect = val;
  3706. if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
  3707. spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
  3708. spec->gpio_mask;
  3709. }
  3710. if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
  3711. spec->gpio_mask &= spec->gpio_mask;
  3712. if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
  3713. spec->gpio_dir &= spec->gpio_mask;
  3714. if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
  3715. spec->eapd_mask &= spec->gpio_mask;
  3716. if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
  3717. spec->gpio_mute &= spec->gpio_mask;
  3718. val = snd_hda_get_bool_hint(codec, "eapd_switch");
  3719. if (val >= 0)
  3720. spec->eapd_switch = val;
  3721. }
  3722. static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins,
  3723. const hda_nid_t *pins)
  3724. {
  3725. while (num_pins--)
  3726. stac_issue_unsol_event(codec, *pins++);
  3727. }
  3728. /* fake event to set up pins */
  3729. static void stac_fake_hp_events(struct hda_codec *codec)
  3730. {
  3731. struct sigmatel_spec *spec = codec->spec;
  3732. if (spec->autocfg.hp_outs)
  3733. stac_issue_unsol_events(codec, spec->autocfg.hp_outs,
  3734. spec->autocfg.hp_pins);
  3735. if (spec->autocfg.line_outs &&
  3736. spec->autocfg.line_out_pins[0] != spec->autocfg.hp_pins[0])
  3737. stac_issue_unsol_events(codec, spec->autocfg.line_outs,
  3738. spec->autocfg.line_out_pins);
  3739. }
  3740. static int stac92xx_init(struct hda_codec *codec)
  3741. {
  3742. struct sigmatel_spec *spec = codec->spec;
  3743. struct auto_pin_cfg *cfg = &spec->autocfg;
  3744. unsigned int gpio;
  3745. int i;
  3746. snd_hda_sequence_write(codec, spec->init);
  3747. /* power down adcs initially */
  3748. if (spec->powerdown_adcs)
  3749. for (i = 0; i < spec->num_adcs; i++)
  3750. snd_hda_codec_write(codec,
  3751. spec->adc_nids[i], 0,
  3752. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  3753. /* override some hints */
  3754. stac_store_hints(codec);
  3755. /* set up GPIO */
  3756. gpio = spec->gpio_data;
  3757. /* turn on EAPD statically when spec->eapd_switch isn't set.
  3758. * otherwise, unsol event will turn it on/off dynamically
  3759. */
  3760. if (!spec->eapd_switch)
  3761. gpio |= spec->eapd_mask;
  3762. stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
  3763. /* set up pins */
  3764. if (spec->hp_detect) {
  3765. /* Enable unsolicited responses on the HP widget */
  3766. for (i = 0; i < cfg->hp_outs; i++) {
  3767. hda_nid_t nid = cfg->hp_pins[i];
  3768. enable_pin_detect(codec, nid, STAC_HP_EVENT);
  3769. }
  3770. if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
  3771. cfg->speaker_outs > 0) {
  3772. /* enable pin-detect for line-outs as well */
  3773. for (i = 0; i < cfg->line_outs; i++) {
  3774. hda_nid_t nid = cfg->line_out_pins[i];
  3775. enable_pin_detect(codec, nid, STAC_LO_EVENT);
  3776. }
  3777. }
  3778. /* force to enable the first line-out; the others are set up
  3779. * in unsol_event
  3780. */
  3781. stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
  3782. AC_PINCTL_OUT_EN);
  3783. /* fake event to set up pins */
  3784. stac_fake_hp_events(codec);
  3785. } else {
  3786. stac92xx_auto_init_multi_out(codec);
  3787. stac92xx_auto_init_hp_out(codec);
  3788. for (i = 0; i < cfg->hp_outs; i++)
  3789. stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
  3790. }
  3791. if (spec->auto_mic) {
  3792. /* initialize connection to analog input */
  3793. if (spec->dmux_nids)
  3794. snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
  3795. AC_VERB_SET_CONNECT_SEL, 0);
  3796. if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
  3797. stac_issue_unsol_event(codec, spec->ext_mic.pin);
  3798. if (enable_pin_detect(codec, spec->dock_mic.pin,
  3799. STAC_MIC_EVENT))
  3800. stac_issue_unsol_event(codec, spec->dock_mic.pin);
  3801. }
  3802. for (i = 0; i < cfg->num_inputs; i++) {
  3803. hda_nid_t nid = cfg->inputs[i].pin;
  3804. int type = cfg->inputs[i].type;
  3805. unsigned int pinctl, conf;
  3806. if (type == AUTO_PIN_MIC) {
  3807. /* for mic pins, force to initialize */
  3808. pinctl = snd_hda_get_default_vref(codec, nid);
  3809. pinctl |= AC_PINCTL_IN_EN;
  3810. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  3811. } else {
  3812. pinctl = snd_hda_codec_read(codec, nid, 0,
  3813. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  3814. /* if PINCTL already set then skip */
  3815. /* Also, if both INPUT and OUTPUT are set,
  3816. * it must be a BIOS bug; need to override, too
  3817. */
  3818. if (!(pinctl & AC_PINCTL_IN_EN) ||
  3819. (pinctl & AC_PINCTL_OUT_EN)) {
  3820. pinctl &= ~AC_PINCTL_OUT_EN;
  3821. pinctl |= AC_PINCTL_IN_EN;
  3822. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  3823. }
  3824. }
  3825. conf = snd_hda_codec_get_pincfg(codec, nid);
  3826. if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
  3827. if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
  3828. stac_issue_unsol_event(codec, nid);
  3829. }
  3830. }
  3831. for (i = 0; i < spec->num_dmics; i++)
  3832. stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
  3833. AC_PINCTL_IN_EN);
  3834. if (cfg->dig_out_pins[0])
  3835. stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
  3836. AC_PINCTL_OUT_EN);
  3837. if (cfg->dig_in_pin)
  3838. stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
  3839. AC_PINCTL_IN_EN);
  3840. for (i = 0; i < spec->num_pwrs; i++) {
  3841. hda_nid_t nid = spec->pwr_nids[i];
  3842. int pinctl, def_conf;
  3843. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  3844. def_conf = get_defcfg_connect(def_conf);
  3845. if (def_conf == AC_JACK_PORT_NONE) {
  3846. /* power off unused ports */
  3847. stac_toggle_power_map(codec, nid, 0);
  3848. continue;
  3849. }
  3850. /* power on when no jack detection is available */
  3851. /* or when the VREF is used for controlling LED */
  3852. if (!spec->hp_detect ||
  3853. spec->vref_mute_led_nid == nid ||
  3854. !is_jack_detectable(codec, nid)) {
  3855. stac_toggle_power_map(codec, nid, 1);
  3856. continue;
  3857. }
  3858. if (is_nid_out_jack_pin(cfg, nid))
  3859. continue; /* already has an unsol event */
  3860. pinctl = snd_hda_codec_read(codec, nid, 0,
  3861. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  3862. /* outputs are only ports capable of power management
  3863. * any attempts on powering down a input port cause the
  3864. * referenced VREF to act quirky.
  3865. */
  3866. if (pinctl & AC_PINCTL_IN_EN) {
  3867. stac_toggle_power_map(codec, nid, 1);
  3868. continue;
  3869. }
  3870. if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
  3871. stac_issue_unsol_event(codec, nid);
  3872. continue;
  3873. }
  3874. /* none of the above, turn the port OFF */
  3875. stac_toggle_power_map(codec, nid, 0);
  3876. }
  3877. snd_hda_jack_report_sync(codec);
  3878. /* sync mute LED */
  3879. snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
  3880. if (spec->dac_list)
  3881. stac92xx_power_down(codec);
  3882. return 0;
  3883. }
  3884. static void stac92xx_free_kctls(struct hda_codec *codec)
  3885. {
  3886. struct sigmatel_spec *spec = codec->spec;
  3887. if (spec->kctls.list) {
  3888. struct snd_kcontrol_new *kctl = spec->kctls.list;
  3889. int i;
  3890. for (i = 0; i < spec->kctls.used; i++)
  3891. kfree(kctl[i].name);
  3892. }
  3893. snd_array_free(&spec->kctls);
  3894. }
  3895. static void stac92xx_shutup_pins(struct hda_codec *codec)
  3896. {
  3897. unsigned int i, def_conf;
  3898. if (codec->bus->shutdown)
  3899. return;
  3900. for (i = 0; i < codec->init_pins.used; i++) {
  3901. struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
  3902. def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
  3903. if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
  3904. snd_hda_set_pin_ctl(codec, pin->nid, 0);
  3905. }
  3906. }
  3907. static void stac92xx_shutup(struct hda_codec *codec)
  3908. {
  3909. struct sigmatel_spec *spec = codec->spec;
  3910. stac92xx_shutup_pins(codec);
  3911. if (spec->eapd_mask)
  3912. stac_gpio_set(codec, spec->gpio_mask,
  3913. spec->gpio_dir, spec->gpio_data &
  3914. ~spec->eapd_mask);
  3915. }
  3916. static void stac92xx_free(struct hda_codec *codec)
  3917. {
  3918. struct sigmatel_spec *spec = codec->spec;
  3919. if (! spec)
  3920. return;
  3921. stac92xx_shutup(codec);
  3922. kfree(spec);
  3923. snd_hda_detach_beep_device(codec);
  3924. }
  3925. static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
  3926. unsigned int flag)
  3927. {
  3928. unsigned int old_ctl, pin_ctl;
  3929. pin_ctl = snd_hda_codec_read(codec, nid,
  3930. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  3931. if (pin_ctl & AC_PINCTL_IN_EN) {
  3932. /*
  3933. * we need to check the current set-up direction of
  3934. * shared input pins since they can be switched via
  3935. * "xxx as Output" mixer switch
  3936. */
  3937. struct sigmatel_spec *spec = codec->spec;
  3938. if (nid == spec->line_switch || nid == spec->mic_switch)
  3939. return;
  3940. }
  3941. old_ctl = pin_ctl;
  3942. /* if setting pin direction bits, clear the current
  3943. direction bits first */
  3944. if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
  3945. pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  3946. pin_ctl |= flag;
  3947. if (old_ctl != pin_ctl)
  3948. snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl);
  3949. }
  3950. static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
  3951. unsigned int flag)
  3952. {
  3953. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  3954. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  3955. if (pin_ctl & flag)
  3956. snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl & ~flag);
  3957. }
  3958. static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
  3959. {
  3960. if (!nid)
  3961. return 0;
  3962. return snd_hda_jack_detect(codec, nid);
  3963. }
  3964. static void stac92xx_line_out_detect(struct hda_codec *codec,
  3965. int presence)
  3966. {
  3967. struct sigmatel_spec *spec = codec->spec;
  3968. struct auto_pin_cfg *cfg = &spec->autocfg;
  3969. int i;
  3970. for (i = 0; i < cfg->line_outs; i++) {
  3971. if (presence)
  3972. break;
  3973. presence = get_pin_presence(codec, cfg->line_out_pins[i]);
  3974. if (presence) {
  3975. unsigned int pinctl;
  3976. pinctl = snd_hda_codec_read(codec,
  3977. cfg->line_out_pins[i], 0,
  3978. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  3979. if (pinctl & AC_PINCTL_IN_EN)
  3980. presence = 0; /* mic- or line-input */
  3981. }
  3982. }
  3983. if (presence) {
  3984. /* disable speakers */
  3985. for (i = 0; i < cfg->speaker_outs; i++)
  3986. stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
  3987. AC_PINCTL_OUT_EN);
  3988. if (spec->eapd_mask && spec->eapd_switch)
  3989. stac_gpio_set(codec, spec->gpio_mask,
  3990. spec->gpio_dir, spec->gpio_data &
  3991. ~spec->eapd_mask);
  3992. } else {
  3993. /* enable speakers */
  3994. for (i = 0; i < cfg->speaker_outs; i++)
  3995. stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
  3996. AC_PINCTL_OUT_EN);
  3997. if (spec->eapd_mask && spec->eapd_switch)
  3998. stac_gpio_set(codec, spec->gpio_mask,
  3999. spec->gpio_dir, spec->gpio_data |
  4000. spec->eapd_mask);
  4001. }
  4002. }
  4003. /* return non-zero if the hp-pin of the given array index isn't
  4004. * a jack-detection target
  4005. */
  4006. static int no_hp_sensing(struct sigmatel_spec *spec, int i)
  4007. {
  4008. struct auto_pin_cfg *cfg = &spec->autocfg;
  4009. /* ignore sensing of shared line and mic jacks */
  4010. if (cfg->hp_pins[i] == spec->line_switch)
  4011. return 1;
  4012. if (cfg->hp_pins[i] == spec->mic_switch)
  4013. return 1;
  4014. /* ignore if the pin is set as line-out */
  4015. if (cfg->hp_pins[i] == spec->hp_switch)
  4016. return 1;
  4017. return 0;
  4018. }
  4019. static void stac92xx_hp_detect(struct hda_codec *codec)
  4020. {
  4021. struct sigmatel_spec *spec = codec->spec;
  4022. struct auto_pin_cfg *cfg = &spec->autocfg;
  4023. int i, presence;
  4024. presence = 0;
  4025. if (spec->gpio_mute)
  4026. presence = !(snd_hda_codec_read(codec, codec->afg, 0,
  4027. AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
  4028. for (i = 0; i < cfg->hp_outs; i++) {
  4029. if (presence)
  4030. break;
  4031. if (no_hp_sensing(spec, i))
  4032. continue;
  4033. presence = get_pin_presence(codec, cfg->hp_pins[i]);
  4034. if (presence) {
  4035. unsigned int pinctl;
  4036. pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
  4037. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  4038. if (pinctl & AC_PINCTL_IN_EN)
  4039. presence = 0; /* mic- or line-input */
  4040. }
  4041. }
  4042. if (presence) {
  4043. /* disable lineouts */
  4044. if (spec->hp_switch)
  4045. stac92xx_reset_pinctl(codec, spec->hp_switch,
  4046. AC_PINCTL_OUT_EN);
  4047. for (i = 0; i < cfg->line_outs; i++)
  4048. stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
  4049. AC_PINCTL_OUT_EN);
  4050. } else {
  4051. /* enable lineouts */
  4052. if (spec->hp_switch)
  4053. stac92xx_set_pinctl(codec, spec->hp_switch,
  4054. AC_PINCTL_OUT_EN);
  4055. for (i = 0; i < cfg->line_outs; i++)
  4056. stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
  4057. AC_PINCTL_OUT_EN);
  4058. }
  4059. stac92xx_line_out_detect(codec, presence);
  4060. /* toggle hp outs */
  4061. for (i = 0; i < cfg->hp_outs; i++) {
  4062. unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
  4063. if (no_hp_sensing(spec, i))
  4064. continue;
  4065. if (1 /*presence*/)
  4066. stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
  4067. #if 0 /* FIXME */
  4068. /* Resetting the pinctl like below may lead to (a sort of) regressions
  4069. * on some devices since they use the HP pin actually for line/speaker
  4070. * outs although the default pin config shows a different pin (that is
  4071. * wrong and useless).
  4072. *
  4073. * So, it's basically a problem of default pin configs, likely a BIOS issue.
  4074. * But, disabling the code below just works around it, and I'm too tired of
  4075. * bug reports with such devices...
  4076. */
  4077. else
  4078. stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
  4079. #endif /* FIXME */
  4080. }
  4081. }
  4082. static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
  4083. int enable)
  4084. {
  4085. struct sigmatel_spec *spec = codec->spec;
  4086. unsigned int idx, val;
  4087. for (idx = 0; idx < spec->num_pwrs; idx++) {
  4088. if (spec->pwr_nids[idx] == nid)
  4089. break;
  4090. }
  4091. if (idx >= spec->num_pwrs)
  4092. return;
  4093. idx = 1 << idx;
  4094. val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
  4095. if (enable)
  4096. val &= ~idx;
  4097. else
  4098. val |= idx;
  4099. /* power down unused output ports */
  4100. snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
  4101. }
  4102. static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
  4103. {
  4104. stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
  4105. }
  4106. /* get the pin connection (fixed, none, etc) */
  4107. static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
  4108. {
  4109. struct sigmatel_spec *spec = codec->spec;
  4110. unsigned int cfg;
  4111. cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
  4112. return get_defcfg_connect(cfg);
  4113. }
  4114. static int stac92xx_connected_ports(struct hda_codec *codec,
  4115. const hda_nid_t *nids, int num_nids)
  4116. {
  4117. struct sigmatel_spec *spec = codec->spec;
  4118. int idx, num;
  4119. unsigned int def_conf;
  4120. for (num = 0; num < num_nids; num++) {
  4121. for (idx = 0; idx < spec->num_pins; idx++)
  4122. if (spec->pin_nids[idx] == nids[num])
  4123. break;
  4124. if (idx >= spec->num_pins)
  4125. break;
  4126. def_conf = stac_get_defcfg_connect(codec, idx);
  4127. if (def_conf == AC_JACK_PORT_NONE)
  4128. break;
  4129. }
  4130. return num;
  4131. }
  4132. static void stac92xx_mic_detect(struct hda_codec *codec)
  4133. {
  4134. struct sigmatel_spec *spec = codec->spec;
  4135. struct sigmatel_mic_route *mic;
  4136. if (get_pin_presence(codec, spec->ext_mic.pin))
  4137. mic = &spec->ext_mic;
  4138. else if (get_pin_presence(codec, spec->dock_mic.pin))
  4139. mic = &spec->dock_mic;
  4140. else
  4141. mic = &spec->int_mic;
  4142. if (mic->dmux_idx >= 0)
  4143. snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
  4144. AC_VERB_SET_CONNECT_SEL,
  4145. mic->dmux_idx);
  4146. if (mic->mux_idx >= 0)
  4147. snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
  4148. AC_VERB_SET_CONNECT_SEL,
  4149. mic->mux_idx);
  4150. }
  4151. static void handle_unsol_event(struct hda_codec *codec,
  4152. struct hda_jack_tbl *event)
  4153. {
  4154. struct sigmatel_spec *spec = codec->spec;
  4155. int data;
  4156. switch (event->action) {
  4157. case STAC_HP_EVENT:
  4158. case STAC_LO_EVENT:
  4159. stac92xx_hp_detect(codec);
  4160. break;
  4161. case STAC_MIC_EVENT:
  4162. stac92xx_mic_detect(codec);
  4163. break;
  4164. }
  4165. switch (event->action) {
  4166. case STAC_HP_EVENT:
  4167. case STAC_LO_EVENT:
  4168. case STAC_MIC_EVENT:
  4169. case STAC_INSERT_EVENT:
  4170. case STAC_PWR_EVENT:
  4171. if (spec->num_pwrs > 0)
  4172. stac92xx_pin_sense(codec, event->nid);
  4173. switch (codec->subsystem_id) {
  4174. case 0x103c308f:
  4175. if (event->nid == 0xb) {
  4176. int pin = AC_PINCTL_IN_EN;
  4177. if (get_pin_presence(codec, 0xa)
  4178. && get_pin_presence(codec, 0xb))
  4179. pin |= AC_PINCTL_VREF_80;
  4180. if (!get_pin_presence(codec, 0xb))
  4181. pin |= AC_PINCTL_VREF_80;
  4182. /* toggle VREF state based on mic + hp pin
  4183. * status
  4184. */
  4185. stac92xx_auto_set_pinctl(codec, 0x0a, pin);
  4186. }
  4187. }
  4188. break;
  4189. case STAC_VREF_EVENT:
  4190. data = snd_hda_codec_read(codec, codec->afg, 0,
  4191. AC_VERB_GET_GPIO_DATA, 0);
  4192. /* toggle VREF state based on GPIOx status */
  4193. snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
  4194. !!(data & (1 << event->private_data)));
  4195. break;
  4196. }
  4197. }
  4198. static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
  4199. {
  4200. struct hda_jack_tbl *event = snd_hda_jack_tbl_get(codec, nid);
  4201. if (!event)
  4202. return;
  4203. handle_unsol_event(codec, event);
  4204. }
  4205. static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
  4206. {
  4207. struct hda_jack_tbl *event;
  4208. int tag;
  4209. tag = (res >> 26) & 0x7f;
  4210. event = snd_hda_jack_tbl_get_from_tag(codec, tag);
  4211. if (!event)
  4212. return;
  4213. event->jack_dirty = 1;
  4214. handle_unsol_event(codec, event);
  4215. snd_hda_jack_report_sync(codec);
  4216. }
  4217. static int hp_blike_system(u32 subsystem_id);
  4218. static void set_hp_led_gpio(struct hda_codec *codec)
  4219. {
  4220. struct sigmatel_spec *spec = codec->spec;
  4221. unsigned int gpio;
  4222. if (spec->gpio_led)
  4223. return;
  4224. gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
  4225. gpio &= AC_GPIO_IO_COUNT;
  4226. if (gpio > 3)
  4227. spec->gpio_led = 0x08; /* GPIO 3 */
  4228. else
  4229. spec->gpio_led = 0x01; /* GPIO 0 */
  4230. }
  4231. /*
  4232. * This method searches for the mute LED GPIO configuration
  4233. * provided as OEM string in SMBIOS. The format of that string
  4234. * is HP_Mute_LED_P_G or HP_Mute_LED_P
  4235. * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
  4236. * that corresponds to the NOT muted state of the master volume
  4237. * and G is the index of the GPIO to use as the mute LED control (0..9)
  4238. * If _G portion is missing it is assigned based on the codec ID
  4239. *
  4240. * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
  4241. * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
  4242. *
  4243. *
  4244. * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
  4245. * SMBIOS - at least the ones I have seen do not have them - which include
  4246. * my own system (HP Pavilion dv6-1110ax) and my cousin's
  4247. * HP Pavilion dv9500t CTO.
  4248. * Need more information on whether it is true across the entire series.
  4249. * -- kunal
  4250. */
  4251. static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity)
  4252. {
  4253. struct sigmatel_spec *spec = codec->spec;
  4254. const struct dmi_device *dev = NULL;
  4255. if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
  4256. get_int_hint(codec, "gpio_led_polarity",
  4257. &spec->gpio_led_polarity);
  4258. return 1;
  4259. }
  4260. if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
  4261. while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
  4262. NULL, dev))) {
  4263. if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
  4264. &spec->gpio_led_polarity,
  4265. &spec->gpio_led) == 2) {
  4266. unsigned int max_gpio;
  4267. max_gpio = snd_hda_param_read(codec, codec->afg,
  4268. AC_PAR_GPIO_CAP);
  4269. max_gpio &= AC_GPIO_IO_COUNT;
  4270. if (spec->gpio_led < max_gpio)
  4271. spec->gpio_led = 1 << spec->gpio_led;
  4272. else
  4273. spec->vref_mute_led_nid = spec->gpio_led;
  4274. return 1;
  4275. }
  4276. if (sscanf(dev->name, "HP_Mute_LED_%d",
  4277. &spec->gpio_led_polarity) == 1) {
  4278. set_hp_led_gpio(codec);
  4279. return 1;
  4280. }
  4281. /* BIOS bug: unfilled OEM string */
  4282. if (strstr(dev->name, "HP_Mute_LED_P_G")) {
  4283. set_hp_led_gpio(codec);
  4284. switch (codec->subsystem_id) {
  4285. case 0x103c148a:
  4286. spec->gpio_led_polarity = 0;
  4287. break;
  4288. default:
  4289. spec->gpio_led_polarity = 1;
  4290. break;
  4291. }
  4292. return 1;
  4293. }
  4294. }
  4295. /*
  4296. * Fallback case - if we don't find the DMI strings,
  4297. * we statically set the GPIO - if not a B-series system
  4298. * and default polarity is provided
  4299. */
  4300. if (!hp_blike_system(codec->subsystem_id) &&
  4301. (default_polarity == 0 || default_polarity == 1)) {
  4302. set_hp_led_gpio(codec);
  4303. spec->gpio_led_polarity = default_polarity;
  4304. return 1;
  4305. }
  4306. }
  4307. return 0;
  4308. }
  4309. static int hp_blike_system(u32 subsystem_id)
  4310. {
  4311. switch (subsystem_id) {
  4312. case 0x103c1520:
  4313. case 0x103c1521:
  4314. case 0x103c1523:
  4315. case 0x103c1524:
  4316. case 0x103c1525:
  4317. case 0x103c1722:
  4318. case 0x103c1723:
  4319. case 0x103c1724:
  4320. case 0x103c1725:
  4321. case 0x103c1726:
  4322. case 0x103c1727:
  4323. case 0x103c1728:
  4324. case 0x103c1729:
  4325. case 0x103c172a:
  4326. case 0x103c172b:
  4327. case 0x103c307e:
  4328. case 0x103c307f:
  4329. case 0x103c3080:
  4330. case 0x103c3081:
  4331. case 0x103c7007:
  4332. case 0x103c7008:
  4333. return 1;
  4334. }
  4335. return 0;
  4336. }
  4337. #ifdef CONFIG_PROC_FS
  4338. static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
  4339. struct hda_codec *codec, hda_nid_t nid)
  4340. {
  4341. if (nid == codec->afg)
  4342. snd_iprintf(buffer, "Power-Map: 0x%02x\n",
  4343. snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
  4344. }
  4345. static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
  4346. struct hda_codec *codec,
  4347. unsigned int verb)
  4348. {
  4349. snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
  4350. snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
  4351. }
  4352. /* stac92hd71bxx, stac92hd73xx */
  4353. static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
  4354. struct hda_codec *codec, hda_nid_t nid)
  4355. {
  4356. stac92hd_proc_hook(buffer, codec, nid);
  4357. if (nid == codec->afg)
  4358. analog_loop_proc_hook(buffer, codec, 0xfa0);
  4359. }
  4360. static void stac9205_proc_hook(struct snd_info_buffer *buffer,
  4361. struct hda_codec *codec, hda_nid_t nid)
  4362. {
  4363. if (nid == codec->afg)
  4364. analog_loop_proc_hook(buffer, codec, 0xfe0);
  4365. }
  4366. static void stac927x_proc_hook(struct snd_info_buffer *buffer,
  4367. struct hda_codec *codec, hda_nid_t nid)
  4368. {
  4369. if (nid == codec->afg)
  4370. analog_loop_proc_hook(buffer, codec, 0xfeb);
  4371. }
  4372. #else
  4373. #define stac92hd_proc_hook NULL
  4374. #define stac92hd7x_proc_hook NULL
  4375. #define stac9205_proc_hook NULL
  4376. #define stac927x_proc_hook NULL
  4377. #endif
  4378. #ifdef CONFIG_PM
  4379. static int stac92xx_resume(struct hda_codec *codec)
  4380. {
  4381. stac92xx_init(codec);
  4382. snd_hda_codec_resume_amp(codec);
  4383. snd_hda_codec_resume_cache(codec);
  4384. /* fake event to set up pins again to override cached values */
  4385. stac_fake_hp_events(codec);
  4386. return 0;
  4387. }
  4388. static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
  4389. {
  4390. stac92xx_shutup(codec);
  4391. return 0;
  4392. }
  4393. static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
  4394. unsigned int power_state)
  4395. {
  4396. unsigned int afg_power_state = power_state;
  4397. struct sigmatel_spec *spec = codec->spec;
  4398. if (power_state == AC_PWRST_D3) {
  4399. if (spec->vref_mute_led_nid) {
  4400. /* with vref-out pin used for mute led control
  4401. * codec AFG is prevented from D3 state
  4402. */
  4403. afg_power_state = AC_PWRST_D1;
  4404. }
  4405. /* this delay seems necessary to avoid click noise at power-down */
  4406. msleep(100);
  4407. }
  4408. snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
  4409. afg_power_state);
  4410. snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
  4411. }
  4412. #else
  4413. #define stac92xx_suspend NULL
  4414. #define stac92xx_resume NULL
  4415. #define stac92xx_set_power_state NULL
  4416. #endif /* CONFIG_PM */
  4417. /* update mute-LED accoring to the master switch */
  4418. static void stac92xx_update_led_status(struct hda_codec *codec, int enabled)
  4419. {
  4420. struct sigmatel_spec *spec = codec->spec;
  4421. int muted = !enabled;
  4422. if (!spec->gpio_led)
  4423. return;
  4424. /* LED state is inverted on these systems */
  4425. if (spec->gpio_led_polarity)
  4426. muted = !muted;
  4427. if (!spec->vref_mute_led_nid) {
  4428. if (muted)
  4429. spec->gpio_data |= spec->gpio_led;
  4430. else
  4431. spec->gpio_data &= ~spec->gpio_led;
  4432. stac_gpio_set(codec, spec->gpio_mask,
  4433. spec->gpio_dir, spec->gpio_data);
  4434. } else {
  4435. spec->vref_led = muted ? AC_PINCTL_VREF_50 : AC_PINCTL_VREF_GRD;
  4436. stac_vrefout_set(codec, spec->vref_mute_led_nid,
  4437. spec->vref_led);
  4438. }
  4439. }
  4440. static const struct hda_codec_ops stac92xx_patch_ops = {
  4441. .build_controls = stac92xx_build_controls,
  4442. .build_pcms = stac92xx_build_pcms,
  4443. .init = stac92xx_init,
  4444. .free = stac92xx_free,
  4445. .unsol_event = stac92xx_unsol_event,
  4446. #ifdef CONFIG_PM
  4447. .suspend = stac92xx_suspend,
  4448. .resume = stac92xx_resume,
  4449. #endif
  4450. .reboot_notify = stac92xx_shutup,
  4451. };
  4452. static int patch_stac9200(struct hda_codec *codec)
  4453. {
  4454. struct sigmatel_spec *spec;
  4455. int err;
  4456. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4457. if (spec == NULL)
  4458. return -ENOMEM;
  4459. codec->no_trigger_sense = 1;
  4460. codec->spec = spec;
  4461. spec->linear_tone_beep = 1;
  4462. spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
  4463. spec->pin_nids = stac9200_pin_nids;
  4464. spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
  4465. stac9200_models,
  4466. stac9200_cfg_tbl);
  4467. if (spec->board_config < 0)
  4468. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4469. codec->chip_name);
  4470. else
  4471. stac92xx_set_config_regs(codec,
  4472. stac9200_brd_tbl[spec->board_config]);
  4473. spec->multiout.max_channels = 2;
  4474. spec->multiout.num_dacs = 1;
  4475. spec->multiout.dac_nids = stac9200_dac_nids;
  4476. spec->adc_nids = stac9200_adc_nids;
  4477. spec->mux_nids = stac9200_mux_nids;
  4478. spec->num_muxes = 1;
  4479. spec->num_dmics = 0;
  4480. spec->num_adcs = 1;
  4481. spec->num_pwrs = 0;
  4482. if (spec->board_config == STAC_9200_M4 ||
  4483. spec->board_config == STAC_9200_M4_2 ||
  4484. spec->board_config == STAC_9200_OQO)
  4485. spec->init = stac9200_eapd_init;
  4486. else
  4487. spec->init = stac9200_core_init;
  4488. spec->mixer = stac9200_mixer;
  4489. if (spec->board_config == STAC_9200_PANASONIC) {
  4490. spec->gpio_mask = spec->gpio_dir = 0x09;
  4491. spec->gpio_data = 0x00;
  4492. }
  4493. err = stac9200_parse_auto_config(codec);
  4494. if (err < 0) {
  4495. stac92xx_free(codec);
  4496. return err;
  4497. }
  4498. /* CF-74 has no headphone detection, and the driver should *NOT*
  4499. * do detection and HP/speaker toggle because the hardware does it.
  4500. */
  4501. if (spec->board_config == STAC_9200_PANASONIC)
  4502. spec->hp_detect = 0;
  4503. codec->patch_ops = stac92xx_patch_ops;
  4504. return 0;
  4505. }
  4506. static int patch_stac925x(struct hda_codec *codec)
  4507. {
  4508. struct sigmatel_spec *spec;
  4509. int err;
  4510. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4511. if (spec == NULL)
  4512. return -ENOMEM;
  4513. codec->no_trigger_sense = 1;
  4514. codec->spec = spec;
  4515. spec->linear_tone_beep = 1;
  4516. spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
  4517. spec->pin_nids = stac925x_pin_nids;
  4518. /* Check first for codec ID */
  4519. spec->board_config = snd_hda_check_board_codec_sid_config(codec,
  4520. STAC_925x_MODELS,
  4521. stac925x_models,
  4522. stac925x_codec_id_cfg_tbl);
  4523. /* Now checks for PCI ID, if codec ID is not found */
  4524. if (spec->board_config < 0)
  4525. spec->board_config = snd_hda_check_board_config(codec,
  4526. STAC_925x_MODELS,
  4527. stac925x_models,
  4528. stac925x_cfg_tbl);
  4529. again:
  4530. if (spec->board_config < 0)
  4531. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4532. codec->chip_name);
  4533. else
  4534. stac92xx_set_config_regs(codec,
  4535. stac925x_brd_tbl[spec->board_config]);
  4536. spec->multiout.max_channels = 2;
  4537. spec->multiout.num_dacs = 1;
  4538. spec->multiout.dac_nids = stac925x_dac_nids;
  4539. spec->adc_nids = stac925x_adc_nids;
  4540. spec->mux_nids = stac925x_mux_nids;
  4541. spec->num_muxes = 1;
  4542. spec->num_adcs = 1;
  4543. spec->num_pwrs = 0;
  4544. switch (codec->vendor_id) {
  4545. case 0x83847632: /* STAC9202 */
  4546. case 0x83847633: /* STAC9202D */
  4547. case 0x83847636: /* STAC9251 */
  4548. case 0x83847637: /* STAC9251D */
  4549. spec->num_dmics = STAC925X_NUM_DMICS;
  4550. spec->dmic_nids = stac925x_dmic_nids;
  4551. spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
  4552. spec->dmux_nids = stac925x_dmux_nids;
  4553. break;
  4554. default:
  4555. spec->num_dmics = 0;
  4556. break;
  4557. }
  4558. spec->init = stac925x_core_init;
  4559. spec->mixer = stac925x_mixer;
  4560. spec->num_caps = 1;
  4561. spec->capvols = stac925x_capvols;
  4562. spec->capsws = stac925x_capsws;
  4563. err = stac92xx_parse_auto_config(codec);
  4564. if (!err) {
  4565. if (spec->board_config < 0) {
  4566. printk(KERN_WARNING "hda_codec: No auto-config is "
  4567. "available, default to model=ref\n");
  4568. spec->board_config = STAC_925x_REF;
  4569. goto again;
  4570. }
  4571. err = -EINVAL;
  4572. }
  4573. if (err < 0) {
  4574. stac92xx_free(codec);
  4575. return err;
  4576. }
  4577. codec->patch_ops = stac92xx_patch_ops;
  4578. return 0;
  4579. }
  4580. static int patch_stac92hd73xx(struct hda_codec *codec)
  4581. {
  4582. struct sigmatel_spec *spec;
  4583. hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
  4584. int err = 0;
  4585. int num_dacs;
  4586. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4587. if (spec == NULL)
  4588. return -ENOMEM;
  4589. codec->no_trigger_sense = 1;
  4590. codec->spec = spec;
  4591. spec->linear_tone_beep = 0;
  4592. codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
  4593. spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
  4594. spec->pin_nids = stac92hd73xx_pin_nids;
  4595. spec->board_config = snd_hda_check_board_config(codec,
  4596. STAC_92HD73XX_MODELS,
  4597. stac92hd73xx_models,
  4598. stac92hd73xx_cfg_tbl);
  4599. /* check codec subsystem id if not found */
  4600. if (spec->board_config < 0)
  4601. spec->board_config =
  4602. snd_hda_check_board_codec_sid_config(codec,
  4603. STAC_92HD73XX_MODELS, stac92hd73xx_models,
  4604. stac92hd73xx_codec_id_cfg_tbl);
  4605. again:
  4606. if (spec->board_config < 0)
  4607. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4608. codec->chip_name);
  4609. else
  4610. stac92xx_set_config_regs(codec,
  4611. stac92hd73xx_brd_tbl[spec->board_config]);
  4612. num_dacs = snd_hda_get_connections(codec, 0x0a,
  4613. conn, STAC92HD73_DAC_COUNT + 2) - 1;
  4614. if (num_dacs < 3 || num_dacs > 5) {
  4615. printk(KERN_WARNING "hda_codec: Could not determine "
  4616. "number of channels defaulting to DAC count\n");
  4617. num_dacs = STAC92HD73_DAC_COUNT;
  4618. }
  4619. spec->init = stac92hd73xx_core_init;
  4620. switch (num_dacs) {
  4621. case 0x3: /* 6 Channel */
  4622. spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
  4623. break;
  4624. case 0x4: /* 8 Channel */
  4625. spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
  4626. break;
  4627. case 0x5: /* 10 Channel */
  4628. spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
  4629. break;
  4630. }
  4631. spec->multiout.dac_nids = spec->dac_nids;
  4632. spec->aloopback_mask = 0x01;
  4633. spec->aloopback_shift = 8;
  4634. spec->digbeep_nid = 0x1c;
  4635. spec->mux_nids = stac92hd73xx_mux_nids;
  4636. spec->adc_nids = stac92hd73xx_adc_nids;
  4637. spec->dmic_nids = stac92hd73xx_dmic_nids;
  4638. spec->dmux_nids = stac92hd73xx_dmux_nids;
  4639. spec->smux_nids = stac92hd73xx_smux_nids;
  4640. spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
  4641. spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
  4642. spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
  4643. spec->num_caps = STAC92HD73XX_NUM_CAPS;
  4644. spec->capvols = stac92hd73xx_capvols;
  4645. spec->capsws = stac92hd73xx_capsws;
  4646. switch (spec->board_config) {
  4647. case STAC_DELL_EQ:
  4648. spec->init = dell_eq_core_init;
  4649. /* fallthru */
  4650. case STAC_DELL_M6_AMIC:
  4651. case STAC_DELL_M6_DMIC:
  4652. case STAC_DELL_M6_BOTH:
  4653. spec->num_smuxes = 0;
  4654. spec->eapd_switch = 0;
  4655. switch (spec->board_config) {
  4656. case STAC_DELL_M6_AMIC: /* Analog Mics */
  4657. snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
  4658. spec->num_dmics = 0;
  4659. break;
  4660. case STAC_DELL_M6_DMIC: /* Digital Mics */
  4661. snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
  4662. spec->num_dmics = 1;
  4663. break;
  4664. case STAC_DELL_M6_BOTH: /* Both */
  4665. snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
  4666. snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
  4667. spec->num_dmics = 1;
  4668. break;
  4669. }
  4670. break;
  4671. case STAC_ALIENWARE_M17X:
  4672. spec->num_dmics = STAC92HD73XX_NUM_DMICS;
  4673. spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
  4674. spec->eapd_switch = 0;
  4675. break;
  4676. default:
  4677. spec->num_dmics = STAC92HD73XX_NUM_DMICS;
  4678. spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
  4679. spec->eapd_switch = 1;
  4680. break;
  4681. }
  4682. if (spec->board_config != STAC_92HD73XX_REF) {
  4683. /* GPIO0 High = Enable EAPD */
  4684. spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
  4685. spec->gpio_data = 0x01;
  4686. }
  4687. spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
  4688. spec->pwr_nids = stac92hd73xx_pwr_nids;
  4689. err = stac92xx_parse_auto_config(codec);
  4690. if (!err) {
  4691. if (spec->board_config < 0) {
  4692. printk(KERN_WARNING "hda_codec: No auto-config is "
  4693. "available, default to model=ref\n");
  4694. spec->board_config = STAC_92HD73XX_REF;
  4695. goto again;
  4696. }
  4697. err = -EINVAL;
  4698. }
  4699. if (err < 0) {
  4700. stac92xx_free(codec);
  4701. return err;
  4702. }
  4703. if (spec->board_config == STAC_92HD73XX_NO_JD)
  4704. spec->hp_detect = 0;
  4705. codec->patch_ops = stac92xx_patch_ops;
  4706. codec->proc_widget_hook = stac92hd7x_proc_hook;
  4707. return 0;
  4708. }
  4709. static int hp_bnb2011_with_dock(struct hda_codec *codec)
  4710. {
  4711. if (codec->vendor_id != 0x111d7605 &&
  4712. codec->vendor_id != 0x111d76d1)
  4713. return 0;
  4714. switch (codec->subsystem_id) {
  4715. case 0x103c1618:
  4716. case 0x103c1619:
  4717. case 0x103c161a:
  4718. case 0x103c161b:
  4719. case 0x103c161c:
  4720. case 0x103c161d:
  4721. case 0x103c161e:
  4722. case 0x103c161f:
  4723. case 0x103c162a:
  4724. case 0x103c162b:
  4725. case 0x103c1630:
  4726. case 0x103c1631:
  4727. case 0x103c1633:
  4728. case 0x103c1634:
  4729. case 0x103c1635:
  4730. case 0x103c3587:
  4731. case 0x103c3588:
  4732. case 0x103c3589:
  4733. case 0x103c358a:
  4734. case 0x103c3667:
  4735. case 0x103c3668:
  4736. case 0x103c3669:
  4737. return 1;
  4738. }
  4739. return 0;
  4740. }
  4741. static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid)
  4742. {
  4743. struct sigmatel_spec *spec = codec->spec;
  4744. unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
  4745. int i;
  4746. spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
  4747. spec->auto_pin_cnt++;
  4748. if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
  4749. get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
  4750. for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
  4751. if (nid == stac92hd83xxx_dmic_nids[i]) {
  4752. spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
  4753. spec->auto_dmic_cnt++;
  4754. }
  4755. }
  4756. }
  4757. }
  4758. static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
  4759. {
  4760. struct sigmatel_spec *spec = codec->spec;
  4761. spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
  4762. spec->auto_adc_cnt++;
  4763. }
  4764. static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
  4765. {
  4766. int i, j;
  4767. struct sigmatel_spec *spec = codec->spec;
  4768. for (i = 0; i < spec->auto_adc_cnt; i++) {
  4769. if (get_connection_index(codec,
  4770. spec->auto_adc_nids[i], nid) >= 0) {
  4771. /* mux and volume for adc_nids[i] */
  4772. if (!spec->auto_mux_nids[i]) {
  4773. spec->auto_mux_nids[i] = nid;
  4774. /* 92hd codecs capture volume is in mux */
  4775. spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid,
  4776. 3, 0, HDA_OUTPUT);
  4777. }
  4778. for (j = 0; j < spec->auto_dmic_cnt; j++) {
  4779. if (get_connection_index(codec, nid,
  4780. spec->auto_dmic_nids[j]) >= 0) {
  4781. /* dmux for adc_nids[i] */
  4782. if (!spec->auto_dmux_nids[i])
  4783. spec->auto_dmux_nids[i] = nid;
  4784. break;
  4785. }
  4786. }
  4787. break;
  4788. }
  4789. }
  4790. }
  4791. static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
  4792. {
  4793. hda_nid_t nid, end_nid;
  4794. unsigned int wid_caps, wid_type;
  4795. struct sigmatel_spec *spec = codec->spec;
  4796. end_nid = codec->start_nid + codec->num_nodes;
  4797. for (nid = codec->start_nid; nid < end_nid; nid++) {
  4798. wid_caps = get_wcaps(codec, nid);
  4799. wid_type = get_wcaps_type(wid_caps);
  4800. if (wid_type == AC_WID_PIN)
  4801. stac92hd8x_add_pin(codec, nid);
  4802. if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
  4803. stac92hd8x_add_adc(codec, nid);
  4804. }
  4805. for (nid = codec->start_nid; nid < end_nid; nid++) {
  4806. wid_caps = get_wcaps(codec, nid);
  4807. wid_type = get_wcaps_type(wid_caps);
  4808. if (wid_type == AC_WID_AUD_SEL)
  4809. stac92hd8x_add_mux(codec, nid);
  4810. }
  4811. spec->pin_nids = spec->auto_pin_nids;
  4812. spec->num_pins = spec->auto_pin_cnt;
  4813. spec->adc_nids = spec->auto_adc_nids;
  4814. spec->num_adcs = spec->auto_adc_cnt;
  4815. spec->capvols = spec->auto_capvols;
  4816. spec->capsws = spec->auto_capvols;
  4817. spec->num_caps = spec->auto_adc_cnt;
  4818. spec->mux_nids = spec->auto_mux_nids;
  4819. spec->num_muxes = spec->auto_adc_cnt;
  4820. spec->dmux_nids = spec->auto_dmux_nids;
  4821. spec->num_dmuxes = spec->auto_adc_cnt;
  4822. spec->dmic_nids = spec->auto_dmic_nids;
  4823. spec->num_dmics = spec->auto_dmic_cnt;
  4824. }
  4825. static int patch_stac92hd83xxx(struct hda_codec *codec)
  4826. {
  4827. struct sigmatel_spec *spec;
  4828. int err;
  4829. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4830. if (spec == NULL)
  4831. return -ENOMEM;
  4832. if (hp_bnb2011_with_dock(codec)) {
  4833. snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
  4834. snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
  4835. }
  4836. codec->no_trigger_sense = 1;
  4837. codec->spec = spec;
  4838. stac92hd8x_fill_auto_spec(codec);
  4839. spec->linear_tone_beep = 0;
  4840. codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
  4841. spec->digbeep_nid = 0x21;
  4842. spec->pwr_nids = stac92hd83xxx_pwr_nids;
  4843. spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
  4844. spec->multiout.dac_nids = spec->dac_nids;
  4845. spec->init = stac92hd83xxx_core_init;
  4846. spec->board_config = snd_hda_check_board_config(codec,
  4847. STAC_92HD83XXX_MODELS,
  4848. stac92hd83xxx_models,
  4849. stac92hd83xxx_cfg_tbl);
  4850. /* check codec subsystem id if not found */
  4851. if (spec->board_config < 0)
  4852. spec->board_config =
  4853. snd_hda_check_board_codec_sid_config(codec,
  4854. STAC_92HD83XXX_MODELS, stac92hd83xxx_models,
  4855. stac92hd83xxx_codec_id_cfg_tbl);
  4856. again:
  4857. if (spec->board_config < 0)
  4858. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4859. codec->chip_name);
  4860. else
  4861. stac92xx_set_config_regs(codec,
  4862. stac92hd83xxx_brd_tbl[spec->board_config]);
  4863. codec->patch_ops = stac92xx_patch_ops;
  4864. switch (spec->board_config) {
  4865. case STAC_HP_ZEPHYR:
  4866. spec->init = stac92hd83xxx_hp_zephyr_init;
  4867. break;
  4868. }
  4869. if (find_mute_led_cfg(codec, -1/*no default cfg*/))
  4870. snd_printd("mute LED gpio %d polarity %d\n",
  4871. spec->gpio_led,
  4872. spec->gpio_led_polarity);
  4873. if (spec->gpio_led) {
  4874. if (!spec->vref_mute_led_nid) {
  4875. spec->gpio_mask |= spec->gpio_led;
  4876. spec->gpio_dir |= spec->gpio_led;
  4877. spec->gpio_data |= spec->gpio_led;
  4878. } else {
  4879. codec->patch_ops.set_power_state =
  4880. stac92xx_set_power_state;
  4881. }
  4882. }
  4883. err = stac92xx_parse_auto_config(codec);
  4884. if (!err) {
  4885. if (spec->board_config < 0) {
  4886. printk(KERN_WARNING "hda_codec: No auto-config is "
  4887. "available, default to model=ref\n");
  4888. spec->board_config = STAC_92HD83XXX_REF;
  4889. goto again;
  4890. }
  4891. err = -EINVAL;
  4892. }
  4893. if (err < 0) {
  4894. stac92xx_free(codec);
  4895. return err;
  4896. }
  4897. codec->proc_widget_hook = stac92hd_proc_hook;
  4898. return 0;
  4899. }
  4900. static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
  4901. hda_nid_t dig0pin)
  4902. {
  4903. struct sigmatel_spec *spec = codec->spec;
  4904. int idx;
  4905. for (idx = 0; idx < spec->num_pins; idx++)
  4906. if (spec->pin_nids[idx] == dig0pin)
  4907. break;
  4908. if ((idx + 2) >= spec->num_pins)
  4909. return 0;
  4910. /* dig1pin case */
  4911. if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
  4912. return 2;
  4913. /* dig0pin + dig2pin case */
  4914. if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
  4915. return 2;
  4916. if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
  4917. return 1;
  4918. else
  4919. return 0;
  4920. }
  4921. /* HP dv7 bass switch - GPIO5 */
  4922. #define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
  4923. static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
  4924. struct snd_ctl_elem_value *ucontrol)
  4925. {
  4926. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  4927. struct sigmatel_spec *spec = codec->spec;
  4928. ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
  4929. return 0;
  4930. }
  4931. static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
  4932. struct snd_ctl_elem_value *ucontrol)
  4933. {
  4934. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  4935. struct sigmatel_spec *spec = codec->spec;
  4936. unsigned int gpio_data;
  4937. gpio_data = (spec->gpio_data & ~0x20) |
  4938. (ucontrol->value.integer.value[0] ? 0x20 : 0);
  4939. if (gpio_data == spec->gpio_data)
  4940. return 0;
  4941. spec->gpio_data = gpio_data;
  4942. stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
  4943. return 1;
  4944. }
  4945. static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
  4946. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4947. .info = stac_hp_bass_gpio_info,
  4948. .get = stac_hp_bass_gpio_get,
  4949. .put = stac_hp_bass_gpio_put,
  4950. };
  4951. static int stac_add_hp_bass_switch(struct hda_codec *codec)
  4952. {
  4953. struct sigmatel_spec *spec = codec->spec;
  4954. if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
  4955. "Bass Speaker Playback Switch", 0))
  4956. return -ENOMEM;
  4957. spec->gpio_mask |= 0x20;
  4958. spec->gpio_dir |= 0x20;
  4959. spec->gpio_data |= 0x20;
  4960. return 0;
  4961. }
  4962. static int patch_stac92hd71bxx(struct hda_codec *codec)
  4963. {
  4964. struct sigmatel_spec *spec;
  4965. const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
  4966. unsigned int pin_cfg;
  4967. int err = 0;
  4968. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4969. if (spec == NULL)
  4970. return -ENOMEM;
  4971. codec->no_trigger_sense = 1;
  4972. codec->spec = spec;
  4973. spec->linear_tone_beep = 0;
  4974. codec->patch_ops = stac92xx_patch_ops;
  4975. spec->num_pins = STAC92HD71BXX_NUM_PINS;
  4976. switch (codec->vendor_id) {
  4977. case 0x111d76b6:
  4978. case 0x111d76b7:
  4979. spec->pin_nids = stac92hd71bxx_pin_nids_4port;
  4980. break;
  4981. case 0x111d7603:
  4982. case 0x111d7608:
  4983. /* On 92HD75Bx 0x27 isn't a pin nid */
  4984. spec->num_pins--;
  4985. /* fallthrough */
  4986. default:
  4987. spec->pin_nids = stac92hd71bxx_pin_nids_6port;
  4988. }
  4989. spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
  4990. spec->board_config = snd_hda_check_board_config(codec,
  4991. STAC_92HD71BXX_MODELS,
  4992. stac92hd71bxx_models,
  4993. stac92hd71bxx_cfg_tbl);
  4994. again:
  4995. if (spec->board_config < 0)
  4996. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4997. codec->chip_name);
  4998. else
  4999. stac92xx_set_config_regs(codec,
  5000. stac92hd71bxx_brd_tbl[spec->board_config]);
  5001. if (spec->board_config != STAC_92HD71BXX_REF) {
  5002. /* GPIO0 = EAPD */
  5003. spec->gpio_mask = 0x01;
  5004. spec->gpio_dir = 0x01;
  5005. spec->gpio_data = 0x01;
  5006. }
  5007. spec->dmic_nids = stac92hd71bxx_dmic_nids;
  5008. spec->dmux_nids = stac92hd71bxx_dmux_nids;
  5009. spec->num_caps = STAC92HD71BXX_NUM_CAPS;
  5010. spec->capvols = stac92hd71bxx_capvols;
  5011. spec->capsws = stac92hd71bxx_capsws;
  5012. switch (codec->vendor_id) {
  5013. case 0x111d76b6: /* 4 Port without Analog Mixer */
  5014. case 0x111d76b7:
  5015. unmute_init++;
  5016. /* fallthru */
  5017. case 0x111d76b4: /* 6 Port without Analog Mixer */
  5018. case 0x111d76b5:
  5019. spec->init = stac92hd71bxx_core_init;
  5020. codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
  5021. spec->num_dmics = stac92xx_connected_ports(codec,
  5022. stac92hd71bxx_dmic_nids,
  5023. STAC92HD71BXX_NUM_DMICS);
  5024. break;
  5025. case 0x111d7608: /* 5 Port with Analog Mixer */
  5026. switch (spec->board_config) {
  5027. case STAC_HP_M4:
  5028. /* Enable VREF power saving on GPIO1 detect */
  5029. err = stac_add_event(codec, codec->afg,
  5030. STAC_VREF_EVENT, 0x02);
  5031. if (err < 0)
  5032. return err;
  5033. snd_hda_codec_write_cache(codec, codec->afg, 0,
  5034. AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
  5035. snd_hda_jack_detect_enable(codec, codec->afg, 0);
  5036. spec->gpio_mask |= 0x02;
  5037. break;
  5038. }
  5039. if ((codec->revision_id & 0xf) == 0 ||
  5040. (codec->revision_id & 0xf) == 1)
  5041. spec->stream_delay = 40; /* 40 milliseconds */
  5042. /* disable VSW */
  5043. spec->init = stac92hd71bxx_core_init;
  5044. unmute_init++;
  5045. snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
  5046. snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
  5047. spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
  5048. spec->num_dmics = stac92xx_connected_ports(codec,
  5049. stac92hd71bxx_dmic_5port_nids,
  5050. STAC92HD71BXX_NUM_DMICS - 1);
  5051. break;
  5052. case 0x111d7603: /* 6 Port with Analog Mixer */
  5053. if ((codec->revision_id & 0xf) == 1)
  5054. spec->stream_delay = 40; /* 40 milliseconds */
  5055. /* fallthru */
  5056. default:
  5057. spec->init = stac92hd71bxx_core_init;
  5058. codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
  5059. spec->num_dmics = stac92xx_connected_ports(codec,
  5060. stac92hd71bxx_dmic_nids,
  5061. STAC92HD71BXX_NUM_DMICS);
  5062. break;
  5063. }
  5064. if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
  5065. snd_hda_sequence_write_cache(codec, unmute_init);
  5066. spec->aloopback_ctl = stac92hd71bxx_loopback;
  5067. spec->aloopback_mask = 0x50;
  5068. spec->aloopback_shift = 0;
  5069. spec->powerdown_adcs = 1;
  5070. spec->digbeep_nid = 0x26;
  5071. spec->mux_nids = stac92hd71bxx_mux_nids;
  5072. spec->adc_nids = stac92hd71bxx_adc_nids;
  5073. spec->smux_nids = stac92hd71bxx_smux_nids;
  5074. spec->pwr_nids = stac92hd71bxx_pwr_nids;
  5075. spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
  5076. spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
  5077. spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
  5078. spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
  5079. snd_printdd("Found board config: %d\n", spec->board_config);
  5080. switch (spec->board_config) {
  5081. case STAC_HP_M4:
  5082. /* enable internal microphone */
  5083. snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
  5084. stac92xx_auto_set_pinctl(codec, 0x0e,
  5085. AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
  5086. /* fallthru */
  5087. case STAC_DELL_M4_2:
  5088. spec->num_dmics = 0;
  5089. spec->num_smuxes = 0;
  5090. spec->num_dmuxes = 0;
  5091. break;
  5092. case STAC_DELL_M4_1:
  5093. case STAC_DELL_M4_3:
  5094. spec->num_dmics = 1;
  5095. spec->num_smuxes = 0;
  5096. spec->num_dmuxes = 1;
  5097. break;
  5098. case STAC_HP_DV4_1222NR:
  5099. spec->num_dmics = 1;
  5100. /* I don't know if it needs 1 or 2 smuxes - will wait for
  5101. * bug reports to fix if needed
  5102. */
  5103. spec->num_smuxes = 1;
  5104. spec->num_dmuxes = 1;
  5105. /* fallthrough */
  5106. case STAC_HP_DV4:
  5107. spec->gpio_led = 0x01;
  5108. /* fallthrough */
  5109. case STAC_HP_DV5:
  5110. snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
  5111. stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
  5112. /* HP dv6 gives the headphone pin as a line-out. Thus we
  5113. * need to set hp_detect flag here to force to enable HP
  5114. * detection.
  5115. */
  5116. spec->hp_detect = 1;
  5117. break;
  5118. case STAC_HP_HDX:
  5119. spec->num_dmics = 1;
  5120. spec->num_dmuxes = 1;
  5121. spec->num_smuxes = 1;
  5122. spec->gpio_led = 0x08;
  5123. break;
  5124. }
  5125. if (hp_blike_system(codec->subsystem_id)) {
  5126. pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
  5127. if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
  5128. get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
  5129. get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
  5130. /* It was changed in the BIOS to just satisfy MS DTM.
  5131. * Lets turn it back into slaved HP
  5132. */
  5133. pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
  5134. | (AC_JACK_HP_OUT <<
  5135. AC_DEFCFG_DEVICE_SHIFT);
  5136. pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
  5137. | AC_DEFCFG_SEQUENCE)))
  5138. | 0x1f;
  5139. snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
  5140. }
  5141. }
  5142. if (find_mute_led_cfg(codec, 1))
  5143. snd_printd("mute LED gpio %d polarity %d\n",
  5144. spec->gpio_led,
  5145. spec->gpio_led_polarity);
  5146. if (spec->gpio_led) {
  5147. if (!spec->vref_mute_led_nid) {
  5148. spec->gpio_mask |= spec->gpio_led;
  5149. spec->gpio_dir |= spec->gpio_led;
  5150. spec->gpio_data |= spec->gpio_led;
  5151. } else {
  5152. codec->patch_ops.set_power_state =
  5153. stac92xx_set_power_state;
  5154. }
  5155. }
  5156. spec->multiout.dac_nids = spec->dac_nids;
  5157. err = stac92xx_parse_auto_config(codec);
  5158. if (!err) {
  5159. if (spec->board_config < 0) {
  5160. printk(KERN_WARNING "hda_codec: No auto-config is "
  5161. "available, default to model=ref\n");
  5162. spec->board_config = STAC_92HD71BXX_REF;
  5163. goto again;
  5164. }
  5165. err = -EINVAL;
  5166. }
  5167. if (err < 0) {
  5168. stac92xx_free(codec);
  5169. return err;
  5170. }
  5171. /* enable bass on HP dv7 */
  5172. if (spec->board_config == STAC_HP_DV4 ||
  5173. spec->board_config == STAC_HP_DV5) {
  5174. unsigned int cap;
  5175. cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
  5176. cap &= AC_GPIO_IO_COUNT;
  5177. if (cap >= 6)
  5178. stac_add_hp_bass_switch(codec);
  5179. }
  5180. codec->proc_widget_hook = stac92hd7x_proc_hook;
  5181. return 0;
  5182. }
  5183. static int patch_stac922x(struct hda_codec *codec)
  5184. {
  5185. struct sigmatel_spec *spec;
  5186. int err;
  5187. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  5188. if (spec == NULL)
  5189. return -ENOMEM;
  5190. codec->no_trigger_sense = 1;
  5191. codec->spec = spec;
  5192. spec->linear_tone_beep = 1;
  5193. spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
  5194. spec->pin_nids = stac922x_pin_nids;
  5195. spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
  5196. stac922x_models,
  5197. stac922x_cfg_tbl);
  5198. if (spec->board_config == STAC_INTEL_MAC_AUTO) {
  5199. spec->gpio_mask = spec->gpio_dir = 0x03;
  5200. spec->gpio_data = 0x03;
  5201. /* Intel Macs have all same PCI SSID, so we need to check
  5202. * codec SSID to distinguish the exact models
  5203. */
  5204. printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
  5205. switch (codec->subsystem_id) {
  5206. case 0x106b0800:
  5207. spec->board_config = STAC_INTEL_MAC_V1;
  5208. break;
  5209. case 0x106b0600:
  5210. case 0x106b0700:
  5211. spec->board_config = STAC_INTEL_MAC_V2;
  5212. break;
  5213. case 0x106b0e00:
  5214. case 0x106b0f00:
  5215. case 0x106b1600:
  5216. case 0x106b1700:
  5217. case 0x106b0200:
  5218. case 0x106b1e00:
  5219. spec->board_config = STAC_INTEL_MAC_V3;
  5220. break;
  5221. case 0x106b1a00:
  5222. case 0x00000100:
  5223. spec->board_config = STAC_INTEL_MAC_V4;
  5224. break;
  5225. case 0x106b0a00:
  5226. case 0x106b2200:
  5227. spec->board_config = STAC_INTEL_MAC_V5;
  5228. break;
  5229. default:
  5230. spec->board_config = STAC_INTEL_MAC_V3;
  5231. break;
  5232. }
  5233. }
  5234. again:
  5235. if (spec->board_config < 0)
  5236. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  5237. codec->chip_name);
  5238. else
  5239. stac92xx_set_config_regs(codec,
  5240. stac922x_brd_tbl[spec->board_config]);
  5241. spec->adc_nids = stac922x_adc_nids;
  5242. spec->mux_nids = stac922x_mux_nids;
  5243. spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
  5244. spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
  5245. spec->num_dmics = 0;
  5246. spec->num_pwrs = 0;
  5247. spec->init = stac922x_core_init;
  5248. spec->num_caps = STAC922X_NUM_CAPS;
  5249. spec->capvols = stac922x_capvols;
  5250. spec->capsws = stac922x_capsws;
  5251. spec->multiout.dac_nids = spec->dac_nids;
  5252. err = stac92xx_parse_auto_config(codec);
  5253. if (!err) {
  5254. if (spec->board_config < 0) {
  5255. printk(KERN_WARNING "hda_codec: No auto-config is "
  5256. "available, default to model=ref\n");
  5257. spec->board_config = STAC_D945_REF;
  5258. goto again;
  5259. }
  5260. err = -EINVAL;
  5261. }
  5262. if (err < 0) {
  5263. stac92xx_free(codec);
  5264. return err;
  5265. }
  5266. codec->patch_ops = stac92xx_patch_ops;
  5267. /* Fix Mux capture level; max to 2 */
  5268. snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
  5269. (0 << AC_AMPCAP_OFFSET_SHIFT) |
  5270. (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  5271. (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  5272. (0 << AC_AMPCAP_MUTE_SHIFT));
  5273. return 0;
  5274. }
  5275. static int patch_stac927x(struct hda_codec *codec)
  5276. {
  5277. struct sigmatel_spec *spec;
  5278. int err;
  5279. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  5280. if (spec == NULL)
  5281. return -ENOMEM;
  5282. codec->no_trigger_sense = 1;
  5283. codec->spec = spec;
  5284. spec->linear_tone_beep = 1;
  5285. codec->slave_dig_outs = stac927x_slave_dig_outs;
  5286. spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
  5287. spec->pin_nids = stac927x_pin_nids;
  5288. spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
  5289. stac927x_models,
  5290. stac927x_cfg_tbl);
  5291. again:
  5292. if (spec->board_config < 0)
  5293. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  5294. codec->chip_name);
  5295. else
  5296. stac92xx_set_config_regs(codec,
  5297. stac927x_brd_tbl[spec->board_config]);
  5298. spec->digbeep_nid = 0x23;
  5299. spec->adc_nids = stac927x_adc_nids;
  5300. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  5301. spec->mux_nids = stac927x_mux_nids;
  5302. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  5303. spec->smux_nids = stac927x_smux_nids;
  5304. spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
  5305. spec->spdif_labels = stac927x_spdif_labels;
  5306. spec->dac_list = stac927x_dac_nids;
  5307. spec->multiout.dac_nids = spec->dac_nids;
  5308. if (spec->board_config != STAC_D965_REF) {
  5309. /* GPIO0 High = Enable EAPD */
  5310. spec->eapd_mask = spec->gpio_mask = 0x01;
  5311. spec->gpio_dir = spec->gpio_data = 0x01;
  5312. }
  5313. switch (spec->board_config) {
  5314. case STAC_D965_3ST:
  5315. case STAC_D965_5ST:
  5316. /* GPIO0 High = Enable EAPD */
  5317. spec->num_dmics = 0;
  5318. spec->init = d965_core_init;
  5319. break;
  5320. case STAC_DELL_BIOS:
  5321. switch (codec->subsystem_id) {
  5322. case 0x10280209:
  5323. case 0x1028022e:
  5324. /* correct the device field to SPDIF out */
  5325. snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
  5326. break;
  5327. }
  5328. /* configure the analog microphone on some laptops */
  5329. snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
  5330. /* correct the front output jack as a hp out */
  5331. snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
  5332. /* correct the front input jack as a mic */
  5333. snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
  5334. /* fallthru */
  5335. case STAC_DELL_3ST:
  5336. if (codec->subsystem_id != 0x1028022f) {
  5337. /* GPIO2 High = Enable EAPD */
  5338. spec->eapd_mask = spec->gpio_mask = 0x04;
  5339. spec->gpio_dir = spec->gpio_data = 0x04;
  5340. }
  5341. spec->dmic_nids = stac927x_dmic_nids;
  5342. spec->num_dmics = STAC927X_NUM_DMICS;
  5343. spec->init = dell_3st_core_init;
  5344. spec->dmux_nids = stac927x_dmux_nids;
  5345. spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
  5346. break;
  5347. case STAC_927X_VOLKNOB:
  5348. spec->num_dmics = 0;
  5349. spec->init = stac927x_volknob_core_init;
  5350. break;
  5351. default:
  5352. spec->num_dmics = 0;
  5353. spec->init = stac927x_core_init;
  5354. break;
  5355. }
  5356. spec->num_caps = STAC927X_NUM_CAPS;
  5357. spec->capvols = stac927x_capvols;
  5358. spec->capsws = stac927x_capsws;
  5359. spec->num_pwrs = 0;
  5360. spec->aloopback_ctl = stac927x_loopback;
  5361. spec->aloopback_mask = 0x40;
  5362. spec->aloopback_shift = 0;
  5363. spec->eapd_switch = 1;
  5364. err = stac92xx_parse_auto_config(codec);
  5365. if (!err) {
  5366. if (spec->board_config < 0) {
  5367. printk(KERN_WARNING "hda_codec: No auto-config is "
  5368. "available, default to model=ref\n");
  5369. spec->board_config = STAC_D965_REF;
  5370. goto again;
  5371. }
  5372. err = -EINVAL;
  5373. }
  5374. if (err < 0) {
  5375. stac92xx_free(codec);
  5376. return err;
  5377. }
  5378. codec->patch_ops = stac92xx_patch_ops;
  5379. codec->proc_widget_hook = stac927x_proc_hook;
  5380. /*
  5381. * !!FIXME!!
  5382. * The STAC927x seem to require fairly long delays for certain
  5383. * command sequences. With too short delays (even if the answer
  5384. * is set to RIRB properly), it results in the silence output
  5385. * on some hardwares like Dell.
  5386. *
  5387. * The below flag enables the longer delay (see get_response
  5388. * in hda_intel.c).
  5389. */
  5390. codec->bus->needs_damn_long_delay = 1;
  5391. /* no jack detecion for ref-no-jd model */
  5392. if (spec->board_config == STAC_D965_REF_NO_JD)
  5393. spec->hp_detect = 0;
  5394. return 0;
  5395. }
  5396. static int patch_stac9205(struct hda_codec *codec)
  5397. {
  5398. struct sigmatel_spec *spec;
  5399. int err;
  5400. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  5401. if (spec == NULL)
  5402. return -ENOMEM;
  5403. codec->no_trigger_sense = 1;
  5404. codec->spec = spec;
  5405. spec->linear_tone_beep = 1;
  5406. spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
  5407. spec->pin_nids = stac9205_pin_nids;
  5408. spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
  5409. stac9205_models,
  5410. stac9205_cfg_tbl);
  5411. again:
  5412. if (spec->board_config < 0)
  5413. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  5414. codec->chip_name);
  5415. else
  5416. stac92xx_set_config_regs(codec,
  5417. stac9205_brd_tbl[spec->board_config]);
  5418. spec->digbeep_nid = 0x23;
  5419. spec->adc_nids = stac9205_adc_nids;
  5420. spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
  5421. spec->mux_nids = stac9205_mux_nids;
  5422. spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
  5423. spec->smux_nids = stac9205_smux_nids;
  5424. spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
  5425. spec->dmic_nids = stac9205_dmic_nids;
  5426. spec->num_dmics = STAC9205_NUM_DMICS;
  5427. spec->dmux_nids = stac9205_dmux_nids;
  5428. spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
  5429. spec->num_pwrs = 0;
  5430. spec->init = stac9205_core_init;
  5431. spec->aloopback_ctl = stac9205_loopback;
  5432. spec->num_caps = STAC9205_NUM_CAPS;
  5433. spec->capvols = stac9205_capvols;
  5434. spec->capsws = stac9205_capsws;
  5435. spec->aloopback_mask = 0x40;
  5436. spec->aloopback_shift = 0;
  5437. /* Turn on/off EAPD per HP plugging */
  5438. if (spec->board_config != STAC_9205_EAPD)
  5439. spec->eapd_switch = 1;
  5440. spec->multiout.dac_nids = spec->dac_nids;
  5441. switch (spec->board_config){
  5442. case STAC_9205_DELL_M43:
  5443. /* Enable SPDIF in/out */
  5444. snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
  5445. snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
  5446. /* Enable unsol response for GPIO4/Dock HP connection */
  5447. err = stac_add_event(codec, codec->afg, STAC_VREF_EVENT, 0x01);
  5448. if (err < 0)
  5449. return err;
  5450. snd_hda_codec_write_cache(codec, codec->afg, 0,
  5451. AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
  5452. snd_hda_jack_detect_enable(codec, codec->afg, 0);
  5453. spec->gpio_dir = 0x0b;
  5454. spec->eapd_mask = 0x01;
  5455. spec->gpio_mask = 0x1b;
  5456. spec->gpio_mute = 0x10;
  5457. /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
  5458. * GPIO3 Low = DRM
  5459. */
  5460. spec->gpio_data = 0x01;
  5461. break;
  5462. case STAC_9205_REF:
  5463. /* SPDIF-In enabled */
  5464. break;
  5465. default:
  5466. /* GPIO0 High = EAPD */
  5467. spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
  5468. spec->gpio_data = 0x01;
  5469. break;
  5470. }
  5471. err = stac92xx_parse_auto_config(codec);
  5472. if (!err) {
  5473. if (spec->board_config < 0) {
  5474. printk(KERN_WARNING "hda_codec: No auto-config is "
  5475. "available, default to model=ref\n");
  5476. spec->board_config = STAC_9205_REF;
  5477. goto again;
  5478. }
  5479. err = -EINVAL;
  5480. }
  5481. if (err < 0) {
  5482. stac92xx_free(codec);
  5483. return err;
  5484. }
  5485. codec->patch_ops = stac92xx_patch_ops;
  5486. codec->proc_widget_hook = stac9205_proc_hook;
  5487. return 0;
  5488. }
  5489. /*
  5490. * STAC9872 hack
  5491. */
  5492. static const struct hda_verb stac9872_core_init[] = {
  5493. {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
  5494. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  5495. {}
  5496. };
  5497. static const hda_nid_t stac9872_pin_nids[] = {
  5498. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  5499. 0x11, 0x13, 0x14,
  5500. };
  5501. static const hda_nid_t stac9872_adc_nids[] = {
  5502. 0x8 /*,0x6*/
  5503. };
  5504. static const hda_nid_t stac9872_mux_nids[] = {
  5505. 0x15
  5506. };
  5507. static const unsigned long stac9872_capvols[] = {
  5508. HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
  5509. };
  5510. #define stac9872_capsws stac9872_capvols
  5511. static const unsigned int stac9872_vaio_pin_configs[9] = {
  5512. 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
  5513. 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
  5514. 0x90a7013e
  5515. };
  5516. static const char * const stac9872_models[STAC_9872_MODELS] = {
  5517. [STAC_9872_AUTO] = "auto",
  5518. [STAC_9872_VAIO] = "vaio",
  5519. };
  5520. static const unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
  5521. [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
  5522. };
  5523. static const struct snd_pci_quirk stac9872_cfg_tbl[] = {
  5524. SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
  5525. "Sony VAIO F/S", STAC_9872_VAIO),
  5526. {} /* terminator */
  5527. };
  5528. static int patch_stac9872(struct hda_codec *codec)
  5529. {
  5530. struct sigmatel_spec *spec;
  5531. int err;
  5532. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  5533. if (spec == NULL)
  5534. return -ENOMEM;
  5535. codec->no_trigger_sense = 1;
  5536. codec->spec = spec;
  5537. spec->linear_tone_beep = 1;
  5538. spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
  5539. spec->pin_nids = stac9872_pin_nids;
  5540. spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
  5541. stac9872_models,
  5542. stac9872_cfg_tbl);
  5543. if (spec->board_config < 0)
  5544. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  5545. codec->chip_name);
  5546. else
  5547. stac92xx_set_config_regs(codec,
  5548. stac9872_brd_tbl[spec->board_config]);
  5549. spec->multiout.dac_nids = spec->dac_nids;
  5550. spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
  5551. spec->adc_nids = stac9872_adc_nids;
  5552. spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
  5553. spec->mux_nids = stac9872_mux_nids;
  5554. spec->init = stac9872_core_init;
  5555. spec->num_caps = 1;
  5556. spec->capvols = stac9872_capvols;
  5557. spec->capsws = stac9872_capsws;
  5558. err = stac92xx_parse_auto_config(codec);
  5559. if (err < 0) {
  5560. stac92xx_free(codec);
  5561. return -EINVAL;
  5562. }
  5563. spec->input_mux = &spec->private_imux;
  5564. codec->patch_ops = stac92xx_patch_ops;
  5565. return 0;
  5566. }
  5567. /*
  5568. * patch entries
  5569. */
  5570. static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
  5571. { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
  5572. { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
  5573. { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
  5574. { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
  5575. { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
  5576. { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
  5577. { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
  5578. { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
  5579. { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
  5580. { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
  5581. { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
  5582. { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
  5583. { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
  5584. { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
  5585. { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
  5586. { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
  5587. { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
  5588. { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
  5589. { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
  5590. { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
  5591. { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
  5592. { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
  5593. { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
  5594. { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
  5595. { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
  5596. { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
  5597. { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
  5598. { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
  5599. { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
  5600. { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
  5601. { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
  5602. /* The following does not take into account .id=0x83847661 when subsys =
  5603. * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
  5604. * currently not fully supported.
  5605. */
  5606. { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
  5607. { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
  5608. { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
  5609. { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
  5610. { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
  5611. { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
  5612. { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
  5613. { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
  5614. { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
  5615. { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
  5616. { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
  5617. { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
  5618. { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
  5619. { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
  5620. { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
  5621. { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
  5622. { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
  5623. { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
  5624. { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
  5625. { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
  5626. { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
  5627. { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
  5628. { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
  5629. { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
  5630. { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
  5631. { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
  5632. { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
  5633. { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
  5634. { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
  5635. { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
  5636. { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
  5637. { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
  5638. { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
  5639. { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
  5640. { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
  5641. { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
  5642. { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
  5643. { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
  5644. { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
  5645. { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
  5646. { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
  5647. { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
  5648. { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
  5649. { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
  5650. { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
  5651. { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
  5652. { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
  5653. { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
  5654. { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
  5655. { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
  5656. { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
  5657. { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
  5658. { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
  5659. { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
  5660. { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
  5661. { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
  5662. { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
  5663. { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
  5664. { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
  5665. { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
  5666. { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
  5667. { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
  5668. { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
  5669. { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
  5670. { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
  5671. { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
  5672. { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
  5673. {} /* terminator */
  5674. };
  5675. MODULE_ALIAS("snd-hda-codec-id:8384*");
  5676. MODULE_ALIAS("snd-hda-codec-id:111d*");
  5677. MODULE_LICENSE("GPL");
  5678. MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
  5679. static struct hda_codec_preset_list sigmatel_list = {
  5680. .preset = snd_hda_preset_sigmatel,
  5681. .owner = THIS_MODULE,
  5682. };
  5683. static int __init patch_sigmatel_init(void)
  5684. {
  5685. return snd_hda_add_codec_preset(&sigmatel_list);
  5686. }
  5687. static void __exit patch_sigmatel_exit(void)
  5688. {
  5689. snd_hda_delete_codec_preset(&sigmatel_list);
  5690. }
  5691. module_init(patch_sigmatel_init)
  5692. module_exit(patch_sigmatel_exit)