patch_via.c 109 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
  5. *
  6. * (C) 2006-2009 VIA Technology, Inc.
  7. * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
  8. *
  9. * This driver is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This driver is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
  24. /* */
  25. /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
  26. /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
  27. /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
  28. /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
  29. /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
  30. /* 2007-09-17 Lydia Wang Add VT1708B codec support */
  31. /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
  32. /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
  33. /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
  34. /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
  35. /* 2008-04-09 Lydia Wang Add Independent HP feature */
  36. /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
  37. /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
  38. /* 2009-02-16 Logan Li Add support for VT1718S */
  39. /* 2009-03-13 Logan Li Add support for VT1716S */
  40. /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
  41. /* 2009-07-08 Lydia Wang Add support for VT2002P */
  42. /* 2009-07-21 Lydia Wang Add support for VT1812 */
  43. /* 2009-09-19 Lydia Wang Add support for VT1818S */
  44. /* */
  45. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  46. #include <linux/init.h>
  47. #include <linux/delay.h>
  48. #include <linux/slab.h>
  49. #include <linux/module.h>
  50. #include <sound/core.h>
  51. #include <sound/asoundef.h>
  52. #include "hda_codec.h"
  53. #include "hda_local.h"
  54. #include "hda_auto_parser.h"
  55. #include "hda_jack.h"
  56. /* Pin Widget NID */
  57. #define VT1708_HP_PIN_NID 0x20
  58. #define VT1708_CD_PIN_NID 0x24
  59. enum VIA_HDA_CODEC {
  60. UNKNOWN = -1,
  61. VT1708,
  62. VT1709_10CH,
  63. VT1709_6CH,
  64. VT1708B_8CH,
  65. VT1708B_4CH,
  66. VT1708S,
  67. VT1708BCE,
  68. VT1702,
  69. VT1718S,
  70. VT1716S,
  71. VT2002P,
  72. VT1812,
  73. VT1802,
  74. VT1705CF,
  75. VT1808,
  76. CODEC_TYPES,
  77. };
  78. #define VT2002P_COMPATIBLE(spec) \
  79. ((spec)->codec_type == VT2002P ||\
  80. (spec)->codec_type == VT1812 ||\
  81. (spec)->codec_type == VT1802)
  82. #define MAX_NID_PATH_DEPTH 5
  83. /* output-path: DAC -> ... -> pin
  84. * idx[] contains the source index number of the next widget;
  85. * e.g. idx[0] is the index of the DAC selected by path[1] widget
  86. * multi[] indicates whether it's a selector widget with multi-connectors
  87. * (i.e. the connection selection is mandatory)
  88. * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
  89. */
  90. struct nid_path {
  91. int depth;
  92. hda_nid_t path[MAX_NID_PATH_DEPTH];
  93. unsigned char idx[MAX_NID_PATH_DEPTH];
  94. unsigned char multi[MAX_NID_PATH_DEPTH];
  95. unsigned int vol_ctl;
  96. unsigned int mute_ctl;
  97. };
  98. /* input-path */
  99. struct via_input {
  100. hda_nid_t pin; /* input-pin or aa-mix */
  101. int adc_idx; /* ADC index to be used */
  102. int mux_idx; /* MUX index (if any) */
  103. const char *label; /* input-source label */
  104. };
  105. #define VIA_MAX_ADCS 3
  106. enum {
  107. STREAM_MULTI_OUT = (1 << 0),
  108. STREAM_INDEP_HP = (1 << 1),
  109. };
  110. struct via_spec {
  111. /* codec parameterization */
  112. const struct snd_kcontrol_new *mixers[6];
  113. unsigned int num_mixers;
  114. const struct hda_verb *init_verbs[5];
  115. unsigned int num_iverbs;
  116. char stream_name_analog[32];
  117. char stream_name_hp[32];
  118. const struct hda_pcm_stream *stream_analog_playback;
  119. const struct hda_pcm_stream *stream_analog_capture;
  120. char stream_name_digital[32];
  121. const struct hda_pcm_stream *stream_digital_playback;
  122. const struct hda_pcm_stream *stream_digital_capture;
  123. /* playback */
  124. struct hda_multi_out multiout;
  125. hda_nid_t slave_dig_outs[2];
  126. hda_nid_t hp_dac_nid;
  127. hda_nid_t speaker_dac_nid;
  128. int hp_indep_shared; /* indep HP-DAC is shared with side ch */
  129. int opened_streams; /* STREAM_* bits */
  130. int active_streams; /* STREAM_* bits */
  131. int aamix_mode; /* loopback is enabled for output-path? */
  132. /* Output-paths:
  133. * There are different output-paths depending on the setup.
  134. * out_path, hp_path and speaker_path are primary paths. If both
  135. * direct DAC and aa-loopback routes are available, these contain
  136. * the former paths. Meanwhile *_mix_path contain the paths with
  137. * loopback mixer. (Since the loopback is only for front channel,
  138. * no out_mix_path for surround channels.)
  139. * The HP output has another path, hp_indep_path, which is used in
  140. * the independent-HP mode.
  141. */
  142. struct nid_path out_path[HDA_SIDE + 1];
  143. struct nid_path out_mix_path;
  144. struct nid_path hp_path;
  145. struct nid_path hp_mix_path;
  146. struct nid_path hp_indep_path;
  147. struct nid_path speaker_path;
  148. struct nid_path speaker_mix_path;
  149. /* capture */
  150. unsigned int num_adc_nids;
  151. hda_nid_t adc_nids[VIA_MAX_ADCS];
  152. hda_nid_t mux_nids[VIA_MAX_ADCS];
  153. hda_nid_t aa_mix_nid;
  154. hda_nid_t dig_in_nid;
  155. /* capture source */
  156. bool dyn_adc_switch;
  157. int num_inputs;
  158. struct via_input inputs[AUTO_CFG_MAX_INS + 1];
  159. unsigned int cur_mux[VIA_MAX_ADCS];
  160. /* dynamic DAC switching */
  161. unsigned int cur_dac_stream_tag;
  162. unsigned int cur_dac_format;
  163. unsigned int cur_hp_stream_tag;
  164. unsigned int cur_hp_format;
  165. /* dynamic ADC switching */
  166. hda_nid_t cur_adc;
  167. unsigned int cur_adc_stream_tag;
  168. unsigned int cur_adc_format;
  169. /* PCM information */
  170. struct hda_pcm pcm_rec[3];
  171. /* dynamic controls, init_verbs and input_mux */
  172. struct auto_pin_cfg autocfg;
  173. struct snd_array kctls;
  174. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  175. /* HP mode source */
  176. unsigned int hp_independent_mode;
  177. unsigned int dmic_enabled;
  178. unsigned int no_pin_power_ctl;
  179. enum VIA_HDA_CODEC codec_type;
  180. /* analog low-power control */
  181. bool alc_mode;
  182. /* smart51 setup */
  183. unsigned int smart51_nums;
  184. hda_nid_t smart51_pins[2];
  185. int smart51_idxs[2];
  186. const char *smart51_labels[2];
  187. unsigned int smart51_enabled;
  188. /* work to check hp jack state */
  189. struct hda_codec *codec;
  190. struct delayed_work vt1708_hp_work;
  191. int hp_work_active;
  192. int vt1708_jack_detect;
  193. int vt1708_hp_present;
  194. void (*set_widgets_power_state)(struct hda_codec *codec);
  195. unsigned int dac_stream_tag[4];
  196. struct hda_loopback_check loopback;
  197. int num_loopbacks;
  198. struct hda_amp_list loopback_list[8];
  199. /* bind capture-volume */
  200. struct hda_bind_ctls *bind_cap_vol;
  201. struct hda_bind_ctls *bind_cap_sw;
  202. struct mutex config_mutex;
  203. };
  204. static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
  205. static struct via_spec * via_new_spec(struct hda_codec *codec)
  206. {
  207. struct via_spec *spec;
  208. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  209. if (spec == NULL)
  210. return NULL;
  211. snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
  212. mutex_init(&spec->config_mutex);
  213. codec->spec = spec;
  214. spec->codec = codec;
  215. spec->codec_type = get_codec_type(codec);
  216. /* VT1708BCE & VT1708S are almost same */
  217. if (spec->codec_type == VT1708BCE)
  218. spec->codec_type = VT1708S;
  219. return spec;
  220. }
  221. static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
  222. {
  223. u32 vendor_id = codec->vendor_id;
  224. u16 ven_id = vendor_id >> 16;
  225. u16 dev_id = vendor_id & 0xffff;
  226. enum VIA_HDA_CODEC codec_type;
  227. /* get codec type */
  228. if (ven_id != 0x1106)
  229. codec_type = UNKNOWN;
  230. else if (dev_id >= 0x1708 && dev_id <= 0x170b)
  231. codec_type = VT1708;
  232. else if (dev_id >= 0xe710 && dev_id <= 0xe713)
  233. codec_type = VT1709_10CH;
  234. else if (dev_id >= 0xe714 && dev_id <= 0xe717)
  235. codec_type = VT1709_6CH;
  236. else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
  237. codec_type = VT1708B_8CH;
  238. if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
  239. codec_type = VT1708BCE;
  240. } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
  241. codec_type = VT1708B_4CH;
  242. else if ((dev_id & 0xfff) == 0x397
  243. && (dev_id >> 12) < 8)
  244. codec_type = VT1708S;
  245. else if ((dev_id & 0xfff) == 0x398
  246. && (dev_id >> 12) < 8)
  247. codec_type = VT1702;
  248. else if ((dev_id & 0xfff) == 0x428
  249. && (dev_id >> 12) < 8)
  250. codec_type = VT1718S;
  251. else if (dev_id == 0x0433 || dev_id == 0xa721)
  252. codec_type = VT1716S;
  253. else if (dev_id == 0x0441 || dev_id == 0x4441)
  254. codec_type = VT1718S;
  255. else if (dev_id == 0x0438 || dev_id == 0x4438)
  256. codec_type = VT2002P;
  257. else if (dev_id == 0x0448)
  258. codec_type = VT1812;
  259. else if (dev_id == 0x0440)
  260. codec_type = VT1708S;
  261. else if ((dev_id & 0xfff) == 0x446)
  262. codec_type = VT1802;
  263. else if (dev_id == 0x4760)
  264. codec_type = VT1705CF;
  265. else if (dev_id == 0x4761 || dev_id == 0x4762)
  266. codec_type = VT1808;
  267. else
  268. codec_type = UNKNOWN;
  269. return codec_type;
  270. };
  271. #define VIA_JACK_EVENT 0x20
  272. #define VIA_HP_EVENT 0x01
  273. #define VIA_LINE_EVENT 0x03
  274. enum {
  275. VIA_CTL_WIDGET_VOL,
  276. VIA_CTL_WIDGET_MUTE,
  277. VIA_CTL_WIDGET_ANALOG_MUTE,
  278. };
  279. static void analog_low_current_mode(struct hda_codec *codec);
  280. static bool is_aa_path_mute(struct hda_codec *codec);
  281. #define hp_detect_with_aa(codec) \
  282. (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
  283. !is_aa_path_mute(codec))
  284. static void vt1708_stop_hp_work(struct via_spec *spec)
  285. {
  286. if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
  287. return;
  288. if (spec->hp_work_active) {
  289. snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 1);
  290. cancel_delayed_work_sync(&spec->vt1708_hp_work);
  291. spec->hp_work_active = 0;
  292. }
  293. }
  294. static void vt1708_update_hp_work(struct via_spec *spec)
  295. {
  296. if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
  297. return;
  298. if (spec->vt1708_jack_detect &&
  299. (spec->active_streams || hp_detect_with_aa(spec->codec))) {
  300. if (!spec->hp_work_active) {
  301. snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 0);
  302. schedule_delayed_work(&spec->vt1708_hp_work,
  303. msecs_to_jiffies(100));
  304. spec->hp_work_active = 1;
  305. }
  306. } else if (!hp_detect_with_aa(spec->codec))
  307. vt1708_stop_hp_work(spec);
  308. }
  309. static void set_widgets_power_state(struct hda_codec *codec)
  310. {
  311. struct via_spec *spec = codec->spec;
  312. if (spec->set_widgets_power_state)
  313. spec->set_widgets_power_state(codec);
  314. }
  315. static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
  316. struct snd_ctl_elem_value *ucontrol)
  317. {
  318. int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
  319. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  320. set_widgets_power_state(codec);
  321. analog_low_current_mode(snd_kcontrol_chip(kcontrol));
  322. vt1708_update_hp_work(codec->spec);
  323. return change;
  324. }
  325. /* modify .put = snd_hda_mixer_amp_switch_put */
  326. #define ANALOG_INPUT_MUTE \
  327. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  328. .name = NULL, \
  329. .index = 0, \
  330. .info = snd_hda_mixer_amp_switch_info, \
  331. .get = snd_hda_mixer_amp_switch_get, \
  332. .put = analog_input_switch_put, \
  333. .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
  334. static const struct snd_kcontrol_new via_control_templates[] = {
  335. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  336. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  337. ANALOG_INPUT_MUTE,
  338. };
  339. /* add dynamic controls */
  340. static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
  341. const struct snd_kcontrol_new *tmpl,
  342. const char *name)
  343. {
  344. struct snd_kcontrol_new *knew;
  345. knew = snd_array_new(&spec->kctls);
  346. if (!knew)
  347. return NULL;
  348. *knew = *tmpl;
  349. if (!name)
  350. name = tmpl->name;
  351. if (name) {
  352. knew->name = kstrdup(name, GFP_KERNEL);
  353. if (!knew->name)
  354. return NULL;
  355. }
  356. return knew;
  357. }
  358. static int __via_add_control(struct via_spec *spec, int type, const char *name,
  359. int idx, unsigned long val)
  360. {
  361. struct snd_kcontrol_new *knew;
  362. knew = __via_clone_ctl(spec, &via_control_templates[type], name);
  363. if (!knew)
  364. return -ENOMEM;
  365. knew->index = idx;
  366. if (get_amp_nid_(val))
  367. knew->subdevice = HDA_SUBDEV_AMP_FLAG;
  368. knew->private_value = val;
  369. return 0;
  370. }
  371. #define via_add_control(spec, type, name, val) \
  372. __via_add_control(spec, type, name, 0, val)
  373. #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
  374. static void via_free_kctls(struct hda_codec *codec)
  375. {
  376. struct via_spec *spec = codec->spec;
  377. if (spec->kctls.list) {
  378. struct snd_kcontrol_new *kctl = spec->kctls.list;
  379. int i;
  380. for (i = 0; i < spec->kctls.used; i++)
  381. kfree(kctl[i].name);
  382. }
  383. snd_array_free(&spec->kctls);
  384. }
  385. /* create input playback/capture controls for the given pin */
  386. static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
  387. int type_idx, int idx, int mix_nid)
  388. {
  389. char name[32];
  390. int err;
  391. sprintf(name, "%s Playback Volume", ctlname);
  392. err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
  393. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  394. if (err < 0)
  395. return err;
  396. sprintf(name, "%s Playback Switch", ctlname);
  397. err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
  398. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  399. if (err < 0)
  400. return err;
  401. return 0;
  402. }
  403. #define get_connection_index(codec, mux, nid) \
  404. snd_hda_get_conn_index(codec, mux, nid, 0)
  405. static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
  406. unsigned int mask)
  407. {
  408. unsigned int caps;
  409. if (!nid)
  410. return false;
  411. caps = get_wcaps(codec, nid);
  412. if (dir == HDA_INPUT)
  413. caps &= AC_WCAP_IN_AMP;
  414. else
  415. caps &= AC_WCAP_OUT_AMP;
  416. if (!caps)
  417. return false;
  418. if (query_amp_caps(codec, nid, dir) & mask)
  419. return true;
  420. return false;
  421. }
  422. #define have_mute(codec, nid, dir) \
  423. check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
  424. /* enable/disable the output-route mixers */
  425. static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
  426. hda_nid_t mix_nid, int idx, bool enable)
  427. {
  428. int i, num, val;
  429. if (!path)
  430. return;
  431. num = snd_hda_get_num_conns(codec, mix_nid);
  432. for (i = 0; i < num; i++) {
  433. if (i == idx)
  434. val = AMP_IN_UNMUTE(i);
  435. else
  436. val = AMP_IN_MUTE(i);
  437. snd_hda_codec_write(codec, mix_nid, 0,
  438. AC_VERB_SET_AMP_GAIN_MUTE, val);
  439. }
  440. }
  441. /* enable/disable the output-route */
  442. static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
  443. bool enable, bool force)
  444. {
  445. struct via_spec *spec = codec->spec;
  446. int i;
  447. for (i = 0; i < path->depth; i++) {
  448. hda_nid_t src, dst;
  449. int idx = path->idx[i];
  450. src = path->path[i];
  451. if (i < path->depth - 1)
  452. dst = path->path[i + 1];
  453. else
  454. dst = 0;
  455. if (enable && path->multi[i])
  456. snd_hda_codec_write(codec, dst, 0,
  457. AC_VERB_SET_CONNECT_SEL, idx);
  458. if (!force && (dst == spec->aa_mix_nid))
  459. continue;
  460. if (have_mute(codec, dst, HDA_INPUT))
  461. activate_output_mix(codec, path, dst, idx, enable);
  462. if (!force && (src == path->vol_ctl || src == path->mute_ctl))
  463. continue;
  464. if (have_mute(codec, src, HDA_OUTPUT)) {
  465. int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
  466. snd_hda_codec_write(codec, src, 0,
  467. AC_VERB_SET_AMP_GAIN_MUTE, val);
  468. }
  469. }
  470. }
  471. /* set the given pin as output */
  472. static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
  473. int pin_type)
  474. {
  475. if (!pin)
  476. return;
  477. snd_hda_set_pin_ctl(codec, pin, pin_type);
  478. if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
  479. snd_hda_codec_write(codec, pin, 0,
  480. AC_VERB_SET_EAPD_BTLENABLE, 0x02);
  481. }
  482. static void via_auto_init_output(struct hda_codec *codec,
  483. struct nid_path *path, int pin_type)
  484. {
  485. unsigned int caps;
  486. hda_nid_t pin;
  487. if (!path->depth)
  488. return;
  489. pin = path->path[path->depth - 1];
  490. init_output_pin(codec, pin, pin_type);
  491. if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
  492. caps = query_amp_caps(codec, pin, HDA_OUTPUT);
  493. else
  494. caps = 0;
  495. if (caps & AC_AMPCAP_MUTE) {
  496. unsigned int val;
  497. val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
  498. snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  499. AMP_OUT_MUTE | val);
  500. }
  501. activate_output_path(codec, path, true, true); /* force on */
  502. }
  503. static void via_auto_init_multi_out(struct hda_codec *codec)
  504. {
  505. struct via_spec *spec = codec->spec;
  506. struct nid_path *path;
  507. int i;
  508. for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
  509. path = &spec->out_path[i];
  510. if (!i && spec->aamix_mode && spec->out_mix_path.depth)
  511. path = &spec->out_mix_path;
  512. via_auto_init_output(codec, path, PIN_OUT);
  513. }
  514. }
  515. /* deactivate the inactive headphone-paths */
  516. static void deactivate_hp_paths(struct hda_codec *codec)
  517. {
  518. struct via_spec *spec = codec->spec;
  519. int shared = spec->hp_indep_shared;
  520. if (spec->hp_independent_mode) {
  521. activate_output_path(codec, &spec->hp_path, false, false);
  522. activate_output_path(codec, &spec->hp_mix_path, false, false);
  523. if (shared)
  524. activate_output_path(codec, &spec->out_path[shared],
  525. false, false);
  526. } else if (spec->aamix_mode || !spec->hp_path.depth) {
  527. activate_output_path(codec, &spec->hp_indep_path, false, false);
  528. activate_output_path(codec, &spec->hp_path, false, false);
  529. } else {
  530. activate_output_path(codec, &spec->hp_indep_path, false, false);
  531. activate_output_path(codec, &spec->hp_mix_path, false, false);
  532. }
  533. }
  534. static void via_auto_init_hp_out(struct hda_codec *codec)
  535. {
  536. struct via_spec *spec = codec->spec;
  537. if (!spec->hp_path.depth) {
  538. via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
  539. return;
  540. }
  541. deactivate_hp_paths(codec);
  542. if (spec->hp_independent_mode)
  543. via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
  544. else if (spec->aamix_mode)
  545. via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
  546. else
  547. via_auto_init_output(codec, &spec->hp_path, PIN_HP);
  548. }
  549. static void via_auto_init_speaker_out(struct hda_codec *codec)
  550. {
  551. struct via_spec *spec = codec->spec;
  552. if (!spec->autocfg.speaker_outs)
  553. return;
  554. if (!spec->speaker_path.depth) {
  555. via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
  556. return;
  557. }
  558. if (!spec->aamix_mode) {
  559. activate_output_path(codec, &spec->speaker_mix_path,
  560. false, false);
  561. via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
  562. } else {
  563. activate_output_path(codec, &spec->speaker_path, false, false);
  564. via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
  565. }
  566. }
  567. static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
  568. static void via_hp_automute(struct hda_codec *codec);
  569. static void via_auto_init_analog_input(struct hda_codec *codec)
  570. {
  571. struct via_spec *spec = codec->spec;
  572. const struct auto_pin_cfg *cfg = &spec->autocfg;
  573. hda_nid_t conn[HDA_MAX_CONNECTIONS];
  574. unsigned int ctl;
  575. int i, num_conns;
  576. /* init ADCs */
  577. for (i = 0; i < spec->num_adc_nids; i++) {
  578. hda_nid_t nid = spec->adc_nids[i];
  579. if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP) ||
  580. !(query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE))
  581. continue;
  582. snd_hda_codec_write(codec, spec->adc_nids[i], 0,
  583. AC_VERB_SET_AMP_GAIN_MUTE,
  584. AMP_IN_UNMUTE(0));
  585. }
  586. /* init pins */
  587. for (i = 0; i < cfg->num_inputs; i++) {
  588. hda_nid_t nid = cfg->inputs[i].pin;
  589. if (spec->smart51_enabled && is_smart51_pins(codec, nid))
  590. ctl = PIN_OUT;
  591. else {
  592. ctl = PIN_IN;
  593. if (cfg->inputs[i].type == AUTO_PIN_MIC)
  594. ctl |= snd_hda_get_default_vref(codec, nid);
  595. }
  596. snd_hda_set_pin_ctl(codec, nid, ctl);
  597. }
  598. /* init input-src */
  599. for (i = 0; i < spec->num_adc_nids; i++) {
  600. int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
  601. /* secondary ADCs must have the unique MUX */
  602. if (i > 0 && !spec->mux_nids[i])
  603. break;
  604. if (spec->mux_nids[adc_idx]) {
  605. int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
  606. snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
  607. AC_VERB_SET_CONNECT_SEL,
  608. mux_idx);
  609. }
  610. if (spec->dyn_adc_switch)
  611. break; /* only one input-src */
  612. }
  613. /* init aa-mixer */
  614. if (!spec->aa_mix_nid)
  615. return;
  616. num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
  617. ARRAY_SIZE(conn));
  618. for (i = 0; i < num_conns; i++) {
  619. unsigned int caps = get_wcaps(codec, conn[i]);
  620. if (get_wcaps_type(caps) == AC_WID_PIN)
  621. snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
  622. AC_VERB_SET_AMP_GAIN_MUTE,
  623. AMP_IN_MUTE(i));
  624. }
  625. }
  626. static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
  627. unsigned int parm)
  628. {
  629. if (snd_hda_codec_read(codec, nid, 0,
  630. AC_VERB_GET_POWER_STATE, 0) == parm)
  631. return;
  632. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
  633. }
  634. static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
  635. unsigned int parm, unsigned int index)
  636. {
  637. struct via_spec *spec = codec->spec;
  638. unsigned int format;
  639. if (snd_hda_codec_read(codec, nid, 0,
  640. AC_VERB_GET_POWER_STATE, 0) == parm)
  641. return;
  642. format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
  643. if (format && (spec->dac_stream_tag[index] != format))
  644. spec->dac_stream_tag[index] = format;
  645. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
  646. if (parm == AC_PWRST_D0) {
  647. format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
  648. if (!format && (spec->dac_stream_tag[index] != format))
  649. snd_hda_codec_write(codec, nid, 0,
  650. AC_VERB_SET_CHANNEL_STREAMID,
  651. spec->dac_stream_tag[index]);
  652. }
  653. }
  654. static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
  655. unsigned int *affected_parm)
  656. {
  657. unsigned parm;
  658. unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
  659. unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
  660. >> AC_DEFCFG_MISC_SHIFT
  661. & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
  662. struct via_spec *spec = codec->spec;
  663. unsigned present = 0;
  664. no_presence |= spec->no_pin_power_ctl;
  665. if (!no_presence)
  666. present = snd_hda_jack_detect(codec, nid);
  667. if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
  668. || ((no_presence || present)
  669. && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
  670. *affected_parm = AC_PWRST_D0; /* if it's connected */
  671. parm = AC_PWRST_D0;
  672. } else
  673. parm = AC_PWRST_D3;
  674. update_power_state(codec, nid, parm);
  675. }
  676. static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
  677. struct snd_ctl_elem_info *uinfo)
  678. {
  679. return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
  680. }
  681. static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
  682. struct snd_ctl_elem_value *ucontrol)
  683. {
  684. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  685. struct via_spec *spec = codec->spec;
  686. ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
  687. return 0;
  688. }
  689. static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
  690. struct snd_ctl_elem_value *ucontrol)
  691. {
  692. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  693. struct via_spec *spec = codec->spec;
  694. unsigned int val = !ucontrol->value.enumerated.item[0];
  695. if (val == spec->no_pin_power_ctl)
  696. return 0;
  697. spec->no_pin_power_ctl = val;
  698. set_widgets_power_state(codec);
  699. analog_low_current_mode(codec);
  700. return 1;
  701. }
  702. static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
  703. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  704. .name = "Dynamic Power-Control",
  705. .info = via_pin_power_ctl_info,
  706. .get = via_pin_power_ctl_get,
  707. .put = via_pin_power_ctl_put,
  708. };
  709. static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
  710. struct snd_ctl_elem_info *uinfo)
  711. {
  712. static const char * const texts[] = { "OFF", "ON" };
  713. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  714. uinfo->count = 1;
  715. uinfo->value.enumerated.items = 2;
  716. if (uinfo->value.enumerated.item >= 2)
  717. uinfo->value.enumerated.item = 1;
  718. strcpy(uinfo->value.enumerated.name,
  719. texts[uinfo->value.enumerated.item]);
  720. return 0;
  721. }
  722. static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
  723. struct snd_ctl_elem_value *ucontrol)
  724. {
  725. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  726. struct via_spec *spec = codec->spec;
  727. ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
  728. return 0;
  729. }
  730. /* adjust spec->multiout setup according to the current flags */
  731. static void setup_playback_multi_pcm(struct via_spec *spec)
  732. {
  733. const struct auto_pin_cfg *cfg = &spec->autocfg;
  734. spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
  735. spec->multiout.hp_nid = 0;
  736. if (!spec->hp_independent_mode) {
  737. if (!spec->hp_indep_shared)
  738. spec->multiout.hp_nid = spec->hp_dac_nid;
  739. } else {
  740. if (spec->hp_indep_shared)
  741. spec->multiout.num_dacs = cfg->line_outs - 1;
  742. }
  743. }
  744. /* update DAC setups according to indep-HP switch;
  745. * this function is called only when indep-HP is modified
  746. */
  747. static void switch_indep_hp_dacs(struct hda_codec *codec)
  748. {
  749. struct via_spec *spec = codec->spec;
  750. int shared = spec->hp_indep_shared;
  751. hda_nid_t shared_dac, hp_dac;
  752. if (!spec->opened_streams)
  753. return;
  754. shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
  755. hp_dac = spec->hp_dac_nid;
  756. if (spec->hp_independent_mode) {
  757. /* switch to indep-HP mode */
  758. if (spec->active_streams & STREAM_MULTI_OUT) {
  759. __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
  760. __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
  761. }
  762. if (spec->active_streams & STREAM_INDEP_HP)
  763. snd_hda_codec_setup_stream(codec, hp_dac,
  764. spec->cur_hp_stream_tag, 0,
  765. spec->cur_hp_format);
  766. } else {
  767. /* back to HP or shared-DAC */
  768. if (spec->active_streams & STREAM_INDEP_HP)
  769. __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
  770. if (spec->active_streams & STREAM_MULTI_OUT) {
  771. hda_nid_t dac;
  772. int ch;
  773. if (shared_dac) { /* reset mutli-ch DAC */
  774. dac = shared_dac;
  775. ch = shared * 2;
  776. } else { /* reset HP DAC */
  777. dac = hp_dac;
  778. ch = 0;
  779. }
  780. snd_hda_codec_setup_stream(codec, dac,
  781. spec->cur_dac_stream_tag, ch,
  782. spec->cur_dac_format);
  783. }
  784. }
  785. setup_playback_multi_pcm(spec);
  786. }
  787. static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
  788. struct snd_ctl_elem_value *ucontrol)
  789. {
  790. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  791. struct via_spec *spec = codec->spec;
  792. int cur, shared;
  793. mutex_lock(&spec->config_mutex);
  794. cur = !!ucontrol->value.enumerated.item[0];
  795. if (spec->hp_independent_mode == cur) {
  796. mutex_unlock(&spec->config_mutex);
  797. return 0;
  798. }
  799. spec->hp_independent_mode = cur;
  800. shared = spec->hp_indep_shared;
  801. deactivate_hp_paths(codec);
  802. if (cur)
  803. activate_output_path(codec, &spec->hp_indep_path, true, false);
  804. else {
  805. if (shared)
  806. activate_output_path(codec, &spec->out_path[shared],
  807. true, false);
  808. if (spec->aamix_mode || !spec->hp_path.depth)
  809. activate_output_path(codec, &spec->hp_mix_path,
  810. true, false);
  811. else
  812. activate_output_path(codec, &spec->hp_path,
  813. true, false);
  814. }
  815. switch_indep_hp_dacs(codec);
  816. mutex_unlock(&spec->config_mutex);
  817. /* update jack power state */
  818. set_widgets_power_state(codec);
  819. via_hp_automute(codec);
  820. return 1;
  821. }
  822. static const struct snd_kcontrol_new via_hp_mixer = {
  823. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  824. .name = "Independent HP",
  825. .info = via_independent_hp_info,
  826. .get = via_independent_hp_get,
  827. .put = via_independent_hp_put,
  828. };
  829. static int via_hp_build(struct hda_codec *codec)
  830. {
  831. struct via_spec *spec = codec->spec;
  832. struct snd_kcontrol_new *knew;
  833. hda_nid_t nid;
  834. nid = spec->autocfg.hp_pins[0];
  835. knew = via_clone_control(spec, &via_hp_mixer);
  836. if (knew == NULL)
  837. return -ENOMEM;
  838. knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
  839. return 0;
  840. }
  841. static void notify_aa_path_ctls(struct hda_codec *codec)
  842. {
  843. struct via_spec *spec = codec->spec;
  844. int i;
  845. for (i = 0; i < spec->smart51_nums; i++) {
  846. struct snd_kcontrol *ctl;
  847. struct snd_ctl_elem_id id;
  848. memset(&id, 0, sizeof(id));
  849. id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  850. sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
  851. ctl = snd_hda_find_mixer_ctl(codec, id.name);
  852. if (ctl)
  853. snd_ctl_notify(codec->bus->card,
  854. SNDRV_CTL_EVENT_MASK_VALUE,
  855. &ctl->id);
  856. }
  857. }
  858. static void mute_aa_path(struct hda_codec *codec, int mute)
  859. {
  860. struct via_spec *spec = codec->spec;
  861. int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
  862. int i;
  863. /* check AA path's mute status */
  864. for (i = 0; i < spec->smart51_nums; i++) {
  865. if (spec->smart51_idxs[i] < 0)
  866. continue;
  867. snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
  868. HDA_INPUT, spec->smart51_idxs[i],
  869. HDA_AMP_MUTE, val);
  870. }
  871. }
  872. static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
  873. {
  874. struct via_spec *spec = codec->spec;
  875. int i;
  876. for (i = 0; i < spec->smart51_nums; i++)
  877. if (spec->smart51_pins[i] == pin)
  878. return true;
  879. return false;
  880. }
  881. static int via_smart51_get(struct snd_kcontrol *kcontrol,
  882. struct snd_ctl_elem_value *ucontrol)
  883. {
  884. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  885. struct via_spec *spec = codec->spec;
  886. *ucontrol->value.integer.value = spec->smart51_enabled;
  887. return 0;
  888. }
  889. static int via_smart51_put(struct snd_kcontrol *kcontrol,
  890. struct snd_ctl_elem_value *ucontrol)
  891. {
  892. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  893. struct via_spec *spec = codec->spec;
  894. int out_in = *ucontrol->value.integer.value
  895. ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
  896. int i;
  897. for (i = 0; i < spec->smart51_nums; i++) {
  898. hda_nid_t nid = spec->smart51_pins[i];
  899. unsigned int parm;
  900. parm = snd_hda_codec_read(codec, nid, 0,
  901. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  902. parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  903. parm |= out_in;
  904. snd_hda_set_pin_ctl(codec, nid, parm);
  905. if (out_in == AC_PINCTL_OUT_EN) {
  906. mute_aa_path(codec, 1);
  907. notify_aa_path_ctls(codec);
  908. }
  909. }
  910. spec->smart51_enabled = *ucontrol->value.integer.value;
  911. set_widgets_power_state(codec);
  912. return 1;
  913. }
  914. static const struct snd_kcontrol_new via_smart51_mixer = {
  915. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  916. .name = "Smart 5.1",
  917. .count = 1,
  918. .info = snd_ctl_boolean_mono_info,
  919. .get = via_smart51_get,
  920. .put = via_smart51_put,
  921. };
  922. static int via_smart51_build(struct hda_codec *codec)
  923. {
  924. struct via_spec *spec = codec->spec;
  925. if (!spec->smart51_nums)
  926. return 0;
  927. if (!via_clone_control(spec, &via_smart51_mixer))
  928. return -ENOMEM;
  929. return 0;
  930. }
  931. /* check AA path's mute status */
  932. static bool is_aa_path_mute(struct hda_codec *codec)
  933. {
  934. struct via_spec *spec = codec->spec;
  935. const struct hda_amp_list *p;
  936. int i, ch, v;
  937. for (i = 0; i < spec->num_loopbacks; i++) {
  938. p = &spec->loopback_list[i];
  939. for (ch = 0; ch < 2; ch++) {
  940. v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
  941. p->idx);
  942. if (!(v & HDA_AMP_MUTE) && v > 0)
  943. return false;
  944. }
  945. }
  946. return true;
  947. }
  948. /* enter/exit analog low-current mode */
  949. static void __analog_low_current_mode(struct hda_codec *codec, bool force)
  950. {
  951. struct via_spec *spec = codec->spec;
  952. bool enable;
  953. unsigned int verb, parm;
  954. if (spec->no_pin_power_ctl)
  955. enable = false;
  956. else
  957. enable = is_aa_path_mute(codec) && !spec->opened_streams;
  958. if (enable == spec->alc_mode && !force)
  959. return;
  960. spec->alc_mode = enable;
  961. /* decide low current mode's verb & parameter */
  962. switch (spec->codec_type) {
  963. case VT1708B_8CH:
  964. case VT1708B_4CH:
  965. verb = 0xf70;
  966. parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
  967. break;
  968. case VT1708S:
  969. case VT1718S:
  970. case VT1716S:
  971. verb = 0xf73;
  972. parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
  973. break;
  974. case VT1702:
  975. verb = 0xf73;
  976. parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
  977. break;
  978. case VT2002P:
  979. case VT1812:
  980. case VT1802:
  981. verb = 0xf93;
  982. parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
  983. break;
  984. case VT1705CF:
  985. case VT1808:
  986. verb = 0xf82;
  987. parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
  988. break;
  989. default:
  990. return; /* other codecs are not supported */
  991. }
  992. /* send verb */
  993. snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
  994. }
  995. static void analog_low_current_mode(struct hda_codec *codec)
  996. {
  997. return __analog_low_current_mode(codec, false);
  998. }
  999. /*
  1000. * generic initialization of ADC, input mixers and output mixers
  1001. */
  1002. static const struct hda_verb vt1708_init_verbs[] = {
  1003. /* power down jack detect function */
  1004. {0x1, 0xf81, 0x1},
  1005. { }
  1006. };
  1007. static void set_stream_open(struct hda_codec *codec, int bit, bool active)
  1008. {
  1009. struct via_spec *spec = codec->spec;
  1010. if (active)
  1011. spec->opened_streams |= bit;
  1012. else
  1013. spec->opened_streams &= ~bit;
  1014. analog_low_current_mode(codec);
  1015. }
  1016. static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
  1017. struct hda_codec *codec,
  1018. struct snd_pcm_substream *substream)
  1019. {
  1020. struct via_spec *spec = codec->spec;
  1021. const struct auto_pin_cfg *cfg = &spec->autocfg;
  1022. int err;
  1023. spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
  1024. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1025. set_stream_open(codec, STREAM_MULTI_OUT, true);
  1026. err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  1027. hinfo);
  1028. if (err < 0) {
  1029. set_stream_open(codec, STREAM_MULTI_OUT, false);
  1030. return err;
  1031. }
  1032. return 0;
  1033. }
  1034. static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
  1035. struct hda_codec *codec,
  1036. struct snd_pcm_substream *substream)
  1037. {
  1038. set_stream_open(codec, STREAM_MULTI_OUT, false);
  1039. return 0;
  1040. }
  1041. static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
  1042. struct hda_codec *codec,
  1043. struct snd_pcm_substream *substream)
  1044. {
  1045. struct via_spec *spec = codec->spec;
  1046. if (snd_BUG_ON(!spec->hp_dac_nid))
  1047. return -EINVAL;
  1048. set_stream_open(codec, STREAM_INDEP_HP, true);
  1049. return 0;
  1050. }
  1051. static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
  1052. struct hda_codec *codec,
  1053. struct snd_pcm_substream *substream)
  1054. {
  1055. set_stream_open(codec, STREAM_INDEP_HP, false);
  1056. return 0;
  1057. }
  1058. static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
  1059. struct hda_codec *codec,
  1060. unsigned int stream_tag,
  1061. unsigned int format,
  1062. struct snd_pcm_substream *substream)
  1063. {
  1064. struct via_spec *spec = codec->spec;
  1065. mutex_lock(&spec->config_mutex);
  1066. setup_playback_multi_pcm(spec);
  1067. snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
  1068. format, substream);
  1069. /* remember for dynamic DAC switch with indep-HP */
  1070. spec->active_streams |= STREAM_MULTI_OUT;
  1071. spec->cur_dac_stream_tag = stream_tag;
  1072. spec->cur_dac_format = format;
  1073. mutex_unlock(&spec->config_mutex);
  1074. vt1708_update_hp_work(spec);
  1075. return 0;
  1076. }
  1077. static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
  1078. struct hda_codec *codec,
  1079. unsigned int stream_tag,
  1080. unsigned int format,
  1081. struct snd_pcm_substream *substream)
  1082. {
  1083. struct via_spec *spec = codec->spec;
  1084. mutex_lock(&spec->config_mutex);
  1085. if (spec->hp_independent_mode)
  1086. snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
  1087. stream_tag, 0, format);
  1088. spec->active_streams |= STREAM_INDEP_HP;
  1089. spec->cur_hp_stream_tag = stream_tag;
  1090. spec->cur_hp_format = format;
  1091. mutex_unlock(&spec->config_mutex);
  1092. vt1708_update_hp_work(spec);
  1093. return 0;
  1094. }
  1095. static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1096. struct hda_codec *codec,
  1097. struct snd_pcm_substream *substream)
  1098. {
  1099. struct via_spec *spec = codec->spec;
  1100. mutex_lock(&spec->config_mutex);
  1101. snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  1102. spec->active_streams &= ~STREAM_MULTI_OUT;
  1103. mutex_unlock(&spec->config_mutex);
  1104. vt1708_update_hp_work(spec);
  1105. return 0;
  1106. }
  1107. static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1108. struct hda_codec *codec,
  1109. struct snd_pcm_substream *substream)
  1110. {
  1111. struct via_spec *spec = codec->spec;
  1112. mutex_lock(&spec->config_mutex);
  1113. if (spec->hp_independent_mode)
  1114. snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
  1115. spec->active_streams &= ~STREAM_INDEP_HP;
  1116. mutex_unlock(&spec->config_mutex);
  1117. vt1708_update_hp_work(spec);
  1118. return 0;
  1119. }
  1120. /*
  1121. * Digital out
  1122. */
  1123. static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1124. struct hda_codec *codec,
  1125. struct snd_pcm_substream *substream)
  1126. {
  1127. struct via_spec *spec = codec->spec;
  1128. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1129. }
  1130. static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1131. struct hda_codec *codec,
  1132. struct snd_pcm_substream *substream)
  1133. {
  1134. struct via_spec *spec = codec->spec;
  1135. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1136. }
  1137. static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1138. struct hda_codec *codec,
  1139. unsigned int stream_tag,
  1140. unsigned int format,
  1141. struct snd_pcm_substream *substream)
  1142. {
  1143. struct via_spec *spec = codec->spec;
  1144. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1145. stream_tag, format, substream);
  1146. }
  1147. static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1148. struct hda_codec *codec,
  1149. struct snd_pcm_substream *substream)
  1150. {
  1151. struct via_spec *spec = codec->spec;
  1152. snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  1153. return 0;
  1154. }
  1155. /*
  1156. * Analog capture
  1157. */
  1158. static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1159. struct hda_codec *codec,
  1160. unsigned int stream_tag,
  1161. unsigned int format,
  1162. struct snd_pcm_substream *substream)
  1163. {
  1164. struct via_spec *spec = codec->spec;
  1165. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  1166. stream_tag, 0, format);
  1167. return 0;
  1168. }
  1169. static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1170. struct hda_codec *codec,
  1171. struct snd_pcm_substream *substream)
  1172. {
  1173. struct via_spec *spec = codec->spec;
  1174. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  1175. return 0;
  1176. }
  1177. /* analog capture with dynamic ADC switching */
  1178. static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1179. struct hda_codec *codec,
  1180. unsigned int stream_tag,
  1181. unsigned int format,
  1182. struct snd_pcm_substream *substream)
  1183. {
  1184. struct via_spec *spec = codec->spec;
  1185. int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
  1186. mutex_lock(&spec->config_mutex);
  1187. spec->cur_adc = spec->adc_nids[adc_idx];
  1188. spec->cur_adc_stream_tag = stream_tag;
  1189. spec->cur_adc_format = format;
  1190. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  1191. mutex_unlock(&spec->config_mutex);
  1192. return 0;
  1193. }
  1194. static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1195. struct hda_codec *codec,
  1196. struct snd_pcm_substream *substream)
  1197. {
  1198. struct via_spec *spec = codec->spec;
  1199. mutex_lock(&spec->config_mutex);
  1200. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1201. spec->cur_adc = 0;
  1202. mutex_unlock(&spec->config_mutex);
  1203. return 0;
  1204. }
  1205. /* re-setup the stream if running; called from input-src put */
  1206. static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
  1207. {
  1208. struct via_spec *spec = codec->spec;
  1209. int adc_idx = spec->inputs[cur].adc_idx;
  1210. hda_nid_t adc = spec->adc_nids[adc_idx];
  1211. bool ret = false;
  1212. mutex_lock(&spec->config_mutex);
  1213. if (spec->cur_adc && spec->cur_adc != adc) {
  1214. /* stream is running, let's swap the current ADC */
  1215. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  1216. spec->cur_adc = adc;
  1217. snd_hda_codec_setup_stream(codec, adc,
  1218. spec->cur_adc_stream_tag, 0,
  1219. spec->cur_adc_format);
  1220. ret = true;
  1221. }
  1222. mutex_unlock(&spec->config_mutex);
  1223. return ret;
  1224. }
  1225. static const struct hda_pcm_stream via_pcm_analog_playback = {
  1226. .substreams = 1,
  1227. .channels_min = 2,
  1228. .channels_max = 8,
  1229. /* NID is set in via_build_pcms */
  1230. .ops = {
  1231. .open = via_playback_multi_pcm_open,
  1232. .close = via_playback_multi_pcm_close,
  1233. .prepare = via_playback_multi_pcm_prepare,
  1234. .cleanup = via_playback_multi_pcm_cleanup
  1235. },
  1236. };
  1237. static const struct hda_pcm_stream via_pcm_hp_playback = {
  1238. .substreams = 1,
  1239. .channels_min = 2,
  1240. .channels_max = 2,
  1241. /* NID is set in via_build_pcms */
  1242. .ops = {
  1243. .open = via_playback_hp_pcm_open,
  1244. .close = via_playback_hp_pcm_close,
  1245. .prepare = via_playback_hp_pcm_prepare,
  1246. .cleanup = via_playback_hp_pcm_cleanup
  1247. },
  1248. };
  1249. static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
  1250. .substreams = 1,
  1251. .channels_min = 2,
  1252. .channels_max = 8,
  1253. /* NID is set in via_build_pcms */
  1254. /* We got noisy outputs on the right channel on VT1708 when
  1255. * 24bit samples are used. Until any workaround is found,
  1256. * disable the 24bit format, so far.
  1257. */
  1258. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1259. .ops = {
  1260. .open = via_playback_multi_pcm_open,
  1261. .close = via_playback_multi_pcm_close,
  1262. .prepare = via_playback_multi_pcm_prepare,
  1263. .cleanup = via_playback_multi_pcm_cleanup
  1264. },
  1265. };
  1266. static const struct hda_pcm_stream via_pcm_analog_capture = {
  1267. .substreams = 1, /* will be changed in via_build_pcms() */
  1268. .channels_min = 2,
  1269. .channels_max = 2,
  1270. /* NID is set in via_build_pcms */
  1271. .ops = {
  1272. .prepare = via_capture_pcm_prepare,
  1273. .cleanup = via_capture_pcm_cleanup
  1274. },
  1275. };
  1276. static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
  1277. .substreams = 1,
  1278. .channels_min = 2,
  1279. .channels_max = 2,
  1280. /* NID is set in via_build_pcms */
  1281. .ops = {
  1282. .prepare = via_dyn_adc_capture_pcm_prepare,
  1283. .cleanup = via_dyn_adc_capture_pcm_cleanup,
  1284. },
  1285. };
  1286. static const struct hda_pcm_stream via_pcm_digital_playback = {
  1287. .substreams = 1,
  1288. .channels_min = 2,
  1289. .channels_max = 2,
  1290. /* NID is set in via_build_pcms */
  1291. .ops = {
  1292. .open = via_dig_playback_pcm_open,
  1293. .close = via_dig_playback_pcm_close,
  1294. .prepare = via_dig_playback_pcm_prepare,
  1295. .cleanup = via_dig_playback_pcm_cleanup
  1296. },
  1297. };
  1298. static const struct hda_pcm_stream via_pcm_digital_capture = {
  1299. .substreams = 1,
  1300. .channels_min = 2,
  1301. .channels_max = 2,
  1302. };
  1303. /*
  1304. * slave controls for virtual master
  1305. */
  1306. static const char * const via_slave_pfxs[] = {
  1307. "Front", "Surround", "Center", "LFE", "Side",
  1308. "Headphone", "Speaker", "Bass Speaker",
  1309. NULL,
  1310. };
  1311. static int via_build_controls(struct hda_codec *codec)
  1312. {
  1313. struct via_spec *spec = codec->spec;
  1314. struct snd_kcontrol *kctl;
  1315. int err, i;
  1316. spec->no_pin_power_ctl = 1;
  1317. if (spec->set_widgets_power_state)
  1318. if (!via_clone_control(spec, &via_pin_power_ctl_enum))
  1319. return -ENOMEM;
  1320. for (i = 0; i < spec->num_mixers; i++) {
  1321. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  1322. if (err < 0)
  1323. return err;
  1324. }
  1325. if (spec->multiout.dig_out_nid) {
  1326. err = snd_hda_create_spdif_out_ctls(codec,
  1327. spec->multiout.dig_out_nid,
  1328. spec->multiout.dig_out_nid);
  1329. if (err < 0)
  1330. return err;
  1331. err = snd_hda_create_spdif_share_sw(codec,
  1332. &spec->multiout);
  1333. if (err < 0)
  1334. return err;
  1335. spec->multiout.share_spdif = 1;
  1336. }
  1337. if (spec->dig_in_nid) {
  1338. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  1339. if (err < 0)
  1340. return err;
  1341. }
  1342. /* if we have no master control, let's create it */
  1343. if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  1344. unsigned int vmaster_tlv[4];
  1345. snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
  1346. HDA_OUTPUT, vmaster_tlv);
  1347. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  1348. vmaster_tlv, via_slave_pfxs,
  1349. "Playback Volume");
  1350. if (err < 0)
  1351. return err;
  1352. }
  1353. if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  1354. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  1355. NULL, via_slave_pfxs,
  1356. "Playback Switch");
  1357. if (err < 0)
  1358. return err;
  1359. }
  1360. /* assign Capture Source enums to NID */
  1361. kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
  1362. for (i = 0; kctl && i < kctl->count; i++) {
  1363. if (!spec->mux_nids[i])
  1364. continue;
  1365. err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
  1366. if (err < 0)
  1367. return err;
  1368. }
  1369. via_free_kctls(codec); /* no longer needed */
  1370. err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
  1371. if (err < 0)
  1372. return err;
  1373. return 0;
  1374. }
  1375. static int via_build_pcms(struct hda_codec *codec)
  1376. {
  1377. struct via_spec *spec = codec->spec;
  1378. struct hda_pcm *info = spec->pcm_rec;
  1379. codec->num_pcms = 0;
  1380. codec->pcm_info = info;
  1381. if (spec->multiout.num_dacs || spec->num_adc_nids) {
  1382. snprintf(spec->stream_name_analog,
  1383. sizeof(spec->stream_name_analog),
  1384. "%s Analog", codec->chip_name);
  1385. info->name = spec->stream_name_analog;
  1386. if (spec->multiout.num_dacs) {
  1387. if (!spec->stream_analog_playback)
  1388. spec->stream_analog_playback =
  1389. &via_pcm_analog_playback;
  1390. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  1391. *spec->stream_analog_playback;
  1392. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  1393. spec->multiout.dac_nids[0];
  1394. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  1395. spec->multiout.max_channels;
  1396. if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT
  1397. && spec->autocfg.line_outs == 2)
  1398. info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
  1399. snd_pcm_2_1_chmaps;
  1400. }
  1401. if (!spec->stream_analog_capture) {
  1402. if (spec->dyn_adc_switch)
  1403. spec->stream_analog_capture =
  1404. &via_pcm_dyn_adc_analog_capture;
  1405. else
  1406. spec->stream_analog_capture =
  1407. &via_pcm_analog_capture;
  1408. }
  1409. if (spec->num_adc_nids) {
  1410. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  1411. *spec->stream_analog_capture;
  1412. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  1413. spec->adc_nids[0];
  1414. if (!spec->dyn_adc_switch)
  1415. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  1416. spec->num_adc_nids;
  1417. }
  1418. codec->num_pcms++;
  1419. info++;
  1420. }
  1421. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  1422. snprintf(spec->stream_name_digital,
  1423. sizeof(spec->stream_name_digital),
  1424. "%s Digital", codec->chip_name);
  1425. info->name = spec->stream_name_digital;
  1426. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  1427. if (spec->multiout.dig_out_nid) {
  1428. if (!spec->stream_digital_playback)
  1429. spec->stream_digital_playback =
  1430. &via_pcm_digital_playback;
  1431. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  1432. *spec->stream_digital_playback;
  1433. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  1434. spec->multiout.dig_out_nid;
  1435. }
  1436. if (spec->dig_in_nid) {
  1437. if (!spec->stream_digital_capture)
  1438. spec->stream_digital_capture =
  1439. &via_pcm_digital_capture;
  1440. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  1441. *spec->stream_digital_capture;
  1442. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  1443. spec->dig_in_nid;
  1444. }
  1445. codec->num_pcms++;
  1446. info++;
  1447. }
  1448. if (spec->hp_dac_nid) {
  1449. snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
  1450. "%s HP", codec->chip_name);
  1451. info->name = spec->stream_name_hp;
  1452. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
  1453. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  1454. spec->hp_dac_nid;
  1455. codec->num_pcms++;
  1456. info++;
  1457. }
  1458. return 0;
  1459. }
  1460. static void via_free(struct hda_codec *codec)
  1461. {
  1462. struct via_spec *spec = codec->spec;
  1463. if (!spec)
  1464. return;
  1465. via_free_kctls(codec);
  1466. vt1708_stop_hp_work(spec);
  1467. kfree(spec->bind_cap_vol);
  1468. kfree(spec->bind_cap_sw);
  1469. kfree(spec);
  1470. }
  1471. /* mute/unmute outputs */
  1472. static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
  1473. hda_nid_t *pins, bool mute)
  1474. {
  1475. int i;
  1476. for (i = 0; i < num_pins; i++) {
  1477. unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
  1478. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  1479. if (parm & AC_PINCTL_IN_EN)
  1480. continue;
  1481. if (mute)
  1482. parm &= ~AC_PINCTL_OUT_EN;
  1483. else
  1484. parm |= AC_PINCTL_OUT_EN;
  1485. snd_hda_set_pin_ctl(codec, pins[i], parm);
  1486. }
  1487. }
  1488. /* mute internal speaker if line-out is plugged */
  1489. static void via_line_automute(struct hda_codec *codec, int present)
  1490. {
  1491. struct via_spec *spec = codec->spec;
  1492. if (!spec->autocfg.speaker_outs)
  1493. return;
  1494. if (!present)
  1495. present = snd_hda_jack_detect(codec,
  1496. spec->autocfg.line_out_pins[0]);
  1497. toggle_output_mutes(codec, spec->autocfg.speaker_outs,
  1498. spec->autocfg.speaker_pins,
  1499. present);
  1500. }
  1501. /* mute internal speaker if HP is plugged */
  1502. static void via_hp_automute(struct hda_codec *codec)
  1503. {
  1504. int present = 0;
  1505. int nums;
  1506. struct via_spec *spec = codec->spec;
  1507. if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0] &&
  1508. (spec->codec_type != VT1708 || spec->vt1708_jack_detect) &&
  1509. is_jack_detectable(codec, spec->autocfg.hp_pins[0]))
  1510. present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
  1511. if (spec->smart51_enabled)
  1512. nums = spec->autocfg.line_outs + spec->smart51_nums;
  1513. else
  1514. nums = spec->autocfg.line_outs;
  1515. toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
  1516. via_line_automute(codec, present);
  1517. }
  1518. #ifdef CONFIG_PM
  1519. static int via_suspend(struct hda_codec *codec)
  1520. {
  1521. struct via_spec *spec = codec->spec;
  1522. vt1708_stop_hp_work(spec);
  1523. if (spec->codec_type == VT1802) {
  1524. /* Fix pop noise on headphones */
  1525. int i;
  1526. for (i = 0; i < spec->autocfg.hp_outs; i++)
  1527. snd_hda_set_pin_ctl(codec, spec->autocfg.hp_pins[i], 0);
  1528. }
  1529. return 0;
  1530. }
  1531. #endif
  1532. #ifdef CONFIG_PM
  1533. static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  1534. {
  1535. struct via_spec *spec = codec->spec;
  1536. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  1537. }
  1538. #endif
  1539. /*
  1540. */
  1541. static int via_init(struct hda_codec *codec);
  1542. static const struct hda_codec_ops via_patch_ops = {
  1543. .build_controls = via_build_controls,
  1544. .build_pcms = via_build_pcms,
  1545. .init = via_init,
  1546. .free = via_free,
  1547. .unsol_event = snd_hda_jack_unsol_event,
  1548. #ifdef CONFIG_PM
  1549. .suspend = via_suspend,
  1550. .check_power_status = via_check_power_status,
  1551. #endif
  1552. };
  1553. static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
  1554. {
  1555. struct via_spec *spec = codec->spec;
  1556. int i;
  1557. for (i = 0; i < spec->multiout.num_dacs; i++) {
  1558. if (spec->multiout.dac_nids[i] == dac)
  1559. return false;
  1560. }
  1561. if (spec->hp_dac_nid == dac)
  1562. return false;
  1563. return true;
  1564. }
  1565. static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
  1566. hda_nid_t target_dac, int with_aa_mix,
  1567. struct nid_path *path, int depth)
  1568. {
  1569. struct via_spec *spec = codec->spec;
  1570. hda_nid_t conn[8];
  1571. int i, nums;
  1572. if (nid == spec->aa_mix_nid) {
  1573. if (!with_aa_mix)
  1574. return false;
  1575. with_aa_mix = 2; /* mark aa-mix is included */
  1576. }
  1577. nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
  1578. for (i = 0; i < nums; i++) {
  1579. if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
  1580. continue;
  1581. if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
  1582. /* aa-mix is requested but not included? */
  1583. if (!(spec->aa_mix_nid && with_aa_mix == 1))
  1584. goto found;
  1585. }
  1586. }
  1587. if (depth >= MAX_NID_PATH_DEPTH)
  1588. return false;
  1589. for (i = 0; i < nums; i++) {
  1590. unsigned int type;
  1591. type = get_wcaps_type(get_wcaps(codec, conn[i]));
  1592. if (type == AC_WID_AUD_OUT)
  1593. continue;
  1594. if (__parse_output_path(codec, conn[i], target_dac,
  1595. with_aa_mix, path, depth + 1))
  1596. goto found;
  1597. }
  1598. return false;
  1599. found:
  1600. path->path[path->depth] = conn[i];
  1601. path->idx[path->depth] = i;
  1602. if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
  1603. path->multi[path->depth] = 1;
  1604. path->depth++;
  1605. return true;
  1606. }
  1607. static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
  1608. hda_nid_t target_dac, int with_aa_mix,
  1609. struct nid_path *path)
  1610. {
  1611. if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
  1612. path->path[path->depth] = nid;
  1613. path->depth++;
  1614. snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
  1615. path->depth, path->path[0], path->path[1],
  1616. path->path[2], path->path[3], path->path[4]);
  1617. return true;
  1618. }
  1619. return false;
  1620. }
  1621. static int via_auto_fill_dac_nids(struct hda_codec *codec)
  1622. {
  1623. struct via_spec *spec = codec->spec;
  1624. const struct auto_pin_cfg *cfg = &spec->autocfg;
  1625. int i;
  1626. hda_nid_t nid;
  1627. spec->multiout.num_dacs = 0;
  1628. spec->multiout.dac_nids = spec->private_dac_nids;
  1629. for (i = 0; i < cfg->line_outs; i++) {
  1630. hda_nid_t dac = 0;
  1631. nid = cfg->line_out_pins[i];
  1632. if (!nid)
  1633. continue;
  1634. if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
  1635. dac = spec->out_path[i].path[0];
  1636. if (!i && parse_output_path(codec, nid, dac, 1,
  1637. &spec->out_mix_path))
  1638. dac = spec->out_mix_path.path[0];
  1639. if (dac)
  1640. spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
  1641. }
  1642. if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
  1643. spec->out_path[0] = spec->out_mix_path;
  1644. spec->out_mix_path.depth = 0;
  1645. }
  1646. return 0;
  1647. }
  1648. static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
  1649. int chs, bool check_dac, struct nid_path *path)
  1650. {
  1651. struct via_spec *spec = codec->spec;
  1652. char name[32];
  1653. hda_nid_t dac, pin, sel, nid;
  1654. int err;
  1655. dac = check_dac ? path->path[0] : 0;
  1656. pin = path->path[path->depth - 1];
  1657. sel = path->depth > 1 ? path->path[1] : 0;
  1658. if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
  1659. nid = dac;
  1660. else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
  1661. nid = pin;
  1662. else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
  1663. nid = sel;
  1664. else
  1665. nid = 0;
  1666. if (nid) {
  1667. sprintf(name, "%s Playback Volume", pfx);
  1668. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1669. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1670. if (err < 0)
  1671. return err;
  1672. path->vol_ctl = nid;
  1673. }
  1674. if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
  1675. nid = dac;
  1676. else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
  1677. nid = pin;
  1678. else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
  1679. nid = sel;
  1680. else
  1681. nid = 0;
  1682. if (nid) {
  1683. sprintf(name, "%s Playback Switch", pfx);
  1684. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1685. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1686. if (err < 0)
  1687. return err;
  1688. path->mute_ctl = nid;
  1689. }
  1690. return 0;
  1691. }
  1692. static void mangle_smart51(struct hda_codec *codec)
  1693. {
  1694. struct via_spec *spec = codec->spec;
  1695. struct auto_pin_cfg *cfg = &spec->autocfg;
  1696. struct auto_pin_cfg_item *ins = cfg->inputs;
  1697. int i, j, nums, attr;
  1698. int pins[AUTO_CFG_MAX_INS];
  1699. for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
  1700. nums = 0;
  1701. for (i = 0; i < cfg->num_inputs; i++) {
  1702. unsigned int def;
  1703. if (ins[i].type > AUTO_PIN_LINE_IN)
  1704. continue;
  1705. def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
  1706. if (snd_hda_get_input_pin_attr(def) != attr)
  1707. continue;
  1708. for (j = 0; j < nums; j++)
  1709. if (ins[pins[j]].type < ins[i].type) {
  1710. memmove(pins + j + 1, pins + j,
  1711. (nums - j) * sizeof(int));
  1712. break;
  1713. }
  1714. pins[j] = i;
  1715. nums++;
  1716. }
  1717. if (cfg->line_outs + nums < 3)
  1718. continue;
  1719. for (i = 0; i < nums; i++) {
  1720. hda_nid_t pin = ins[pins[i]].pin;
  1721. spec->smart51_pins[spec->smart51_nums++] = pin;
  1722. cfg->line_out_pins[cfg->line_outs++] = pin;
  1723. if (cfg->line_outs == 3)
  1724. break;
  1725. }
  1726. return;
  1727. }
  1728. }
  1729. static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
  1730. {
  1731. dst->vol_ctl = src->vol_ctl;
  1732. dst->mute_ctl = src->mute_ctl;
  1733. }
  1734. /* add playback controls from the parsed DAC table */
  1735. static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
  1736. {
  1737. struct via_spec *spec = codec->spec;
  1738. struct auto_pin_cfg *cfg = &spec->autocfg;
  1739. struct nid_path *path;
  1740. static const char * const chname[4] = {
  1741. "Front", "Surround", NULL /* "CLFE" */, "Side"
  1742. };
  1743. int i, idx, err;
  1744. int old_line_outs;
  1745. /* check smart51 */
  1746. old_line_outs = cfg->line_outs;
  1747. if (cfg->line_outs == 1)
  1748. mangle_smart51(codec);
  1749. err = via_auto_fill_dac_nids(codec);
  1750. if (err < 0)
  1751. return err;
  1752. if (spec->multiout.num_dacs < 3) {
  1753. spec->smart51_nums = 0;
  1754. cfg->line_outs = old_line_outs;
  1755. }
  1756. for (i = 0; i < cfg->line_outs; i++) {
  1757. hda_nid_t pin, dac;
  1758. pin = cfg->line_out_pins[i];
  1759. dac = spec->multiout.dac_nids[i];
  1760. if (!pin || !dac)
  1761. continue;
  1762. path = spec->out_path + i;
  1763. if (i == HDA_CLFE) {
  1764. err = create_ch_ctls(codec, "Center", 1, true, path);
  1765. if (err < 0)
  1766. return err;
  1767. err = create_ch_ctls(codec, "LFE", 2, true, path);
  1768. if (err < 0)
  1769. return err;
  1770. } else {
  1771. const char *pfx = chname[i];
  1772. if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
  1773. cfg->line_outs <= 2)
  1774. pfx = i ? "Bass Speaker" : "Speaker";
  1775. err = create_ch_ctls(codec, pfx, 3, true, path);
  1776. if (err < 0)
  1777. return err;
  1778. }
  1779. if (path != spec->out_path + i)
  1780. copy_path_mixer_ctls(&spec->out_path[i], path);
  1781. if (path == spec->out_path && spec->out_mix_path.depth)
  1782. copy_path_mixer_ctls(&spec->out_mix_path, path);
  1783. }
  1784. idx = get_connection_index(codec, spec->aa_mix_nid,
  1785. spec->multiout.dac_nids[0]);
  1786. if (idx >= 0) {
  1787. /* add control to mixer */
  1788. const char *name;
  1789. name = spec->out_mix_path.depth ?
  1790. "PCM Loopback Playback Volume" : "PCM Playback Volume";
  1791. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1792. HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
  1793. idx, HDA_INPUT));
  1794. if (err < 0)
  1795. return err;
  1796. name = spec->out_mix_path.depth ?
  1797. "PCM Loopback Playback Switch" : "PCM Playback Switch";
  1798. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1799. HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
  1800. idx, HDA_INPUT));
  1801. if (err < 0)
  1802. return err;
  1803. }
  1804. cfg->line_outs = old_line_outs;
  1805. return 0;
  1806. }
  1807. static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
  1808. {
  1809. struct via_spec *spec = codec->spec;
  1810. struct nid_path *path;
  1811. bool check_dac;
  1812. int i, err;
  1813. if (!pin)
  1814. return 0;
  1815. if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
  1816. for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
  1817. if (i < spec->multiout.num_dacs &&
  1818. parse_output_path(codec, pin,
  1819. spec->multiout.dac_nids[i], 0,
  1820. &spec->hp_indep_path)) {
  1821. spec->hp_indep_shared = i;
  1822. break;
  1823. }
  1824. }
  1825. }
  1826. if (spec->hp_indep_path.depth) {
  1827. spec->hp_dac_nid = spec->hp_indep_path.path[0];
  1828. if (!spec->hp_indep_shared)
  1829. spec->hp_path = spec->hp_indep_path;
  1830. }
  1831. /* optionally check front-path w/o AA-mix */
  1832. if (!spec->hp_path.depth)
  1833. parse_output_path(codec, pin,
  1834. spec->multiout.dac_nids[HDA_FRONT], 0,
  1835. &spec->hp_path);
  1836. if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
  1837. 1, &spec->hp_mix_path) && !spec->hp_path.depth)
  1838. return 0;
  1839. if (spec->hp_path.depth) {
  1840. path = &spec->hp_path;
  1841. check_dac = true;
  1842. } else {
  1843. path = &spec->hp_mix_path;
  1844. check_dac = false;
  1845. }
  1846. err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
  1847. if (err < 0)
  1848. return err;
  1849. if (check_dac)
  1850. copy_path_mixer_ctls(&spec->hp_mix_path, path);
  1851. else
  1852. copy_path_mixer_ctls(&spec->hp_path, path);
  1853. if (spec->hp_indep_path.depth)
  1854. copy_path_mixer_ctls(&spec->hp_indep_path, path);
  1855. return 0;
  1856. }
  1857. static int via_auto_create_speaker_ctls(struct hda_codec *codec)
  1858. {
  1859. struct via_spec *spec = codec->spec;
  1860. struct nid_path *path;
  1861. bool check_dac;
  1862. hda_nid_t pin, dac = 0;
  1863. int err;
  1864. pin = spec->autocfg.speaker_pins[0];
  1865. if (!spec->autocfg.speaker_outs || !pin)
  1866. return 0;
  1867. if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
  1868. dac = spec->speaker_path.path[0];
  1869. if (!dac)
  1870. parse_output_path(codec, pin,
  1871. spec->multiout.dac_nids[HDA_FRONT], 0,
  1872. &spec->speaker_path);
  1873. if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
  1874. 1, &spec->speaker_mix_path) && !dac)
  1875. return 0;
  1876. /* no AA-path for front? */
  1877. if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
  1878. dac = 0;
  1879. spec->speaker_dac_nid = dac;
  1880. spec->multiout.extra_out_nid[0] = dac;
  1881. if (dac) {
  1882. path = &spec->speaker_path;
  1883. check_dac = true;
  1884. } else {
  1885. path = &spec->speaker_mix_path;
  1886. check_dac = false;
  1887. }
  1888. err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
  1889. if (err < 0)
  1890. return err;
  1891. if (check_dac)
  1892. copy_path_mixer_ctls(&spec->speaker_mix_path, path);
  1893. else
  1894. copy_path_mixer_ctls(&spec->speaker_path, path);
  1895. return 0;
  1896. }
  1897. #define via_aamix_ctl_info via_pin_power_ctl_info
  1898. static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
  1899. struct snd_ctl_elem_value *ucontrol)
  1900. {
  1901. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1902. struct via_spec *spec = codec->spec;
  1903. ucontrol->value.enumerated.item[0] = spec->aamix_mode;
  1904. return 0;
  1905. }
  1906. static void update_aamix_paths(struct hda_codec *codec, int do_mix,
  1907. struct nid_path *nomix, struct nid_path *mix)
  1908. {
  1909. if (do_mix) {
  1910. activate_output_path(codec, nomix, false, false);
  1911. activate_output_path(codec, mix, true, false);
  1912. } else {
  1913. activate_output_path(codec, mix, false, false);
  1914. activate_output_path(codec, nomix, true, false);
  1915. }
  1916. }
  1917. static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
  1918. struct snd_ctl_elem_value *ucontrol)
  1919. {
  1920. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1921. struct via_spec *spec = codec->spec;
  1922. unsigned int val = ucontrol->value.enumerated.item[0];
  1923. if (val == spec->aamix_mode)
  1924. return 0;
  1925. spec->aamix_mode = val;
  1926. /* update front path */
  1927. update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
  1928. /* update HP path */
  1929. if (!spec->hp_independent_mode) {
  1930. update_aamix_paths(codec, val, &spec->hp_path,
  1931. &spec->hp_mix_path);
  1932. }
  1933. /* update speaker path */
  1934. update_aamix_paths(codec, val, &spec->speaker_path,
  1935. &spec->speaker_mix_path);
  1936. return 1;
  1937. }
  1938. static const struct snd_kcontrol_new via_aamix_ctl_enum = {
  1939. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1940. .name = "Loopback Mixing",
  1941. .info = via_aamix_ctl_info,
  1942. .get = via_aamix_ctl_get,
  1943. .put = via_aamix_ctl_put,
  1944. };
  1945. static int via_auto_create_loopback_switch(struct hda_codec *codec)
  1946. {
  1947. struct via_spec *spec = codec->spec;
  1948. if (!spec->aa_mix_nid)
  1949. return 0; /* no loopback switching available */
  1950. if (!(spec->out_mix_path.depth || spec->hp_mix_path.depth ||
  1951. spec->speaker_path.depth))
  1952. return 0; /* no loopback switching available */
  1953. if (!via_clone_control(spec, &via_aamix_ctl_enum))
  1954. return -ENOMEM;
  1955. return 0;
  1956. }
  1957. /* look for ADCs */
  1958. static int via_fill_adcs(struct hda_codec *codec)
  1959. {
  1960. struct via_spec *spec = codec->spec;
  1961. hda_nid_t nid = codec->start_nid;
  1962. int i;
  1963. for (i = 0; i < codec->num_nodes; i++, nid++) {
  1964. unsigned int wcaps = get_wcaps(codec, nid);
  1965. if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
  1966. continue;
  1967. if (wcaps & AC_WCAP_DIGITAL)
  1968. continue;
  1969. if (!(wcaps & AC_WCAP_CONN_LIST))
  1970. continue;
  1971. if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
  1972. return -ENOMEM;
  1973. spec->adc_nids[spec->num_adc_nids++] = nid;
  1974. }
  1975. return 0;
  1976. }
  1977. /* input-src control */
  1978. static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
  1979. struct snd_ctl_elem_info *uinfo)
  1980. {
  1981. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1982. struct via_spec *spec = codec->spec;
  1983. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1984. uinfo->count = 1;
  1985. uinfo->value.enumerated.items = spec->num_inputs;
  1986. if (uinfo->value.enumerated.item >= spec->num_inputs)
  1987. uinfo->value.enumerated.item = spec->num_inputs - 1;
  1988. strcpy(uinfo->value.enumerated.name,
  1989. spec->inputs[uinfo->value.enumerated.item].label);
  1990. return 0;
  1991. }
  1992. static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
  1993. struct snd_ctl_elem_value *ucontrol)
  1994. {
  1995. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1996. struct via_spec *spec = codec->spec;
  1997. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1998. ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
  1999. return 0;
  2000. }
  2001. static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
  2002. struct snd_ctl_elem_value *ucontrol)
  2003. {
  2004. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2005. struct via_spec *spec = codec->spec;
  2006. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  2007. hda_nid_t mux;
  2008. int cur;
  2009. cur = ucontrol->value.enumerated.item[0];
  2010. if (cur < 0 || cur >= spec->num_inputs)
  2011. return -EINVAL;
  2012. if (spec->cur_mux[idx] == cur)
  2013. return 0;
  2014. spec->cur_mux[idx] = cur;
  2015. if (spec->dyn_adc_switch) {
  2016. int adc_idx = spec->inputs[cur].adc_idx;
  2017. mux = spec->mux_nids[adc_idx];
  2018. via_dyn_adc_pcm_resetup(codec, cur);
  2019. } else {
  2020. mux = spec->mux_nids[idx];
  2021. if (snd_BUG_ON(!mux))
  2022. return -EINVAL;
  2023. }
  2024. if (mux) {
  2025. /* switch to D0 beofre change index */
  2026. update_power_state(codec, mux, AC_PWRST_D0);
  2027. snd_hda_codec_write(codec, mux, 0,
  2028. AC_VERB_SET_CONNECT_SEL,
  2029. spec->inputs[cur].mux_idx);
  2030. }
  2031. /* update jack power state */
  2032. set_widgets_power_state(codec);
  2033. return 0;
  2034. }
  2035. static const struct snd_kcontrol_new via_input_src_ctl = {
  2036. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2037. /* The multiple "Capture Source" controls confuse alsamixer
  2038. * So call somewhat different..
  2039. */
  2040. /* .name = "Capture Source", */
  2041. .name = "Input Source",
  2042. .info = via_mux_enum_info,
  2043. .get = via_mux_enum_get,
  2044. .put = via_mux_enum_put,
  2045. };
  2046. static int create_input_src_ctls(struct hda_codec *codec, int count)
  2047. {
  2048. struct via_spec *spec = codec->spec;
  2049. struct snd_kcontrol_new *knew;
  2050. if (spec->num_inputs <= 1 || !count)
  2051. return 0; /* no need for single src */
  2052. knew = via_clone_control(spec, &via_input_src_ctl);
  2053. if (!knew)
  2054. return -ENOMEM;
  2055. knew->count = count;
  2056. return 0;
  2057. }
  2058. /* add the powersave loopback-list entry */
  2059. static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
  2060. {
  2061. struct hda_amp_list *list;
  2062. if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
  2063. return;
  2064. list = spec->loopback_list + spec->num_loopbacks;
  2065. list->nid = mix;
  2066. list->dir = HDA_INPUT;
  2067. list->idx = idx;
  2068. spec->num_loopbacks++;
  2069. spec->loopback.amplist = spec->loopback_list;
  2070. }
  2071. static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
  2072. hda_nid_t dst)
  2073. {
  2074. return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
  2075. }
  2076. /* add the input-route to the given pin */
  2077. static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
  2078. {
  2079. struct via_spec *spec = codec->spec;
  2080. int c, idx;
  2081. spec->inputs[spec->num_inputs].adc_idx = -1;
  2082. spec->inputs[spec->num_inputs].pin = pin;
  2083. for (c = 0; c < spec->num_adc_nids; c++) {
  2084. if (spec->mux_nids[c]) {
  2085. idx = get_connection_index(codec, spec->mux_nids[c],
  2086. pin);
  2087. if (idx < 0)
  2088. continue;
  2089. spec->inputs[spec->num_inputs].mux_idx = idx;
  2090. } else {
  2091. if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
  2092. continue;
  2093. }
  2094. spec->inputs[spec->num_inputs].adc_idx = c;
  2095. /* Can primary ADC satisfy all inputs? */
  2096. if (!spec->dyn_adc_switch &&
  2097. spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
  2098. snd_printd(KERN_INFO
  2099. "via: dynamic ADC switching enabled\n");
  2100. spec->dyn_adc_switch = 1;
  2101. }
  2102. return true;
  2103. }
  2104. return false;
  2105. }
  2106. static int get_mux_nids(struct hda_codec *codec);
  2107. /* parse input-routes; fill ADCs, MUXs and input-src entries */
  2108. static int parse_analog_inputs(struct hda_codec *codec)
  2109. {
  2110. struct via_spec *spec = codec->spec;
  2111. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2112. int i, err;
  2113. err = via_fill_adcs(codec);
  2114. if (err < 0)
  2115. return err;
  2116. err = get_mux_nids(codec);
  2117. if (err < 0)
  2118. return err;
  2119. /* fill all input-routes */
  2120. for (i = 0; i < cfg->num_inputs; i++) {
  2121. if (add_input_route(codec, cfg->inputs[i].pin))
  2122. spec->inputs[spec->num_inputs++].label =
  2123. hda_get_autocfg_input_label(codec, cfg, i);
  2124. }
  2125. /* check for internal loopback recording */
  2126. if (spec->aa_mix_nid &&
  2127. add_input_route(codec, spec->aa_mix_nid))
  2128. spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
  2129. return 0;
  2130. }
  2131. /* create analog-loopback volume/switch controls */
  2132. static int create_loopback_ctls(struct hda_codec *codec)
  2133. {
  2134. struct via_spec *spec = codec->spec;
  2135. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2136. const char *prev_label = NULL;
  2137. int type_idx = 0;
  2138. int i, j, err, idx;
  2139. if (!spec->aa_mix_nid)
  2140. return 0;
  2141. for (i = 0; i < cfg->num_inputs; i++) {
  2142. hda_nid_t pin = cfg->inputs[i].pin;
  2143. const char *label = hda_get_autocfg_input_label(codec, cfg, i);
  2144. if (prev_label && !strcmp(label, prev_label))
  2145. type_idx++;
  2146. else
  2147. type_idx = 0;
  2148. prev_label = label;
  2149. idx = get_connection_index(codec, spec->aa_mix_nid, pin);
  2150. if (idx >= 0) {
  2151. err = via_new_analog_input(spec, label, type_idx,
  2152. idx, spec->aa_mix_nid);
  2153. if (err < 0)
  2154. return err;
  2155. add_loopback_list(spec, spec->aa_mix_nid, idx);
  2156. }
  2157. /* remember the label for smart51 control */
  2158. for (j = 0; j < spec->smart51_nums; j++) {
  2159. if (spec->smart51_pins[j] == pin) {
  2160. spec->smart51_idxs[j] = idx;
  2161. spec->smart51_labels[j] = label;
  2162. break;
  2163. }
  2164. }
  2165. }
  2166. return 0;
  2167. }
  2168. /* create mic-boost controls (if present) */
  2169. static int create_mic_boost_ctls(struct hda_codec *codec)
  2170. {
  2171. struct via_spec *spec = codec->spec;
  2172. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2173. const char *prev_label = NULL;
  2174. int type_idx = 0;
  2175. int i, err;
  2176. for (i = 0; i < cfg->num_inputs; i++) {
  2177. hda_nid_t pin = cfg->inputs[i].pin;
  2178. unsigned int caps;
  2179. const char *label;
  2180. char name[32];
  2181. if (cfg->inputs[i].type != AUTO_PIN_MIC)
  2182. continue;
  2183. caps = query_amp_caps(codec, pin, HDA_INPUT);
  2184. if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
  2185. continue;
  2186. label = hda_get_autocfg_input_label(codec, cfg, i);
  2187. if (prev_label && !strcmp(label, prev_label))
  2188. type_idx++;
  2189. else
  2190. type_idx = 0;
  2191. prev_label = label;
  2192. snprintf(name, sizeof(name), "%s Boost Volume", label);
  2193. err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
  2194. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
  2195. if (err < 0)
  2196. return err;
  2197. }
  2198. return 0;
  2199. }
  2200. /* create capture and input-src controls for multiple streams */
  2201. static int create_multi_adc_ctls(struct hda_codec *codec)
  2202. {
  2203. struct via_spec *spec = codec->spec;
  2204. int i, err;
  2205. /* create capture mixer elements */
  2206. for (i = 0; i < spec->num_adc_nids; i++) {
  2207. hda_nid_t adc = spec->adc_nids[i];
  2208. err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2209. "Capture Volume", i,
  2210. HDA_COMPOSE_AMP_VAL(adc, 3, 0,
  2211. HDA_INPUT));
  2212. if (err < 0)
  2213. return err;
  2214. err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2215. "Capture Switch", i,
  2216. HDA_COMPOSE_AMP_VAL(adc, 3, 0,
  2217. HDA_INPUT));
  2218. if (err < 0)
  2219. return err;
  2220. }
  2221. /* input-source control */
  2222. for (i = 0; i < spec->num_adc_nids; i++)
  2223. if (!spec->mux_nids[i])
  2224. break;
  2225. err = create_input_src_ctls(codec, i);
  2226. if (err < 0)
  2227. return err;
  2228. return 0;
  2229. }
  2230. /* bind capture volume/switch */
  2231. static struct snd_kcontrol_new via_bind_cap_vol_ctl =
  2232. HDA_BIND_VOL("Capture Volume", 0);
  2233. static struct snd_kcontrol_new via_bind_cap_sw_ctl =
  2234. HDA_BIND_SW("Capture Switch", 0);
  2235. static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
  2236. struct hda_ctl_ops *ops)
  2237. {
  2238. struct hda_bind_ctls *ctl;
  2239. int i;
  2240. ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
  2241. if (!ctl)
  2242. return -ENOMEM;
  2243. ctl->ops = ops;
  2244. for (i = 0; i < spec->num_adc_nids; i++)
  2245. ctl->values[i] =
  2246. HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
  2247. *ctl_ret = ctl;
  2248. return 0;
  2249. }
  2250. /* create capture and input-src controls for dynamic ADC-switch case */
  2251. static int create_dyn_adc_ctls(struct hda_codec *codec)
  2252. {
  2253. struct via_spec *spec = codec->spec;
  2254. struct snd_kcontrol_new *knew;
  2255. int err;
  2256. /* set up the bind capture ctls */
  2257. err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
  2258. if (err < 0)
  2259. return err;
  2260. err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
  2261. if (err < 0)
  2262. return err;
  2263. /* create capture mixer elements */
  2264. knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
  2265. if (!knew)
  2266. return -ENOMEM;
  2267. knew->private_value = (long)spec->bind_cap_vol;
  2268. knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
  2269. if (!knew)
  2270. return -ENOMEM;
  2271. knew->private_value = (long)spec->bind_cap_sw;
  2272. /* input-source control */
  2273. err = create_input_src_ctls(codec, 1);
  2274. if (err < 0)
  2275. return err;
  2276. return 0;
  2277. }
  2278. /* parse and create capture-related stuff */
  2279. static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
  2280. {
  2281. struct via_spec *spec = codec->spec;
  2282. int err;
  2283. err = parse_analog_inputs(codec);
  2284. if (err < 0)
  2285. return err;
  2286. if (spec->dyn_adc_switch)
  2287. err = create_dyn_adc_ctls(codec);
  2288. else
  2289. err = create_multi_adc_ctls(codec);
  2290. if (err < 0)
  2291. return err;
  2292. err = create_loopback_ctls(codec);
  2293. if (err < 0)
  2294. return err;
  2295. err = create_mic_boost_ctls(codec);
  2296. if (err < 0)
  2297. return err;
  2298. return 0;
  2299. }
  2300. static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
  2301. {
  2302. unsigned int def_conf;
  2303. unsigned char seqassoc;
  2304. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  2305. seqassoc = (unsigned char) get_defcfg_association(def_conf);
  2306. seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
  2307. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
  2308. && (seqassoc == 0xf0 || seqassoc == 0xff)) {
  2309. def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
  2310. snd_hda_codec_set_pincfg(codec, nid, def_conf);
  2311. }
  2312. return;
  2313. }
  2314. static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
  2315. struct snd_ctl_elem_value *ucontrol)
  2316. {
  2317. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2318. struct via_spec *spec = codec->spec;
  2319. if (spec->codec_type != VT1708)
  2320. return 0;
  2321. ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
  2322. return 0;
  2323. }
  2324. static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
  2325. struct snd_ctl_elem_value *ucontrol)
  2326. {
  2327. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2328. struct via_spec *spec = codec->spec;
  2329. int val;
  2330. if (spec->codec_type != VT1708)
  2331. return 0;
  2332. val = !!ucontrol->value.integer.value[0];
  2333. if (spec->vt1708_jack_detect == val)
  2334. return 0;
  2335. spec->vt1708_jack_detect = val;
  2336. if (spec->vt1708_jack_detect &&
  2337. snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) {
  2338. mute_aa_path(codec, 1);
  2339. notify_aa_path_ctls(codec);
  2340. }
  2341. via_hp_automute(codec);
  2342. vt1708_update_hp_work(spec);
  2343. return 1;
  2344. }
  2345. static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
  2346. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2347. .name = "Jack Detect",
  2348. .count = 1,
  2349. .info = snd_ctl_boolean_mono_info,
  2350. .get = vt1708_jack_detect_get,
  2351. .put = vt1708_jack_detect_put,
  2352. };
  2353. static void fill_dig_outs(struct hda_codec *codec);
  2354. static void fill_dig_in(struct hda_codec *codec);
  2355. static int via_parse_auto_config(struct hda_codec *codec)
  2356. {
  2357. struct via_spec *spec = codec->spec;
  2358. int err;
  2359. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2360. if (err < 0)
  2361. return err;
  2362. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2363. return -EINVAL;
  2364. err = via_auto_create_multi_out_ctls(codec);
  2365. if (err < 0)
  2366. return err;
  2367. err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
  2368. if (err < 0)
  2369. return err;
  2370. err = via_auto_create_speaker_ctls(codec);
  2371. if (err < 0)
  2372. return err;
  2373. err = via_auto_create_loopback_switch(codec);
  2374. if (err < 0)
  2375. return err;
  2376. err = via_auto_create_analog_input_ctls(codec);
  2377. if (err < 0)
  2378. return err;
  2379. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2380. fill_dig_outs(codec);
  2381. fill_dig_in(codec);
  2382. if (spec->kctls.list)
  2383. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2384. if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
  2385. err = via_hp_build(codec);
  2386. if (err < 0)
  2387. return err;
  2388. }
  2389. err = via_smart51_build(codec);
  2390. if (err < 0)
  2391. return err;
  2392. /* assign slave outs */
  2393. if (spec->slave_dig_outs[0])
  2394. codec->slave_dig_outs = spec->slave_dig_outs;
  2395. return 1;
  2396. }
  2397. static void via_auto_init_dig_outs(struct hda_codec *codec)
  2398. {
  2399. struct via_spec *spec = codec->spec;
  2400. if (spec->multiout.dig_out_nid)
  2401. init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
  2402. if (spec->slave_dig_outs[0])
  2403. init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
  2404. }
  2405. static void via_auto_init_dig_in(struct hda_codec *codec)
  2406. {
  2407. struct via_spec *spec = codec->spec;
  2408. if (!spec->dig_in_nid)
  2409. return;
  2410. snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN);
  2411. }
  2412. static void via_jack_output_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
  2413. {
  2414. set_widgets_power_state(codec);
  2415. via_hp_automute(codec);
  2416. }
  2417. static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
  2418. {
  2419. set_widgets_power_state(codec);
  2420. }
  2421. /* initialize the unsolicited events */
  2422. static void via_auto_init_unsol_event(struct hda_codec *codec)
  2423. {
  2424. struct via_spec *spec = codec->spec;
  2425. struct auto_pin_cfg *cfg = &spec->autocfg;
  2426. unsigned int ev;
  2427. int i;
  2428. hda_jack_callback cb;
  2429. if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
  2430. snd_hda_jack_detect_enable_callback(codec, cfg->hp_pins[0],
  2431. VIA_HP_EVENT | VIA_JACK_EVENT,
  2432. via_jack_output_event);
  2433. if (cfg->speaker_pins[0])
  2434. ev = VIA_LINE_EVENT;
  2435. else
  2436. ev = 0;
  2437. cb = ev ? via_jack_output_event : via_jack_powerstate_event;
  2438. for (i = 0; i < cfg->line_outs; i++) {
  2439. if (cfg->line_out_pins[i] &&
  2440. is_jack_detectable(codec, cfg->line_out_pins[i]))
  2441. snd_hda_jack_detect_enable_callback(codec, cfg->line_out_pins[i],
  2442. ev | VIA_JACK_EVENT, cb);
  2443. }
  2444. for (i = 0; i < cfg->num_inputs; i++) {
  2445. if (is_jack_detectable(codec, cfg->inputs[i].pin))
  2446. snd_hda_jack_detect_enable_callback(codec, cfg->inputs[i].pin,
  2447. VIA_JACK_EVENT,
  2448. via_jack_powerstate_event);
  2449. }
  2450. }
  2451. static int via_init(struct hda_codec *codec)
  2452. {
  2453. struct via_spec *spec = codec->spec;
  2454. int i;
  2455. for (i = 0; i < spec->num_iverbs; i++)
  2456. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  2457. /* init power states */
  2458. set_widgets_power_state(codec);
  2459. __analog_low_current_mode(codec, true);
  2460. via_auto_init_multi_out(codec);
  2461. via_auto_init_hp_out(codec);
  2462. via_auto_init_speaker_out(codec);
  2463. via_auto_init_analog_input(codec);
  2464. via_auto_init_dig_outs(codec);
  2465. via_auto_init_dig_in(codec);
  2466. via_auto_init_unsol_event(codec);
  2467. via_hp_automute(codec);
  2468. vt1708_update_hp_work(spec);
  2469. return 0;
  2470. }
  2471. static void vt1708_update_hp_jack_state(struct work_struct *work)
  2472. {
  2473. struct via_spec *spec = container_of(work, struct via_spec,
  2474. vt1708_hp_work.work);
  2475. if (spec->codec_type != VT1708)
  2476. return;
  2477. snd_hda_jack_set_dirty_all(spec->codec);
  2478. /* if jack state toggled */
  2479. if (spec->vt1708_hp_present
  2480. != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
  2481. spec->vt1708_hp_present ^= 1;
  2482. via_hp_automute(spec->codec);
  2483. }
  2484. if (spec->vt1708_jack_detect)
  2485. schedule_delayed_work(&spec->vt1708_hp_work,
  2486. msecs_to_jiffies(100));
  2487. }
  2488. static int get_mux_nids(struct hda_codec *codec)
  2489. {
  2490. struct via_spec *spec = codec->spec;
  2491. hda_nid_t nid, conn[8];
  2492. unsigned int type;
  2493. int i, n;
  2494. for (i = 0; i < spec->num_adc_nids; i++) {
  2495. nid = spec->adc_nids[i];
  2496. while (nid) {
  2497. type = get_wcaps_type(get_wcaps(codec, nid));
  2498. if (type == AC_WID_PIN)
  2499. break;
  2500. n = snd_hda_get_connections(codec, nid, conn,
  2501. ARRAY_SIZE(conn));
  2502. if (n <= 0)
  2503. break;
  2504. if (n > 1) {
  2505. spec->mux_nids[i] = nid;
  2506. break;
  2507. }
  2508. nid = conn[0];
  2509. }
  2510. }
  2511. return 0;
  2512. }
  2513. static int patch_vt1708(struct hda_codec *codec)
  2514. {
  2515. struct via_spec *spec;
  2516. int err;
  2517. /* create a codec specific record */
  2518. spec = via_new_spec(codec);
  2519. if (spec == NULL)
  2520. return -ENOMEM;
  2521. spec->aa_mix_nid = 0x17;
  2522. /* Add HP and CD pin config connect bit re-config action */
  2523. vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
  2524. vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
  2525. /* automatic parse from the BIOS config */
  2526. err = via_parse_auto_config(codec);
  2527. if (err < 0) {
  2528. via_free(codec);
  2529. return err;
  2530. }
  2531. /* add jack detect on/off control */
  2532. if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
  2533. return -ENOMEM;
  2534. /* disable 32bit format on VT1708 */
  2535. if (codec->vendor_id == 0x11061708)
  2536. spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
  2537. spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
  2538. codec->patch_ops = via_patch_ops;
  2539. INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
  2540. return 0;
  2541. }
  2542. static int patch_vt1709(struct hda_codec *codec)
  2543. {
  2544. struct via_spec *spec;
  2545. int err;
  2546. /* create a codec specific record */
  2547. spec = via_new_spec(codec);
  2548. if (spec == NULL)
  2549. return -ENOMEM;
  2550. spec->aa_mix_nid = 0x18;
  2551. err = via_parse_auto_config(codec);
  2552. if (err < 0) {
  2553. via_free(codec);
  2554. return err;
  2555. }
  2556. codec->patch_ops = via_patch_ops;
  2557. return 0;
  2558. }
  2559. static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
  2560. {
  2561. struct via_spec *spec = codec->spec;
  2562. int imux_is_smixer;
  2563. unsigned int parm;
  2564. int is_8ch = 0;
  2565. if ((spec->codec_type != VT1708B_4CH) &&
  2566. (codec->vendor_id != 0x11064397))
  2567. is_8ch = 1;
  2568. /* SW0 (17h) = stereo mixer */
  2569. imux_is_smixer =
  2570. (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
  2571. == ((spec->codec_type == VT1708S) ? 5 : 0));
  2572. /* inputs */
  2573. /* PW 1/2/5 (1ah/1bh/1eh) */
  2574. parm = AC_PWRST_D3;
  2575. set_pin_power_state(codec, 0x1a, &parm);
  2576. set_pin_power_state(codec, 0x1b, &parm);
  2577. set_pin_power_state(codec, 0x1e, &parm);
  2578. if (imux_is_smixer)
  2579. parm = AC_PWRST_D0;
  2580. /* SW0 (17h), AIW 0/1 (13h/14h) */
  2581. update_power_state(codec, 0x17, parm);
  2582. update_power_state(codec, 0x13, parm);
  2583. update_power_state(codec, 0x14, parm);
  2584. /* outputs */
  2585. /* PW0 (19h), SW1 (18h), AOW1 (11h) */
  2586. parm = AC_PWRST_D3;
  2587. set_pin_power_state(codec, 0x19, &parm);
  2588. if (spec->smart51_enabled)
  2589. set_pin_power_state(codec, 0x1b, &parm);
  2590. update_power_state(codec, 0x18, parm);
  2591. update_power_state(codec, 0x11, parm);
  2592. /* PW6 (22h), SW2 (26h), AOW2 (24h) */
  2593. if (is_8ch) {
  2594. parm = AC_PWRST_D3;
  2595. set_pin_power_state(codec, 0x22, &parm);
  2596. if (spec->smart51_enabled)
  2597. set_pin_power_state(codec, 0x1a, &parm);
  2598. update_power_state(codec, 0x26, parm);
  2599. update_power_state(codec, 0x24, parm);
  2600. } else if (codec->vendor_id == 0x11064397) {
  2601. /* PW7(23h), SW2(27h), AOW2(25h) */
  2602. parm = AC_PWRST_D3;
  2603. set_pin_power_state(codec, 0x23, &parm);
  2604. if (spec->smart51_enabled)
  2605. set_pin_power_state(codec, 0x1a, &parm);
  2606. update_power_state(codec, 0x27, parm);
  2607. update_power_state(codec, 0x25, parm);
  2608. }
  2609. /* PW 3/4/7 (1ch/1dh/23h) */
  2610. parm = AC_PWRST_D3;
  2611. /* force to D0 for internal Speaker */
  2612. set_pin_power_state(codec, 0x1c, &parm);
  2613. set_pin_power_state(codec, 0x1d, &parm);
  2614. if (is_8ch)
  2615. set_pin_power_state(codec, 0x23, &parm);
  2616. /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
  2617. update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
  2618. update_power_state(codec, 0x10, parm);
  2619. if (is_8ch) {
  2620. update_power_state(codec, 0x25, parm);
  2621. update_power_state(codec, 0x27, parm);
  2622. } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
  2623. update_power_state(codec, 0x25, parm);
  2624. }
  2625. static int patch_vt1708S(struct hda_codec *codec);
  2626. static int patch_vt1708B(struct hda_codec *codec)
  2627. {
  2628. struct via_spec *spec;
  2629. int err;
  2630. if (get_codec_type(codec) == VT1708BCE)
  2631. return patch_vt1708S(codec);
  2632. /* create a codec specific record */
  2633. spec = via_new_spec(codec);
  2634. if (spec == NULL)
  2635. return -ENOMEM;
  2636. spec->aa_mix_nid = 0x16;
  2637. /* automatic parse from the BIOS config */
  2638. err = via_parse_auto_config(codec);
  2639. if (err < 0) {
  2640. via_free(codec);
  2641. return err;
  2642. }
  2643. codec->patch_ops = via_patch_ops;
  2644. spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
  2645. return 0;
  2646. }
  2647. /* Patch for VT1708S */
  2648. static const struct hda_verb vt1708S_init_verbs[] = {
  2649. /* Enable Mic Boost Volume backdoor */
  2650. {0x1, 0xf98, 0x1},
  2651. /* don't bybass mixer */
  2652. {0x1, 0xf88, 0xc0},
  2653. { }
  2654. };
  2655. /* fill out digital output widgets; one for master and one for slave outputs */
  2656. static void fill_dig_outs(struct hda_codec *codec)
  2657. {
  2658. struct via_spec *spec = codec->spec;
  2659. int i;
  2660. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  2661. hda_nid_t nid;
  2662. int conn;
  2663. nid = spec->autocfg.dig_out_pins[i];
  2664. if (!nid)
  2665. continue;
  2666. conn = snd_hda_get_connections(codec, nid, &nid, 1);
  2667. if (conn < 1)
  2668. continue;
  2669. if (!spec->multiout.dig_out_nid)
  2670. spec->multiout.dig_out_nid = nid;
  2671. else {
  2672. spec->slave_dig_outs[0] = nid;
  2673. break; /* at most two dig outs */
  2674. }
  2675. }
  2676. }
  2677. static void fill_dig_in(struct hda_codec *codec)
  2678. {
  2679. struct via_spec *spec = codec->spec;
  2680. hda_nid_t dig_nid;
  2681. int i, err;
  2682. if (!spec->autocfg.dig_in_pin)
  2683. return;
  2684. dig_nid = codec->start_nid;
  2685. for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
  2686. unsigned int wcaps = get_wcaps(codec, dig_nid);
  2687. if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
  2688. continue;
  2689. if (!(wcaps & AC_WCAP_DIGITAL))
  2690. continue;
  2691. if (!(wcaps & AC_WCAP_CONN_LIST))
  2692. continue;
  2693. err = get_connection_index(codec, dig_nid,
  2694. spec->autocfg.dig_in_pin);
  2695. if (err >= 0) {
  2696. spec->dig_in_nid = dig_nid;
  2697. break;
  2698. }
  2699. }
  2700. }
  2701. static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
  2702. int offset, int num_steps, int step_size)
  2703. {
  2704. snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
  2705. (offset << AC_AMPCAP_OFFSET_SHIFT) |
  2706. (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2707. (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2708. (0 << AC_AMPCAP_MUTE_SHIFT));
  2709. }
  2710. static int patch_vt1708S(struct hda_codec *codec)
  2711. {
  2712. struct via_spec *spec;
  2713. int err;
  2714. /* create a codec specific record */
  2715. spec = via_new_spec(codec);
  2716. if (spec == NULL)
  2717. return -ENOMEM;
  2718. spec->aa_mix_nid = 0x16;
  2719. override_mic_boost(codec, 0x1a, 0, 3, 40);
  2720. override_mic_boost(codec, 0x1e, 0, 3, 40);
  2721. /* automatic parse from the BIOS config */
  2722. err = via_parse_auto_config(codec);
  2723. if (err < 0) {
  2724. via_free(codec);
  2725. return err;
  2726. }
  2727. spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
  2728. codec->patch_ops = via_patch_ops;
  2729. /* correct names for VT1708BCE */
  2730. if (get_codec_type(codec) == VT1708BCE) {
  2731. kfree(codec->chip_name);
  2732. codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
  2733. snprintf(codec->bus->card->mixername,
  2734. sizeof(codec->bus->card->mixername),
  2735. "%s %s", codec->vendor_name, codec->chip_name);
  2736. }
  2737. /* correct names for VT1705 */
  2738. if (codec->vendor_id == 0x11064397) {
  2739. kfree(codec->chip_name);
  2740. codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
  2741. snprintf(codec->bus->card->mixername,
  2742. sizeof(codec->bus->card->mixername),
  2743. "%s %s", codec->vendor_name, codec->chip_name);
  2744. }
  2745. spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
  2746. return 0;
  2747. }
  2748. /* Patch for VT1702 */
  2749. static const struct hda_verb vt1702_init_verbs[] = {
  2750. /* mixer enable */
  2751. {0x1, 0xF88, 0x3},
  2752. /* GPIO 0~2 */
  2753. {0x1, 0xF82, 0x3F},
  2754. { }
  2755. };
  2756. static void set_widgets_power_state_vt1702(struct hda_codec *codec)
  2757. {
  2758. int imux_is_smixer =
  2759. snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
  2760. unsigned int parm;
  2761. /* inputs */
  2762. /* PW 1/2/5 (14h/15h/18h) */
  2763. parm = AC_PWRST_D3;
  2764. set_pin_power_state(codec, 0x14, &parm);
  2765. set_pin_power_state(codec, 0x15, &parm);
  2766. set_pin_power_state(codec, 0x18, &parm);
  2767. if (imux_is_smixer)
  2768. parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
  2769. /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
  2770. update_power_state(codec, 0x13, parm);
  2771. update_power_state(codec, 0x12, parm);
  2772. update_power_state(codec, 0x1f, parm);
  2773. update_power_state(codec, 0x20, parm);
  2774. /* outputs */
  2775. /* PW 3/4 (16h/17h) */
  2776. parm = AC_PWRST_D3;
  2777. set_pin_power_state(codec, 0x17, &parm);
  2778. set_pin_power_state(codec, 0x16, &parm);
  2779. /* MW0 (1ah), AOW 0/1 (10h/1dh) */
  2780. update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
  2781. update_power_state(codec, 0x10, parm);
  2782. update_power_state(codec, 0x1d, parm);
  2783. }
  2784. static int patch_vt1702(struct hda_codec *codec)
  2785. {
  2786. struct via_spec *spec;
  2787. int err;
  2788. /* create a codec specific record */
  2789. spec = via_new_spec(codec);
  2790. if (spec == NULL)
  2791. return -ENOMEM;
  2792. spec->aa_mix_nid = 0x1a;
  2793. /* limit AA path volume to 0 dB */
  2794. snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
  2795. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  2796. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2797. (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2798. (1 << AC_AMPCAP_MUTE_SHIFT));
  2799. /* automatic parse from the BIOS config */
  2800. err = via_parse_auto_config(codec);
  2801. if (err < 0) {
  2802. via_free(codec);
  2803. return err;
  2804. }
  2805. spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
  2806. codec->patch_ops = via_patch_ops;
  2807. spec->set_widgets_power_state = set_widgets_power_state_vt1702;
  2808. return 0;
  2809. }
  2810. /* Patch for VT1718S */
  2811. static const struct hda_verb vt1718S_init_verbs[] = {
  2812. /* Enable MW0 adjust Gain 5 */
  2813. {0x1, 0xfb2, 0x10},
  2814. /* Enable Boost Volume backdoor */
  2815. {0x1, 0xf88, 0x8},
  2816. { }
  2817. };
  2818. static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
  2819. {
  2820. struct via_spec *spec = codec->spec;
  2821. int imux_is_smixer;
  2822. unsigned int parm, parm2;
  2823. /* MUX6 (1eh) = stereo mixer */
  2824. imux_is_smixer =
  2825. snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
  2826. /* inputs */
  2827. /* PW 5/6/7 (29h/2ah/2bh) */
  2828. parm = AC_PWRST_D3;
  2829. set_pin_power_state(codec, 0x29, &parm);
  2830. set_pin_power_state(codec, 0x2a, &parm);
  2831. set_pin_power_state(codec, 0x2b, &parm);
  2832. if (imux_is_smixer)
  2833. parm = AC_PWRST_D0;
  2834. /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
  2835. update_power_state(codec, 0x1e, parm);
  2836. update_power_state(codec, 0x1f, parm);
  2837. update_power_state(codec, 0x10, parm);
  2838. update_power_state(codec, 0x11, parm);
  2839. /* outputs */
  2840. /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
  2841. parm = AC_PWRST_D3;
  2842. set_pin_power_state(codec, 0x27, &parm);
  2843. update_power_state(codec, 0x1a, parm);
  2844. parm2 = parm; /* for pin 0x0b */
  2845. /* PW2 (26h), AOW2 (ah) */
  2846. parm = AC_PWRST_D3;
  2847. set_pin_power_state(codec, 0x26, &parm);
  2848. if (spec->smart51_enabled)
  2849. set_pin_power_state(codec, 0x2b, &parm);
  2850. update_power_state(codec, 0xa, parm);
  2851. /* PW0 (24h), AOW0 (8h) */
  2852. parm = AC_PWRST_D3;
  2853. set_pin_power_state(codec, 0x24, &parm);
  2854. if (!spec->hp_independent_mode) /* check for redirected HP */
  2855. set_pin_power_state(codec, 0x28, &parm);
  2856. update_power_state(codec, 0x8, parm);
  2857. if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3)
  2858. parm = parm2;
  2859. update_power_state(codec, 0xb, parm);
  2860. /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
  2861. update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
  2862. /* PW1 (25h), AOW1 (9h) */
  2863. parm = AC_PWRST_D3;
  2864. set_pin_power_state(codec, 0x25, &parm);
  2865. if (spec->smart51_enabled)
  2866. set_pin_power_state(codec, 0x2a, &parm);
  2867. update_power_state(codec, 0x9, parm);
  2868. if (spec->hp_independent_mode) {
  2869. /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
  2870. parm = AC_PWRST_D3;
  2871. set_pin_power_state(codec, 0x28, &parm);
  2872. update_power_state(codec, 0x1b, parm);
  2873. update_power_state(codec, 0x34, parm);
  2874. update_power_state(codec, 0xc, parm);
  2875. }
  2876. }
  2877. /* Add a connection to the primary DAC from AA-mixer for some codecs
  2878. * This isn't listed from the raw info, but the chip has a secret connection.
  2879. */
  2880. static int add_secret_dac_path(struct hda_codec *codec)
  2881. {
  2882. struct via_spec *spec = codec->spec;
  2883. int i, nums;
  2884. hda_nid_t conn[8];
  2885. hda_nid_t nid;
  2886. if (!spec->aa_mix_nid)
  2887. return 0;
  2888. nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
  2889. ARRAY_SIZE(conn) - 1);
  2890. for (i = 0; i < nums; i++) {
  2891. if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
  2892. return 0;
  2893. }
  2894. /* find the primary DAC and add to the connection list */
  2895. nid = codec->start_nid;
  2896. for (i = 0; i < codec->num_nodes; i++, nid++) {
  2897. unsigned int caps = get_wcaps(codec, nid);
  2898. if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
  2899. !(caps & AC_WCAP_DIGITAL)) {
  2900. conn[nums++] = nid;
  2901. return snd_hda_override_conn_list(codec,
  2902. spec->aa_mix_nid,
  2903. nums, conn);
  2904. }
  2905. }
  2906. return 0;
  2907. }
  2908. static int patch_vt1718S(struct hda_codec *codec)
  2909. {
  2910. struct via_spec *spec;
  2911. int err;
  2912. /* create a codec specific record */
  2913. spec = via_new_spec(codec);
  2914. if (spec == NULL)
  2915. return -ENOMEM;
  2916. spec->aa_mix_nid = 0x21;
  2917. override_mic_boost(codec, 0x2b, 0, 3, 40);
  2918. override_mic_boost(codec, 0x29, 0, 3, 40);
  2919. add_secret_dac_path(codec);
  2920. /* automatic parse from the BIOS config */
  2921. err = via_parse_auto_config(codec);
  2922. if (err < 0) {
  2923. via_free(codec);
  2924. return err;
  2925. }
  2926. spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
  2927. codec->patch_ops = via_patch_ops;
  2928. spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
  2929. return 0;
  2930. }
  2931. /* Patch for VT1716S */
  2932. static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
  2933. struct snd_ctl_elem_info *uinfo)
  2934. {
  2935. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2936. uinfo->count = 1;
  2937. uinfo->value.integer.min = 0;
  2938. uinfo->value.integer.max = 1;
  2939. return 0;
  2940. }
  2941. static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
  2942. struct snd_ctl_elem_value *ucontrol)
  2943. {
  2944. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2945. int index = 0;
  2946. index = snd_hda_codec_read(codec, 0x26, 0,
  2947. AC_VERB_GET_CONNECT_SEL, 0);
  2948. if (index != -1)
  2949. *ucontrol->value.integer.value = index;
  2950. return 0;
  2951. }
  2952. static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
  2953. struct snd_ctl_elem_value *ucontrol)
  2954. {
  2955. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2956. struct via_spec *spec = codec->spec;
  2957. int index = *ucontrol->value.integer.value;
  2958. snd_hda_codec_write(codec, 0x26, 0,
  2959. AC_VERB_SET_CONNECT_SEL, index);
  2960. spec->dmic_enabled = index;
  2961. set_widgets_power_state(codec);
  2962. return 1;
  2963. }
  2964. static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
  2965. HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
  2966. {
  2967. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2968. .name = "Digital Mic Capture Switch",
  2969. .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
  2970. .count = 1,
  2971. .info = vt1716s_dmic_info,
  2972. .get = vt1716s_dmic_get,
  2973. .put = vt1716s_dmic_put,
  2974. },
  2975. {} /* end */
  2976. };
  2977. /* mono-out mixer elements */
  2978. static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
  2979. HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
  2980. { } /* end */
  2981. };
  2982. static const struct hda_verb vt1716S_init_verbs[] = {
  2983. /* Enable Boost Volume backdoor */
  2984. {0x1, 0xf8a, 0x80},
  2985. /* don't bybass mixer */
  2986. {0x1, 0xf88, 0xc0},
  2987. /* Enable mono output */
  2988. {0x1, 0xf90, 0x08},
  2989. { }
  2990. };
  2991. static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
  2992. {
  2993. struct via_spec *spec = codec->spec;
  2994. int imux_is_smixer;
  2995. unsigned int parm;
  2996. unsigned int mono_out, present;
  2997. /* SW0 (17h) = stereo mixer */
  2998. imux_is_smixer =
  2999. (snd_hda_codec_read(codec, 0x17, 0,
  3000. AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
  3001. /* inputs */
  3002. /* PW 1/2/5 (1ah/1bh/1eh) */
  3003. parm = AC_PWRST_D3;
  3004. set_pin_power_state(codec, 0x1a, &parm);
  3005. set_pin_power_state(codec, 0x1b, &parm);
  3006. set_pin_power_state(codec, 0x1e, &parm);
  3007. if (imux_is_smixer)
  3008. parm = AC_PWRST_D0;
  3009. /* SW0 (17h), AIW0(13h) */
  3010. update_power_state(codec, 0x17, parm);
  3011. update_power_state(codec, 0x13, parm);
  3012. parm = AC_PWRST_D3;
  3013. set_pin_power_state(codec, 0x1e, &parm);
  3014. /* PW11 (22h) */
  3015. if (spec->dmic_enabled)
  3016. set_pin_power_state(codec, 0x22, &parm);
  3017. else
  3018. update_power_state(codec, 0x22, AC_PWRST_D3);
  3019. /* SW2(26h), AIW1(14h) */
  3020. update_power_state(codec, 0x26, parm);
  3021. update_power_state(codec, 0x14, parm);
  3022. /* outputs */
  3023. /* PW0 (19h), SW1 (18h), AOW1 (11h) */
  3024. parm = AC_PWRST_D3;
  3025. set_pin_power_state(codec, 0x19, &parm);
  3026. /* Smart 5.1 PW2(1bh) */
  3027. if (spec->smart51_enabled)
  3028. set_pin_power_state(codec, 0x1b, &parm);
  3029. update_power_state(codec, 0x18, parm);
  3030. update_power_state(codec, 0x11, parm);
  3031. /* PW7 (23h), SW3 (27h), AOW3 (25h) */
  3032. parm = AC_PWRST_D3;
  3033. set_pin_power_state(codec, 0x23, &parm);
  3034. /* Smart 5.1 PW1(1ah) */
  3035. if (spec->smart51_enabled)
  3036. set_pin_power_state(codec, 0x1a, &parm);
  3037. update_power_state(codec, 0x27, parm);
  3038. /* Smart 5.1 PW5(1eh) */
  3039. if (spec->smart51_enabled)
  3040. set_pin_power_state(codec, 0x1e, &parm);
  3041. update_power_state(codec, 0x25, parm);
  3042. /* Mono out */
  3043. /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
  3044. present = snd_hda_jack_detect(codec, 0x1c);
  3045. if (present)
  3046. mono_out = 0;
  3047. else {
  3048. present = snd_hda_jack_detect(codec, 0x1d);
  3049. if (!spec->hp_independent_mode && present)
  3050. mono_out = 0;
  3051. else
  3052. mono_out = 1;
  3053. }
  3054. parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
  3055. update_power_state(codec, 0x28, parm);
  3056. update_power_state(codec, 0x29, parm);
  3057. update_power_state(codec, 0x2a, parm);
  3058. /* PW 3/4 (1ch/1dh) */
  3059. parm = AC_PWRST_D3;
  3060. set_pin_power_state(codec, 0x1c, &parm);
  3061. set_pin_power_state(codec, 0x1d, &parm);
  3062. /* HP Independent Mode, power on AOW3 */
  3063. if (spec->hp_independent_mode)
  3064. update_power_state(codec, 0x25, parm);
  3065. /* force to D0 for internal Speaker */
  3066. /* MW0 (16h), AOW0 (10h) */
  3067. update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
  3068. update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
  3069. }
  3070. static int patch_vt1716S(struct hda_codec *codec)
  3071. {
  3072. struct via_spec *spec;
  3073. int err;
  3074. /* create a codec specific record */
  3075. spec = via_new_spec(codec);
  3076. if (spec == NULL)
  3077. return -ENOMEM;
  3078. spec->aa_mix_nid = 0x16;
  3079. override_mic_boost(codec, 0x1a, 0, 3, 40);
  3080. override_mic_boost(codec, 0x1e, 0, 3, 40);
  3081. /* automatic parse from the BIOS config */
  3082. err = via_parse_auto_config(codec);
  3083. if (err < 0) {
  3084. via_free(codec);
  3085. return err;
  3086. }
  3087. spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
  3088. spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
  3089. spec->num_mixers++;
  3090. spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
  3091. codec->patch_ops = via_patch_ops;
  3092. spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
  3093. return 0;
  3094. }
  3095. /* for vt2002P */
  3096. static const struct hda_verb vt2002P_init_verbs[] = {
  3097. /* Class-D speaker related verbs */
  3098. {0x1, 0xfe0, 0x4},
  3099. {0x1, 0xfe9, 0x80},
  3100. {0x1, 0xfe2, 0x22},
  3101. /* Enable Boost Volume backdoor */
  3102. {0x1, 0xfb9, 0x24},
  3103. /* Enable AOW0 to MW9 */
  3104. {0x1, 0xfb8, 0x88},
  3105. { }
  3106. };
  3107. static const struct hda_verb vt1802_init_verbs[] = {
  3108. /* Enable Boost Volume backdoor */
  3109. {0x1, 0xfb9, 0x24},
  3110. /* Enable AOW0 to MW9 */
  3111. {0x1, 0xfb8, 0x88},
  3112. { }
  3113. };
  3114. static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
  3115. {
  3116. struct via_spec *spec = codec->spec;
  3117. int imux_is_smixer;
  3118. unsigned int parm;
  3119. unsigned int present;
  3120. /* MUX9 (1eh) = stereo mixer */
  3121. imux_is_smixer =
  3122. snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
  3123. /* inputs */
  3124. /* PW 5/6/7 (29h/2ah/2bh) */
  3125. parm = AC_PWRST_D3;
  3126. set_pin_power_state(codec, 0x29, &parm);
  3127. set_pin_power_state(codec, 0x2a, &parm);
  3128. set_pin_power_state(codec, 0x2b, &parm);
  3129. parm = AC_PWRST_D0;
  3130. /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
  3131. update_power_state(codec, 0x1e, parm);
  3132. update_power_state(codec, 0x1f, parm);
  3133. update_power_state(codec, 0x10, parm);
  3134. update_power_state(codec, 0x11, parm);
  3135. /* outputs */
  3136. /* AOW0 (8h)*/
  3137. update_power_state(codec, 0x8, parm);
  3138. if (spec->codec_type == VT1802) {
  3139. /* PW4 (28h), MW4 (18h), MUX4(38h) */
  3140. parm = AC_PWRST_D3;
  3141. set_pin_power_state(codec, 0x28, &parm);
  3142. update_power_state(codec, 0x18, parm);
  3143. update_power_state(codec, 0x38, parm);
  3144. } else {
  3145. /* PW4 (26h), MW4 (1ch), MUX4(37h) */
  3146. parm = AC_PWRST_D3;
  3147. set_pin_power_state(codec, 0x26, &parm);
  3148. update_power_state(codec, 0x1c, parm);
  3149. update_power_state(codec, 0x37, parm);
  3150. }
  3151. if (spec->codec_type == VT1802) {
  3152. /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
  3153. parm = AC_PWRST_D3;
  3154. set_pin_power_state(codec, 0x25, &parm);
  3155. update_power_state(codec, 0x15, parm);
  3156. update_power_state(codec, 0x35, parm);
  3157. } else {
  3158. /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
  3159. parm = AC_PWRST_D3;
  3160. set_pin_power_state(codec, 0x25, &parm);
  3161. update_power_state(codec, 0x19, parm);
  3162. update_power_state(codec, 0x35, parm);
  3163. }
  3164. if (spec->hp_independent_mode)
  3165. update_power_state(codec, 0x9, AC_PWRST_D0);
  3166. /* Class-D */
  3167. /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
  3168. present = snd_hda_jack_detect(codec, 0x25);
  3169. parm = AC_PWRST_D3;
  3170. set_pin_power_state(codec, 0x24, &parm);
  3171. parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
  3172. if (spec->codec_type == VT1802)
  3173. update_power_state(codec, 0x14, parm);
  3174. else
  3175. update_power_state(codec, 0x18, parm);
  3176. update_power_state(codec, 0x34, parm);
  3177. /* Mono Out */
  3178. present = snd_hda_jack_detect(codec, 0x26);
  3179. parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
  3180. if (spec->codec_type == VT1802) {
  3181. /* PW15 (33h), MW8(1ch), MUX8(3ch) */
  3182. update_power_state(codec, 0x33, parm);
  3183. update_power_state(codec, 0x1c, parm);
  3184. update_power_state(codec, 0x3c, parm);
  3185. } else {
  3186. /* PW15 (31h), MW8(17h), MUX8(3bh) */
  3187. update_power_state(codec, 0x31, parm);
  3188. update_power_state(codec, 0x17, parm);
  3189. update_power_state(codec, 0x3b, parm);
  3190. }
  3191. /* MW9 (21h) */
  3192. if (imux_is_smixer || !is_aa_path_mute(codec))
  3193. update_power_state(codec, 0x21, AC_PWRST_D0);
  3194. else
  3195. update_power_state(codec, 0x21, AC_PWRST_D3);
  3196. }
  3197. /*
  3198. * pin fix-up
  3199. */
  3200. enum {
  3201. VIA_FIXUP_INTMIC_BOOST,
  3202. VIA_FIXUP_ASUS_G75,
  3203. };
  3204. static void via_fixup_intmic_boost(struct hda_codec *codec,
  3205. const struct hda_fixup *fix, int action)
  3206. {
  3207. if (action == HDA_FIXUP_ACT_PRE_PROBE)
  3208. override_mic_boost(codec, 0x30, 0, 2, 40);
  3209. }
  3210. static const struct hda_fixup via_fixups[] = {
  3211. [VIA_FIXUP_INTMIC_BOOST] = {
  3212. .type = HDA_FIXUP_FUNC,
  3213. .v.func = via_fixup_intmic_boost,
  3214. },
  3215. [VIA_FIXUP_ASUS_G75] = {
  3216. .type = HDA_FIXUP_PINS,
  3217. .v.pins = (const struct hda_pintbl[]) {
  3218. /* set 0x24 and 0x33 as speakers */
  3219. { 0x24, 0x991301f0 },
  3220. { 0x33, 0x991301f1 }, /* subwoofer */
  3221. { }
  3222. }
  3223. },
  3224. };
  3225. static const struct snd_pci_quirk vt2002p_fixups[] = {
  3226. SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
  3227. SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
  3228. {}
  3229. };
  3230. /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
  3231. * Replace this with mixer NID 0x1c
  3232. */
  3233. static void fix_vt1802_connections(struct hda_codec *codec)
  3234. {
  3235. static hda_nid_t conn_24[] = { 0x14, 0x1c };
  3236. static hda_nid_t conn_33[] = { 0x1c };
  3237. snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
  3238. snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
  3239. }
  3240. /* patch for vt2002P */
  3241. static int patch_vt2002P(struct hda_codec *codec)
  3242. {
  3243. struct via_spec *spec;
  3244. int err;
  3245. /* create a codec specific record */
  3246. spec = via_new_spec(codec);
  3247. if (spec == NULL)
  3248. return -ENOMEM;
  3249. spec->aa_mix_nid = 0x21;
  3250. override_mic_boost(codec, 0x2b, 0, 3, 40);
  3251. override_mic_boost(codec, 0x29, 0, 3, 40);
  3252. if (spec->codec_type == VT1802)
  3253. fix_vt1802_connections(codec);
  3254. add_secret_dac_path(codec);
  3255. snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
  3256. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  3257. /* automatic parse from the BIOS config */
  3258. err = via_parse_auto_config(codec);
  3259. if (err < 0) {
  3260. via_free(codec);
  3261. return err;
  3262. }
  3263. if (spec->codec_type == VT1802)
  3264. spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
  3265. else
  3266. spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
  3267. codec->patch_ops = via_patch_ops;
  3268. spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
  3269. return 0;
  3270. }
  3271. /* for vt1812 */
  3272. static const struct hda_verb vt1812_init_verbs[] = {
  3273. /* Enable Boost Volume backdoor */
  3274. {0x1, 0xfb9, 0x24},
  3275. /* Enable AOW0 to MW9 */
  3276. {0x1, 0xfb8, 0xa8},
  3277. { }
  3278. };
  3279. static void set_widgets_power_state_vt1812(struct hda_codec *codec)
  3280. {
  3281. struct via_spec *spec = codec->spec;
  3282. unsigned int parm;
  3283. unsigned int present;
  3284. /* inputs */
  3285. /* PW 5/6/7 (29h/2ah/2bh) */
  3286. parm = AC_PWRST_D3;
  3287. set_pin_power_state(codec, 0x29, &parm);
  3288. set_pin_power_state(codec, 0x2a, &parm);
  3289. set_pin_power_state(codec, 0x2b, &parm);
  3290. parm = AC_PWRST_D0;
  3291. /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
  3292. update_power_state(codec, 0x1e, parm);
  3293. update_power_state(codec, 0x1f, parm);
  3294. update_power_state(codec, 0x10, parm);
  3295. update_power_state(codec, 0x11, parm);
  3296. /* outputs */
  3297. /* AOW0 (8h)*/
  3298. update_power_state(codec, 0x8, AC_PWRST_D0);
  3299. /* PW4 (28h), MW4 (18h), MUX4(38h) */
  3300. parm = AC_PWRST_D3;
  3301. set_pin_power_state(codec, 0x28, &parm);
  3302. update_power_state(codec, 0x18, parm);
  3303. update_power_state(codec, 0x38, parm);
  3304. /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
  3305. parm = AC_PWRST_D3;
  3306. set_pin_power_state(codec, 0x25, &parm);
  3307. update_power_state(codec, 0x15, parm);
  3308. update_power_state(codec, 0x35, parm);
  3309. if (spec->hp_independent_mode)
  3310. update_power_state(codec, 0x9, AC_PWRST_D0);
  3311. /* Internal Speaker */
  3312. /* PW0 (24h), MW0(14h), MUX0(34h) */
  3313. present = snd_hda_jack_detect(codec, 0x25);
  3314. parm = AC_PWRST_D3;
  3315. set_pin_power_state(codec, 0x24, &parm);
  3316. if (present) {
  3317. update_power_state(codec, 0x14, AC_PWRST_D3);
  3318. update_power_state(codec, 0x34, AC_PWRST_D3);
  3319. } else {
  3320. update_power_state(codec, 0x14, AC_PWRST_D0);
  3321. update_power_state(codec, 0x34, AC_PWRST_D0);
  3322. }
  3323. /* Mono Out */
  3324. /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
  3325. present = snd_hda_jack_detect(codec, 0x28);
  3326. parm = AC_PWRST_D3;
  3327. set_pin_power_state(codec, 0x31, &parm);
  3328. if (present) {
  3329. update_power_state(codec, 0x1c, AC_PWRST_D3);
  3330. update_power_state(codec, 0x3c, AC_PWRST_D3);
  3331. update_power_state(codec, 0x3e, AC_PWRST_D3);
  3332. } else {
  3333. update_power_state(codec, 0x1c, AC_PWRST_D0);
  3334. update_power_state(codec, 0x3c, AC_PWRST_D0);
  3335. update_power_state(codec, 0x3e, AC_PWRST_D0);
  3336. }
  3337. /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
  3338. parm = AC_PWRST_D3;
  3339. set_pin_power_state(codec, 0x33, &parm);
  3340. update_power_state(codec, 0x1d, parm);
  3341. update_power_state(codec, 0x3d, parm);
  3342. }
  3343. /* patch for vt1812 */
  3344. static int patch_vt1812(struct hda_codec *codec)
  3345. {
  3346. struct via_spec *spec;
  3347. int err;
  3348. /* create a codec specific record */
  3349. spec = via_new_spec(codec);
  3350. if (spec == NULL)
  3351. return -ENOMEM;
  3352. spec->aa_mix_nid = 0x21;
  3353. override_mic_boost(codec, 0x2b, 0, 3, 40);
  3354. override_mic_boost(codec, 0x29, 0, 3, 40);
  3355. add_secret_dac_path(codec);
  3356. /* automatic parse from the BIOS config */
  3357. err = via_parse_auto_config(codec);
  3358. if (err < 0) {
  3359. via_free(codec);
  3360. return err;
  3361. }
  3362. spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
  3363. codec->patch_ops = via_patch_ops;
  3364. spec->set_widgets_power_state = set_widgets_power_state_vt1812;
  3365. return 0;
  3366. }
  3367. /* patch for vt3476 */
  3368. static const struct hda_verb vt3476_init_verbs[] = {
  3369. /* Enable DMic 8/16/32K */
  3370. {0x1, 0xF7B, 0x30},
  3371. /* Enable Boost Volume backdoor */
  3372. {0x1, 0xFB9, 0x20},
  3373. /* Enable AOW-MW9 path */
  3374. {0x1, 0xFB8, 0x10},
  3375. { }
  3376. };
  3377. static void set_widgets_power_state_vt3476(struct hda_codec *codec)
  3378. {
  3379. struct via_spec *spec = codec->spec;
  3380. int imux_is_smixer;
  3381. unsigned int parm, parm2;
  3382. /* MUX10 (1eh) = stereo mixer */
  3383. imux_is_smixer =
  3384. snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
  3385. /* inputs */
  3386. /* PW 5/6/7 (29h/2ah/2bh) */
  3387. parm = AC_PWRST_D3;
  3388. set_pin_power_state(codec, 0x29, &parm);
  3389. set_pin_power_state(codec, 0x2a, &parm);
  3390. set_pin_power_state(codec, 0x2b, &parm);
  3391. if (imux_is_smixer)
  3392. parm = AC_PWRST_D0;
  3393. /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
  3394. update_power_state(codec, 0x1e, parm);
  3395. update_power_state(codec, 0x1f, parm);
  3396. update_power_state(codec, 0x10, parm);
  3397. update_power_state(codec, 0x11, parm);
  3398. /* outputs */
  3399. /* PW3 (27h), MW3(37h), AOW3 (bh) */
  3400. if (spec->codec_type == VT1705CF) {
  3401. parm = AC_PWRST_D3;
  3402. update_power_state(codec, 0x27, parm);
  3403. update_power_state(codec, 0x37, parm);
  3404. } else {
  3405. parm = AC_PWRST_D3;
  3406. set_pin_power_state(codec, 0x27, &parm);
  3407. update_power_state(codec, 0x37, parm);
  3408. }
  3409. /* PW2 (26h), MW2(36h), AOW2 (ah) */
  3410. parm = AC_PWRST_D3;
  3411. set_pin_power_state(codec, 0x26, &parm);
  3412. update_power_state(codec, 0x36, parm);
  3413. if (spec->smart51_enabled) {
  3414. /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
  3415. set_pin_power_state(codec, 0x2b, &parm);
  3416. update_power_state(codec, 0x3b, parm);
  3417. update_power_state(codec, 0x1b, parm);
  3418. }
  3419. update_conv_power_state(codec, 0xa, parm, 2);
  3420. /* PW1 (25h), MW1(35h), AOW1 (9h) */
  3421. parm = AC_PWRST_D3;
  3422. set_pin_power_state(codec, 0x25, &parm);
  3423. update_power_state(codec, 0x35, parm);
  3424. if (spec->smart51_enabled) {
  3425. /* PW6(2ah), MW6(3ah), MUX6(1ah) */
  3426. set_pin_power_state(codec, 0x2a, &parm);
  3427. update_power_state(codec, 0x3a, parm);
  3428. update_power_state(codec, 0x1a, parm);
  3429. }
  3430. update_conv_power_state(codec, 0x9, parm, 1);
  3431. /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
  3432. parm = AC_PWRST_D3;
  3433. set_pin_power_state(codec, 0x28, &parm);
  3434. update_power_state(codec, 0x38, parm);
  3435. update_power_state(codec, 0x18, parm);
  3436. if (spec->hp_independent_mode)
  3437. update_conv_power_state(codec, 0xb, parm, 3);
  3438. parm2 = parm; /* for pin 0x0b */
  3439. /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
  3440. parm = AC_PWRST_D3;
  3441. set_pin_power_state(codec, 0x24, &parm);
  3442. update_power_state(codec, 0x34, parm);
  3443. if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3)
  3444. parm = parm2;
  3445. update_conv_power_state(codec, 0x8, parm, 0);
  3446. /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
  3447. update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
  3448. }
  3449. static int patch_vt3476(struct hda_codec *codec)
  3450. {
  3451. struct via_spec *spec;
  3452. int err;
  3453. /* create a codec specific record */
  3454. spec = via_new_spec(codec);
  3455. if (spec == NULL)
  3456. return -ENOMEM;
  3457. spec->aa_mix_nid = 0x3f;
  3458. add_secret_dac_path(codec);
  3459. /* automatic parse from the BIOS config */
  3460. err = via_parse_auto_config(codec);
  3461. if (err < 0) {
  3462. via_free(codec);
  3463. return err;
  3464. }
  3465. spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
  3466. codec->patch_ops = via_patch_ops;
  3467. spec->set_widgets_power_state = set_widgets_power_state_vt3476;
  3468. return 0;
  3469. }
  3470. /*
  3471. * patch entries
  3472. */
  3473. static const struct hda_codec_preset snd_hda_preset_via[] = {
  3474. { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
  3475. { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
  3476. { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
  3477. { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
  3478. { .id = 0x1106e710, .name = "VT1709 10-Ch",
  3479. .patch = patch_vt1709},
  3480. { .id = 0x1106e711, .name = "VT1709 10-Ch",
  3481. .patch = patch_vt1709},
  3482. { .id = 0x1106e712, .name = "VT1709 10-Ch",
  3483. .patch = patch_vt1709},
  3484. { .id = 0x1106e713, .name = "VT1709 10-Ch",
  3485. .patch = patch_vt1709},
  3486. { .id = 0x1106e714, .name = "VT1709 6-Ch",
  3487. .patch = patch_vt1709},
  3488. { .id = 0x1106e715, .name = "VT1709 6-Ch",
  3489. .patch = patch_vt1709},
  3490. { .id = 0x1106e716, .name = "VT1709 6-Ch",
  3491. .patch = patch_vt1709},
  3492. { .id = 0x1106e717, .name = "VT1709 6-Ch",
  3493. .patch = patch_vt1709},
  3494. { .id = 0x1106e720, .name = "VT1708B 8-Ch",
  3495. .patch = patch_vt1708B},
  3496. { .id = 0x1106e721, .name = "VT1708B 8-Ch",
  3497. .patch = patch_vt1708B},
  3498. { .id = 0x1106e722, .name = "VT1708B 8-Ch",
  3499. .patch = patch_vt1708B},
  3500. { .id = 0x1106e723, .name = "VT1708B 8-Ch",
  3501. .patch = patch_vt1708B},
  3502. { .id = 0x1106e724, .name = "VT1708B 4-Ch",
  3503. .patch = patch_vt1708B},
  3504. { .id = 0x1106e725, .name = "VT1708B 4-Ch",
  3505. .patch = patch_vt1708B},
  3506. { .id = 0x1106e726, .name = "VT1708B 4-Ch",
  3507. .patch = patch_vt1708B},
  3508. { .id = 0x1106e727, .name = "VT1708B 4-Ch",
  3509. .patch = patch_vt1708B},
  3510. { .id = 0x11060397, .name = "VT1708S",
  3511. .patch = patch_vt1708S},
  3512. { .id = 0x11061397, .name = "VT1708S",
  3513. .patch = patch_vt1708S},
  3514. { .id = 0x11062397, .name = "VT1708S",
  3515. .patch = patch_vt1708S},
  3516. { .id = 0x11063397, .name = "VT1708S",
  3517. .patch = patch_vt1708S},
  3518. { .id = 0x11064397, .name = "VT1705",
  3519. .patch = patch_vt1708S},
  3520. { .id = 0x11065397, .name = "VT1708S",
  3521. .patch = patch_vt1708S},
  3522. { .id = 0x11066397, .name = "VT1708S",
  3523. .patch = patch_vt1708S},
  3524. { .id = 0x11067397, .name = "VT1708S",
  3525. .patch = patch_vt1708S},
  3526. { .id = 0x11060398, .name = "VT1702",
  3527. .patch = patch_vt1702},
  3528. { .id = 0x11061398, .name = "VT1702",
  3529. .patch = patch_vt1702},
  3530. { .id = 0x11062398, .name = "VT1702",
  3531. .patch = patch_vt1702},
  3532. { .id = 0x11063398, .name = "VT1702",
  3533. .patch = patch_vt1702},
  3534. { .id = 0x11064398, .name = "VT1702",
  3535. .patch = patch_vt1702},
  3536. { .id = 0x11065398, .name = "VT1702",
  3537. .patch = patch_vt1702},
  3538. { .id = 0x11066398, .name = "VT1702",
  3539. .patch = patch_vt1702},
  3540. { .id = 0x11067398, .name = "VT1702",
  3541. .patch = patch_vt1702},
  3542. { .id = 0x11060428, .name = "VT1718S",
  3543. .patch = patch_vt1718S},
  3544. { .id = 0x11064428, .name = "VT1718S",
  3545. .patch = patch_vt1718S},
  3546. { .id = 0x11060441, .name = "VT2020",
  3547. .patch = patch_vt1718S},
  3548. { .id = 0x11064441, .name = "VT1828S",
  3549. .patch = patch_vt1718S},
  3550. { .id = 0x11060433, .name = "VT1716S",
  3551. .patch = patch_vt1716S},
  3552. { .id = 0x1106a721, .name = "VT1716S",
  3553. .patch = patch_vt1716S},
  3554. { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
  3555. { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
  3556. { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
  3557. { .id = 0x11060440, .name = "VT1818S",
  3558. .patch = patch_vt1708S},
  3559. { .id = 0x11060446, .name = "VT1802",
  3560. .patch = patch_vt2002P},
  3561. { .id = 0x11068446, .name = "VT1802",
  3562. .patch = patch_vt2002P},
  3563. { .id = 0x11064760, .name = "VT1705CF",
  3564. .patch = patch_vt3476},
  3565. { .id = 0x11064761, .name = "VT1708SCE",
  3566. .patch = patch_vt3476},
  3567. { .id = 0x11064762, .name = "VT1808",
  3568. .patch = patch_vt3476},
  3569. {} /* terminator */
  3570. };
  3571. MODULE_ALIAS("snd-hda-codec-id:1106*");
  3572. static struct hda_codec_preset_list via_list = {
  3573. .preset = snd_hda_preset_via,
  3574. .owner = THIS_MODULE,
  3575. };
  3576. MODULE_LICENSE("GPL");
  3577. MODULE_DESCRIPTION("VIA HD-audio codec");
  3578. static int __init patch_via_init(void)
  3579. {
  3580. return snd_hda_add_codec_preset(&via_list);
  3581. }
  3582. static void __exit patch_via_exit(void)
  3583. {
  3584. snd_hda_delete_codec_preset(&via_list);
  3585. }
  3586. module_init(patch_via_init)
  3587. module_exit(patch_via_exit)