patch_via.c 169 KB

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