patch_via.c 166 KB

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