patch_sigmatel.c 166 KB

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