patch_via.c 104 KB

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