patch_via.c 169 KB

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