patch_via.c 138 KB

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