patch_via.c 174 KB

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