patch_via.c 166 KB

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