patch_via.c 169 KB

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