patch_via.c 170 KB

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