patch_via.c 166 KB

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