patch_via.c 166 KB

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