patch_via.c 155 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec
  5. *
  6. * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com>
  7. * Takashi Iwai <tiwai@suse.de>
  8. *
  9. * This driver is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This driver is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
  24. /* */
  25. /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
  26. /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
  27. /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
  28. /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
  29. /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
  30. /* 2007-09-17 Lydia Wang Add VT1708B codec support */
  31. /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
  32. /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
  33. /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
  34. /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
  35. /* 2008-04-09 Lydia Wang Add Independent HP feature */
  36. /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
  37. /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
  38. /* */
  39. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  40. #include <linux/init.h>
  41. #include <linux/delay.h>
  42. #include <linux/slab.h>
  43. #include <sound/core.h>
  44. #include <sound/asoundef.h>
  45. #include "hda_codec.h"
  46. #include "hda_local.h"
  47. /* amp values */
  48. #define AMP_VAL_IDX_SHIFT 19
  49. #define AMP_VAL_IDX_MASK (0x0f<<19)
  50. /* Pin Widget NID */
  51. #define VT1708_HP_NID 0x13
  52. #define VT1708_DIGOUT_NID 0x14
  53. #define VT1708_DIGIN_NID 0x16
  54. #define VT1708_DIGIN_PIN 0x26
  55. #define VT1708_HP_PIN_NID 0x20
  56. #define VT1708_CD_PIN_NID 0x24
  57. #define VT1709_HP_DAC_NID 0x28
  58. #define VT1709_DIGOUT_NID 0x13
  59. #define VT1709_DIGIN_NID 0x17
  60. #define VT1709_DIGIN_PIN 0x25
  61. #define VT1708B_HP_NID 0x25
  62. #define VT1708B_DIGOUT_NID 0x12
  63. #define VT1708B_DIGIN_NID 0x15
  64. #define VT1708B_DIGIN_PIN 0x21
  65. #define VT1708S_HP_NID 0x25
  66. #define VT1708S_DIGOUT_NID 0x12
  67. #define VT1702_HP_NID 0x17
  68. #define VT1702_DIGOUT_NID 0x11
  69. enum VIA_HDA_CODEC {
  70. UNKNOWN = -1,
  71. VT1708,
  72. VT1709_10CH,
  73. VT1709_6CH,
  74. VT1708B_8CH,
  75. VT1708B_4CH,
  76. VT1708S,
  77. VT1708BCE,
  78. VT1702,
  79. VT1718S,
  80. VT1716S,
  81. VT2002P,
  82. CODEC_TYPES,
  83. };
  84. struct via_spec {
  85. /* codec parameterization */
  86. struct snd_kcontrol_new *mixers[6];
  87. unsigned int num_mixers;
  88. struct hda_verb *init_verbs[5];
  89. unsigned int num_iverbs;
  90. char *stream_name_analog;
  91. struct hda_pcm_stream *stream_analog_playback;
  92. struct hda_pcm_stream *stream_analog_capture;
  93. char *stream_name_digital;
  94. struct hda_pcm_stream *stream_digital_playback;
  95. struct hda_pcm_stream *stream_digital_capture;
  96. /* playback */
  97. struct hda_multi_out multiout;
  98. hda_nid_t slave_dig_outs[2];
  99. /* capture */
  100. unsigned int num_adc_nids;
  101. hda_nid_t *adc_nids;
  102. hda_nid_t mux_nids[3];
  103. hda_nid_t dig_in_nid;
  104. hda_nid_t dig_in_pin;
  105. /* capture source */
  106. const struct hda_input_mux *input_mux;
  107. unsigned int cur_mux[3];
  108. /* PCM information */
  109. struct hda_pcm pcm_rec[3];
  110. /* dynamic controls, init_verbs and input_mux */
  111. struct auto_pin_cfg autocfg;
  112. struct snd_array kctls;
  113. struct hda_input_mux private_imux[2];
  114. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  115. /* HP mode source */
  116. const struct hda_input_mux *hp_mux;
  117. unsigned int hp_independent_mode;
  118. unsigned int hp_independent_mode_index;
  119. unsigned int smart51_enabled;
  120. unsigned int dmic_enabled;
  121. enum VIA_HDA_CODEC codec_type;
  122. /* work to check hp jack state */
  123. struct hda_codec *codec;
  124. struct delayed_work vt1708_hp_work;
  125. int vt1708_jack_detectect;
  126. int vt1708_hp_present;
  127. #ifdef CONFIG_SND_HDA_POWER_SAVE
  128. struct hda_loopback_check loopback;
  129. #endif
  130. };
  131. static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
  132. {
  133. u32 vendor_id = codec->vendor_id;
  134. u16 ven_id = vendor_id >> 16;
  135. u16 dev_id = vendor_id & 0xffff;
  136. enum VIA_HDA_CODEC codec_type;
  137. /* get codec type */
  138. if (ven_id != 0x1106)
  139. codec_type = UNKNOWN;
  140. else if (dev_id >= 0x1708 && dev_id <= 0x170b)
  141. codec_type = VT1708;
  142. else if (dev_id >= 0xe710 && dev_id <= 0xe713)
  143. codec_type = VT1709_10CH;
  144. else if (dev_id >= 0xe714 && dev_id <= 0xe717)
  145. codec_type = VT1709_6CH;
  146. else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
  147. codec_type = VT1708B_8CH;
  148. if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
  149. codec_type = VT1708BCE;
  150. } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
  151. codec_type = VT1708B_4CH;
  152. else if ((dev_id & 0xfff) == 0x397
  153. && (dev_id >> 12) < 8)
  154. codec_type = VT1708S;
  155. else if ((dev_id & 0xfff) == 0x398
  156. && (dev_id >> 12) < 8)
  157. codec_type = VT1702;
  158. else if ((dev_id & 0xfff) == 0x428
  159. && (dev_id >> 12) < 8)
  160. codec_type = VT1718S;
  161. else if (dev_id == 0x0433 || dev_id == 0xa721)
  162. codec_type = VT1716S;
  163. else if (dev_id == 0x0441 || dev_id == 0x4441)
  164. codec_type = VT1718S;
  165. else if (dev_id == 0x0438 || dev_id == 0x4438)
  166. codec_type = VT2002P;
  167. else
  168. codec_type = UNKNOWN;
  169. return codec_type;
  170. };
  171. #define VIA_HP_EVENT 0x01
  172. #define VIA_GPIO_EVENT 0x02
  173. #define VIA_JACK_EVENT 0x04
  174. #define VIA_MONO_EVENT 0x08
  175. #define VIA_SPEAKER_EVENT 0x10
  176. #define VIA_BIND_HP_EVENT 0x20
  177. enum {
  178. VIA_CTL_WIDGET_VOL,
  179. VIA_CTL_WIDGET_MUTE,
  180. VIA_CTL_WIDGET_ANALOG_MUTE,
  181. VIA_CTL_WIDGET_BIND_PIN_MUTE,
  182. };
  183. enum {
  184. AUTO_SEQ_FRONT = 0,
  185. AUTO_SEQ_SURROUND,
  186. AUTO_SEQ_CENLFE,
  187. AUTO_SEQ_SIDE
  188. };
  189. static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
  190. static void set_jack_power_state(struct hda_codec *codec);
  191. static int is_aa_path_mute(struct hda_codec *codec);
  192. static void vt1708_start_hp_work(struct via_spec *spec)
  193. {
  194. if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
  195. return;
  196. snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
  197. !spec->vt1708_jack_detectect);
  198. if (!delayed_work_pending(&spec->vt1708_hp_work))
  199. schedule_delayed_work(&spec->vt1708_hp_work,
  200. msecs_to_jiffies(100));
  201. }
  202. static void vt1708_stop_hp_work(struct via_spec *spec)
  203. {
  204. if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
  205. return;
  206. if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
  207. && !is_aa_path_mute(spec->codec))
  208. return;
  209. snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
  210. !spec->vt1708_jack_detectect);
  211. cancel_delayed_work(&spec->vt1708_hp_work);
  212. flush_scheduled_work();
  213. }
  214. static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
  215. struct snd_ctl_elem_value *ucontrol)
  216. {
  217. int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
  218. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  219. set_jack_power_state(codec);
  220. analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
  221. if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
  222. if (is_aa_path_mute(codec))
  223. vt1708_start_hp_work(codec->spec);
  224. else
  225. vt1708_stop_hp_work(codec->spec);
  226. }
  227. return change;
  228. }
  229. /* modify .put = snd_hda_mixer_amp_switch_put */
  230. #define ANALOG_INPUT_MUTE \
  231. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  232. .name = NULL, \
  233. .index = 0, \
  234. .info = snd_hda_mixer_amp_switch_info, \
  235. .get = snd_hda_mixer_amp_switch_get, \
  236. .put = analog_input_switch_put, \
  237. .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
  238. static void via_hp_bind_automute(struct hda_codec *codec);
  239. static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
  240. struct snd_ctl_elem_value *ucontrol)
  241. {
  242. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  243. struct via_spec *spec = codec->spec;
  244. int i;
  245. int change = 0;
  246. long *valp = ucontrol->value.integer.value;
  247. int lmute, rmute;
  248. if (strstr(kcontrol->id.name, "Switch") == NULL) {
  249. snd_printd("Invalid control!\n");
  250. return change;
  251. }
  252. change = snd_hda_mixer_amp_switch_put(kcontrol,
  253. ucontrol);
  254. /* Get mute value */
  255. lmute = *valp ? 0 : HDA_AMP_MUTE;
  256. valp++;
  257. rmute = *valp ? 0 : HDA_AMP_MUTE;
  258. /* Set hp pins */
  259. if (!spec->hp_independent_mode) {
  260. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  261. snd_hda_codec_amp_update(
  262. codec, spec->autocfg.hp_pins[i],
  263. 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  264. lmute);
  265. snd_hda_codec_amp_update(
  266. codec, spec->autocfg.hp_pins[i],
  267. 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  268. rmute);
  269. }
  270. }
  271. if (!lmute && !rmute) {
  272. /* Line Outs */
  273. for (i = 0; i < spec->autocfg.line_outs; i++)
  274. snd_hda_codec_amp_stereo(
  275. codec, spec->autocfg.line_out_pins[i],
  276. HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
  277. /* Speakers */
  278. for (i = 0; i < spec->autocfg.speaker_outs; i++)
  279. snd_hda_codec_amp_stereo(
  280. codec, spec->autocfg.speaker_pins[i],
  281. HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
  282. /* unmute */
  283. via_hp_bind_automute(codec);
  284. } else {
  285. if (lmute) {
  286. /* Mute all left channels */
  287. for (i = 1; i < spec->autocfg.line_outs; i++)
  288. snd_hda_codec_amp_update(
  289. codec,
  290. spec->autocfg.line_out_pins[i],
  291. 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  292. lmute);
  293. for (i = 0; i < spec->autocfg.speaker_outs; i++)
  294. snd_hda_codec_amp_update(
  295. codec,
  296. spec->autocfg.speaker_pins[i],
  297. 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  298. lmute);
  299. }
  300. if (rmute) {
  301. /* mute all right channels */
  302. for (i = 1; i < spec->autocfg.line_outs; i++)
  303. snd_hda_codec_amp_update(
  304. codec,
  305. spec->autocfg.line_out_pins[i],
  306. 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  307. rmute);
  308. for (i = 0; i < spec->autocfg.speaker_outs; i++)
  309. snd_hda_codec_amp_update(
  310. codec,
  311. spec->autocfg.speaker_pins[i],
  312. 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  313. rmute);
  314. }
  315. }
  316. return change;
  317. }
  318. #define BIND_PIN_MUTE \
  319. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  320. .name = NULL, \
  321. .index = 0, \
  322. .info = snd_hda_mixer_amp_switch_info, \
  323. .get = snd_hda_mixer_amp_switch_get, \
  324. .put = bind_pin_switch_put, \
  325. .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
  326. static struct snd_kcontrol_new vt1708_control_templates[] = {
  327. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  328. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  329. ANALOG_INPUT_MUTE,
  330. BIND_PIN_MUTE,
  331. };
  332. static hda_nid_t vt1708_adc_nids[2] = {
  333. /* ADC1-2 */
  334. 0x15, 0x27
  335. };
  336. static hda_nid_t vt1709_adc_nids[3] = {
  337. /* ADC1-2 */
  338. 0x14, 0x15, 0x16
  339. };
  340. static hda_nid_t vt1708B_adc_nids[2] = {
  341. /* ADC1-2 */
  342. 0x13, 0x14
  343. };
  344. static hda_nid_t vt1708S_adc_nids[2] = {
  345. /* ADC1-2 */
  346. 0x13, 0x14
  347. };
  348. static hda_nid_t vt1702_adc_nids[3] = {
  349. /* ADC1-2 */
  350. 0x12, 0x20, 0x1F
  351. };
  352. static hda_nid_t vt1718S_adc_nids[2] = {
  353. /* ADC1-2 */
  354. 0x10, 0x11
  355. };
  356. static hda_nid_t vt1716S_adc_nids[2] = {
  357. /* ADC1-2 */
  358. 0x13, 0x14
  359. };
  360. static hda_nid_t vt2002P_adc_nids[2] = {
  361. /* ADC1-2 */
  362. 0x10, 0x11
  363. };
  364. /* add dynamic controls */
  365. static int via_add_control(struct via_spec *spec, int type, const char *name,
  366. unsigned long val)
  367. {
  368. struct snd_kcontrol_new *knew;
  369. snd_array_init(&spec->kctls, sizeof(*knew), 32);
  370. knew = snd_array_new(&spec->kctls);
  371. if (!knew)
  372. return -ENOMEM;
  373. *knew = vt1708_control_templates[type];
  374. knew->name = kstrdup(name, GFP_KERNEL);
  375. if (!knew->name)
  376. return -ENOMEM;
  377. knew->private_value = val;
  378. return 0;
  379. }
  380. static void via_free_kctls(struct hda_codec *codec)
  381. {
  382. struct via_spec *spec = codec->spec;
  383. if (spec->kctls.list) {
  384. struct snd_kcontrol_new *kctl = spec->kctls.list;
  385. int i;
  386. for (i = 0; i < spec->kctls.used; i++)
  387. kfree(kctl[i].name);
  388. }
  389. snd_array_free(&spec->kctls);
  390. }
  391. /* create input playback/capture controls for the given pin */
  392. static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
  393. int idx, int mix_nid)
  394. {
  395. char name[32];
  396. int err;
  397. sprintf(name, "%s Playback Volume", ctlname);
  398. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  399. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  400. if (err < 0)
  401. return err;
  402. sprintf(name, "%s Playback Switch", ctlname);
  403. err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name,
  404. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  405. if (err < 0)
  406. return err;
  407. return 0;
  408. }
  409. static void via_auto_set_output_and_unmute(struct hda_codec *codec,
  410. hda_nid_t nid, int pin_type,
  411. int dac_idx)
  412. {
  413. /* set as output */
  414. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  415. pin_type);
  416. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  417. AMP_OUT_UNMUTE);
  418. if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
  419. snd_hda_codec_write(codec, nid, 0,
  420. AC_VERB_SET_EAPD_BTLENABLE, 0x02);
  421. }
  422. static void via_auto_init_multi_out(struct hda_codec *codec)
  423. {
  424. struct via_spec *spec = codec->spec;
  425. int i;
  426. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  427. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  428. if (nid)
  429. via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
  430. }
  431. }
  432. static void via_auto_init_hp_out(struct hda_codec *codec)
  433. {
  434. struct via_spec *spec = codec->spec;
  435. hda_nid_t pin;
  436. int i;
  437. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  438. pin = spec->autocfg.hp_pins[i];
  439. if (pin) /* connect to front */
  440. via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
  441. }
  442. }
  443. static void via_auto_init_analog_input(struct hda_codec *codec)
  444. {
  445. struct via_spec *spec = codec->spec;
  446. int i;
  447. for (i = 0; i < AUTO_PIN_LAST; i++) {
  448. hda_nid_t nid = spec->autocfg.input_pins[i];
  449. snd_hda_codec_write(codec, nid, 0,
  450. AC_VERB_SET_PIN_WIDGET_CONTROL,
  451. (i <= AUTO_PIN_FRONT_MIC ?
  452. PIN_VREF50 : PIN_IN));
  453. }
  454. }
  455. static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
  456. static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
  457. unsigned int *affected_parm)
  458. {
  459. unsigned parm;
  460. unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
  461. unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
  462. >> AC_DEFCFG_MISC_SHIFT
  463. & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
  464. unsigned present = snd_hda_codec_read(codec, nid, 0,
  465. AC_VERB_GET_PIN_SENSE, 0) >> 31;
  466. struct via_spec *spec = codec->spec;
  467. if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
  468. || ((no_presence || present)
  469. && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
  470. *affected_parm = AC_PWRST_D0; /* if it's connected */
  471. parm = AC_PWRST_D0;
  472. } else
  473. parm = AC_PWRST_D3;
  474. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
  475. }
  476. static void set_jack_power_state(struct hda_codec *codec)
  477. {
  478. struct via_spec *spec = codec->spec;
  479. int imux_is_smixer;
  480. unsigned int parm;
  481. if (spec->codec_type == VT1702) {
  482. imux_is_smixer = snd_hda_codec_read(
  483. codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
  484. /* inputs */
  485. /* PW 1/2/5 (14h/15h/18h) */
  486. parm = AC_PWRST_D3;
  487. set_pin_power_state(codec, 0x14, &parm);
  488. set_pin_power_state(codec, 0x15, &parm);
  489. set_pin_power_state(codec, 0x18, &parm);
  490. if (imux_is_smixer)
  491. parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
  492. /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
  493. snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
  494. parm);
  495. snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
  496. parm);
  497. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
  498. parm);
  499. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
  500. parm);
  501. /* outputs */
  502. /* PW 3/4 (16h/17h) */
  503. parm = AC_PWRST_D3;
  504. set_pin_power_state(codec, 0x16, &parm);
  505. set_pin_power_state(codec, 0x17, &parm);
  506. /* MW0 (1ah), AOW 0/1 (10h/1dh) */
  507. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
  508. imux_is_smixer ? AC_PWRST_D0 : parm);
  509. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
  510. parm);
  511. snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
  512. parm);
  513. } else if (spec->codec_type == VT1708B_8CH
  514. || spec->codec_type == VT1708B_4CH
  515. || spec->codec_type == VT1708S) {
  516. /* SW0 (17h) = stereo mixer */
  517. int is_8ch = spec->codec_type != VT1708B_4CH;
  518. imux_is_smixer = snd_hda_codec_read(
  519. codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
  520. == ((spec->codec_type == VT1708S) ? 5 : 0);
  521. /* inputs */
  522. /* PW 1/2/5 (1ah/1bh/1eh) */
  523. parm = AC_PWRST_D3;
  524. set_pin_power_state(codec, 0x1a, &parm);
  525. set_pin_power_state(codec, 0x1b, &parm);
  526. set_pin_power_state(codec, 0x1e, &parm);
  527. if (imux_is_smixer)
  528. parm = AC_PWRST_D0;
  529. /* SW0 (17h), AIW 0/1 (13h/14h) */
  530. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
  531. parm);
  532. snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
  533. parm);
  534. snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
  535. parm);
  536. /* outputs */
  537. /* PW0 (19h), SW1 (18h), AOW1 (11h) */
  538. parm = AC_PWRST_D3;
  539. set_pin_power_state(codec, 0x19, &parm);
  540. snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
  541. parm);
  542. snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
  543. parm);
  544. /* PW6 (22h), SW2 (26h), AOW2 (24h) */
  545. if (is_8ch) {
  546. parm = AC_PWRST_D3;
  547. set_pin_power_state(codec, 0x22, &parm);
  548. snd_hda_codec_write(codec, 0x26, 0,
  549. AC_VERB_SET_POWER_STATE, parm);
  550. snd_hda_codec_write(codec, 0x24, 0,
  551. AC_VERB_SET_POWER_STATE, parm);
  552. }
  553. /* PW 3/4/7 (1ch/1dh/23h) */
  554. parm = AC_PWRST_D3;
  555. /* force to D0 for internal Speaker */
  556. set_pin_power_state(codec, 0x1c, &parm);
  557. set_pin_power_state(codec, 0x1d, &parm);
  558. if (is_8ch)
  559. set_pin_power_state(codec, 0x23, &parm);
  560. /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
  561. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
  562. imux_is_smixer ? AC_PWRST_D0 : parm);
  563. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
  564. parm);
  565. if (is_8ch) {
  566. snd_hda_codec_write(codec, 0x25, 0,
  567. AC_VERB_SET_POWER_STATE, parm);
  568. snd_hda_codec_write(codec, 0x27, 0,
  569. AC_VERB_SET_POWER_STATE, parm);
  570. }
  571. } else if (spec->codec_type == VT1718S) {
  572. /* MUX6 (1eh) = stereo mixer */
  573. imux_is_smixer = snd_hda_codec_read(
  574. codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
  575. /* inputs */
  576. /* PW 5/6/7 (29h/2ah/2bh) */
  577. parm = AC_PWRST_D3;
  578. set_pin_power_state(codec, 0x29, &parm);
  579. set_pin_power_state(codec, 0x2a, &parm);
  580. set_pin_power_state(codec, 0x2b, &parm);
  581. if (imux_is_smixer)
  582. parm = AC_PWRST_D0;
  583. /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
  584. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
  585. parm);
  586. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
  587. parm);
  588. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
  589. parm);
  590. snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
  591. parm);
  592. /* outputs */
  593. /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
  594. parm = AC_PWRST_D3;
  595. set_pin_power_state(codec, 0x27, &parm);
  596. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
  597. parm);
  598. snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
  599. parm);
  600. /* PW2 (26h), AOW2 (ah) */
  601. parm = AC_PWRST_D3;
  602. set_pin_power_state(codec, 0x26, &parm);
  603. snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
  604. parm);
  605. /* PW0/1 (24h/25h) */
  606. parm = AC_PWRST_D3;
  607. set_pin_power_state(codec, 0x24, &parm);
  608. set_pin_power_state(codec, 0x25, &parm);
  609. if (!spec->hp_independent_mode) /* check for redirected HP */
  610. set_pin_power_state(codec, 0x28, &parm);
  611. snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
  612. parm);
  613. snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
  614. parm);
  615. /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
  616. snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
  617. imux_is_smixer ? AC_PWRST_D0 : parm);
  618. if (spec->hp_independent_mode) {
  619. /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
  620. parm = AC_PWRST_D3;
  621. set_pin_power_state(codec, 0x28, &parm);
  622. snd_hda_codec_write(codec, 0x1b, 0,
  623. AC_VERB_SET_POWER_STATE, parm);
  624. snd_hda_codec_write(codec, 0x34, 0,
  625. AC_VERB_SET_POWER_STATE, parm);
  626. snd_hda_codec_write(codec, 0xc, 0,
  627. AC_VERB_SET_POWER_STATE, parm);
  628. }
  629. } else if (spec->codec_type == VT1716S) {
  630. unsigned int mono_out, present;
  631. /* SW0 (17h) = stereo mixer */
  632. imux_is_smixer = snd_hda_codec_read(
  633. codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
  634. /* inputs */
  635. /* PW 1/2/5 (1ah/1bh/1eh) */
  636. parm = AC_PWRST_D3;
  637. set_pin_power_state(codec, 0x1a, &parm);
  638. set_pin_power_state(codec, 0x1b, &parm);
  639. set_pin_power_state(codec, 0x1e, &parm);
  640. if (imux_is_smixer)
  641. parm = AC_PWRST_D0;
  642. /* SW0 (17h), AIW0(13h) */
  643. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
  644. parm);
  645. snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
  646. parm);
  647. parm = AC_PWRST_D3;
  648. set_pin_power_state(codec, 0x1e, &parm);
  649. /* PW11 (22h) */
  650. if (spec->dmic_enabled)
  651. set_pin_power_state(codec, 0x22, &parm);
  652. else
  653. snd_hda_codec_write(
  654. codec, 0x22, 0,
  655. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  656. /* SW2(26h), AIW1(14h) */
  657. snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
  658. parm);
  659. snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
  660. parm);
  661. /* outputs */
  662. /* PW0 (19h), SW1 (18h), AOW1 (11h) */
  663. parm = AC_PWRST_D3;
  664. set_pin_power_state(codec, 0x19, &parm);
  665. /* Smart 5.1 PW2(1bh) */
  666. if (spec->smart51_enabled)
  667. set_pin_power_state(codec, 0x1b, &parm);
  668. snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
  669. parm);
  670. snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
  671. parm);
  672. /* PW7 (23h), SW3 (27h), AOW3 (25h) */
  673. parm = AC_PWRST_D3;
  674. set_pin_power_state(codec, 0x23, &parm);
  675. /* Smart 5.1 PW1(1ah) */
  676. if (spec->smart51_enabled)
  677. set_pin_power_state(codec, 0x1a, &parm);
  678. snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
  679. parm);
  680. /* Smart 5.1 PW5(1eh) */
  681. if (spec->smart51_enabled)
  682. set_pin_power_state(codec, 0x1e, &parm);
  683. snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
  684. parm);
  685. /* Mono out */
  686. /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
  687. present = snd_hda_codec_read(
  688. codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  689. if (present)
  690. mono_out = 0;
  691. else {
  692. present = snd_hda_codec_read(
  693. codec, 0x1d, 0, AC_VERB_GET_PIN_SENSE, 0)
  694. & 0x80000000;
  695. if (!spec->hp_independent_mode && present)
  696. mono_out = 0;
  697. else
  698. mono_out = 1;
  699. }
  700. parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
  701. snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
  702. parm);
  703. snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
  704. parm);
  705. snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
  706. parm);
  707. /* PW 3/4 (1ch/1dh) */
  708. parm = AC_PWRST_D3;
  709. set_pin_power_state(codec, 0x1c, &parm);
  710. set_pin_power_state(codec, 0x1d, &parm);
  711. /* HP Independent Mode, power on AOW3 */
  712. if (spec->hp_independent_mode)
  713. snd_hda_codec_write(codec, 0x25, 0,
  714. AC_VERB_SET_POWER_STATE, parm);
  715. /* force to D0 for internal Speaker */
  716. /* MW0 (16h), AOW0 (10h) */
  717. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
  718. imux_is_smixer ? AC_PWRST_D0 : parm);
  719. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
  720. mono_out ? AC_PWRST_D0 : parm);
  721. } else if (spec->codec_type == VT2002P) {
  722. unsigned int present;
  723. /* MUX9 (1eh) = stereo mixer */
  724. imux_is_smixer = snd_hda_codec_read(
  725. codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
  726. /* inputs */
  727. /* PW 5/6/7 (29h/2ah/2bh) */
  728. parm = AC_PWRST_D3;
  729. set_pin_power_state(codec, 0x29, &parm);
  730. set_pin_power_state(codec, 0x2a, &parm);
  731. set_pin_power_state(codec, 0x2b, &parm);
  732. if (imux_is_smixer)
  733. parm = AC_PWRST_D0;
  734. /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
  735. snd_hda_codec_write(codec, 0x1e, 0,
  736. AC_VERB_SET_POWER_STATE, parm);
  737. snd_hda_codec_write(codec, 0x1f, 0,
  738. AC_VERB_SET_POWER_STATE, parm);
  739. snd_hda_codec_write(codec, 0x10, 0,
  740. AC_VERB_SET_POWER_STATE, parm);
  741. snd_hda_codec_write(codec, 0x11, 0,
  742. AC_VERB_SET_POWER_STATE, parm);
  743. /* outputs */
  744. /* AOW0 (8h)*/
  745. snd_hda_codec_write(codec, 0x8, 0,
  746. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  747. /* PW4 (26h), MW4 (1ch), MUX4(37h) */
  748. parm = AC_PWRST_D3;
  749. set_pin_power_state(codec, 0x26, &parm);
  750. snd_hda_codec_write(codec, 0x1c, 0,
  751. AC_VERB_SET_POWER_STATE, parm);
  752. snd_hda_codec_write(codec, 0x37,
  753. 0, AC_VERB_SET_POWER_STATE, parm);
  754. /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
  755. parm = AC_PWRST_D3;
  756. set_pin_power_state(codec, 0x25, &parm);
  757. snd_hda_codec_write(codec, 0x19, 0,
  758. AC_VERB_SET_POWER_STATE, parm);
  759. snd_hda_codec_write(codec, 0x35, 0,
  760. AC_VERB_SET_POWER_STATE, parm);
  761. if (spec->hp_independent_mode) {
  762. snd_hda_codec_write(codec, 0x9, 0,
  763. AC_VERB_SET_POWER_STATE, parm);
  764. }
  765. /* Class-D */
  766. /* PW0 (24h), MW0(18h), MUX0(34h) */
  767. present = snd_hda_codec_read(
  768. codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  769. parm = AC_PWRST_D3;
  770. set_pin_power_state(codec, 0x24, &parm);
  771. if (present) {
  772. snd_hda_codec_write(
  773. codec, 0x18, 0,
  774. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  775. snd_hda_codec_write(
  776. codec, 0x34, 0,
  777. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  778. } else {
  779. snd_hda_codec_write(
  780. codec, 0x18, 0,
  781. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  782. snd_hda_codec_write(
  783. codec, 0x34, 0,
  784. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  785. }
  786. /* Mono Out */
  787. /* PW15 (31h), MW8(17h), MUX8(3bh) */
  788. present = snd_hda_codec_read(
  789. codec, 0x26, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  790. parm = AC_PWRST_D3;
  791. set_pin_power_state(codec, 0x31, &parm);
  792. if (present) {
  793. snd_hda_codec_write(
  794. codec, 0x17, 0,
  795. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  796. snd_hda_codec_write(
  797. codec, 0x3b, 0,
  798. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  799. } else {
  800. snd_hda_codec_write(
  801. codec, 0x17, 0,
  802. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  803. snd_hda_codec_write(
  804. codec, 0x3b, 0,
  805. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  806. }
  807. /* MW9 (21h) */
  808. if (imux_is_smixer || !is_aa_path_mute(codec))
  809. snd_hda_codec_write(
  810. codec, 0x21, 0,
  811. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  812. else
  813. snd_hda_codec_write(
  814. codec, 0x21, 0,
  815. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  816. }
  817. }
  818. /*
  819. * input MUX handling
  820. */
  821. static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
  822. struct snd_ctl_elem_info *uinfo)
  823. {
  824. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  825. struct via_spec *spec = codec->spec;
  826. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  827. }
  828. static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
  829. struct snd_ctl_elem_value *ucontrol)
  830. {
  831. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  832. struct via_spec *spec = codec->spec;
  833. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  834. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  835. return 0;
  836. }
  837. static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
  838. struct snd_ctl_elem_value *ucontrol)
  839. {
  840. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  841. struct via_spec *spec = codec->spec;
  842. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  843. if (!spec->mux_nids[adc_idx])
  844. return -EINVAL;
  845. /* switch to D0 beofre change index */
  846. if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
  847. AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
  848. snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
  849. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  850. /* update jack power state */
  851. set_jack_power_state(codec);
  852. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  853. spec->mux_nids[adc_idx],
  854. &spec->cur_mux[adc_idx]);
  855. }
  856. static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
  857. struct snd_ctl_elem_info *uinfo)
  858. {
  859. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  860. struct via_spec *spec = codec->spec;
  861. return snd_hda_input_mux_info(spec->hp_mux, uinfo);
  862. }
  863. static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
  864. struct snd_ctl_elem_value *ucontrol)
  865. {
  866. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  867. struct via_spec *spec = codec->spec;
  868. hda_nid_t nid;
  869. unsigned int pinsel;
  870. switch (spec->codec_type) {
  871. case VT1718S:
  872. nid = 0x34;
  873. break;
  874. case VT2002P:
  875. nid = 0x35;
  876. break;
  877. default:
  878. nid = spec->autocfg.hp_pins[0];
  879. break;
  880. }
  881. /* use !! to translate conn sel 2 for VT1718S */
  882. pinsel = !!snd_hda_codec_read(codec, nid, 0,
  883. AC_VERB_GET_CONNECT_SEL,
  884. 0x00);
  885. ucontrol->value.enumerated.item[0] = pinsel;
  886. return 0;
  887. }
  888. static void activate_ctl(struct hda_codec *codec, const char *name, int active)
  889. {
  890. struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
  891. if (ctl) {
  892. ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  893. ctl->vd[0].access |= active
  894. ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  895. snd_ctl_notify(codec->bus->card,
  896. SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
  897. }
  898. }
  899. static int update_side_mute_status(struct hda_codec *codec)
  900. {
  901. /* mute side channel */
  902. struct via_spec *spec = codec->spec;
  903. unsigned int parm = spec->hp_independent_mode
  904. ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
  905. hda_nid_t sw3;
  906. switch (spec->codec_type) {
  907. case VT1708:
  908. sw3 = 0x1b;
  909. break;
  910. case VT1709_10CH:
  911. sw3 = 0x29;
  912. break;
  913. case VT1708B_8CH:
  914. case VT1708S:
  915. sw3 = 0x27;
  916. break;
  917. default:
  918. sw3 = 0;
  919. break;
  920. }
  921. if (sw3)
  922. snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  923. parm);
  924. return 0;
  925. }
  926. static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
  927. struct snd_ctl_elem_value *ucontrol)
  928. {
  929. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  930. struct via_spec *spec = codec->spec;
  931. hda_nid_t nid = spec->autocfg.hp_pins[0];
  932. unsigned int pinsel = ucontrol->value.enumerated.item[0];
  933. /* Get Independent Mode index of headphone pin widget */
  934. spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
  935. ? 1 : 0;
  936. switch (spec->codec_type) {
  937. case VT1718S:
  938. nid = 0x34;
  939. pinsel = pinsel ? 2 : 0; /* indep HP use AOW4 (index 2) */
  940. spec->multiout.num_dacs = 4;
  941. break;
  942. case VT2002P:
  943. nid = 0x35;
  944. break;
  945. default:
  946. nid = spec->autocfg.hp_pins[0];
  947. break;
  948. }
  949. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
  950. if (spec->multiout.hp_nid && spec->multiout.hp_nid
  951. != spec->multiout.dac_nids[HDA_FRONT])
  952. snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
  953. 0, 0, 0);
  954. update_side_mute_status(codec);
  955. /* update HP volume/swtich active state */
  956. if (spec->codec_type == VT1708S
  957. || spec->codec_type == VT1702
  958. || spec->codec_type == VT1718S
  959. || spec->codec_type == VT1716S
  960. || spec->codec_type == VT2002P) {
  961. activate_ctl(codec, "Headphone Playback Volume",
  962. spec->hp_independent_mode);
  963. activate_ctl(codec, "Headphone Playback Switch",
  964. spec->hp_independent_mode);
  965. }
  966. return 0;
  967. }
  968. static struct snd_kcontrol_new via_hp_mixer[] = {
  969. {
  970. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  971. .name = "Independent HP",
  972. .count = 1,
  973. .info = via_independent_hp_info,
  974. .get = via_independent_hp_get,
  975. .put = via_independent_hp_put,
  976. },
  977. { } /* end */
  978. };
  979. static void notify_aa_path_ctls(struct hda_codec *codec)
  980. {
  981. int i;
  982. struct snd_ctl_elem_id id;
  983. const char *labels[] = {"Mic", "Front Mic", "Line"};
  984. memset(&id, 0, sizeof(id));
  985. id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  986. for (i = 0; i < ARRAY_SIZE(labels); i++) {
  987. sprintf(id.name, "%s Playback Volume", labels[i]);
  988. snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
  989. &id);
  990. }
  991. }
  992. static void mute_aa_path(struct hda_codec *codec, int mute)
  993. {
  994. struct via_spec *spec = codec->spec;
  995. hda_nid_t nid_mixer;
  996. int start_idx;
  997. int end_idx;
  998. int i;
  999. /* get nid of MW0 and start & end index */
  1000. switch (spec->codec_type) {
  1001. case VT1708:
  1002. nid_mixer = 0x17;
  1003. start_idx = 2;
  1004. end_idx = 4;
  1005. break;
  1006. case VT1709_10CH:
  1007. case VT1709_6CH:
  1008. nid_mixer = 0x18;
  1009. start_idx = 2;
  1010. end_idx = 4;
  1011. break;
  1012. case VT1708B_8CH:
  1013. case VT1708B_4CH:
  1014. case VT1708S:
  1015. case VT1716S:
  1016. nid_mixer = 0x16;
  1017. start_idx = 2;
  1018. end_idx = 4;
  1019. break;
  1020. default:
  1021. return;
  1022. }
  1023. /* check AA path's mute status */
  1024. for (i = start_idx; i <= end_idx; i++) {
  1025. int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
  1026. snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
  1027. HDA_AMP_MUTE, val);
  1028. }
  1029. }
  1030. static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
  1031. {
  1032. int res = 0;
  1033. int index;
  1034. for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
  1035. if (pin == spec->autocfg.input_pins[index]) {
  1036. res = 1;
  1037. break;
  1038. }
  1039. }
  1040. return res;
  1041. }
  1042. static int via_smart51_info(struct snd_kcontrol *kcontrol,
  1043. struct snd_ctl_elem_info *uinfo)
  1044. {
  1045. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1046. uinfo->count = 1;
  1047. uinfo->value.integer.min = 0;
  1048. uinfo->value.integer.max = 1;
  1049. return 0;
  1050. }
  1051. static int via_smart51_get(struct snd_kcontrol *kcontrol,
  1052. struct snd_ctl_elem_value *ucontrol)
  1053. {
  1054. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1055. struct via_spec *spec = codec->spec;
  1056. int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
  1057. int on = 1;
  1058. int i;
  1059. for (i = 0; i < ARRAY_SIZE(index); i++) {
  1060. hda_nid_t nid = spec->autocfg.input_pins[index[i]];
  1061. if (nid) {
  1062. int ctl =
  1063. snd_hda_codec_read(codec, nid, 0,
  1064. AC_VERB_GET_PIN_WIDGET_CONTROL,
  1065. 0);
  1066. if (i == AUTO_PIN_FRONT_MIC
  1067. && spec->hp_independent_mode
  1068. && spec->codec_type != VT1718S)
  1069. continue; /* ignore FMic for independent HP */
  1070. if (ctl & AC_PINCTL_IN_EN
  1071. && !(ctl & AC_PINCTL_OUT_EN))
  1072. on = 0;
  1073. }
  1074. }
  1075. *ucontrol->value.integer.value = on;
  1076. return 0;
  1077. }
  1078. static int via_smart51_put(struct snd_kcontrol *kcontrol,
  1079. struct snd_ctl_elem_value *ucontrol)
  1080. {
  1081. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1082. struct via_spec *spec = codec->spec;
  1083. int out_in = *ucontrol->value.integer.value
  1084. ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
  1085. int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
  1086. int i;
  1087. for (i = 0; i < ARRAY_SIZE(index); i++) {
  1088. hda_nid_t nid = spec->autocfg.input_pins[index[i]];
  1089. if (i == AUTO_PIN_FRONT_MIC
  1090. && spec->hp_independent_mode
  1091. && spec->codec_type != VT1718S)
  1092. continue; /* don't retask FMic for independent HP */
  1093. if (nid) {
  1094. unsigned int parm = snd_hda_codec_read(
  1095. codec, nid, 0,
  1096. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  1097. parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  1098. parm |= out_in;
  1099. snd_hda_codec_write(codec, nid, 0,
  1100. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1101. parm);
  1102. if (out_in == AC_PINCTL_OUT_EN) {
  1103. mute_aa_path(codec, 1);
  1104. notify_aa_path_ctls(codec);
  1105. }
  1106. if (spec->codec_type == VT1718S)
  1107. snd_hda_codec_amp_stereo(
  1108. codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  1109. HDA_AMP_UNMUTE);
  1110. }
  1111. if (i == AUTO_PIN_FRONT_MIC) {
  1112. if (spec->codec_type == VT1708S
  1113. || spec->codec_type == VT1716S) {
  1114. /* input = index 1 (AOW3) */
  1115. snd_hda_codec_write(
  1116. codec, nid, 0,
  1117. AC_VERB_SET_CONNECT_SEL, 1);
  1118. snd_hda_codec_amp_stereo(
  1119. codec, nid, HDA_OUTPUT,
  1120. 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
  1121. }
  1122. }
  1123. }
  1124. spec->smart51_enabled = *ucontrol->value.integer.value;
  1125. set_jack_power_state(codec);
  1126. return 1;
  1127. }
  1128. static struct snd_kcontrol_new via_smart51_mixer[] = {
  1129. {
  1130. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1131. .name = "Smart 5.1",
  1132. .count = 1,
  1133. .info = via_smart51_info,
  1134. .get = via_smart51_get,
  1135. .put = via_smart51_put,
  1136. },
  1137. {} /* end */
  1138. };
  1139. /* capture mixer elements */
  1140. static struct snd_kcontrol_new vt1708_capture_mixer[] = {
  1141. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
  1142. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
  1143. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
  1144. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
  1145. {
  1146. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1147. /* The multiple "Capture Source" controls confuse alsamixer
  1148. * So call somewhat different..
  1149. */
  1150. /* .name = "Capture Source", */
  1151. .name = "Input Source",
  1152. .count = 1,
  1153. .info = via_mux_enum_info,
  1154. .get = via_mux_enum_get,
  1155. .put = via_mux_enum_put,
  1156. },
  1157. { } /* end */
  1158. };
  1159. /* check AA path's mute statue */
  1160. static int is_aa_path_mute(struct hda_codec *codec)
  1161. {
  1162. int mute = 1;
  1163. hda_nid_t nid_mixer;
  1164. int start_idx;
  1165. int end_idx;
  1166. int i;
  1167. struct via_spec *spec = codec->spec;
  1168. /* get nid of MW0 and start & end index */
  1169. switch (spec->codec_type) {
  1170. case VT1708B_8CH:
  1171. case VT1708B_4CH:
  1172. case VT1708S:
  1173. case VT1716S:
  1174. nid_mixer = 0x16;
  1175. start_idx = 2;
  1176. end_idx = 4;
  1177. break;
  1178. case VT1702:
  1179. nid_mixer = 0x1a;
  1180. start_idx = 1;
  1181. end_idx = 3;
  1182. break;
  1183. case VT1718S:
  1184. nid_mixer = 0x21;
  1185. start_idx = 1;
  1186. end_idx = 3;
  1187. break;
  1188. case VT2002P:
  1189. nid_mixer = 0x21;
  1190. start_idx = 0;
  1191. end_idx = 2;
  1192. break;
  1193. default:
  1194. return 0;
  1195. }
  1196. /* check AA path's mute status */
  1197. for (i = start_idx; i <= end_idx; i++) {
  1198. unsigned int con_list = snd_hda_codec_read(
  1199. codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
  1200. int shift = 8 * (i % 4);
  1201. hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
  1202. unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
  1203. if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
  1204. /* check mute status while the pin is connected */
  1205. int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
  1206. HDA_INPUT, i) >> 7;
  1207. int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
  1208. HDA_INPUT, i) >> 7;
  1209. if (!mute_l || !mute_r) {
  1210. mute = 0;
  1211. break;
  1212. }
  1213. }
  1214. }
  1215. return mute;
  1216. }
  1217. /* enter/exit analog low-current mode */
  1218. static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
  1219. {
  1220. struct via_spec *spec = codec->spec;
  1221. static int saved_stream_idle = 1; /* saved stream idle status */
  1222. int enable = is_aa_path_mute(codec);
  1223. unsigned int verb = 0;
  1224. unsigned int parm = 0;
  1225. if (stream_idle == -1) /* stream status did not change */
  1226. enable = enable && saved_stream_idle;
  1227. else {
  1228. enable = enable && stream_idle;
  1229. saved_stream_idle = stream_idle;
  1230. }
  1231. /* decide low current mode's verb & parameter */
  1232. switch (spec->codec_type) {
  1233. case VT1708B_8CH:
  1234. case VT1708B_4CH:
  1235. verb = 0xf70;
  1236. parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
  1237. break;
  1238. case VT1708S:
  1239. case VT1718S:
  1240. case VT1716S:
  1241. verb = 0xf73;
  1242. parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
  1243. break;
  1244. case VT1702:
  1245. verb = 0xf73;
  1246. parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
  1247. break;
  1248. case VT2002P:
  1249. verb = 0xf93;
  1250. parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
  1251. break;
  1252. default:
  1253. return; /* other codecs are not supported */
  1254. }
  1255. /* send verb */
  1256. snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
  1257. }
  1258. /*
  1259. * generic initialization of ADC, input mixers and output mixers
  1260. */
  1261. static struct hda_verb vt1708_volume_init_verbs[] = {
  1262. /*
  1263. * Unmute ADC0-1 and set the default input to mic-in
  1264. */
  1265. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1266. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1267. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  1268. * mixer widget
  1269. */
  1270. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  1271. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1272. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1273. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  1274. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  1275. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  1276. /*
  1277. * Set up output mixers (0x19 - 0x1b)
  1278. */
  1279. /* set vol=0 to output mixers */
  1280. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1281. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1282. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1283. /* Setup default input to PW4 */
  1284. {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
  1285. /* PW9 Output enable */
  1286. {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  1287. { }
  1288. };
  1289. static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1290. struct hda_codec *codec,
  1291. struct snd_pcm_substream *substream)
  1292. {
  1293. struct via_spec *spec = codec->spec;
  1294. int idle = substream->pstr->substream_opened == 1
  1295. && substream->ref_count == 0;
  1296. analog_low_current_mode(codec, idle);
  1297. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  1298. hinfo);
  1299. }
  1300. static void playback_multi_pcm_prep_0(struct hda_codec *codec,
  1301. unsigned int stream_tag,
  1302. unsigned int format,
  1303. struct snd_pcm_substream *substream)
  1304. {
  1305. struct via_spec *spec = codec->spec;
  1306. struct hda_multi_out *mout = &spec->multiout;
  1307. hda_nid_t *nids = mout->dac_nids;
  1308. int chs = substream->runtime->channels;
  1309. int i;
  1310. mutex_lock(&codec->spdif_mutex);
  1311. if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
  1312. if (chs == 2 &&
  1313. snd_hda_is_supported_format(codec, mout->dig_out_nid,
  1314. format) &&
  1315. !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
  1316. mout->dig_out_used = HDA_DIG_ANALOG_DUP;
  1317. /* turn off SPDIF once; otherwise the IEC958 bits won't
  1318. * be updated */
  1319. if (codec->spdif_ctls & AC_DIG1_ENABLE)
  1320. snd_hda_codec_write(codec, mout->dig_out_nid, 0,
  1321. AC_VERB_SET_DIGI_CONVERT_1,
  1322. codec->spdif_ctls &
  1323. ~AC_DIG1_ENABLE & 0xff);
  1324. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  1325. stream_tag, 0, format);
  1326. /* turn on again (if needed) */
  1327. if (codec->spdif_ctls & AC_DIG1_ENABLE)
  1328. snd_hda_codec_write(codec, mout->dig_out_nid, 0,
  1329. AC_VERB_SET_DIGI_CONVERT_1,
  1330. codec->spdif_ctls & 0xff);
  1331. } else {
  1332. mout->dig_out_used = 0;
  1333. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  1334. 0, 0, 0);
  1335. }
  1336. }
  1337. mutex_unlock(&codec->spdif_mutex);
  1338. /* front */
  1339. snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
  1340. 0, format);
  1341. if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
  1342. && !spec->hp_independent_mode)
  1343. /* headphone out will just decode front left/right (stereo) */
  1344. snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
  1345. 0, format);
  1346. /* extra outputs copied from front */
  1347. for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
  1348. if (mout->extra_out_nid[i])
  1349. snd_hda_codec_setup_stream(codec,
  1350. mout->extra_out_nid[i],
  1351. stream_tag, 0, format);
  1352. /* surrounds */
  1353. for (i = 1; i < mout->num_dacs; i++) {
  1354. if (chs >= (i + 1) * 2) /* independent out */
  1355. snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
  1356. i * 2, format);
  1357. else /* copy front */
  1358. snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
  1359. 0, format);
  1360. }
  1361. }
  1362. static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
  1363. struct hda_codec *codec,
  1364. unsigned int stream_tag,
  1365. unsigned int format,
  1366. struct snd_pcm_substream *substream)
  1367. {
  1368. struct via_spec *spec = codec->spec;
  1369. struct hda_multi_out *mout = &spec->multiout;
  1370. hda_nid_t *nids = mout->dac_nids;
  1371. if (substream->number == 0)
  1372. playback_multi_pcm_prep_0(codec, stream_tag, format,
  1373. substream);
  1374. else {
  1375. if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
  1376. spec->hp_independent_mode)
  1377. snd_hda_codec_setup_stream(codec, mout->hp_nid,
  1378. stream_tag, 0, format);
  1379. }
  1380. vt1708_start_hp_work(spec);
  1381. return 0;
  1382. }
  1383. static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1384. struct hda_codec *codec,
  1385. struct snd_pcm_substream *substream)
  1386. {
  1387. struct via_spec *spec = codec->spec;
  1388. struct hda_multi_out *mout = &spec->multiout;
  1389. hda_nid_t *nids = mout->dac_nids;
  1390. int i;
  1391. if (substream->number == 0) {
  1392. for (i = 0; i < mout->num_dacs; i++)
  1393. snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
  1394. if (mout->hp_nid && !spec->hp_independent_mode)
  1395. snd_hda_codec_setup_stream(codec, mout->hp_nid,
  1396. 0, 0, 0);
  1397. for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
  1398. if (mout->extra_out_nid[i])
  1399. snd_hda_codec_setup_stream(codec,
  1400. mout->extra_out_nid[i],
  1401. 0, 0, 0);
  1402. mutex_lock(&codec->spdif_mutex);
  1403. if (mout->dig_out_nid &&
  1404. mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
  1405. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  1406. 0, 0, 0);
  1407. mout->dig_out_used = 0;
  1408. }
  1409. mutex_unlock(&codec->spdif_mutex);
  1410. } else {
  1411. if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
  1412. spec->hp_independent_mode)
  1413. snd_hda_codec_setup_stream(codec, mout->hp_nid,
  1414. 0, 0, 0);
  1415. }
  1416. vt1708_stop_hp_work(spec);
  1417. return 0;
  1418. }
  1419. /*
  1420. * Digital out
  1421. */
  1422. static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1423. struct hda_codec *codec,
  1424. struct snd_pcm_substream *substream)
  1425. {
  1426. struct via_spec *spec = codec->spec;
  1427. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1428. }
  1429. static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1430. struct hda_codec *codec,
  1431. struct snd_pcm_substream *substream)
  1432. {
  1433. struct via_spec *spec = codec->spec;
  1434. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1435. }
  1436. static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1437. struct hda_codec *codec,
  1438. unsigned int stream_tag,
  1439. unsigned int format,
  1440. struct snd_pcm_substream *substream)
  1441. {
  1442. struct via_spec *spec = codec->spec;
  1443. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1444. stream_tag, format, substream);
  1445. }
  1446. static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1447. struct hda_codec *codec,
  1448. struct snd_pcm_substream *substream)
  1449. {
  1450. struct via_spec *spec = codec->spec;
  1451. snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  1452. return 0;
  1453. }
  1454. /*
  1455. * Analog capture
  1456. */
  1457. static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1458. struct hda_codec *codec,
  1459. unsigned int stream_tag,
  1460. unsigned int format,
  1461. struct snd_pcm_substream *substream)
  1462. {
  1463. struct via_spec *spec = codec->spec;
  1464. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  1465. stream_tag, 0, format);
  1466. return 0;
  1467. }
  1468. static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1469. struct hda_codec *codec,
  1470. struct snd_pcm_substream *substream)
  1471. {
  1472. struct via_spec *spec = codec->spec;
  1473. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  1474. return 0;
  1475. }
  1476. static struct hda_pcm_stream vt1708_pcm_analog_playback = {
  1477. .substreams = 2,
  1478. .channels_min = 2,
  1479. .channels_max = 8,
  1480. .nid = 0x10, /* NID to query formats and rates */
  1481. .ops = {
  1482. .open = via_playback_pcm_open,
  1483. .prepare = via_playback_multi_pcm_prepare,
  1484. .cleanup = via_playback_multi_pcm_cleanup
  1485. },
  1486. };
  1487. static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
  1488. .substreams = 2,
  1489. .channels_min = 2,
  1490. .channels_max = 8,
  1491. .nid = 0x10, /* NID to query formats and rates */
  1492. /* We got noisy outputs on the right channel on VT1708 when
  1493. * 24bit samples are used. Until any workaround is found,
  1494. * disable the 24bit format, so far.
  1495. */
  1496. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1497. .ops = {
  1498. .open = via_playback_pcm_open,
  1499. .prepare = via_playback_multi_pcm_prepare,
  1500. .cleanup = via_playback_multi_pcm_cleanup
  1501. },
  1502. };
  1503. static struct hda_pcm_stream vt1708_pcm_analog_capture = {
  1504. .substreams = 2,
  1505. .channels_min = 2,
  1506. .channels_max = 2,
  1507. .nid = 0x15, /* NID to query formats and rates */
  1508. .ops = {
  1509. .prepare = via_capture_pcm_prepare,
  1510. .cleanup = via_capture_pcm_cleanup
  1511. },
  1512. };
  1513. static struct hda_pcm_stream vt1708_pcm_digital_playback = {
  1514. .substreams = 1,
  1515. .channels_min = 2,
  1516. .channels_max = 2,
  1517. /* NID is set in via_build_pcms */
  1518. .ops = {
  1519. .open = via_dig_playback_pcm_open,
  1520. .close = via_dig_playback_pcm_close,
  1521. .prepare = via_dig_playback_pcm_prepare,
  1522. .cleanup = via_dig_playback_pcm_cleanup
  1523. },
  1524. };
  1525. static struct hda_pcm_stream vt1708_pcm_digital_capture = {
  1526. .substreams = 1,
  1527. .channels_min = 2,
  1528. .channels_max = 2,
  1529. };
  1530. static int via_build_controls(struct hda_codec *codec)
  1531. {
  1532. struct via_spec *spec = codec->spec;
  1533. int err;
  1534. int i;
  1535. for (i = 0; i < spec->num_mixers; i++) {
  1536. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  1537. if (err < 0)
  1538. return err;
  1539. }
  1540. if (spec->multiout.dig_out_nid) {
  1541. err = snd_hda_create_spdif_out_ctls(codec,
  1542. spec->multiout.dig_out_nid);
  1543. if (err < 0)
  1544. return err;
  1545. err = snd_hda_create_spdif_share_sw(codec,
  1546. &spec->multiout);
  1547. if (err < 0)
  1548. return err;
  1549. spec->multiout.share_spdif = 1;
  1550. }
  1551. if (spec->dig_in_nid) {
  1552. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  1553. if (err < 0)
  1554. return err;
  1555. }
  1556. /* init power states */
  1557. set_jack_power_state(codec);
  1558. analog_low_current_mode(codec, 1);
  1559. via_free_kctls(codec); /* no longer needed */
  1560. return 0;
  1561. }
  1562. static int via_build_pcms(struct hda_codec *codec)
  1563. {
  1564. struct via_spec *spec = codec->spec;
  1565. struct hda_pcm *info = spec->pcm_rec;
  1566. codec->num_pcms = 1;
  1567. codec->pcm_info = info;
  1568. info->name = spec->stream_name_analog;
  1569. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
  1570. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  1571. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
  1572. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  1573. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  1574. spec->multiout.max_channels;
  1575. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  1576. codec->num_pcms++;
  1577. info++;
  1578. info->name = spec->stream_name_digital;
  1579. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  1580. if (spec->multiout.dig_out_nid) {
  1581. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  1582. *(spec->stream_digital_playback);
  1583. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  1584. spec->multiout.dig_out_nid;
  1585. }
  1586. if (spec->dig_in_nid) {
  1587. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  1588. *(spec->stream_digital_capture);
  1589. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  1590. spec->dig_in_nid;
  1591. }
  1592. }
  1593. return 0;
  1594. }
  1595. static void via_free(struct hda_codec *codec)
  1596. {
  1597. struct via_spec *spec = codec->spec;
  1598. if (!spec)
  1599. return;
  1600. via_free_kctls(codec);
  1601. vt1708_stop_hp_work(spec);
  1602. kfree(codec->spec);
  1603. }
  1604. /* mute internal speaker if HP is plugged */
  1605. static void via_hp_automute(struct hda_codec *codec)
  1606. {
  1607. unsigned int present = 0;
  1608. struct via_spec *spec = codec->spec;
  1609. present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
  1610. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1611. if (!spec->hp_independent_mode) {
  1612. struct snd_ctl_elem_id id;
  1613. /* auto mute */
  1614. snd_hda_codec_amp_stereo(
  1615. codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
  1616. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  1617. /* notify change */
  1618. memset(&id, 0, sizeof(id));
  1619. id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  1620. strcpy(id.name, "Front Playback Switch");
  1621. snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
  1622. &id);
  1623. }
  1624. }
  1625. /* mute mono out if HP or Line out is plugged */
  1626. static void via_mono_automute(struct hda_codec *codec)
  1627. {
  1628. unsigned int hp_present, lineout_present;
  1629. struct via_spec *spec = codec->spec;
  1630. if (spec->codec_type != VT1716S)
  1631. return;
  1632. lineout_present = snd_hda_codec_read(
  1633. codec, spec->autocfg.line_out_pins[0], 0,
  1634. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1635. /* Mute Mono Out if Line Out is plugged */
  1636. if (lineout_present) {
  1637. snd_hda_codec_amp_stereo(
  1638. codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
  1639. return;
  1640. }
  1641. hp_present = snd_hda_codec_read(
  1642. codec, spec->autocfg.hp_pins[0], 0,
  1643. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1644. if (!spec->hp_independent_mode)
  1645. snd_hda_codec_amp_stereo(
  1646. codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
  1647. hp_present ? HDA_AMP_MUTE : 0);
  1648. }
  1649. static void via_gpio_control(struct hda_codec *codec)
  1650. {
  1651. unsigned int gpio_data;
  1652. unsigned int vol_counter;
  1653. unsigned int vol;
  1654. unsigned int master_vol;
  1655. struct via_spec *spec = codec->spec;
  1656. gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
  1657. AC_VERB_GET_GPIO_DATA, 0) & 0x03;
  1658. vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
  1659. 0xF84, 0) & 0x3F0000) >> 16;
  1660. vol = vol_counter & 0x1F;
  1661. master_vol = snd_hda_codec_read(codec, 0x1A, 0,
  1662. AC_VERB_GET_AMP_GAIN_MUTE,
  1663. AC_AMP_GET_INPUT);
  1664. if (gpio_data == 0x02) {
  1665. /* unmute line out */
  1666. snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
  1667. HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
  1668. if (vol_counter & 0x20) {
  1669. /* decrease volume */
  1670. if (vol > master_vol)
  1671. vol = master_vol;
  1672. snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
  1673. 0, HDA_AMP_VOLMASK,
  1674. master_vol-vol);
  1675. } else {
  1676. /* increase volume */
  1677. snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
  1678. HDA_AMP_VOLMASK,
  1679. ((master_vol+vol) > 0x2A) ? 0x2A :
  1680. (master_vol+vol));
  1681. }
  1682. } else if (!(gpio_data & 0x02)) {
  1683. /* mute line out */
  1684. snd_hda_codec_amp_stereo(codec,
  1685. spec->autocfg.line_out_pins[0],
  1686. HDA_OUTPUT, 0, HDA_AMP_MUTE,
  1687. HDA_AMP_MUTE);
  1688. }
  1689. }
  1690. /* mute Internal-Speaker if HP is plugged */
  1691. static void via_speaker_automute(struct hda_codec *codec)
  1692. {
  1693. unsigned int hp_present;
  1694. struct via_spec *spec = codec->spec;
  1695. if (spec->codec_type != VT2002P)
  1696. return;
  1697. hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
  1698. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1699. if (!spec->hp_independent_mode) {
  1700. struct snd_ctl_elem_id id;
  1701. snd_hda_codec_amp_stereo(
  1702. codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
  1703. HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
  1704. /* notify change */
  1705. memset(&id, 0, sizeof(id));
  1706. id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  1707. strcpy(id.name, "Speaker Playback Switch");
  1708. snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
  1709. &id);
  1710. }
  1711. }
  1712. /* mute line-out and internal speaker if HP is plugged */
  1713. static void via_hp_bind_automute(struct hda_codec *codec)
  1714. {
  1715. unsigned int hp_present, present = 0;
  1716. struct via_spec *spec = codec->spec;
  1717. int i;
  1718. if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
  1719. return;
  1720. hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
  1721. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1722. present = snd_hda_codec_read(codec, spec->autocfg.line_out_pins[0], 0,
  1723. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1724. if (!spec->hp_independent_mode) {
  1725. /* Mute Line-Outs */
  1726. for (i = 0; i < spec->autocfg.line_outs; i++)
  1727. snd_hda_codec_amp_stereo(
  1728. codec, spec->autocfg.line_out_pins[i],
  1729. HDA_OUTPUT, 0,
  1730. HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
  1731. if (hp_present)
  1732. present = hp_present;
  1733. }
  1734. /* Speakers */
  1735. for (i = 0; i < spec->autocfg.speaker_outs; i++)
  1736. snd_hda_codec_amp_stereo(
  1737. codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
  1738. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  1739. }
  1740. /* unsolicited event for jack sensing */
  1741. static void via_unsol_event(struct hda_codec *codec,
  1742. unsigned int res)
  1743. {
  1744. res >>= 26;
  1745. if (res & VIA_HP_EVENT)
  1746. via_hp_automute(codec);
  1747. if (res & VIA_GPIO_EVENT)
  1748. via_gpio_control(codec);
  1749. if (res & VIA_JACK_EVENT)
  1750. set_jack_power_state(codec);
  1751. if (res & VIA_MONO_EVENT)
  1752. via_mono_automute(codec);
  1753. if (res & VIA_SPEAKER_EVENT)
  1754. via_speaker_automute(codec);
  1755. if (res & VIA_BIND_HP_EVENT)
  1756. via_hp_bind_automute(codec);
  1757. }
  1758. static int via_init(struct hda_codec *codec)
  1759. {
  1760. struct via_spec *spec = codec->spec;
  1761. int i;
  1762. for (i = 0; i < spec->num_iverbs; i++)
  1763. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  1764. spec->codec_type = get_codec_type(codec);
  1765. if (spec->codec_type == VT1708BCE)
  1766. spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
  1767. same */
  1768. /* Lydia Add for EAPD enable */
  1769. if (!spec->dig_in_nid) { /* No Digital In connection */
  1770. if (spec->dig_in_pin) {
  1771. snd_hda_codec_write(codec, spec->dig_in_pin, 0,
  1772. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1773. PIN_OUT);
  1774. snd_hda_codec_write(codec, spec->dig_in_pin, 0,
  1775. AC_VERB_SET_EAPD_BTLENABLE, 0x02);
  1776. }
  1777. } else /* enable SPDIF-input pin */
  1778. snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
  1779. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
  1780. /* assign slave outs */
  1781. if (spec->slave_dig_outs[0])
  1782. codec->slave_dig_outs = spec->slave_dig_outs;
  1783. return 0;
  1784. }
  1785. #ifdef SND_HDA_NEEDS_RESUME
  1786. static int via_suspend(struct hda_codec *codec, pm_message_t state)
  1787. {
  1788. struct via_spec *spec = codec->spec;
  1789. vt1708_stop_hp_work(spec);
  1790. return 0;
  1791. }
  1792. #endif
  1793. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1794. static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  1795. {
  1796. struct via_spec *spec = codec->spec;
  1797. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  1798. }
  1799. #endif
  1800. /*
  1801. */
  1802. static struct hda_codec_ops via_patch_ops = {
  1803. .build_controls = via_build_controls,
  1804. .build_pcms = via_build_pcms,
  1805. .init = via_init,
  1806. .free = via_free,
  1807. #ifdef SND_HDA_NEEDS_RESUME
  1808. .suspend = via_suspend,
  1809. #endif
  1810. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1811. .check_power_status = via_check_power_status,
  1812. #endif
  1813. };
  1814. /* fill in the dac_nids table from the parsed pin configuration */
  1815. static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
  1816. const struct auto_pin_cfg *cfg)
  1817. {
  1818. int i;
  1819. hda_nid_t nid;
  1820. spec->multiout.num_dacs = cfg->line_outs;
  1821. spec->multiout.dac_nids = spec->private_dac_nids;
  1822. for(i = 0; i < 4; i++) {
  1823. nid = cfg->line_out_pins[i];
  1824. if (nid) {
  1825. /* config dac list */
  1826. switch (i) {
  1827. case AUTO_SEQ_FRONT:
  1828. spec->multiout.dac_nids[i] = 0x10;
  1829. break;
  1830. case AUTO_SEQ_CENLFE:
  1831. spec->multiout.dac_nids[i] = 0x12;
  1832. break;
  1833. case AUTO_SEQ_SURROUND:
  1834. spec->multiout.dac_nids[i] = 0x11;
  1835. break;
  1836. case AUTO_SEQ_SIDE:
  1837. spec->multiout.dac_nids[i] = 0x13;
  1838. break;
  1839. }
  1840. }
  1841. }
  1842. return 0;
  1843. }
  1844. /* add playback controls from the parsed DAC table */
  1845. static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
  1846. const struct auto_pin_cfg *cfg)
  1847. {
  1848. char name[32];
  1849. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  1850. hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
  1851. int i, err;
  1852. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  1853. nid = cfg->line_out_pins[i];
  1854. if (!nid)
  1855. continue;
  1856. nid_vol = nid_vols[i];
  1857. if (i == AUTO_SEQ_CENLFE) {
  1858. /* Center/LFE */
  1859. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1860. "Center Playback Volume",
  1861. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  1862. HDA_OUTPUT));
  1863. if (err < 0)
  1864. return err;
  1865. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1866. "LFE Playback Volume",
  1867. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  1868. HDA_OUTPUT));
  1869. if (err < 0)
  1870. return err;
  1871. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1872. "Center Playback Switch",
  1873. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  1874. HDA_OUTPUT));
  1875. if (err < 0)
  1876. return err;
  1877. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1878. "LFE Playback Switch",
  1879. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  1880. HDA_OUTPUT));
  1881. if (err < 0)
  1882. return err;
  1883. } else if (i == AUTO_SEQ_FRONT){
  1884. /* add control to mixer index 0 */
  1885. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1886. "Master Front Playback Volume",
  1887. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  1888. HDA_INPUT));
  1889. if (err < 0)
  1890. return err;
  1891. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1892. "Master Front Playback Switch",
  1893. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  1894. HDA_INPUT));
  1895. if (err < 0)
  1896. return err;
  1897. /* add control to PW3 */
  1898. sprintf(name, "%s Playback Volume", chname[i]);
  1899. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1900. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  1901. HDA_OUTPUT));
  1902. if (err < 0)
  1903. return err;
  1904. sprintf(name, "%s Playback Switch", chname[i]);
  1905. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1906. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  1907. HDA_OUTPUT));
  1908. if (err < 0)
  1909. return err;
  1910. } else {
  1911. sprintf(name, "%s Playback Volume", chname[i]);
  1912. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1913. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  1914. HDA_OUTPUT));
  1915. if (err < 0)
  1916. return err;
  1917. sprintf(name, "%s Playback Switch", chname[i]);
  1918. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1919. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  1920. HDA_OUTPUT));
  1921. if (err < 0)
  1922. return err;
  1923. }
  1924. }
  1925. return 0;
  1926. }
  1927. static void create_hp_imux(struct via_spec *spec)
  1928. {
  1929. int i;
  1930. struct hda_input_mux *imux = &spec->private_imux[1];
  1931. static const char *texts[] = { "OFF", "ON", NULL};
  1932. /* for hp mode select */
  1933. i = 0;
  1934. while (texts[i] != NULL) {
  1935. imux->items[imux->num_items].label = texts[i];
  1936. imux->items[imux->num_items].index = i;
  1937. imux->num_items++;
  1938. i++;
  1939. }
  1940. spec->hp_mux = &spec->private_imux[1];
  1941. }
  1942. static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  1943. {
  1944. int err;
  1945. if (!pin)
  1946. return 0;
  1947. spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
  1948. spec->hp_independent_mode_index = 1;
  1949. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1950. "Headphone Playback Volume",
  1951. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  1952. if (err < 0)
  1953. return err;
  1954. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1955. "Headphone Playback Switch",
  1956. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  1957. if (err < 0)
  1958. return err;
  1959. create_hp_imux(spec);
  1960. return 0;
  1961. }
  1962. /* create playback/capture controls for input pins */
  1963. static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
  1964. const struct auto_pin_cfg *cfg)
  1965. {
  1966. static char *labels[] = {
  1967. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  1968. };
  1969. struct hda_input_mux *imux = &spec->private_imux[0];
  1970. int i, err, idx = 0;
  1971. /* for internal loopback recording select */
  1972. imux->items[imux->num_items].label = "Stereo Mixer";
  1973. imux->items[imux->num_items].index = idx;
  1974. imux->num_items++;
  1975. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1976. if (!cfg->input_pins[i])
  1977. continue;
  1978. switch (cfg->input_pins[i]) {
  1979. case 0x1d: /* Mic */
  1980. idx = 2;
  1981. break;
  1982. case 0x1e: /* Line In */
  1983. idx = 3;
  1984. break;
  1985. case 0x21: /* Front Mic */
  1986. idx = 4;
  1987. break;
  1988. case 0x24: /* CD */
  1989. idx = 1;
  1990. break;
  1991. }
  1992. err = via_new_analog_input(spec, labels[i], idx, 0x17);
  1993. if (err < 0)
  1994. return err;
  1995. imux->items[imux->num_items].label = labels[i];
  1996. imux->items[imux->num_items].index = idx;
  1997. imux->num_items++;
  1998. }
  1999. return 0;
  2000. }
  2001. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2002. static struct hda_amp_list vt1708_loopbacks[] = {
  2003. { 0x17, HDA_INPUT, 1 },
  2004. { 0x17, HDA_INPUT, 2 },
  2005. { 0x17, HDA_INPUT, 3 },
  2006. { 0x17, HDA_INPUT, 4 },
  2007. { } /* end */
  2008. };
  2009. #endif
  2010. static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
  2011. {
  2012. unsigned int def_conf;
  2013. unsigned char seqassoc;
  2014. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  2015. seqassoc = (unsigned char) get_defcfg_association(def_conf);
  2016. seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
  2017. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
  2018. && (seqassoc == 0xf0 || seqassoc == 0xff)) {
  2019. def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
  2020. snd_hda_codec_set_pincfg(codec, nid, def_conf);
  2021. }
  2022. return;
  2023. }
  2024. static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
  2025. struct snd_ctl_elem_value *ucontrol)
  2026. {
  2027. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2028. struct via_spec *spec = codec->spec;
  2029. if (spec->codec_type != VT1708)
  2030. return 0;
  2031. spec->vt1708_jack_detectect =
  2032. !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
  2033. ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
  2034. return 0;
  2035. }
  2036. static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
  2037. struct snd_ctl_elem_value *ucontrol)
  2038. {
  2039. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2040. struct via_spec *spec = codec->spec;
  2041. int change;
  2042. if (spec->codec_type != VT1708)
  2043. return 0;
  2044. spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
  2045. change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
  2046. == !spec->vt1708_jack_detectect;
  2047. if (spec->vt1708_jack_detectect) {
  2048. mute_aa_path(codec, 1);
  2049. notify_aa_path_ctls(codec);
  2050. }
  2051. return change;
  2052. }
  2053. static struct snd_kcontrol_new vt1708_jack_detectect[] = {
  2054. {
  2055. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2056. .name = "Jack Detect",
  2057. .count = 1,
  2058. .info = snd_ctl_boolean_mono_info,
  2059. .get = vt1708_jack_detectect_get,
  2060. .put = vt1708_jack_detectect_put,
  2061. },
  2062. {} /* end */
  2063. };
  2064. static int vt1708_parse_auto_config(struct hda_codec *codec)
  2065. {
  2066. struct via_spec *spec = codec->spec;
  2067. int err;
  2068. /* Add HP and CD pin config connect bit re-config action */
  2069. vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
  2070. vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
  2071. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2072. if (err < 0)
  2073. return err;
  2074. err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
  2075. if (err < 0)
  2076. return err;
  2077. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2078. return 0; /* can't find valid BIOS pin config */
  2079. err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
  2080. if (err < 0)
  2081. return err;
  2082. err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  2083. if (err < 0)
  2084. return err;
  2085. err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
  2086. if (err < 0)
  2087. return err;
  2088. /* add jack detect on/off control */
  2089. err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
  2090. if (err < 0)
  2091. return err;
  2092. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2093. if (spec->autocfg.dig_outs)
  2094. spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
  2095. spec->dig_in_pin = VT1708_DIGIN_PIN;
  2096. if (spec->autocfg.dig_in_pin)
  2097. spec->dig_in_nid = VT1708_DIGIN_NID;
  2098. if (spec->kctls.list)
  2099. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2100. spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
  2101. spec->input_mux = &spec->private_imux[0];
  2102. if (spec->hp_mux)
  2103. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  2104. spec->mixers[spec->num_mixers++] = via_smart51_mixer;
  2105. return 1;
  2106. }
  2107. /* init callback for auto-configuration model -- overriding the default init */
  2108. static int via_auto_init(struct hda_codec *codec)
  2109. {
  2110. struct via_spec *spec = codec->spec;
  2111. via_init(codec);
  2112. via_auto_init_multi_out(codec);
  2113. via_auto_init_hp_out(codec);
  2114. via_auto_init_analog_input(codec);
  2115. if (spec->codec_type == VT2002P) {
  2116. via_hp_bind_automute(codec);
  2117. } else {
  2118. via_hp_automute(codec);
  2119. via_speaker_automute(codec);
  2120. }
  2121. return 0;
  2122. }
  2123. static void vt1708_update_hp_jack_state(struct work_struct *work)
  2124. {
  2125. struct via_spec *spec = container_of(work, struct via_spec,
  2126. vt1708_hp_work.work);
  2127. if (spec->codec_type != VT1708)
  2128. return;
  2129. /* if jack state toggled */
  2130. if (spec->vt1708_hp_present
  2131. != (snd_hda_codec_read(spec->codec, spec->autocfg.hp_pins[0], 0,
  2132. AC_VERB_GET_PIN_SENSE, 0) >> 31)) {
  2133. spec->vt1708_hp_present ^= 1;
  2134. via_hp_automute(spec->codec);
  2135. }
  2136. vt1708_start_hp_work(spec);
  2137. }
  2138. static int get_mux_nids(struct hda_codec *codec)
  2139. {
  2140. struct via_spec *spec = codec->spec;
  2141. hda_nid_t nid, conn[8];
  2142. unsigned int type;
  2143. int i, n;
  2144. for (i = 0; i < spec->num_adc_nids; i++) {
  2145. nid = spec->adc_nids[i];
  2146. while (nid) {
  2147. type = get_wcaps_type(get_wcaps(codec, nid));
  2148. if (type == AC_WID_PIN)
  2149. break;
  2150. n = snd_hda_get_connections(codec, nid, conn,
  2151. ARRAY_SIZE(conn));
  2152. if (n <= 0)
  2153. break;
  2154. if (n > 1) {
  2155. spec->mux_nids[i] = nid;
  2156. break;
  2157. }
  2158. nid = conn[0];
  2159. }
  2160. }
  2161. return 0;
  2162. }
  2163. static int patch_vt1708(struct hda_codec *codec)
  2164. {
  2165. struct via_spec *spec;
  2166. int err;
  2167. /* create a codec specific record */
  2168. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2169. if (spec == NULL)
  2170. return -ENOMEM;
  2171. codec->spec = spec;
  2172. /* automatic parse from the BIOS config */
  2173. err = vt1708_parse_auto_config(codec);
  2174. if (err < 0) {
  2175. via_free(codec);
  2176. return err;
  2177. } else if (!err) {
  2178. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  2179. "from BIOS. Using genenic mode...\n");
  2180. }
  2181. spec->stream_name_analog = "VT1708 Analog";
  2182. spec->stream_analog_playback = &vt1708_pcm_analog_playback;
  2183. /* disable 32bit format on VT1708 */
  2184. if (codec->vendor_id == 0x11061708)
  2185. spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
  2186. spec->stream_analog_capture = &vt1708_pcm_analog_capture;
  2187. spec->stream_name_digital = "VT1708 Digital";
  2188. spec->stream_digital_playback = &vt1708_pcm_digital_playback;
  2189. spec->stream_digital_capture = &vt1708_pcm_digital_capture;
  2190. if (!spec->adc_nids && spec->input_mux) {
  2191. spec->adc_nids = vt1708_adc_nids;
  2192. spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
  2193. get_mux_nids(codec);
  2194. spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
  2195. spec->num_mixers++;
  2196. }
  2197. codec->patch_ops = via_patch_ops;
  2198. codec->patch_ops.init = via_auto_init;
  2199. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2200. spec->loopback.amplist = vt1708_loopbacks;
  2201. #endif
  2202. spec->codec = codec;
  2203. INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
  2204. return 0;
  2205. }
  2206. /* capture mixer elements */
  2207. static struct snd_kcontrol_new vt1709_capture_mixer[] = {
  2208. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
  2209. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
  2210. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
  2211. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
  2212. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
  2213. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
  2214. {
  2215. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2216. /* The multiple "Capture Source" controls confuse alsamixer
  2217. * So call somewhat different..
  2218. */
  2219. /* .name = "Capture Source", */
  2220. .name = "Input Source",
  2221. .count = 1,
  2222. .info = via_mux_enum_info,
  2223. .get = via_mux_enum_get,
  2224. .put = via_mux_enum_put,
  2225. },
  2226. { } /* end */
  2227. };
  2228. static struct hda_verb vt1709_uniwill_init_verbs[] = {
  2229. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
  2230. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
  2231. { }
  2232. };
  2233. /*
  2234. * generic initialization of ADC, input mixers and output mixers
  2235. */
  2236. static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
  2237. /*
  2238. * Unmute ADC0-2 and set the default input to mic-in
  2239. */
  2240. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2241. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2242. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2243. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  2244. * mixer widget
  2245. */
  2246. /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  2247. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2248. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2249. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2250. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2251. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2252. /*
  2253. * Set up output selector (0x1a, 0x1b, 0x29)
  2254. */
  2255. /* set vol=0 to output mixers */
  2256. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2257. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2258. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2259. /*
  2260. * Unmute PW3 and PW4
  2261. */
  2262. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2263. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2264. /* Set input of PW4 as AOW4 */
  2265. {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
  2266. /* PW9 Output enable */
  2267. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2268. { }
  2269. };
  2270. static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
  2271. .substreams = 1,
  2272. .channels_min = 2,
  2273. .channels_max = 10,
  2274. .nid = 0x10, /* NID to query formats and rates */
  2275. .ops = {
  2276. .open = via_playback_pcm_open,
  2277. .prepare = via_playback_multi_pcm_prepare,
  2278. .cleanup = via_playback_multi_pcm_cleanup,
  2279. },
  2280. };
  2281. static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
  2282. .substreams = 1,
  2283. .channels_min = 2,
  2284. .channels_max = 6,
  2285. .nid = 0x10, /* NID to query formats and rates */
  2286. .ops = {
  2287. .open = via_playback_pcm_open,
  2288. .prepare = via_playback_multi_pcm_prepare,
  2289. .cleanup = via_playback_multi_pcm_cleanup,
  2290. },
  2291. };
  2292. static struct hda_pcm_stream vt1709_pcm_analog_capture = {
  2293. .substreams = 2,
  2294. .channels_min = 2,
  2295. .channels_max = 2,
  2296. .nid = 0x14, /* NID to query formats and rates */
  2297. .ops = {
  2298. .prepare = via_capture_pcm_prepare,
  2299. .cleanup = via_capture_pcm_cleanup
  2300. },
  2301. };
  2302. static struct hda_pcm_stream vt1709_pcm_digital_playback = {
  2303. .substreams = 1,
  2304. .channels_min = 2,
  2305. .channels_max = 2,
  2306. /* NID is set in via_build_pcms */
  2307. .ops = {
  2308. .open = via_dig_playback_pcm_open,
  2309. .close = via_dig_playback_pcm_close
  2310. },
  2311. };
  2312. static struct hda_pcm_stream vt1709_pcm_digital_capture = {
  2313. .substreams = 1,
  2314. .channels_min = 2,
  2315. .channels_max = 2,
  2316. };
  2317. static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
  2318. const struct auto_pin_cfg *cfg)
  2319. {
  2320. int i;
  2321. hda_nid_t nid;
  2322. if (cfg->line_outs == 4) /* 10 channels */
  2323. spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
  2324. else if (cfg->line_outs == 3) /* 6 channels */
  2325. spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
  2326. spec->multiout.dac_nids = spec->private_dac_nids;
  2327. if (cfg->line_outs == 4) { /* 10 channels */
  2328. for (i = 0; i < cfg->line_outs; i++) {
  2329. nid = cfg->line_out_pins[i];
  2330. if (nid) {
  2331. /* config dac list */
  2332. switch (i) {
  2333. case AUTO_SEQ_FRONT:
  2334. /* AOW0 */
  2335. spec->multiout.dac_nids[i] = 0x10;
  2336. break;
  2337. case AUTO_SEQ_CENLFE:
  2338. /* AOW2 */
  2339. spec->multiout.dac_nids[i] = 0x12;
  2340. break;
  2341. case AUTO_SEQ_SURROUND:
  2342. /* AOW3 */
  2343. spec->multiout.dac_nids[i] = 0x11;
  2344. break;
  2345. case AUTO_SEQ_SIDE:
  2346. /* AOW1 */
  2347. spec->multiout.dac_nids[i] = 0x27;
  2348. break;
  2349. default:
  2350. break;
  2351. }
  2352. }
  2353. }
  2354. spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
  2355. } else if (cfg->line_outs == 3) { /* 6 channels */
  2356. for(i = 0; i < cfg->line_outs; i++) {
  2357. nid = cfg->line_out_pins[i];
  2358. if (nid) {
  2359. /* config dac list */
  2360. switch(i) {
  2361. case AUTO_SEQ_FRONT:
  2362. /* AOW0 */
  2363. spec->multiout.dac_nids[i] = 0x10;
  2364. break;
  2365. case AUTO_SEQ_CENLFE:
  2366. /* AOW2 */
  2367. spec->multiout.dac_nids[i] = 0x12;
  2368. break;
  2369. case AUTO_SEQ_SURROUND:
  2370. /* AOW1 */
  2371. spec->multiout.dac_nids[i] = 0x11;
  2372. break;
  2373. default:
  2374. break;
  2375. }
  2376. }
  2377. }
  2378. }
  2379. return 0;
  2380. }
  2381. /* add playback controls from the parsed DAC table */
  2382. static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
  2383. const struct auto_pin_cfg *cfg)
  2384. {
  2385. char name[32];
  2386. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  2387. hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
  2388. int i, err;
  2389. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  2390. nid = cfg->line_out_pins[i];
  2391. if (!nid)
  2392. continue;
  2393. nid_vol = nid_vols[i];
  2394. if (i == AUTO_SEQ_CENLFE) {
  2395. /* Center/LFE */
  2396. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2397. "Center Playback Volume",
  2398. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  2399. HDA_OUTPUT));
  2400. if (err < 0)
  2401. return err;
  2402. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2403. "LFE Playback Volume",
  2404. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  2405. HDA_OUTPUT));
  2406. if (err < 0)
  2407. return err;
  2408. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2409. "Center Playback Switch",
  2410. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  2411. HDA_OUTPUT));
  2412. if (err < 0)
  2413. return err;
  2414. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2415. "LFE Playback Switch",
  2416. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  2417. HDA_OUTPUT));
  2418. if (err < 0)
  2419. return err;
  2420. } else if (i == AUTO_SEQ_FRONT){
  2421. /* ADD control to mixer index 0 */
  2422. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2423. "Master Front Playback Volume",
  2424. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2425. HDA_INPUT));
  2426. if (err < 0)
  2427. return err;
  2428. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2429. "Master Front Playback Switch",
  2430. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2431. HDA_INPUT));
  2432. if (err < 0)
  2433. return err;
  2434. /* add control to PW3 */
  2435. sprintf(name, "%s Playback Volume", chname[i]);
  2436. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2437. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  2438. HDA_OUTPUT));
  2439. if (err < 0)
  2440. return err;
  2441. sprintf(name, "%s Playback Switch", chname[i]);
  2442. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2443. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  2444. HDA_OUTPUT));
  2445. if (err < 0)
  2446. return err;
  2447. } else if (i == AUTO_SEQ_SURROUND) {
  2448. sprintf(name, "%s Playback Volume", chname[i]);
  2449. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2450. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2451. HDA_OUTPUT));
  2452. if (err < 0)
  2453. return err;
  2454. sprintf(name, "%s Playback Switch", chname[i]);
  2455. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2456. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2457. HDA_OUTPUT));
  2458. if (err < 0)
  2459. return err;
  2460. } else if (i == AUTO_SEQ_SIDE) {
  2461. sprintf(name, "%s Playback Volume", chname[i]);
  2462. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2463. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2464. HDA_OUTPUT));
  2465. if (err < 0)
  2466. return err;
  2467. sprintf(name, "%s Playback Switch", chname[i]);
  2468. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2469. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2470. HDA_OUTPUT));
  2471. if (err < 0)
  2472. return err;
  2473. }
  2474. }
  2475. return 0;
  2476. }
  2477. static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  2478. {
  2479. int err;
  2480. if (!pin)
  2481. return 0;
  2482. if (spec->multiout.num_dacs == 5) /* 10 channels */
  2483. spec->multiout.hp_nid = VT1709_HP_DAC_NID;
  2484. else if (spec->multiout.num_dacs == 3) /* 6 channels */
  2485. spec->multiout.hp_nid = 0;
  2486. spec->hp_independent_mode_index = 1;
  2487. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2488. "Headphone Playback Volume",
  2489. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2490. if (err < 0)
  2491. return err;
  2492. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2493. "Headphone Playback Switch",
  2494. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2495. if (err < 0)
  2496. return err;
  2497. return 0;
  2498. }
  2499. /* create playback/capture controls for input pins */
  2500. static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
  2501. const struct auto_pin_cfg *cfg)
  2502. {
  2503. static char *labels[] = {
  2504. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  2505. };
  2506. struct hda_input_mux *imux = &spec->private_imux[0];
  2507. int i, err, idx = 0;
  2508. /* for internal loopback recording select */
  2509. imux->items[imux->num_items].label = "Stereo Mixer";
  2510. imux->items[imux->num_items].index = idx;
  2511. imux->num_items++;
  2512. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2513. if (!cfg->input_pins[i])
  2514. continue;
  2515. switch (cfg->input_pins[i]) {
  2516. case 0x1d: /* Mic */
  2517. idx = 2;
  2518. break;
  2519. case 0x1e: /* Line In */
  2520. idx = 3;
  2521. break;
  2522. case 0x21: /* Front Mic */
  2523. idx = 4;
  2524. break;
  2525. case 0x23: /* CD */
  2526. idx = 1;
  2527. break;
  2528. }
  2529. err = via_new_analog_input(spec, labels[i], idx, 0x18);
  2530. if (err < 0)
  2531. return err;
  2532. imux->items[imux->num_items].label = labels[i];
  2533. imux->items[imux->num_items].index = idx;
  2534. imux->num_items++;
  2535. }
  2536. return 0;
  2537. }
  2538. static int vt1709_parse_auto_config(struct hda_codec *codec)
  2539. {
  2540. struct via_spec *spec = codec->spec;
  2541. int err;
  2542. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2543. if (err < 0)
  2544. return err;
  2545. err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
  2546. if (err < 0)
  2547. return err;
  2548. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2549. return 0; /* can't find valid BIOS pin config */
  2550. err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
  2551. if (err < 0)
  2552. return err;
  2553. err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  2554. if (err < 0)
  2555. return err;
  2556. err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
  2557. if (err < 0)
  2558. return err;
  2559. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2560. if (spec->autocfg.dig_outs)
  2561. spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
  2562. spec->dig_in_pin = VT1709_DIGIN_PIN;
  2563. if (spec->autocfg.dig_in_pin)
  2564. spec->dig_in_nid = VT1709_DIGIN_NID;
  2565. if (spec->kctls.list)
  2566. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2567. spec->input_mux = &spec->private_imux[0];
  2568. if (spec->hp_mux)
  2569. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  2570. spec->mixers[spec->num_mixers++] = via_smart51_mixer;
  2571. return 1;
  2572. }
  2573. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2574. static struct hda_amp_list vt1709_loopbacks[] = {
  2575. { 0x18, HDA_INPUT, 1 },
  2576. { 0x18, HDA_INPUT, 2 },
  2577. { 0x18, HDA_INPUT, 3 },
  2578. { 0x18, HDA_INPUT, 4 },
  2579. { } /* end */
  2580. };
  2581. #endif
  2582. static int patch_vt1709_10ch(struct hda_codec *codec)
  2583. {
  2584. struct via_spec *spec;
  2585. int err;
  2586. /* create a codec specific record */
  2587. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2588. if (spec == NULL)
  2589. return -ENOMEM;
  2590. codec->spec = spec;
  2591. err = vt1709_parse_auto_config(codec);
  2592. if (err < 0) {
  2593. via_free(codec);
  2594. return err;
  2595. } else if (!err) {
  2596. printk(KERN_INFO "hda_codec: Cannot set up configuration. "
  2597. "Using genenic mode...\n");
  2598. }
  2599. spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
  2600. spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
  2601. spec->stream_name_analog = "VT1709 Analog";
  2602. spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
  2603. spec->stream_analog_capture = &vt1709_pcm_analog_capture;
  2604. spec->stream_name_digital = "VT1709 Digital";
  2605. spec->stream_digital_playback = &vt1709_pcm_digital_playback;
  2606. spec->stream_digital_capture = &vt1709_pcm_digital_capture;
  2607. if (!spec->adc_nids && spec->input_mux) {
  2608. spec->adc_nids = vt1709_adc_nids;
  2609. spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
  2610. get_mux_nids(codec);
  2611. spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
  2612. spec->num_mixers++;
  2613. }
  2614. codec->patch_ops = via_patch_ops;
  2615. codec->patch_ops.init = via_auto_init;
  2616. codec->patch_ops.unsol_event = via_unsol_event;
  2617. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2618. spec->loopback.amplist = vt1709_loopbacks;
  2619. #endif
  2620. return 0;
  2621. }
  2622. /*
  2623. * generic initialization of ADC, input mixers and output mixers
  2624. */
  2625. static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
  2626. /*
  2627. * Unmute ADC0-2 and set the default input to mic-in
  2628. */
  2629. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2630. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2631. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2632. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  2633. * mixer widget
  2634. */
  2635. /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  2636. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2637. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2638. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2639. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2640. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2641. /*
  2642. * Set up output selector (0x1a, 0x1b, 0x29)
  2643. */
  2644. /* set vol=0 to output mixers */
  2645. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2646. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2647. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2648. /*
  2649. * Unmute PW3 and PW4
  2650. */
  2651. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2652. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2653. /* Set input of PW4 as MW0 */
  2654. {0x20, AC_VERB_SET_CONNECT_SEL, 0},
  2655. /* PW9 Output enable */
  2656. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2657. { }
  2658. };
  2659. static int patch_vt1709_6ch(struct hda_codec *codec)
  2660. {
  2661. struct via_spec *spec;
  2662. int err;
  2663. /* create a codec specific record */
  2664. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2665. if (spec == NULL)
  2666. return -ENOMEM;
  2667. codec->spec = spec;
  2668. err = vt1709_parse_auto_config(codec);
  2669. if (err < 0) {
  2670. via_free(codec);
  2671. return err;
  2672. } else if (!err) {
  2673. printk(KERN_INFO "hda_codec: Cannot set up configuration. "
  2674. "Using genenic mode...\n");
  2675. }
  2676. spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
  2677. spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
  2678. spec->stream_name_analog = "VT1709 Analog";
  2679. spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
  2680. spec->stream_analog_capture = &vt1709_pcm_analog_capture;
  2681. spec->stream_name_digital = "VT1709 Digital";
  2682. spec->stream_digital_playback = &vt1709_pcm_digital_playback;
  2683. spec->stream_digital_capture = &vt1709_pcm_digital_capture;
  2684. if (!spec->adc_nids && spec->input_mux) {
  2685. spec->adc_nids = vt1709_adc_nids;
  2686. spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
  2687. get_mux_nids(codec);
  2688. spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
  2689. spec->num_mixers++;
  2690. }
  2691. codec->patch_ops = via_patch_ops;
  2692. codec->patch_ops.init = via_auto_init;
  2693. codec->patch_ops.unsol_event = via_unsol_event;
  2694. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2695. spec->loopback.amplist = vt1709_loopbacks;
  2696. #endif
  2697. return 0;
  2698. }
  2699. /* capture mixer elements */
  2700. static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
  2701. HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
  2702. HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
  2703. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
  2704. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
  2705. {
  2706. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2707. /* The multiple "Capture Source" controls confuse alsamixer
  2708. * So call somewhat different..
  2709. */
  2710. /* .name = "Capture Source", */
  2711. .name = "Input Source",
  2712. .count = 1,
  2713. .info = via_mux_enum_info,
  2714. .get = via_mux_enum_get,
  2715. .put = via_mux_enum_put,
  2716. },
  2717. { } /* end */
  2718. };
  2719. /*
  2720. * generic initialization of ADC, input mixers and output mixers
  2721. */
  2722. static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
  2723. /*
  2724. * Unmute ADC0-1 and set the default input to mic-in
  2725. */
  2726. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2727. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2728. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  2729. * mixer widget
  2730. */
  2731. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  2732. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2733. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2734. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2735. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2736. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2737. /*
  2738. * Set up output mixers
  2739. */
  2740. /* set vol=0 to output mixers */
  2741. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2742. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2743. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2744. /* Setup default input to PW4 */
  2745. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
  2746. /* PW9 Output enable */
  2747. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2748. /* PW10 Input enable */
  2749. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  2750. { }
  2751. };
  2752. static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
  2753. /*
  2754. * Unmute ADC0-1 and set the default input to mic-in
  2755. */
  2756. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2757. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2758. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  2759. * mixer widget
  2760. */
  2761. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  2762. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2763. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2764. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2765. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2766. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2767. /*
  2768. * Set up output mixers
  2769. */
  2770. /* set vol=0 to output mixers */
  2771. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2772. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2773. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2774. /* Setup default input of PW4 to MW0 */
  2775. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
  2776. /* PW9 Output enable */
  2777. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2778. /* PW10 Input enable */
  2779. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  2780. { }
  2781. };
  2782. static struct hda_verb vt1708B_uniwill_init_verbs[] = {
  2783. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
  2784. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
  2785. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2786. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2787. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2788. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2789. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2790. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2791. {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  2792. { }
  2793. };
  2794. static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
  2795. struct hda_codec *codec,
  2796. struct snd_pcm_substream *substream)
  2797. {
  2798. int idle = substream->pstr->substream_opened == 1
  2799. && substream->ref_count == 0;
  2800. analog_low_current_mode(codec, idle);
  2801. return 0;
  2802. }
  2803. static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
  2804. .substreams = 2,
  2805. .channels_min = 2,
  2806. .channels_max = 8,
  2807. .nid = 0x10, /* NID to query formats and rates */
  2808. .ops = {
  2809. .open = via_playback_pcm_open,
  2810. .prepare = via_playback_multi_pcm_prepare,
  2811. .cleanup = via_playback_multi_pcm_cleanup,
  2812. .close = via_pcm_open_close
  2813. },
  2814. };
  2815. static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
  2816. .substreams = 2,
  2817. .channels_min = 2,
  2818. .channels_max = 4,
  2819. .nid = 0x10, /* NID to query formats and rates */
  2820. .ops = {
  2821. .open = via_playback_pcm_open,
  2822. .prepare = via_playback_multi_pcm_prepare,
  2823. .cleanup = via_playback_multi_pcm_cleanup
  2824. },
  2825. };
  2826. static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
  2827. .substreams = 2,
  2828. .channels_min = 2,
  2829. .channels_max = 2,
  2830. .nid = 0x13, /* NID to query formats and rates */
  2831. .ops = {
  2832. .open = via_pcm_open_close,
  2833. .prepare = via_capture_pcm_prepare,
  2834. .cleanup = via_capture_pcm_cleanup,
  2835. .close = via_pcm_open_close
  2836. },
  2837. };
  2838. static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
  2839. .substreams = 1,
  2840. .channels_min = 2,
  2841. .channels_max = 2,
  2842. /* NID is set in via_build_pcms */
  2843. .ops = {
  2844. .open = via_dig_playback_pcm_open,
  2845. .close = via_dig_playback_pcm_close,
  2846. .prepare = via_dig_playback_pcm_prepare,
  2847. .cleanup = via_dig_playback_pcm_cleanup
  2848. },
  2849. };
  2850. static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
  2851. .substreams = 1,
  2852. .channels_min = 2,
  2853. .channels_max = 2,
  2854. };
  2855. /* fill in the dac_nids table from the parsed pin configuration */
  2856. static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
  2857. const struct auto_pin_cfg *cfg)
  2858. {
  2859. int i;
  2860. hda_nid_t nid;
  2861. spec->multiout.num_dacs = cfg->line_outs;
  2862. spec->multiout.dac_nids = spec->private_dac_nids;
  2863. for (i = 0; i < 4; i++) {
  2864. nid = cfg->line_out_pins[i];
  2865. if (nid) {
  2866. /* config dac list */
  2867. switch (i) {
  2868. case AUTO_SEQ_FRONT:
  2869. spec->multiout.dac_nids[i] = 0x10;
  2870. break;
  2871. case AUTO_SEQ_CENLFE:
  2872. spec->multiout.dac_nids[i] = 0x24;
  2873. break;
  2874. case AUTO_SEQ_SURROUND:
  2875. spec->multiout.dac_nids[i] = 0x11;
  2876. break;
  2877. case AUTO_SEQ_SIDE:
  2878. spec->multiout.dac_nids[i] = 0x25;
  2879. break;
  2880. }
  2881. }
  2882. }
  2883. return 0;
  2884. }
  2885. /* add playback controls from the parsed DAC table */
  2886. static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
  2887. const struct auto_pin_cfg *cfg)
  2888. {
  2889. char name[32];
  2890. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  2891. hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
  2892. hda_nid_t nid, nid_vol = 0;
  2893. int i, err;
  2894. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  2895. nid = cfg->line_out_pins[i];
  2896. if (!nid)
  2897. continue;
  2898. nid_vol = nid_vols[i];
  2899. if (i == AUTO_SEQ_CENLFE) {
  2900. /* Center/LFE */
  2901. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2902. "Center Playback Volume",
  2903. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  2904. HDA_OUTPUT));
  2905. if (err < 0)
  2906. return err;
  2907. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2908. "LFE Playback Volume",
  2909. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  2910. HDA_OUTPUT));
  2911. if (err < 0)
  2912. return err;
  2913. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2914. "Center Playback Switch",
  2915. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  2916. HDA_OUTPUT));
  2917. if (err < 0)
  2918. return err;
  2919. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2920. "LFE Playback Switch",
  2921. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  2922. HDA_OUTPUT));
  2923. if (err < 0)
  2924. return err;
  2925. } else if (i == AUTO_SEQ_FRONT) {
  2926. /* add control to mixer index 0 */
  2927. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2928. "Master Front Playback Volume",
  2929. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2930. HDA_INPUT));
  2931. if (err < 0)
  2932. return err;
  2933. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2934. "Master Front Playback Switch",
  2935. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2936. HDA_INPUT));
  2937. if (err < 0)
  2938. return err;
  2939. /* add control to PW3 */
  2940. sprintf(name, "%s Playback Volume", chname[i]);
  2941. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2942. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  2943. HDA_OUTPUT));
  2944. if (err < 0)
  2945. return err;
  2946. sprintf(name, "%s Playback Switch", chname[i]);
  2947. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2948. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  2949. HDA_OUTPUT));
  2950. if (err < 0)
  2951. return err;
  2952. } else {
  2953. sprintf(name, "%s Playback Volume", chname[i]);
  2954. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2955. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2956. HDA_OUTPUT));
  2957. if (err < 0)
  2958. return err;
  2959. sprintf(name, "%s Playback Switch", chname[i]);
  2960. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2961. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2962. HDA_OUTPUT));
  2963. if (err < 0)
  2964. return err;
  2965. }
  2966. }
  2967. return 0;
  2968. }
  2969. static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  2970. {
  2971. int err;
  2972. if (!pin)
  2973. return 0;
  2974. spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
  2975. spec->hp_independent_mode_index = 1;
  2976. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2977. "Headphone Playback Volume",
  2978. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2979. if (err < 0)
  2980. return err;
  2981. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2982. "Headphone Playback Switch",
  2983. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2984. if (err < 0)
  2985. return err;
  2986. create_hp_imux(spec);
  2987. return 0;
  2988. }
  2989. /* create playback/capture controls for input pins */
  2990. static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
  2991. const struct auto_pin_cfg *cfg)
  2992. {
  2993. static char *labels[] = {
  2994. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  2995. };
  2996. struct hda_input_mux *imux = &spec->private_imux[0];
  2997. int i, err, idx = 0;
  2998. /* for internal loopback recording select */
  2999. imux->items[imux->num_items].label = "Stereo Mixer";
  3000. imux->items[imux->num_items].index = idx;
  3001. imux->num_items++;
  3002. for (i = 0; i < AUTO_PIN_LAST; i++) {
  3003. if (!cfg->input_pins[i])
  3004. continue;
  3005. switch (cfg->input_pins[i]) {
  3006. case 0x1a: /* Mic */
  3007. idx = 2;
  3008. break;
  3009. case 0x1b: /* Line In */
  3010. idx = 3;
  3011. break;
  3012. case 0x1e: /* Front Mic */
  3013. idx = 4;
  3014. break;
  3015. case 0x1f: /* CD */
  3016. idx = 1;
  3017. break;
  3018. }
  3019. err = via_new_analog_input(spec, labels[i], idx, 0x16);
  3020. if (err < 0)
  3021. return err;
  3022. imux->items[imux->num_items].label = labels[i];
  3023. imux->items[imux->num_items].index = idx;
  3024. imux->num_items++;
  3025. }
  3026. return 0;
  3027. }
  3028. static int vt1708B_parse_auto_config(struct hda_codec *codec)
  3029. {
  3030. struct via_spec *spec = codec->spec;
  3031. int err;
  3032. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  3033. if (err < 0)
  3034. return err;
  3035. err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
  3036. if (err < 0)
  3037. return err;
  3038. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  3039. return 0; /* can't find valid BIOS pin config */
  3040. err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
  3041. if (err < 0)
  3042. return err;
  3043. err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  3044. if (err < 0)
  3045. return err;
  3046. err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
  3047. if (err < 0)
  3048. return err;
  3049. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3050. if (spec->autocfg.dig_outs)
  3051. spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
  3052. spec->dig_in_pin = VT1708B_DIGIN_PIN;
  3053. if (spec->autocfg.dig_in_pin)
  3054. spec->dig_in_nid = VT1708B_DIGIN_NID;
  3055. if (spec->kctls.list)
  3056. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  3057. spec->input_mux = &spec->private_imux[0];
  3058. if (spec->hp_mux)
  3059. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  3060. spec->mixers[spec->num_mixers++] = via_smart51_mixer;
  3061. return 1;
  3062. }
  3063. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3064. static struct hda_amp_list vt1708B_loopbacks[] = {
  3065. { 0x16, HDA_INPUT, 1 },
  3066. { 0x16, HDA_INPUT, 2 },
  3067. { 0x16, HDA_INPUT, 3 },
  3068. { 0x16, HDA_INPUT, 4 },
  3069. { } /* end */
  3070. };
  3071. #endif
  3072. static int patch_vt1708S(struct hda_codec *codec);
  3073. static int patch_vt1708B_8ch(struct hda_codec *codec)
  3074. {
  3075. struct via_spec *spec;
  3076. int err;
  3077. if (get_codec_type(codec) == VT1708BCE)
  3078. return patch_vt1708S(codec);
  3079. /* create a codec specific record */
  3080. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3081. if (spec == NULL)
  3082. return -ENOMEM;
  3083. codec->spec = spec;
  3084. /* automatic parse from the BIOS config */
  3085. err = vt1708B_parse_auto_config(codec);
  3086. if (err < 0) {
  3087. via_free(codec);
  3088. return err;
  3089. } else if (!err) {
  3090. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  3091. "from BIOS. Using genenic mode...\n");
  3092. }
  3093. spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
  3094. spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
  3095. spec->stream_name_analog = "VT1708B Analog";
  3096. spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
  3097. spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
  3098. spec->stream_name_digital = "VT1708B Digital";
  3099. spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
  3100. spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
  3101. if (!spec->adc_nids && spec->input_mux) {
  3102. spec->adc_nids = vt1708B_adc_nids;
  3103. spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
  3104. get_mux_nids(codec);
  3105. spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
  3106. spec->num_mixers++;
  3107. }
  3108. codec->patch_ops = via_patch_ops;
  3109. codec->patch_ops.init = via_auto_init;
  3110. codec->patch_ops.unsol_event = via_unsol_event;
  3111. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3112. spec->loopback.amplist = vt1708B_loopbacks;
  3113. #endif
  3114. return 0;
  3115. }
  3116. static int patch_vt1708B_4ch(struct hda_codec *codec)
  3117. {
  3118. struct via_spec *spec;
  3119. int err;
  3120. /* create a codec specific record */
  3121. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3122. if (spec == NULL)
  3123. return -ENOMEM;
  3124. codec->spec = spec;
  3125. /* automatic parse from the BIOS config */
  3126. err = vt1708B_parse_auto_config(codec);
  3127. if (err < 0) {
  3128. via_free(codec);
  3129. return err;
  3130. } else if (!err) {
  3131. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  3132. "from BIOS. Using genenic mode...\n");
  3133. }
  3134. spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
  3135. spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
  3136. spec->stream_name_analog = "VT1708B Analog";
  3137. spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
  3138. spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
  3139. spec->stream_name_digital = "VT1708B Digital";
  3140. spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
  3141. spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
  3142. if (!spec->adc_nids && spec->input_mux) {
  3143. spec->adc_nids = vt1708B_adc_nids;
  3144. spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
  3145. get_mux_nids(codec);
  3146. spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
  3147. spec->num_mixers++;
  3148. }
  3149. codec->patch_ops = via_patch_ops;
  3150. codec->patch_ops.init = via_auto_init;
  3151. codec->patch_ops.unsol_event = via_unsol_event;
  3152. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3153. spec->loopback.amplist = vt1708B_loopbacks;
  3154. #endif
  3155. return 0;
  3156. }
  3157. /* Patch for VT1708S */
  3158. /* capture mixer elements */
  3159. static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
  3160. HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
  3161. HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
  3162. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
  3163. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
  3164. HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
  3165. HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
  3166. HDA_INPUT),
  3167. {
  3168. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3169. /* The multiple "Capture Source" controls confuse alsamixer
  3170. * So call somewhat different..
  3171. */
  3172. /* .name = "Capture Source", */
  3173. .name = "Input Source",
  3174. .count = 1,
  3175. .info = via_mux_enum_info,
  3176. .get = via_mux_enum_get,
  3177. .put = via_mux_enum_put,
  3178. },
  3179. { } /* end */
  3180. };
  3181. static struct hda_verb vt1708S_volume_init_verbs[] = {
  3182. /* Unmute ADC0-1 and set the default input to mic-in */
  3183. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3184. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3185. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
  3186. * analog-loopback mixer widget */
  3187. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  3188. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3189. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3190. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  3191. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  3192. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  3193. /* Setup default input of PW4 to MW0 */
  3194. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
  3195. /* PW9, PW10 Output enable */
  3196. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  3197. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  3198. /* Enable Mic Boost Volume backdoor */
  3199. {0x1, 0xf98, 0x1},
  3200. /* don't bybass mixer */
  3201. {0x1, 0xf88, 0xc0},
  3202. { }
  3203. };
  3204. static struct hda_verb vt1708S_uniwill_init_verbs[] = {
  3205. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
  3206. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
  3207. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3208. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3209. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3210. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3211. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3212. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3213. {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3214. { }
  3215. };
  3216. static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
  3217. .substreams = 2,
  3218. .channels_min = 2,
  3219. .channels_max = 8,
  3220. .nid = 0x10, /* NID to query formats and rates */
  3221. .ops = {
  3222. .open = via_playback_pcm_open,
  3223. .prepare = via_playback_multi_pcm_prepare,
  3224. .cleanup = via_playback_multi_pcm_cleanup,
  3225. .close = via_pcm_open_close
  3226. },
  3227. };
  3228. static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
  3229. .substreams = 2,
  3230. .channels_min = 2,
  3231. .channels_max = 2,
  3232. .nid = 0x13, /* NID to query formats and rates */
  3233. .ops = {
  3234. .open = via_pcm_open_close,
  3235. .prepare = via_capture_pcm_prepare,
  3236. .cleanup = via_capture_pcm_cleanup,
  3237. .close = via_pcm_open_close
  3238. },
  3239. };
  3240. static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
  3241. .substreams = 1,
  3242. .channels_min = 2,
  3243. .channels_max = 2,
  3244. /* NID is set in via_build_pcms */
  3245. .ops = {
  3246. .open = via_dig_playback_pcm_open,
  3247. .close = via_dig_playback_pcm_close,
  3248. .prepare = via_dig_playback_pcm_prepare,
  3249. .cleanup = via_dig_playback_pcm_cleanup
  3250. },
  3251. };
  3252. /* fill in the dac_nids table from the parsed pin configuration */
  3253. static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
  3254. const struct auto_pin_cfg *cfg)
  3255. {
  3256. int i;
  3257. hda_nid_t nid;
  3258. spec->multiout.num_dacs = cfg->line_outs;
  3259. spec->multiout.dac_nids = spec->private_dac_nids;
  3260. for (i = 0; i < 4; i++) {
  3261. nid = cfg->line_out_pins[i];
  3262. if (nid) {
  3263. /* config dac list */
  3264. switch (i) {
  3265. case AUTO_SEQ_FRONT:
  3266. spec->multiout.dac_nids[i] = 0x10;
  3267. break;
  3268. case AUTO_SEQ_CENLFE:
  3269. spec->multiout.dac_nids[i] = 0x24;
  3270. break;
  3271. case AUTO_SEQ_SURROUND:
  3272. spec->multiout.dac_nids[i] = 0x11;
  3273. break;
  3274. case AUTO_SEQ_SIDE:
  3275. spec->multiout.dac_nids[i] = 0x25;
  3276. break;
  3277. }
  3278. }
  3279. }
  3280. return 0;
  3281. }
  3282. /* add playback controls from the parsed DAC table */
  3283. static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
  3284. const struct auto_pin_cfg *cfg)
  3285. {
  3286. char name[32];
  3287. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  3288. hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
  3289. hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
  3290. hda_nid_t nid, nid_vol, nid_mute;
  3291. int i, err;
  3292. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  3293. nid = cfg->line_out_pins[i];
  3294. if (!nid)
  3295. continue;
  3296. nid_vol = nid_vols[i];
  3297. nid_mute = nid_mutes[i];
  3298. if (i == AUTO_SEQ_CENLFE) {
  3299. /* Center/LFE */
  3300. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3301. "Center Playback Volume",
  3302. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  3303. HDA_OUTPUT));
  3304. if (err < 0)
  3305. return err;
  3306. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3307. "LFE Playback Volume",
  3308. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  3309. HDA_OUTPUT));
  3310. if (err < 0)
  3311. return err;
  3312. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3313. "Center Playback Switch",
  3314. HDA_COMPOSE_AMP_VAL(nid_mute,
  3315. 1, 0,
  3316. HDA_OUTPUT));
  3317. if (err < 0)
  3318. return err;
  3319. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3320. "LFE Playback Switch",
  3321. HDA_COMPOSE_AMP_VAL(nid_mute,
  3322. 2, 0,
  3323. HDA_OUTPUT));
  3324. if (err < 0)
  3325. return err;
  3326. } else if (i == AUTO_SEQ_FRONT) {
  3327. /* add control to mixer index 0 */
  3328. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3329. "Master Front Playback Volume",
  3330. HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
  3331. HDA_INPUT));
  3332. if (err < 0)
  3333. return err;
  3334. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3335. "Master Front Playback Switch",
  3336. HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
  3337. HDA_INPUT));
  3338. if (err < 0)
  3339. return err;
  3340. /* Front */
  3341. sprintf(name, "%s Playback Volume", chname[i]);
  3342. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  3343. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  3344. HDA_OUTPUT));
  3345. if (err < 0)
  3346. return err;
  3347. sprintf(name, "%s Playback Switch", chname[i]);
  3348. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  3349. HDA_COMPOSE_AMP_VAL(nid_mute,
  3350. 3, 0,
  3351. HDA_OUTPUT));
  3352. if (err < 0)
  3353. return err;
  3354. } else {
  3355. sprintf(name, "%s Playback Volume", chname[i]);
  3356. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  3357. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  3358. HDA_OUTPUT));
  3359. if (err < 0)
  3360. return err;
  3361. sprintf(name, "%s Playback Switch", chname[i]);
  3362. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  3363. HDA_COMPOSE_AMP_VAL(nid_mute,
  3364. 3, 0,
  3365. HDA_OUTPUT));
  3366. if (err < 0)
  3367. return err;
  3368. }
  3369. }
  3370. return 0;
  3371. }
  3372. static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  3373. {
  3374. int err;
  3375. if (!pin)
  3376. return 0;
  3377. spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
  3378. spec->hp_independent_mode_index = 1;
  3379. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3380. "Headphone Playback Volume",
  3381. HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
  3382. if (err < 0)
  3383. return err;
  3384. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3385. "Headphone Playback Switch",
  3386. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  3387. if (err < 0)
  3388. return err;
  3389. create_hp_imux(spec);
  3390. return 0;
  3391. }
  3392. /* create playback/capture controls for input pins */
  3393. static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
  3394. const struct auto_pin_cfg *cfg)
  3395. {
  3396. static char *labels[] = {
  3397. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  3398. };
  3399. struct hda_input_mux *imux = &spec->private_imux[0];
  3400. int i, err, idx = 0;
  3401. /* for internal loopback recording select */
  3402. imux->items[imux->num_items].label = "Stereo Mixer";
  3403. imux->items[imux->num_items].index = 5;
  3404. imux->num_items++;
  3405. for (i = 0; i < AUTO_PIN_LAST; i++) {
  3406. if (!cfg->input_pins[i])
  3407. continue;
  3408. switch (cfg->input_pins[i]) {
  3409. case 0x1a: /* Mic */
  3410. idx = 2;
  3411. break;
  3412. case 0x1b: /* Line In */
  3413. idx = 3;
  3414. break;
  3415. case 0x1e: /* Front Mic */
  3416. idx = 4;
  3417. break;
  3418. case 0x1f: /* CD */
  3419. idx = 1;
  3420. break;
  3421. }
  3422. err = via_new_analog_input(spec, labels[i], idx, 0x16);
  3423. if (err < 0)
  3424. return err;
  3425. imux->items[imux->num_items].label = labels[i];
  3426. imux->items[imux->num_items].index = idx-1;
  3427. imux->num_items++;
  3428. }
  3429. return 0;
  3430. }
  3431. /* fill out digital output widgets; one for master and one for slave outputs */
  3432. static void fill_dig_outs(struct hda_codec *codec)
  3433. {
  3434. struct via_spec *spec = codec->spec;
  3435. int i;
  3436. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  3437. hda_nid_t nid;
  3438. int conn;
  3439. nid = spec->autocfg.dig_out_pins[i];
  3440. if (!nid)
  3441. continue;
  3442. conn = snd_hda_get_connections(codec, nid, &nid, 1);
  3443. if (conn < 1)
  3444. continue;
  3445. if (!spec->multiout.dig_out_nid)
  3446. spec->multiout.dig_out_nid = nid;
  3447. else {
  3448. spec->slave_dig_outs[0] = nid;
  3449. break; /* at most two dig outs */
  3450. }
  3451. }
  3452. }
  3453. static int vt1708S_parse_auto_config(struct hda_codec *codec)
  3454. {
  3455. struct via_spec *spec = codec->spec;
  3456. int err;
  3457. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  3458. if (err < 0)
  3459. return err;
  3460. err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
  3461. if (err < 0)
  3462. return err;
  3463. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  3464. return 0; /* can't find valid BIOS pin config */
  3465. err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
  3466. if (err < 0)
  3467. return err;
  3468. err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  3469. if (err < 0)
  3470. return err;
  3471. err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
  3472. if (err < 0)
  3473. return err;
  3474. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3475. fill_dig_outs(codec);
  3476. if (spec->kctls.list)
  3477. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  3478. spec->input_mux = &spec->private_imux[0];
  3479. if (spec->hp_mux)
  3480. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  3481. spec->mixers[spec->num_mixers++] = via_smart51_mixer;
  3482. return 1;
  3483. }
  3484. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3485. static struct hda_amp_list vt1708S_loopbacks[] = {
  3486. { 0x16, HDA_INPUT, 1 },
  3487. { 0x16, HDA_INPUT, 2 },
  3488. { 0x16, HDA_INPUT, 3 },
  3489. { 0x16, HDA_INPUT, 4 },
  3490. { } /* end */
  3491. };
  3492. #endif
  3493. static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
  3494. int offset, int num_steps, int step_size)
  3495. {
  3496. snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
  3497. (offset << AC_AMPCAP_OFFSET_SHIFT) |
  3498. (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
  3499. (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
  3500. (0 << AC_AMPCAP_MUTE_SHIFT));
  3501. }
  3502. static int patch_vt1708S(struct hda_codec *codec)
  3503. {
  3504. struct via_spec *spec;
  3505. int err;
  3506. /* create a codec specific record */
  3507. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3508. if (spec == NULL)
  3509. return -ENOMEM;
  3510. codec->spec = spec;
  3511. /* automatic parse from the BIOS config */
  3512. err = vt1708S_parse_auto_config(codec);
  3513. if (err < 0) {
  3514. via_free(codec);
  3515. return err;
  3516. } else if (!err) {
  3517. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  3518. "from BIOS. Using genenic mode...\n");
  3519. }
  3520. spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
  3521. spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
  3522. spec->stream_name_analog = "VT1708S Analog";
  3523. spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
  3524. spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
  3525. spec->stream_name_digital = "VT1708S Digital";
  3526. spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
  3527. if (!spec->adc_nids && spec->input_mux) {
  3528. spec->adc_nids = vt1708S_adc_nids;
  3529. spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
  3530. get_mux_nids(codec);
  3531. override_mic_boost(codec, 0x1a, 0, 3, 40);
  3532. override_mic_boost(codec, 0x1e, 0, 3, 40);
  3533. spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
  3534. spec->num_mixers++;
  3535. }
  3536. codec->patch_ops = via_patch_ops;
  3537. codec->patch_ops.init = via_auto_init;
  3538. codec->patch_ops.unsol_event = via_unsol_event;
  3539. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3540. spec->loopback.amplist = vt1708S_loopbacks;
  3541. #endif
  3542. /* correct names for VT1708BCE */
  3543. if (get_codec_type(codec) == VT1708BCE) {
  3544. kfree(codec->chip_name);
  3545. codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
  3546. snprintf(codec->bus->card->mixername,
  3547. sizeof(codec->bus->card->mixername),
  3548. "%s %s", codec->vendor_name, codec->chip_name);
  3549. spec->stream_name_analog = "VT1708BCE Analog";
  3550. spec->stream_name_digital = "VT1708BCE Digital";
  3551. }
  3552. return 0;
  3553. }
  3554. /* Patch for VT1702 */
  3555. /* capture mixer elements */
  3556. static struct snd_kcontrol_new vt1702_capture_mixer[] = {
  3557. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
  3558. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
  3559. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
  3560. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
  3561. HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
  3562. HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
  3563. HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
  3564. HDA_INPUT),
  3565. {
  3566. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3567. /* The multiple "Capture Source" controls confuse alsamixer
  3568. * So call somewhat different..
  3569. */
  3570. /* .name = "Capture Source", */
  3571. .name = "Input Source",
  3572. .count = 1,
  3573. .info = via_mux_enum_info,
  3574. .get = via_mux_enum_get,
  3575. .put = via_mux_enum_put,
  3576. },
  3577. { } /* end */
  3578. };
  3579. static struct hda_verb vt1702_volume_init_verbs[] = {
  3580. /*
  3581. * Unmute ADC0-1 and set the default input to mic-in
  3582. */
  3583. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3584. {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3585. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3586. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  3587. * mixer widget
  3588. */
  3589. /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
  3590. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3591. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3592. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  3593. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  3594. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3595. /* Setup default input of PW4 to MW0 */
  3596. {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
  3597. /* PW6 PW7 Output enable */
  3598. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  3599. {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  3600. /* mixer enable */
  3601. {0x1, 0xF88, 0x3},
  3602. /* GPIO 0~2 */
  3603. {0x1, 0xF82, 0x3F},
  3604. { }
  3605. };
  3606. static struct hda_verb vt1702_uniwill_init_verbs[] = {
  3607. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
  3608. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
  3609. {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3610. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3611. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3612. {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3613. { }
  3614. };
  3615. static struct hda_pcm_stream vt1702_pcm_analog_playback = {
  3616. .substreams = 2,
  3617. .channels_min = 2,
  3618. .channels_max = 2,
  3619. .nid = 0x10, /* NID to query formats and rates */
  3620. .ops = {
  3621. .open = via_playback_pcm_open,
  3622. .prepare = via_playback_multi_pcm_prepare,
  3623. .cleanup = via_playback_multi_pcm_cleanup,
  3624. .close = via_pcm_open_close
  3625. },
  3626. };
  3627. static struct hda_pcm_stream vt1702_pcm_analog_capture = {
  3628. .substreams = 3,
  3629. .channels_min = 2,
  3630. .channels_max = 2,
  3631. .nid = 0x12, /* NID to query formats and rates */
  3632. .ops = {
  3633. .open = via_pcm_open_close,
  3634. .prepare = via_capture_pcm_prepare,
  3635. .cleanup = via_capture_pcm_cleanup,
  3636. .close = via_pcm_open_close
  3637. },
  3638. };
  3639. static struct hda_pcm_stream vt1702_pcm_digital_playback = {
  3640. .substreams = 2,
  3641. .channels_min = 2,
  3642. .channels_max = 2,
  3643. /* NID is set in via_build_pcms */
  3644. .ops = {
  3645. .open = via_dig_playback_pcm_open,
  3646. .close = via_dig_playback_pcm_close,
  3647. .prepare = via_dig_playback_pcm_prepare,
  3648. .cleanup = via_dig_playback_pcm_cleanup
  3649. },
  3650. };
  3651. /* fill in the dac_nids table from the parsed pin configuration */
  3652. static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
  3653. const struct auto_pin_cfg *cfg)
  3654. {
  3655. spec->multiout.num_dacs = 1;
  3656. spec->multiout.dac_nids = spec->private_dac_nids;
  3657. if (cfg->line_out_pins[0]) {
  3658. /* config dac list */
  3659. spec->multiout.dac_nids[0] = 0x10;
  3660. }
  3661. return 0;
  3662. }
  3663. /* add playback controls from the parsed DAC table */
  3664. static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
  3665. const struct auto_pin_cfg *cfg)
  3666. {
  3667. int err;
  3668. if (!cfg->line_out_pins[0])
  3669. return -1;
  3670. /* add control to mixer index 0 */
  3671. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3672. "Master Front Playback Volume",
  3673. HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
  3674. if (err < 0)
  3675. return err;
  3676. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3677. "Master Front Playback Switch",
  3678. HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
  3679. if (err < 0)
  3680. return err;
  3681. /* Front */
  3682. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3683. "Front Playback Volume",
  3684. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
  3685. if (err < 0)
  3686. return err;
  3687. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3688. "Front Playback Switch",
  3689. HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
  3690. if (err < 0)
  3691. return err;
  3692. return 0;
  3693. }
  3694. static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  3695. {
  3696. int err, i;
  3697. struct hda_input_mux *imux;
  3698. static const char *texts[] = { "ON", "OFF", NULL};
  3699. if (!pin)
  3700. return 0;
  3701. spec->multiout.hp_nid = 0x1D;
  3702. spec->hp_independent_mode_index = 0;
  3703. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  3704. "Headphone Playback Volume",
  3705. HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
  3706. if (err < 0)
  3707. return err;
  3708. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  3709. "Headphone Playback Switch",
  3710. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  3711. if (err < 0)
  3712. return err;
  3713. imux = &spec->private_imux[1];
  3714. /* for hp mode select */
  3715. i = 0;
  3716. while (texts[i] != NULL) {
  3717. imux->items[imux->num_items].label = texts[i];
  3718. imux->items[imux->num_items].index = i;
  3719. imux->num_items++;
  3720. i++;
  3721. }
  3722. spec->hp_mux = &spec->private_imux[1];
  3723. return 0;
  3724. }
  3725. /* create playback/capture controls for input pins */
  3726. static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
  3727. const struct auto_pin_cfg *cfg)
  3728. {
  3729. static char *labels[] = {
  3730. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  3731. };
  3732. struct hda_input_mux *imux = &spec->private_imux[0];
  3733. int i, err, idx = 0;
  3734. /* for internal loopback recording select */
  3735. imux->items[imux->num_items].label = "Stereo Mixer";
  3736. imux->items[imux->num_items].index = 3;
  3737. imux->num_items++;
  3738. for (i = 0; i < AUTO_PIN_LAST; i++) {
  3739. if (!cfg->input_pins[i])
  3740. continue;
  3741. switch (cfg->input_pins[i]) {
  3742. case 0x14: /* Mic */
  3743. idx = 1;
  3744. break;
  3745. case 0x15: /* Line In */
  3746. idx = 2;
  3747. break;
  3748. case 0x18: /* Front Mic */
  3749. idx = 3;
  3750. break;
  3751. }
  3752. err = via_new_analog_input(spec, labels[i], idx, 0x1A);
  3753. if (err < 0)
  3754. return err;
  3755. imux->items[imux->num_items].label = labels[i];
  3756. imux->items[imux->num_items].index = idx-1;
  3757. imux->num_items++;
  3758. }
  3759. return 0;
  3760. }
  3761. static int vt1702_parse_auto_config(struct hda_codec *codec)
  3762. {
  3763. struct via_spec *spec = codec->spec;
  3764. int err;
  3765. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  3766. if (err < 0)
  3767. return err;
  3768. err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
  3769. if (err < 0)
  3770. return err;
  3771. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  3772. return 0; /* can't find valid BIOS pin config */
  3773. err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
  3774. if (err < 0)
  3775. return err;
  3776. err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  3777. if (err < 0)
  3778. return err;
  3779. /* limit AA path volume to 0 dB */
  3780. snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
  3781. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  3782. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  3783. (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  3784. (1 << AC_AMPCAP_MUTE_SHIFT));
  3785. err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
  3786. if (err < 0)
  3787. return err;
  3788. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3789. fill_dig_outs(codec);
  3790. if (spec->kctls.list)
  3791. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  3792. spec->input_mux = &spec->private_imux[0];
  3793. if (spec->hp_mux)
  3794. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  3795. return 1;
  3796. }
  3797. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3798. static struct hda_amp_list vt1702_loopbacks[] = {
  3799. { 0x1A, HDA_INPUT, 1 },
  3800. { 0x1A, HDA_INPUT, 2 },
  3801. { 0x1A, HDA_INPUT, 3 },
  3802. { 0x1A, HDA_INPUT, 4 },
  3803. { } /* end */
  3804. };
  3805. #endif
  3806. static int patch_vt1702(struct hda_codec *codec)
  3807. {
  3808. struct via_spec *spec;
  3809. int err;
  3810. /* create a codec specific record */
  3811. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3812. if (spec == NULL)
  3813. return -ENOMEM;
  3814. codec->spec = spec;
  3815. /* automatic parse from the BIOS config */
  3816. err = vt1702_parse_auto_config(codec);
  3817. if (err < 0) {
  3818. via_free(codec);
  3819. return err;
  3820. } else if (!err) {
  3821. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  3822. "from BIOS. Using genenic mode...\n");
  3823. }
  3824. spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
  3825. spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
  3826. spec->stream_name_analog = "VT1702 Analog";
  3827. spec->stream_analog_playback = &vt1702_pcm_analog_playback;
  3828. spec->stream_analog_capture = &vt1702_pcm_analog_capture;
  3829. spec->stream_name_digital = "VT1702 Digital";
  3830. spec->stream_digital_playback = &vt1702_pcm_digital_playback;
  3831. if (!spec->adc_nids && spec->input_mux) {
  3832. spec->adc_nids = vt1702_adc_nids;
  3833. spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
  3834. get_mux_nids(codec);
  3835. spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
  3836. spec->num_mixers++;
  3837. }
  3838. codec->patch_ops = via_patch_ops;
  3839. codec->patch_ops.init = via_auto_init;
  3840. codec->patch_ops.unsol_event = via_unsol_event;
  3841. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3842. spec->loopback.amplist = vt1702_loopbacks;
  3843. #endif
  3844. return 0;
  3845. }
  3846. /* Patch for VT1718S */
  3847. /* capture mixer elements */
  3848. static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
  3849. HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
  3850. HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
  3851. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
  3852. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
  3853. HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
  3854. HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
  3855. HDA_INPUT),
  3856. {
  3857. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3858. /* The multiple "Capture Source" controls confuse alsamixer
  3859. * So call somewhat different..
  3860. */
  3861. .name = "Input Source",
  3862. .count = 2,
  3863. .info = via_mux_enum_info,
  3864. .get = via_mux_enum_get,
  3865. .put = via_mux_enum_put,
  3866. },
  3867. { } /* end */
  3868. };
  3869. static struct hda_verb vt1718S_volume_init_verbs[] = {
  3870. /*
  3871. * Unmute ADC0-1 and set the default input to mic-in
  3872. */
  3873. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3874. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3875. /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  3876. * mixer widget
  3877. */
  3878. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  3879. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3880. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3881. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3882. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3883. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  3884. /* Setup default input of Front HP to MW9 */
  3885. {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
  3886. /* PW9 PW10 Output enable */
  3887. {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
  3888. {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
  3889. /* PW11 Input enable */
  3890. {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
  3891. /* Enable Boost Volume backdoor */
  3892. {0x1, 0xf88, 0x8},
  3893. /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
  3894. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3895. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3896. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3897. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3898. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3899. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3900. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3901. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3902. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3903. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3904. /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
  3905. {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
  3906. {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
  3907. /* Unmute MW4's index 0 */
  3908. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3909. { }
  3910. };
  3911. static struct hda_verb vt1718S_uniwill_init_verbs[] = {
  3912. {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
  3913. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
  3914. {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3915. {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3916. {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3917. {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3918. {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3919. {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3920. {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  3921. { }
  3922. };
  3923. static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
  3924. .substreams = 2,
  3925. .channels_min = 2,
  3926. .channels_max = 10,
  3927. .nid = 0x8, /* NID to query formats and rates */
  3928. .ops = {
  3929. .open = via_playback_pcm_open,
  3930. .prepare = via_playback_multi_pcm_prepare,
  3931. .cleanup = via_playback_multi_pcm_cleanup,
  3932. .close = via_pcm_open_close,
  3933. },
  3934. };
  3935. static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
  3936. .substreams = 2,
  3937. .channels_min = 2,
  3938. .channels_max = 2,
  3939. .nid = 0x10, /* NID to query formats and rates */
  3940. .ops = {
  3941. .open = via_pcm_open_close,
  3942. .prepare = via_capture_pcm_prepare,
  3943. .cleanup = via_capture_pcm_cleanup,
  3944. .close = via_pcm_open_close,
  3945. },
  3946. };
  3947. static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
  3948. .substreams = 2,
  3949. .channels_min = 2,
  3950. .channels_max = 2,
  3951. .rates = SNDRV_PCM_RATE_48000,
  3952. /* NID is set in via_build_pcms */
  3953. .ops = {
  3954. .open = via_dig_playback_pcm_open,
  3955. .close = via_dig_playback_pcm_close,
  3956. .prepare = via_dig_playback_pcm_prepare,
  3957. .cleanup = via_dig_playback_pcm_cleanup
  3958. },
  3959. };
  3960. static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
  3961. .substreams = 1,
  3962. .channels_min = 2,
  3963. .channels_max = 2,
  3964. };
  3965. /* fill in the dac_nids table from the parsed pin configuration */
  3966. static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
  3967. const struct auto_pin_cfg *cfg)
  3968. {
  3969. int i;
  3970. hda_nid_t nid;
  3971. spec->multiout.num_dacs = cfg->line_outs;
  3972. spec->multiout.dac_nids = spec->private_dac_nids;
  3973. for (i = 0; i < 4; i++) {
  3974. nid = cfg->line_out_pins[i];
  3975. if (nid) {
  3976. /* config dac list */
  3977. switch (i) {
  3978. case AUTO_SEQ_FRONT:
  3979. spec->multiout.dac_nids[i] = 0x8;
  3980. break;
  3981. case AUTO_SEQ_CENLFE:
  3982. spec->multiout.dac_nids[i] = 0xa;
  3983. break;
  3984. case AUTO_SEQ_SURROUND:
  3985. spec->multiout.dac_nids[i] = 0x9;
  3986. break;
  3987. case AUTO_SEQ_SIDE:
  3988. spec->multiout.dac_nids[i] = 0xb;
  3989. break;
  3990. }
  3991. }
  3992. }
  3993. return 0;
  3994. }
  3995. /* add playback controls from the parsed DAC table */
  3996. static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
  3997. const struct auto_pin_cfg *cfg)
  3998. {
  3999. char name[32];
  4000. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  4001. hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
  4002. hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
  4003. hda_nid_t nid, nid_vol, nid_mute = 0;
  4004. int i, err;
  4005. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  4006. nid = cfg->line_out_pins[i];
  4007. if (!nid)
  4008. continue;
  4009. nid_vol = nid_vols[i];
  4010. nid_mute = nid_mutes[i];
  4011. if (i == AUTO_SEQ_CENLFE) {
  4012. /* Center/LFE */
  4013. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  4014. "Center Playback Volume",
  4015. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  4016. HDA_OUTPUT));
  4017. if (err < 0)
  4018. return err;
  4019. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  4020. "LFE Playback Volume",
  4021. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  4022. HDA_OUTPUT));
  4023. if (err < 0)
  4024. return err;
  4025. err = via_add_control(
  4026. spec, VIA_CTL_WIDGET_MUTE,
  4027. "Center Playback Switch",
  4028. HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
  4029. HDA_OUTPUT));
  4030. if (err < 0)
  4031. return err;
  4032. err = via_add_control(
  4033. spec, VIA_CTL_WIDGET_MUTE,
  4034. "LFE Playback Switch",
  4035. HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
  4036. HDA_OUTPUT));
  4037. if (err < 0)
  4038. return err;
  4039. } else if (i == AUTO_SEQ_FRONT) {
  4040. /* Front */
  4041. sprintf(name, "%s Playback Volume", chname[i]);
  4042. err = via_add_control(
  4043. spec, VIA_CTL_WIDGET_VOL, name,
  4044. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
  4045. if (err < 0)
  4046. return err;
  4047. sprintf(name, "%s Playback Switch", chname[i]);
  4048. err = via_add_control(
  4049. spec, VIA_CTL_WIDGET_MUTE, name,
  4050. HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
  4051. HDA_OUTPUT));
  4052. if (err < 0)
  4053. return err;
  4054. } else {
  4055. sprintf(name, "%s Playback Volume", chname[i]);
  4056. err = via_add_control(
  4057. spec, VIA_CTL_WIDGET_VOL, name,
  4058. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
  4059. if (err < 0)
  4060. return err;
  4061. sprintf(name, "%s Playback Switch", chname[i]);
  4062. err = via_add_control(
  4063. spec, VIA_CTL_WIDGET_MUTE, name,
  4064. HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
  4065. HDA_OUTPUT));
  4066. if (err < 0)
  4067. return err;
  4068. }
  4069. }
  4070. return 0;
  4071. }
  4072. static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  4073. {
  4074. int err;
  4075. if (!pin)
  4076. return 0;
  4077. spec->multiout.hp_nid = 0xc; /* AOW4 */
  4078. spec->hp_independent_mode_index = 1;
  4079. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  4080. "Headphone Playback Volume",
  4081. HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
  4082. if (err < 0)
  4083. return err;
  4084. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  4085. "Headphone Playback Switch",
  4086. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  4087. if (err < 0)
  4088. return err;
  4089. create_hp_imux(spec);
  4090. return 0;
  4091. }
  4092. /* create playback/capture controls for input pins */
  4093. static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
  4094. const struct auto_pin_cfg *cfg)
  4095. {
  4096. static char *labels[] = {
  4097. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  4098. };
  4099. struct hda_input_mux *imux = &spec->private_imux[0];
  4100. int i, err, idx = 0;
  4101. /* for internal loopback recording select */
  4102. imux->items[imux->num_items].label = "Stereo Mixer";
  4103. imux->items[imux->num_items].index = 5;
  4104. imux->num_items++;
  4105. for (i = 0; i < AUTO_PIN_LAST; i++) {
  4106. if (!cfg->input_pins[i])
  4107. continue;
  4108. switch (cfg->input_pins[i]) {
  4109. case 0x2b: /* Mic */
  4110. idx = 1;
  4111. break;
  4112. case 0x2a: /* Line In */
  4113. idx = 2;
  4114. break;
  4115. case 0x29: /* Front Mic */
  4116. idx = 3;
  4117. break;
  4118. case 0x2c: /* CD */
  4119. idx = 0;
  4120. break;
  4121. }
  4122. err = via_new_analog_input(spec, labels[i], idx, 0x21);
  4123. if (err < 0)
  4124. return err;
  4125. imux->items[imux->num_items].label = labels[i];
  4126. imux->items[imux->num_items].index = idx;
  4127. imux->num_items++;
  4128. }
  4129. return 0;
  4130. }
  4131. static int vt1718S_parse_auto_config(struct hda_codec *codec)
  4132. {
  4133. struct via_spec *spec = codec->spec;
  4134. int err;
  4135. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  4136. if (err < 0)
  4137. return err;
  4138. err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
  4139. if (err < 0)
  4140. return err;
  4141. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  4142. return 0; /* can't find valid BIOS pin config */
  4143. err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
  4144. if (err < 0)
  4145. return err;
  4146. err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  4147. if (err < 0)
  4148. return err;
  4149. err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
  4150. if (err < 0)
  4151. return err;
  4152. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  4153. fill_dig_outs(codec);
  4154. if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
  4155. spec->dig_in_nid = 0x13;
  4156. if (spec->kctls.list)
  4157. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  4158. spec->input_mux = &spec->private_imux[0];
  4159. if (spec->hp_mux)
  4160. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  4161. spec->mixers[spec->num_mixers++] = via_smart51_mixer;
  4162. return 1;
  4163. }
  4164. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4165. static struct hda_amp_list vt1718S_loopbacks[] = {
  4166. { 0x21, HDA_INPUT, 1 },
  4167. { 0x21, HDA_INPUT, 2 },
  4168. { 0x21, HDA_INPUT, 3 },
  4169. { 0x21, HDA_INPUT, 4 },
  4170. { } /* end */
  4171. };
  4172. #endif
  4173. static int patch_vt1718S(struct hda_codec *codec)
  4174. {
  4175. struct via_spec *spec;
  4176. int err;
  4177. /* create a codec specific record */
  4178. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4179. if (spec == NULL)
  4180. return -ENOMEM;
  4181. codec->spec = spec;
  4182. /* automatic parse from the BIOS config */
  4183. err = vt1718S_parse_auto_config(codec);
  4184. if (err < 0) {
  4185. via_free(codec);
  4186. return err;
  4187. } else if (!err) {
  4188. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  4189. "from BIOS. Using genenic mode...\n");
  4190. }
  4191. spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
  4192. spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
  4193. if (codec->vendor_id == 0x11060441)
  4194. spec->stream_name_analog = "VT2020 Analog";
  4195. else if (codec->vendor_id == 0x11064441)
  4196. spec->stream_name_analog = "VT1828S Analog";
  4197. else
  4198. spec->stream_name_analog = "VT1718S Analog";
  4199. spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
  4200. spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
  4201. if (codec->vendor_id == 0x11060441)
  4202. spec->stream_name_digital = "VT2020 Digital";
  4203. else if (codec->vendor_id == 0x11064441)
  4204. spec->stream_name_digital = "VT1828S Digital";
  4205. else
  4206. spec->stream_name_digital = "VT1718S Digital";
  4207. spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
  4208. if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
  4209. spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
  4210. if (!spec->adc_nids && spec->input_mux) {
  4211. spec->adc_nids = vt1718S_adc_nids;
  4212. spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
  4213. get_mux_nids(codec);
  4214. override_mic_boost(codec, 0x2b, 0, 3, 40);
  4215. override_mic_boost(codec, 0x29, 0, 3, 40);
  4216. spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
  4217. spec->num_mixers++;
  4218. }
  4219. codec->patch_ops = via_patch_ops;
  4220. codec->patch_ops.init = via_auto_init;
  4221. codec->patch_ops.unsol_event = via_unsol_event,
  4222. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4223. spec->loopback.amplist = vt1718S_loopbacks;
  4224. #endif
  4225. return 0;
  4226. }
  4227. /* Patch for VT1716S */
  4228. static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
  4229. struct snd_ctl_elem_info *uinfo)
  4230. {
  4231. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  4232. uinfo->count = 1;
  4233. uinfo->value.integer.min = 0;
  4234. uinfo->value.integer.max = 1;
  4235. return 0;
  4236. }
  4237. static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
  4238. struct snd_ctl_elem_value *ucontrol)
  4239. {
  4240. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  4241. int index = 0;
  4242. index = snd_hda_codec_read(codec, 0x26, 0,
  4243. AC_VERB_GET_CONNECT_SEL, 0);
  4244. if (index != -1)
  4245. *ucontrol->value.integer.value = index;
  4246. return 0;
  4247. }
  4248. static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
  4249. struct snd_ctl_elem_value *ucontrol)
  4250. {
  4251. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  4252. struct via_spec *spec = codec->spec;
  4253. int index = *ucontrol->value.integer.value;
  4254. snd_hda_codec_write(codec, 0x26, 0,
  4255. AC_VERB_SET_CONNECT_SEL, index);
  4256. spec->dmic_enabled = index;
  4257. set_jack_power_state(codec);
  4258. return 1;
  4259. }
  4260. /* capture mixer elements */
  4261. static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
  4262. HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
  4263. HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
  4264. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
  4265. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
  4266. HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
  4267. HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
  4268. HDA_INPUT),
  4269. {
  4270. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4271. .name = "Input Source",
  4272. .count = 1,
  4273. .info = via_mux_enum_info,
  4274. .get = via_mux_enum_get,
  4275. .put = via_mux_enum_put,
  4276. },
  4277. { } /* end */
  4278. };
  4279. static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
  4280. HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
  4281. {
  4282. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4283. .name = "Digital Mic Capture Switch",
  4284. .count = 1,
  4285. .info = vt1716s_dmic_info,
  4286. .get = vt1716s_dmic_get,
  4287. .put = vt1716s_dmic_put,
  4288. },
  4289. {} /* end */
  4290. };
  4291. /* mono-out mixer elements */
  4292. static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
  4293. HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
  4294. { } /* end */
  4295. };
  4296. static struct hda_verb vt1716S_volume_init_verbs[] = {
  4297. /*
  4298. * Unmute ADC0-1 and set the default input to mic-in
  4299. */
  4300. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4301. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4302. /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  4303. * mixer widget
  4304. */
  4305. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  4306. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4307. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4308. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  4309. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  4310. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  4311. /* MUX Indices: Stereo Mixer = 5 */
  4312. {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
  4313. /* Setup default input of PW4 to MW0 */
  4314. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
  4315. /* Setup default input of SW1 as MW0 */
  4316. {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
  4317. /* Setup default input of SW4 as AOW0 */
  4318. {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
  4319. /* PW9 PW10 Output enable */
  4320. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  4321. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  4322. /* Unmute SW1, PW12 */
  4323. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4324. {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4325. /* PW12 Output enable */
  4326. {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  4327. /* Enable Boost Volume backdoor */
  4328. {0x1, 0xf8a, 0x80},
  4329. /* don't bybass mixer */
  4330. {0x1, 0xf88, 0xc0},
  4331. /* Enable mono output */
  4332. {0x1, 0xf90, 0x08},
  4333. { }
  4334. };
  4335. static struct hda_verb vt1716S_uniwill_init_verbs[] = {
  4336. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
  4337. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
  4338. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4339. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4340. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4341. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
  4342. AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
  4343. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4344. {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4345. { }
  4346. };
  4347. static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
  4348. .substreams = 2,
  4349. .channels_min = 2,
  4350. .channels_max = 6,
  4351. .nid = 0x10, /* NID to query formats and rates */
  4352. .ops = {
  4353. .open = via_playback_pcm_open,
  4354. .prepare = via_playback_multi_pcm_prepare,
  4355. .cleanup = via_playback_multi_pcm_cleanup,
  4356. .close = via_pcm_open_close,
  4357. },
  4358. };
  4359. static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
  4360. .substreams = 2,
  4361. .channels_min = 2,
  4362. .channels_max = 2,
  4363. .nid = 0x13, /* NID to query formats and rates */
  4364. .ops = {
  4365. .open = via_pcm_open_close,
  4366. .prepare = via_capture_pcm_prepare,
  4367. .cleanup = via_capture_pcm_cleanup,
  4368. .close = via_pcm_open_close,
  4369. },
  4370. };
  4371. static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
  4372. .substreams = 2,
  4373. .channels_min = 2,
  4374. .channels_max = 2,
  4375. .rates = SNDRV_PCM_RATE_48000,
  4376. /* NID is set in via_build_pcms */
  4377. .ops = {
  4378. .open = via_dig_playback_pcm_open,
  4379. .close = via_dig_playback_pcm_close,
  4380. .prepare = via_dig_playback_pcm_prepare,
  4381. .cleanup = via_dig_playback_pcm_cleanup
  4382. },
  4383. };
  4384. /* fill in the dac_nids table from the parsed pin configuration */
  4385. static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
  4386. const struct auto_pin_cfg *cfg)
  4387. { int i;
  4388. hda_nid_t nid;
  4389. spec->multiout.num_dacs = cfg->line_outs;
  4390. spec->multiout.dac_nids = spec->private_dac_nids;
  4391. for (i = 0; i < 3; i++) {
  4392. nid = cfg->line_out_pins[i];
  4393. if (nid) {
  4394. /* config dac list */
  4395. switch (i) {
  4396. case AUTO_SEQ_FRONT:
  4397. spec->multiout.dac_nids[i] = 0x10;
  4398. break;
  4399. case AUTO_SEQ_CENLFE:
  4400. spec->multiout.dac_nids[i] = 0x25;
  4401. break;
  4402. case AUTO_SEQ_SURROUND:
  4403. spec->multiout.dac_nids[i] = 0x11;
  4404. break;
  4405. }
  4406. }
  4407. }
  4408. return 0;
  4409. }
  4410. /* add playback controls from the parsed DAC table */
  4411. static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
  4412. const struct auto_pin_cfg *cfg)
  4413. {
  4414. char name[32];
  4415. static const char *chname[3] = { "Front", "Surround", "C/LFE" };
  4416. hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
  4417. hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
  4418. hda_nid_t nid, nid_vol, nid_mute;
  4419. int i, err;
  4420. for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
  4421. nid = cfg->line_out_pins[i];
  4422. if (!nid)
  4423. continue;
  4424. nid_vol = nid_vols[i];
  4425. nid_mute = nid_mutes[i];
  4426. if (i == AUTO_SEQ_CENLFE) {
  4427. err = via_add_control(
  4428. spec, VIA_CTL_WIDGET_VOL,
  4429. "Center Playback Volume",
  4430. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
  4431. if (err < 0)
  4432. return err;
  4433. err = via_add_control(
  4434. spec, VIA_CTL_WIDGET_VOL,
  4435. "LFE Playback Volume",
  4436. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
  4437. if (err < 0)
  4438. return err;
  4439. err = via_add_control(
  4440. spec, VIA_CTL_WIDGET_MUTE,
  4441. "Center Playback Switch",
  4442. HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
  4443. HDA_OUTPUT));
  4444. if (err < 0)
  4445. return err;
  4446. err = via_add_control(
  4447. spec, VIA_CTL_WIDGET_MUTE,
  4448. "LFE Playback Switch",
  4449. HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
  4450. HDA_OUTPUT));
  4451. if (err < 0)
  4452. return err;
  4453. } else if (i == AUTO_SEQ_FRONT) {
  4454. err = via_add_control(
  4455. spec, VIA_CTL_WIDGET_VOL,
  4456. "Master Front Playback Volume",
  4457. HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
  4458. if (err < 0)
  4459. return err;
  4460. err = via_add_control(
  4461. spec, VIA_CTL_WIDGET_MUTE,
  4462. "Master Front Playback Switch",
  4463. HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
  4464. if (err < 0)
  4465. return err;
  4466. sprintf(name, "%s Playback Volume", chname[i]);
  4467. err = via_add_control(
  4468. spec, VIA_CTL_WIDGET_VOL, name,
  4469. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
  4470. if (err < 0)
  4471. return err;
  4472. sprintf(name, "%s Playback Switch", chname[i]);
  4473. err = via_add_control(
  4474. spec, VIA_CTL_WIDGET_MUTE, name,
  4475. HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
  4476. HDA_OUTPUT));
  4477. if (err < 0)
  4478. return err;
  4479. } else {
  4480. sprintf(name, "%s Playback Volume", chname[i]);
  4481. err = via_add_control(
  4482. spec, VIA_CTL_WIDGET_VOL, name,
  4483. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
  4484. if (err < 0)
  4485. return err;
  4486. sprintf(name, "%s Playback Switch", chname[i]);
  4487. err = via_add_control(
  4488. spec, VIA_CTL_WIDGET_MUTE, name,
  4489. HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
  4490. HDA_OUTPUT));
  4491. if (err < 0)
  4492. return err;
  4493. }
  4494. }
  4495. return 0;
  4496. }
  4497. static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  4498. {
  4499. int err;
  4500. if (!pin)
  4501. return 0;
  4502. spec->multiout.hp_nid = 0x25; /* AOW3 */
  4503. spec->hp_independent_mode_index = 1;
  4504. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  4505. "Headphone Playback Volume",
  4506. HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
  4507. if (err < 0)
  4508. return err;
  4509. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  4510. "Headphone Playback Switch",
  4511. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  4512. if (err < 0)
  4513. return err;
  4514. create_hp_imux(spec);
  4515. return 0;
  4516. }
  4517. /* create playback/capture controls for input pins */
  4518. static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
  4519. const struct auto_pin_cfg *cfg)
  4520. {
  4521. static char *labels[] = {
  4522. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  4523. };
  4524. struct hda_input_mux *imux = &spec->private_imux[0];
  4525. int i, err, idx = 0;
  4526. /* for internal loopback recording select */
  4527. imux->items[imux->num_items].label = "Stereo Mixer";
  4528. imux->items[imux->num_items].index = 5;
  4529. imux->num_items++;
  4530. for (i = 0; i < AUTO_PIN_LAST; i++) {
  4531. if (!cfg->input_pins[i])
  4532. continue;
  4533. switch (cfg->input_pins[i]) {
  4534. case 0x1a: /* Mic */
  4535. idx = 2;
  4536. break;
  4537. case 0x1b: /* Line In */
  4538. idx = 3;
  4539. break;
  4540. case 0x1e: /* Front Mic */
  4541. idx = 4;
  4542. break;
  4543. case 0x1f: /* CD */
  4544. idx = 1;
  4545. break;
  4546. }
  4547. err = via_new_analog_input(spec, labels[i], idx, 0x16);
  4548. if (err < 0)
  4549. return err;
  4550. imux->items[imux->num_items].label = labels[i];
  4551. imux->items[imux->num_items].index = idx-1;
  4552. imux->num_items++;
  4553. }
  4554. return 0;
  4555. }
  4556. static int vt1716S_parse_auto_config(struct hda_codec *codec)
  4557. {
  4558. struct via_spec *spec = codec->spec;
  4559. int err;
  4560. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  4561. if (err < 0)
  4562. return err;
  4563. err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
  4564. if (err < 0)
  4565. return err;
  4566. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  4567. return 0; /* can't find valid BIOS pin config */
  4568. err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
  4569. if (err < 0)
  4570. return err;
  4571. err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  4572. if (err < 0)
  4573. return err;
  4574. err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
  4575. if (err < 0)
  4576. return err;
  4577. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  4578. fill_dig_outs(codec);
  4579. if (spec->kctls.list)
  4580. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  4581. spec->input_mux = &spec->private_imux[0];
  4582. if (spec->hp_mux)
  4583. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  4584. spec->mixers[spec->num_mixers++] = via_smart51_mixer;
  4585. return 1;
  4586. }
  4587. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4588. static struct hda_amp_list vt1716S_loopbacks[] = {
  4589. { 0x16, HDA_INPUT, 1 },
  4590. { 0x16, HDA_INPUT, 2 },
  4591. { 0x16, HDA_INPUT, 3 },
  4592. { 0x16, HDA_INPUT, 4 },
  4593. { } /* end */
  4594. };
  4595. #endif
  4596. static int patch_vt1716S(struct hda_codec *codec)
  4597. {
  4598. struct via_spec *spec;
  4599. int err;
  4600. /* create a codec specific record */
  4601. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4602. if (spec == NULL)
  4603. return -ENOMEM;
  4604. codec->spec = spec;
  4605. /* automatic parse from the BIOS config */
  4606. err = vt1716S_parse_auto_config(codec);
  4607. if (err < 0) {
  4608. via_free(codec);
  4609. return err;
  4610. } else if (!err) {
  4611. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  4612. "from BIOS. Using genenic mode...\n");
  4613. }
  4614. spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
  4615. spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
  4616. spec->stream_name_analog = "VT1716S Analog";
  4617. spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
  4618. spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
  4619. spec->stream_name_digital = "VT1716S Digital";
  4620. spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
  4621. if (!spec->adc_nids && spec->input_mux) {
  4622. spec->adc_nids = vt1716S_adc_nids;
  4623. spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
  4624. get_mux_nids(codec);
  4625. override_mic_boost(codec, 0x1a, 0, 3, 40);
  4626. override_mic_boost(codec, 0x1e, 0, 3, 40);
  4627. spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
  4628. spec->num_mixers++;
  4629. }
  4630. spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
  4631. spec->num_mixers++;
  4632. spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
  4633. codec->patch_ops = via_patch_ops;
  4634. codec->patch_ops.init = via_auto_init;
  4635. codec->patch_ops.unsol_event = via_unsol_event,
  4636. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4637. spec->loopback.amplist = vt1716S_loopbacks;
  4638. #endif
  4639. return 0;
  4640. }
  4641. /* for vt2002P */
  4642. /* capture mixer elements */
  4643. static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
  4644. HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
  4645. HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
  4646. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
  4647. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
  4648. HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
  4649. HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
  4650. HDA_INPUT),
  4651. {
  4652. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4653. /* The multiple "Capture Source" controls confuse alsamixer
  4654. * So call somewhat different..
  4655. */
  4656. /* .name = "Capture Source", */
  4657. .name = "Input Source",
  4658. .count = 2,
  4659. .info = via_mux_enum_info,
  4660. .get = via_mux_enum_get,
  4661. .put = via_mux_enum_put,
  4662. },
  4663. { } /* end */
  4664. };
  4665. static struct hda_verb vt2002P_volume_init_verbs[] = {
  4666. /*
  4667. * Unmute ADC0-1 and set the default input to mic-in
  4668. */
  4669. {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4670. {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4671. /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  4672. * mixer widget
  4673. */
  4674. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  4675. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4676. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4677. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  4678. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  4679. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  4680. /* MUX Indices: Mic = 0 */
  4681. {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
  4682. {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
  4683. /* PW9 Output enable */
  4684. {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
  4685. /* Enable Boost Volume backdoor */
  4686. {0x1, 0xfb9, 0x24},
  4687. /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
  4688. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4689. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4690. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4691. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4692. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4693. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4694. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4695. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4696. /* set MUX0/1/4/8 = 0 (AOW0) */
  4697. {0x34, AC_VERB_SET_CONNECT_SEL, 0},
  4698. {0x35, AC_VERB_SET_CONNECT_SEL, 0},
  4699. {0x37, AC_VERB_SET_CONNECT_SEL, 0},
  4700. {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
  4701. /* set PW0 index=0 (MW0) */
  4702. {0x24, AC_VERB_SET_CONNECT_SEL, 0},
  4703. /* Enable AOW0 to MW9 */
  4704. {0x1, 0xfb8, 0x88},
  4705. { }
  4706. };
  4707. static struct hda_verb vt2002P_uniwill_init_verbs[] = {
  4708. {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
  4709. AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
  4710. {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
  4711. AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
  4712. {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4713. {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4714. {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
  4715. { }
  4716. };
  4717. static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
  4718. .substreams = 2,
  4719. .channels_min = 2,
  4720. .channels_max = 2,
  4721. .nid = 0x8, /* NID to query formats and rates */
  4722. .ops = {
  4723. .open = via_playback_pcm_open,
  4724. .prepare = via_playback_multi_pcm_prepare,
  4725. .cleanup = via_playback_multi_pcm_cleanup,
  4726. .close = via_pcm_open_close,
  4727. },
  4728. };
  4729. static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
  4730. .substreams = 2,
  4731. .channels_min = 2,
  4732. .channels_max = 2,
  4733. .nid = 0x10, /* NID to query formats and rates */
  4734. .ops = {
  4735. .open = via_pcm_open_close,
  4736. .prepare = via_capture_pcm_prepare,
  4737. .cleanup = via_capture_pcm_cleanup,
  4738. .close = via_pcm_open_close,
  4739. },
  4740. };
  4741. static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
  4742. .substreams = 1,
  4743. .channels_min = 2,
  4744. .channels_max = 2,
  4745. .rates = SNDRV_PCM_RATE_48000,
  4746. /* NID is set in via_build_pcms */
  4747. .ops = {
  4748. .open = via_dig_playback_pcm_open,
  4749. .close = via_dig_playback_pcm_close,
  4750. .prepare = via_dig_playback_pcm_prepare,
  4751. .cleanup = via_dig_playback_pcm_cleanup
  4752. },
  4753. };
  4754. /* fill in the dac_nids table from the parsed pin configuration */
  4755. static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
  4756. const struct auto_pin_cfg *cfg)
  4757. {
  4758. spec->multiout.num_dacs = 1;
  4759. spec->multiout.dac_nids = spec->private_dac_nids;
  4760. if (cfg->line_out_pins[0])
  4761. spec->multiout.dac_nids[0] = 0x8;
  4762. return 0;
  4763. }
  4764. /* add playback controls from the parsed DAC table */
  4765. static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
  4766. const struct auto_pin_cfg *cfg)
  4767. {
  4768. int err;
  4769. if (!cfg->line_out_pins[0])
  4770. return -1;
  4771. /* Line-Out: PortE */
  4772. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  4773. "Master Front Playback Volume",
  4774. HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
  4775. if (err < 0)
  4776. return err;
  4777. err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
  4778. "Master Front Playback Switch",
  4779. HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
  4780. if (err < 0)
  4781. return err;
  4782. return 0;
  4783. }
  4784. static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  4785. {
  4786. int err;
  4787. if (!pin)
  4788. return 0;
  4789. spec->multiout.hp_nid = 0x9;
  4790. spec->hp_independent_mode_index = 1;
  4791. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  4792. "Headphone Playback Volume",
  4793. HDA_COMPOSE_AMP_VAL(
  4794. spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
  4795. if (err < 0)
  4796. return err;
  4797. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  4798. "Headphone Playback Switch",
  4799. HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
  4800. if (err < 0)
  4801. return err;
  4802. create_hp_imux(spec);
  4803. return 0;
  4804. }
  4805. /* create playback/capture controls for input pins */
  4806. static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
  4807. const struct auto_pin_cfg *cfg)
  4808. {
  4809. static char *labels[] = {
  4810. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  4811. };
  4812. struct hda_input_mux *imux = &spec->private_imux[0];
  4813. int i, err, idx = 0;
  4814. for (i = 0; i < AUTO_PIN_LAST; i++) {
  4815. if (!cfg->input_pins[i])
  4816. continue;
  4817. switch (cfg->input_pins[i]) {
  4818. case 0x2b: /* Mic */
  4819. idx = 0;
  4820. break;
  4821. case 0x2a: /* Line In */
  4822. idx = 1;
  4823. break;
  4824. case 0x29: /* Front Mic */
  4825. idx = 2;
  4826. break;
  4827. }
  4828. err = via_new_analog_input(spec, labels[i], idx, 0x21);
  4829. if (err < 0)
  4830. return err;
  4831. imux->items[imux->num_items].label = labels[i];
  4832. imux->items[imux->num_items].index = idx;
  4833. imux->num_items++;
  4834. }
  4835. /* build volume/mute control of loopback */
  4836. err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
  4837. if (err < 0)
  4838. return err;
  4839. /* for internal loopback recording select */
  4840. imux->items[imux->num_items].label = "Stereo Mixer";
  4841. imux->items[imux->num_items].index = 3;
  4842. imux->num_items++;
  4843. /* for digital mic select */
  4844. imux->items[imux->num_items].label = "Digital Mic";
  4845. imux->items[imux->num_items].index = 4;
  4846. imux->num_items++;
  4847. return 0;
  4848. }
  4849. static int vt2002P_parse_auto_config(struct hda_codec *codec)
  4850. {
  4851. struct via_spec *spec = codec->spec;
  4852. int err;
  4853. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  4854. if (err < 0)
  4855. return err;
  4856. err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
  4857. if (err < 0)
  4858. return err;
  4859. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  4860. return 0; /* can't find valid BIOS pin config */
  4861. err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
  4862. if (err < 0)
  4863. return err;
  4864. err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  4865. if (err < 0)
  4866. return err;
  4867. err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
  4868. if (err < 0)
  4869. return err;
  4870. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  4871. fill_dig_outs(codec);
  4872. if (spec->kctls.list)
  4873. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  4874. spec->input_mux = &spec->private_imux[0];
  4875. if (spec->hp_mux)
  4876. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  4877. return 1;
  4878. }
  4879. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4880. static struct hda_amp_list vt2002P_loopbacks[] = {
  4881. { 0x21, HDA_INPUT, 0 },
  4882. { 0x21, HDA_INPUT, 1 },
  4883. { 0x21, HDA_INPUT, 2 },
  4884. { } /* end */
  4885. };
  4886. #endif
  4887. /* patch for vt2002P */
  4888. static int patch_vt2002P(struct hda_codec *codec)
  4889. {
  4890. struct via_spec *spec;
  4891. int err;
  4892. /* create a codec specific record */
  4893. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4894. if (spec == NULL)
  4895. return -ENOMEM;
  4896. codec->spec = spec;
  4897. /* automatic parse from the BIOS config */
  4898. err = vt2002P_parse_auto_config(codec);
  4899. if (err < 0) {
  4900. via_free(codec);
  4901. return err;
  4902. } else if (!err) {
  4903. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  4904. "from BIOS. Using genenic mode...\n");
  4905. }
  4906. spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
  4907. spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
  4908. spec->stream_name_analog = "VT2002P Analog";
  4909. spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
  4910. spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
  4911. spec->stream_name_digital = "VT2002P Digital";
  4912. spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
  4913. if (!spec->adc_nids && spec->input_mux) {
  4914. spec->adc_nids = vt2002P_adc_nids;
  4915. spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
  4916. get_mux_nids(codec);
  4917. override_mic_boost(codec, 0x2b, 0, 3, 40);
  4918. override_mic_boost(codec, 0x29, 0, 3, 40);
  4919. spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
  4920. spec->num_mixers++;
  4921. }
  4922. codec->patch_ops = via_patch_ops;
  4923. codec->patch_ops.init = via_auto_init;
  4924. codec->patch_ops.unsol_event = via_unsol_event,
  4925. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4926. spec->loopback.amplist = vt2002P_loopbacks;
  4927. #endif
  4928. return 0;
  4929. }
  4930. /*
  4931. * patch entries
  4932. */
  4933. static struct hda_codec_preset snd_hda_preset_via[] = {
  4934. { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
  4935. { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
  4936. { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
  4937. { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
  4938. { .id = 0x1106e710, .name = "VT1709 10-Ch",
  4939. .patch = patch_vt1709_10ch},
  4940. { .id = 0x1106e711, .name = "VT1709 10-Ch",
  4941. .patch = patch_vt1709_10ch},
  4942. { .id = 0x1106e712, .name = "VT1709 10-Ch",
  4943. .patch = patch_vt1709_10ch},
  4944. { .id = 0x1106e713, .name = "VT1709 10-Ch",
  4945. .patch = patch_vt1709_10ch},
  4946. { .id = 0x1106e714, .name = "VT1709 6-Ch",
  4947. .patch = patch_vt1709_6ch},
  4948. { .id = 0x1106e715, .name = "VT1709 6-Ch",
  4949. .patch = patch_vt1709_6ch},
  4950. { .id = 0x1106e716, .name = "VT1709 6-Ch",
  4951. .patch = patch_vt1709_6ch},
  4952. { .id = 0x1106e717, .name = "VT1709 6-Ch",
  4953. .patch = patch_vt1709_6ch},
  4954. { .id = 0x1106e720, .name = "VT1708B 8-Ch",
  4955. .patch = patch_vt1708B_8ch},
  4956. { .id = 0x1106e721, .name = "VT1708B 8-Ch",
  4957. .patch = patch_vt1708B_8ch},
  4958. { .id = 0x1106e722, .name = "VT1708B 8-Ch",
  4959. .patch = patch_vt1708B_8ch},
  4960. { .id = 0x1106e723, .name = "VT1708B 8-Ch",
  4961. .patch = patch_vt1708B_8ch},
  4962. { .id = 0x1106e724, .name = "VT1708B 4-Ch",
  4963. .patch = patch_vt1708B_4ch},
  4964. { .id = 0x1106e725, .name = "VT1708B 4-Ch",
  4965. .patch = patch_vt1708B_4ch},
  4966. { .id = 0x1106e726, .name = "VT1708B 4-Ch",
  4967. .patch = patch_vt1708B_4ch},
  4968. { .id = 0x1106e727, .name = "VT1708B 4-Ch",
  4969. .patch = patch_vt1708B_4ch},
  4970. { .id = 0x11060397, .name = "VT1708S",
  4971. .patch = patch_vt1708S},
  4972. { .id = 0x11061397, .name = "VT1708S",
  4973. .patch = patch_vt1708S},
  4974. { .id = 0x11062397, .name = "VT1708S",
  4975. .patch = patch_vt1708S},
  4976. { .id = 0x11063397, .name = "VT1708S",
  4977. .patch = patch_vt1708S},
  4978. { .id = 0x11064397, .name = "VT1708S",
  4979. .patch = patch_vt1708S},
  4980. { .id = 0x11065397, .name = "VT1708S",
  4981. .patch = patch_vt1708S},
  4982. { .id = 0x11066397, .name = "VT1708S",
  4983. .patch = patch_vt1708S},
  4984. { .id = 0x11067397, .name = "VT1708S",
  4985. .patch = patch_vt1708S},
  4986. { .id = 0x11060398, .name = "VT1702",
  4987. .patch = patch_vt1702},
  4988. { .id = 0x11061398, .name = "VT1702",
  4989. .patch = patch_vt1702},
  4990. { .id = 0x11062398, .name = "VT1702",
  4991. .patch = patch_vt1702},
  4992. { .id = 0x11063398, .name = "VT1702",
  4993. .patch = patch_vt1702},
  4994. { .id = 0x11064398, .name = "VT1702",
  4995. .patch = patch_vt1702},
  4996. { .id = 0x11065398, .name = "VT1702",
  4997. .patch = patch_vt1702},
  4998. { .id = 0x11066398, .name = "VT1702",
  4999. .patch = patch_vt1702},
  5000. { .id = 0x11067398, .name = "VT1702",
  5001. .patch = patch_vt1702},
  5002. { .id = 0x11060428, .name = "VT1718S",
  5003. .patch = patch_vt1718S},
  5004. { .id = 0x11064428, .name = "VT1718S",
  5005. .patch = patch_vt1718S},
  5006. { .id = 0x11060441, .name = "VT2020",
  5007. .patch = patch_vt1718S},
  5008. { .id = 0x11064441, .name = "VT1828S",
  5009. .patch = patch_vt1718S},
  5010. { .id = 0x11060433, .name = "VT1716S",
  5011. .patch = patch_vt1716S},
  5012. { .id = 0x1106a721, .name = "VT1716S",
  5013. .patch = patch_vt1716S},
  5014. { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
  5015. { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
  5016. {} /* terminator */
  5017. };
  5018. MODULE_ALIAS("snd-hda-codec-id:1106*");
  5019. static struct hda_codec_preset_list via_list = {
  5020. .preset = snd_hda_preset_via,
  5021. .owner = THIS_MODULE,
  5022. };
  5023. MODULE_LICENSE("GPL");
  5024. MODULE_DESCRIPTION("VIA HD-audio codec");
  5025. static int __init patch_via_init(void)
  5026. {
  5027. return snd_hda_add_codec_preset(&via_list);
  5028. }
  5029. static void __exit patch_via_exit(void)
  5030. {
  5031. snd_hda_delete_codec_preset(&via_list);
  5032. }
  5033. module_init(patch_via_init)
  5034. module_exit(patch_via_exit)