patch_via.c 175 KB

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