patch_via.c 167 KB

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