patch_via.c 166 KB

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