patch_via.c 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939
  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_SND_HDA_POWER_SAVE
  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. #endif
  1578. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1579. .check_power_status = via_check_power_status,
  1580. #endif
  1581. };
  1582. static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
  1583. {
  1584. struct via_spec *spec = codec->spec;
  1585. int i;
  1586. for (i = 0; i < spec->multiout.num_dacs; i++) {
  1587. if (spec->multiout.dac_nids[i] == dac)
  1588. return false;
  1589. }
  1590. if (spec->hp_dac_nid == dac)
  1591. return false;
  1592. return true;
  1593. }
  1594. static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
  1595. hda_nid_t target_dac, int with_aa_mix,
  1596. struct nid_path *path, int depth)
  1597. {
  1598. struct via_spec *spec = codec->spec;
  1599. hda_nid_t conn[8];
  1600. int i, nums;
  1601. if (nid == spec->aa_mix_nid) {
  1602. if (!with_aa_mix)
  1603. return false;
  1604. with_aa_mix = 2; /* mark aa-mix is included */
  1605. }
  1606. nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
  1607. for (i = 0; i < nums; i++) {
  1608. if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
  1609. continue;
  1610. if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
  1611. /* aa-mix is requested but not included? */
  1612. if (!(spec->aa_mix_nid && with_aa_mix == 1))
  1613. goto found;
  1614. }
  1615. }
  1616. if (depth >= MAX_NID_PATH_DEPTH)
  1617. return false;
  1618. for (i = 0; i < nums; i++) {
  1619. unsigned int type;
  1620. type = get_wcaps_type(get_wcaps(codec, conn[i]));
  1621. if (type == AC_WID_AUD_OUT)
  1622. continue;
  1623. if (__parse_output_path(codec, conn[i], target_dac,
  1624. with_aa_mix, path, depth + 1))
  1625. goto found;
  1626. }
  1627. return false;
  1628. found:
  1629. path->path[path->depth] = conn[i];
  1630. path->idx[path->depth] = i;
  1631. if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
  1632. path->multi[path->depth] = 1;
  1633. path->depth++;
  1634. return true;
  1635. }
  1636. static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
  1637. hda_nid_t target_dac, int with_aa_mix,
  1638. struct nid_path *path)
  1639. {
  1640. if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
  1641. path->path[path->depth] = nid;
  1642. path->depth++;
  1643. snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
  1644. path->depth, path->path[0], path->path[1],
  1645. path->path[2], path->path[3], path->path[4]);
  1646. return true;
  1647. }
  1648. return false;
  1649. }
  1650. static int via_auto_fill_dac_nids(struct hda_codec *codec)
  1651. {
  1652. struct via_spec *spec = codec->spec;
  1653. const struct auto_pin_cfg *cfg = &spec->autocfg;
  1654. int i, dac_num;
  1655. hda_nid_t nid;
  1656. spec->multiout.dac_nids = spec->private_dac_nids;
  1657. dac_num = 0;
  1658. for (i = 0; i < cfg->line_outs; i++) {
  1659. hda_nid_t dac = 0;
  1660. nid = cfg->line_out_pins[i];
  1661. if (!nid)
  1662. continue;
  1663. if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
  1664. dac = spec->out_path[i].path[0];
  1665. if (!i && parse_output_path(codec, nid, dac, 1,
  1666. &spec->out_mix_path))
  1667. dac = spec->out_mix_path.path[0];
  1668. if (dac) {
  1669. spec->private_dac_nids[i] = dac;
  1670. dac_num++;
  1671. }
  1672. }
  1673. if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
  1674. spec->out_path[0] = spec->out_mix_path;
  1675. spec->out_mix_path.depth = 0;
  1676. }
  1677. spec->multiout.num_dacs = dac_num;
  1678. return 0;
  1679. }
  1680. static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
  1681. int chs, bool check_dac, struct nid_path *path)
  1682. {
  1683. struct via_spec *spec = codec->spec;
  1684. char name[32];
  1685. hda_nid_t dac, pin, sel, nid;
  1686. int err;
  1687. dac = check_dac ? path->path[0] : 0;
  1688. pin = path->path[path->depth - 1];
  1689. sel = path->depth > 1 ? path->path[1] : 0;
  1690. if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
  1691. nid = dac;
  1692. else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
  1693. nid = pin;
  1694. else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
  1695. nid = sel;
  1696. else
  1697. nid = 0;
  1698. if (nid) {
  1699. sprintf(name, "%s Playback Volume", pfx);
  1700. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1701. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1702. if (err < 0)
  1703. return err;
  1704. path->vol_ctl = nid;
  1705. }
  1706. if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
  1707. nid = dac;
  1708. else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
  1709. nid = pin;
  1710. else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
  1711. nid = sel;
  1712. else
  1713. nid = 0;
  1714. if (nid) {
  1715. sprintf(name, "%s Playback Switch", pfx);
  1716. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1717. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1718. if (err < 0)
  1719. return err;
  1720. path->mute_ctl = nid;
  1721. }
  1722. return 0;
  1723. }
  1724. static void mangle_smart51(struct hda_codec *codec)
  1725. {
  1726. struct via_spec *spec = codec->spec;
  1727. struct auto_pin_cfg *cfg = &spec->autocfg;
  1728. struct auto_pin_cfg_item *ins = cfg->inputs;
  1729. int i, j, nums, attr;
  1730. int pins[AUTO_CFG_MAX_INS];
  1731. for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
  1732. nums = 0;
  1733. for (i = 0; i < cfg->num_inputs; i++) {
  1734. unsigned int def;
  1735. if (ins[i].type > AUTO_PIN_LINE_IN)
  1736. continue;
  1737. def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
  1738. if (snd_hda_get_input_pin_attr(def) != attr)
  1739. continue;
  1740. for (j = 0; j < nums; j++)
  1741. if (ins[pins[j]].type < ins[i].type) {
  1742. memmove(pins + j + 1, pins + j,
  1743. (nums - j) * sizeof(int));
  1744. break;
  1745. }
  1746. pins[j] = i;
  1747. nums++;
  1748. }
  1749. if (cfg->line_outs + nums < 3)
  1750. continue;
  1751. for (i = 0; i < nums; i++) {
  1752. hda_nid_t pin = ins[pins[i]].pin;
  1753. spec->smart51_pins[spec->smart51_nums++] = pin;
  1754. cfg->line_out_pins[cfg->line_outs++] = pin;
  1755. if (cfg->line_outs == 3)
  1756. break;
  1757. }
  1758. return;
  1759. }
  1760. }
  1761. static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
  1762. {
  1763. dst->vol_ctl = src->vol_ctl;
  1764. dst->mute_ctl = src->mute_ctl;
  1765. }
  1766. /* add playback controls from the parsed DAC table */
  1767. static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
  1768. {
  1769. struct via_spec *spec = codec->spec;
  1770. struct auto_pin_cfg *cfg = &spec->autocfg;
  1771. struct nid_path *path;
  1772. static const char * const chname[4] = {
  1773. "Front", "Surround", "C/LFE", "Side"
  1774. };
  1775. int i, idx, err;
  1776. int old_line_outs;
  1777. /* check smart51 */
  1778. old_line_outs = cfg->line_outs;
  1779. if (cfg->line_outs == 1)
  1780. mangle_smart51(codec);
  1781. err = via_auto_fill_dac_nids(codec);
  1782. if (err < 0)
  1783. return err;
  1784. if (spec->multiout.num_dacs < 3) {
  1785. spec->smart51_nums = 0;
  1786. cfg->line_outs = old_line_outs;
  1787. }
  1788. for (i = 0; i < cfg->line_outs; i++) {
  1789. hda_nid_t pin, dac;
  1790. pin = cfg->line_out_pins[i];
  1791. dac = spec->multiout.dac_nids[i];
  1792. if (!pin || !dac)
  1793. continue;
  1794. path = spec->out_path + i;
  1795. if (i == HDA_CLFE) {
  1796. err = create_ch_ctls(codec, "Center", 1, true, path);
  1797. if (err < 0)
  1798. return err;
  1799. err = create_ch_ctls(codec, "LFE", 2, true, path);
  1800. if (err < 0)
  1801. return err;
  1802. } else {
  1803. const char *pfx = chname[i];
  1804. if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
  1805. cfg->line_outs == 1)
  1806. pfx = "Speaker";
  1807. err = create_ch_ctls(codec, pfx, 3, true, path);
  1808. if (err < 0)
  1809. return err;
  1810. }
  1811. if (path != spec->out_path + i)
  1812. copy_path_mixer_ctls(&spec->out_path[i], path);
  1813. if (path == spec->out_path && spec->out_mix_path.depth)
  1814. copy_path_mixer_ctls(&spec->out_mix_path, path);
  1815. }
  1816. idx = get_connection_index(codec, spec->aa_mix_nid,
  1817. spec->multiout.dac_nids[0]);
  1818. if (idx >= 0) {
  1819. /* add control to mixer */
  1820. const char *name;
  1821. name = spec->out_mix_path.depth ?
  1822. "PCM Loopback Playback Volume" : "PCM Playback Volume";
  1823. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1824. HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
  1825. idx, HDA_INPUT));
  1826. if (err < 0)
  1827. return err;
  1828. name = spec->out_mix_path.depth ?
  1829. "PCM Loopback Playback Switch" : "PCM Playback Switch";
  1830. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1831. HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
  1832. idx, HDA_INPUT));
  1833. if (err < 0)
  1834. return err;
  1835. }
  1836. cfg->line_outs = old_line_outs;
  1837. return 0;
  1838. }
  1839. static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
  1840. {
  1841. struct via_spec *spec = codec->spec;
  1842. struct nid_path *path;
  1843. bool check_dac;
  1844. int i, err;
  1845. if (!pin)
  1846. return 0;
  1847. if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
  1848. for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
  1849. if (i < spec->multiout.num_dacs &&
  1850. parse_output_path(codec, pin,
  1851. spec->multiout.dac_nids[i], 0,
  1852. &spec->hp_indep_path)) {
  1853. spec->hp_indep_shared = i;
  1854. break;
  1855. }
  1856. }
  1857. }
  1858. if (spec->hp_indep_path.depth) {
  1859. spec->hp_dac_nid = spec->hp_indep_path.path[0];
  1860. if (!spec->hp_indep_shared)
  1861. spec->hp_path = spec->hp_indep_path;
  1862. }
  1863. /* optionally check front-path w/o AA-mix */
  1864. if (!spec->hp_path.depth)
  1865. parse_output_path(codec, pin,
  1866. spec->multiout.dac_nids[HDA_FRONT], 0,
  1867. &spec->hp_path);
  1868. if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
  1869. 1, &spec->hp_mix_path) && !spec->hp_path.depth)
  1870. return 0;
  1871. if (spec->hp_path.depth) {
  1872. path = &spec->hp_path;
  1873. check_dac = true;
  1874. } else {
  1875. path = &spec->hp_mix_path;
  1876. check_dac = false;
  1877. }
  1878. err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
  1879. if (err < 0)
  1880. return err;
  1881. if (check_dac)
  1882. copy_path_mixer_ctls(&spec->hp_mix_path, path);
  1883. else
  1884. copy_path_mixer_ctls(&spec->hp_path, path);
  1885. if (spec->hp_indep_path.depth)
  1886. copy_path_mixer_ctls(&spec->hp_indep_path, path);
  1887. return 0;
  1888. }
  1889. static int via_auto_create_speaker_ctls(struct hda_codec *codec)
  1890. {
  1891. struct via_spec *spec = codec->spec;
  1892. struct nid_path *path;
  1893. bool check_dac;
  1894. hda_nid_t pin, dac = 0;
  1895. int err;
  1896. pin = spec->autocfg.speaker_pins[0];
  1897. if (!spec->autocfg.speaker_outs || !pin)
  1898. return 0;
  1899. if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
  1900. dac = spec->speaker_path.path[0];
  1901. if (!dac)
  1902. parse_output_path(codec, pin,
  1903. spec->multiout.dac_nids[HDA_FRONT], 0,
  1904. &spec->speaker_path);
  1905. if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
  1906. 1, &spec->speaker_mix_path) && !dac)
  1907. return 0;
  1908. /* no AA-path for front? */
  1909. if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
  1910. dac = 0;
  1911. spec->speaker_dac_nid = dac;
  1912. spec->multiout.extra_out_nid[0] = dac;
  1913. if (dac) {
  1914. path = &spec->speaker_path;
  1915. check_dac = true;
  1916. } else {
  1917. path = &spec->speaker_mix_path;
  1918. check_dac = false;
  1919. }
  1920. err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
  1921. if (err < 0)
  1922. return err;
  1923. if (check_dac)
  1924. copy_path_mixer_ctls(&spec->speaker_mix_path, path);
  1925. else
  1926. copy_path_mixer_ctls(&spec->speaker_path, path);
  1927. return 0;
  1928. }
  1929. #define via_aamix_ctl_info via_pin_power_ctl_info
  1930. static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
  1931. struct snd_ctl_elem_value *ucontrol)
  1932. {
  1933. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1934. struct via_spec *spec = codec->spec;
  1935. ucontrol->value.enumerated.item[0] = spec->aamix_mode;
  1936. return 0;
  1937. }
  1938. static void update_aamix_paths(struct hda_codec *codec, int do_mix,
  1939. struct nid_path *nomix, struct nid_path *mix)
  1940. {
  1941. if (do_mix) {
  1942. activate_output_path(codec, nomix, false, false);
  1943. activate_output_path(codec, mix, true, false);
  1944. } else {
  1945. activate_output_path(codec, mix, false, false);
  1946. activate_output_path(codec, nomix, true, false);
  1947. }
  1948. }
  1949. static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
  1950. struct snd_ctl_elem_value *ucontrol)
  1951. {
  1952. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1953. struct via_spec *spec = codec->spec;
  1954. unsigned int val = ucontrol->value.enumerated.item[0];
  1955. if (val == spec->aamix_mode)
  1956. return 0;
  1957. spec->aamix_mode = val;
  1958. /* update front path */
  1959. update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
  1960. /* update HP path */
  1961. if (!spec->hp_independent_mode) {
  1962. update_aamix_paths(codec, val, &spec->hp_path,
  1963. &spec->hp_mix_path);
  1964. }
  1965. /* update speaker path */
  1966. update_aamix_paths(codec, val, &spec->speaker_path,
  1967. &spec->speaker_mix_path);
  1968. return 1;
  1969. }
  1970. static const struct snd_kcontrol_new via_aamix_ctl_enum = {
  1971. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1972. .name = "Loopback Mixing",
  1973. .info = via_aamix_ctl_info,
  1974. .get = via_aamix_ctl_get,
  1975. .put = via_aamix_ctl_put,
  1976. };
  1977. static int via_auto_create_loopback_switch(struct hda_codec *codec)
  1978. {
  1979. struct via_spec *spec = codec->spec;
  1980. if (!spec->aa_mix_nid)
  1981. return 0; /* no loopback switching available */
  1982. if (!(spec->out_mix_path.depth || spec->hp_mix_path.depth ||
  1983. spec->speaker_path.depth))
  1984. return 0; /* no loopback switching available */
  1985. if (!via_clone_control(spec, &via_aamix_ctl_enum))
  1986. return -ENOMEM;
  1987. return 0;
  1988. }
  1989. /* look for ADCs */
  1990. static int via_fill_adcs(struct hda_codec *codec)
  1991. {
  1992. struct via_spec *spec = codec->spec;
  1993. hda_nid_t nid = codec->start_nid;
  1994. int i;
  1995. for (i = 0; i < codec->num_nodes; i++, nid++) {
  1996. unsigned int wcaps = get_wcaps(codec, nid);
  1997. if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
  1998. continue;
  1999. if (wcaps & AC_WCAP_DIGITAL)
  2000. continue;
  2001. if (!(wcaps & AC_WCAP_CONN_LIST))
  2002. continue;
  2003. if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
  2004. return -ENOMEM;
  2005. spec->adc_nids[spec->num_adc_nids++] = nid;
  2006. }
  2007. return 0;
  2008. }
  2009. /* input-src control */
  2010. static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
  2011. struct snd_ctl_elem_info *uinfo)
  2012. {
  2013. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2014. struct via_spec *spec = codec->spec;
  2015. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2016. uinfo->count = 1;
  2017. uinfo->value.enumerated.items = spec->num_inputs;
  2018. if (uinfo->value.enumerated.item >= spec->num_inputs)
  2019. uinfo->value.enumerated.item = spec->num_inputs - 1;
  2020. strcpy(uinfo->value.enumerated.name,
  2021. spec->inputs[uinfo->value.enumerated.item].label);
  2022. return 0;
  2023. }
  2024. static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
  2025. struct snd_ctl_elem_value *ucontrol)
  2026. {
  2027. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2028. struct via_spec *spec = codec->spec;
  2029. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  2030. ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
  2031. return 0;
  2032. }
  2033. static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
  2034. struct snd_ctl_elem_value *ucontrol)
  2035. {
  2036. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2037. struct via_spec *spec = codec->spec;
  2038. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  2039. hda_nid_t mux;
  2040. int cur;
  2041. cur = ucontrol->value.enumerated.item[0];
  2042. if (cur < 0 || cur >= spec->num_inputs)
  2043. return -EINVAL;
  2044. if (spec->cur_mux[idx] == cur)
  2045. return 0;
  2046. spec->cur_mux[idx] = cur;
  2047. if (spec->dyn_adc_switch) {
  2048. int adc_idx = spec->inputs[cur].adc_idx;
  2049. mux = spec->mux_nids[adc_idx];
  2050. via_dyn_adc_pcm_resetup(codec, cur);
  2051. } else {
  2052. mux = spec->mux_nids[idx];
  2053. if (snd_BUG_ON(!mux))
  2054. return -EINVAL;
  2055. }
  2056. if (mux) {
  2057. /* switch to D0 beofre change index */
  2058. update_power_state(codec, mux, AC_PWRST_D0);
  2059. snd_hda_codec_write(codec, mux, 0,
  2060. AC_VERB_SET_CONNECT_SEL,
  2061. spec->inputs[cur].mux_idx);
  2062. }
  2063. /* update jack power state */
  2064. set_widgets_power_state(codec);
  2065. return 0;
  2066. }
  2067. static const struct snd_kcontrol_new via_input_src_ctl = {
  2068. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2069. /* The multiple "Capture Source" controls confuse alsamixer
  2070. * So call somewhat different..
  2071. */
  2072. /* .name = "Capture Source", */
  2073. .name = "Input Source",
  2074. .info = via_mux_enum_info,
  2075. .get = via_mux_enum_get,
  2076. .put = via_mux_enum_put,
  2077. };
  2078. static int create_input_src_ctls(struct hda_codec *codec, int count)
  2079. {
  2080. struct via_spec *spec = codec->spec;
  2081. struct snd_kcontrol_new *knew;
  2082. if (spec->num_inputs <= 1 || !count)
  2083. return 0; /* no need for single src */
  2084. knew = via_clone_control(spec, &via_input_src_ctl);
  2085. if (!knew)
  2086. return -ENOMEM;
  2087. knew->count = count;
  2088. return 0;
  2089. }
  2090. /* add the powersave loopback-list entry */
  2091. static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
  2092. {
  2093. struct hda_amp_list *list;
  2094. if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
  2095. return;
  2096. list = spec->loopback_list + spec->num_loopbacks;
  2097. list->nid = mix;
  2098. list->dir = HDA_INPUT;
  2099. list->idx = idx;
  2100. spec->num_loopbacks++;
  2101. spec->loopback.amplist = spec->loopback_list;
  2102. }
  2103. static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
  2104. hda_nid_t dst)
  2105. {
  2106. return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
  2107. }
  2108. /* add the input-route to the given pin */
  2109. static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
  2110. {
  2111. struct via_spec *spec = codec->spec;
  2112. int c, idx;
  2113. spec->inputs[spec->num_inputs].adc_idx = -1;
  2114. spec->inputs[spec->num_inputs].pin = pin;
  2115. for (c = 0; c < spec->num_adc_nids; c++) {
  2116. if (spec->mux_nids[c]) {
  2117. idx = get_connection_index(codec, spec->mux_nids[c],
  2118. pin);
  2119. if (idx < 0)
  2120. continue;
  2121. spec->inputs[spec->num_inputs].mux_idx = idx;
  2122. } else {
  2123. if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
  2124. continue;
  2125. }
  2126. spec->inputs[spec->num_inputs].adc_idx = c;
  2127. /* Can primary ADC satisfy all inputs? */
  2128. if (!spec->dyn_adc_switch &&
  2129. spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
  2130. snd_printd(KERN_INFO
  2131. "via: dynamic ADC switching enabled\n");
  2132. spec->dyn_adc_switch = 1;
  2133. }
  2134. return true;
  2135. }
  2136. return false;
  2137. }
  2138. static int get_mux_nids(struct hda_codec *codec);
  2139. /* parse input-routes; fill ADCs, MUXs and input-src entries */
  2140. static int parse_analog_inputs(struct hda_codec *codec)
  2141. {
  2142. struct via_spec *spec = codec->spec;
  2143. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2144. int i, err;
  2145. err = via_fill_adcs(codec);
  2146. if (err < 0)
  2147. return err;
  2148. err = get_mux_nids(codec);
  2149. if (err < 0)
  2150. return err;
  2151. /* fill all input-routes */
  2152. for (i = 0; i < cfg->num_inputs; i++) {
  2153. if (add_input_route(codec, cfg->inputs[i].pin))
  2154. spec->inputs[spec->num_inputs++].label =
  2155. hda_get_autocfg_input_label(codec, cfg, i);
  2156. }
  2157. /* check for internal loopback recording */
  2158. if (spec->aa_mix_nid &&
  2159. add_input_route(codec, spec->aa_mix_nid))
  2160. spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
  2161. return 0;
  2162. }
  2163. /* create analog-loopback volume/switch controls */
  2164. static int create_loopback_ctls(struct hda_codec *codec)
  2165. {
  2166. struct via_spec *spec = codec->spec;
  2167. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2168. const char *prev_label = NULL;
  2169. int type_idx = 0;
  2170. int i, j, err, idx;
  2171. if (!spec->aa_mix_nid)
  2172. return 0;
  2173. for (i = 0; i < cfg->num_inputs; i++) {
  2174. hda_nid_t pin = cfg->inputs[i].pin;
  2175. const char *label = hda_get_autocfg_input_label(codec, cfg, i);
  2176. if (prev_label && !strcmp(label, prev_label))
  2177. type_idx++;
  2178. else
  2179. type_idx = 0;
  2180. prev_label = label;
  2181. idx = get_connection_index(codec, spec->aa_mix_nid, pin);
  2182. if (idx >= 0) {
  2183. err = via_new_analog_input(spec, label, type_idx,
  2184. idx, spec->aa_mix_nid);
  2185. if (err < 0)
  2186. return err;
  2187. add_loopback_list(spec, spec->aa_mix_nid, idx);
  2188. }
  2189. /* remember the label for smart51 control */
  2190. for (j = 0; j < spec->smart51_nums; j++) {
  2191. if (spec->smart51_pins[j] == pin) {
  2192. spec->smart51_idxs[j] = idx;
  2193. spec->smart51_labels[j] = label;
  2194. break;
  2195. }
  2196. }
  2197. }
  2198. return 0;
  2199. }
  2200. /* create mic-boost controls (if present) */
  2201. static int create_mic_boost_ctls(struct hda_codec *codec)
  2202. {
  2203. struct via_spec *spec = codec->spec;
  2204. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2205. const char *prev_label = NULL;
  2206. int type_idx = 0;
  2207. int i, err;
  2208. for (i = 0; i < cfg->num_inputs; i++) {
  2209. hda_nid_t pin = cfg->inputs[i].pin;
  2210. unsigned int caps;
  2211. const char *label;
  2212. char name[32];
  2213. if (cfg->inputs[i].type != AUTO_PIN_MIC)
  2214. continue;
  2215. caps = query_amp_caps(codec, pin, HDA_INPUT);
  2216. if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
  2217. continue;
  2218. label = hda_get_autocfg_input_label(codec, cfg, i);
  2219. if (prev_label && !strcmp(label, prev_label))
  2220. type_idx++;
  2221. else
  2222. type_idx = 0;
  2223. prev_label = label;
  2224. snprintf(name, sizeof(name), "%s Boost Volume", label);
  2225. err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
  2226. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
  2227. if (err < 0)
  2228. return err;
  2229. }
  2230. return 0;
  2231. }
  2232. /* create capture and input-src controls for multiple streams */
  2233. static int create_multi_adc_ctls(struct hda_codec *codec)
  2234. {
  2235. struct via_spec *spec = codec->spec;
  2236. int i, err;
  2237. /* create capture mixer elements */
  2238. for (i = 0; i < spec->num_adc_nids; i++) {
  2239. hda_nid_t adc = spec->adc_nids[i];
  2240. err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2241. "Capture Volume", i,
  2242. HDA_COMPOSE_AMP_VAL(adc, 3, 0,
  2243. HDA_INPUT));
  2244. if (err < 0)
  2245. return err;
  2246. err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2247. "Capture Switch", i,
  2248. HDA_COMPOSE_AMP_VAL(adc, 3, 0,
  2249. HDA_INPUT));
  2250. if (err < 0)
  2251. return err;
  2252. }
  2253. /* input-source control */
  2254. for (i = 0; i < spec->num_adc_nids; i++)
  2255. if (!spec->mux_nids[i])
  2256. break;
  2257. err = create_input_src_ctls(codec, i);
  2258. if (err < 0)
  2259. return err;
  2260. return 0;
  2261. }
  2262. /* bind capture volume/switch */
  2263. static struct snd_kcontrol_new via_bind_cap_vol_ctl =
  2264. HDA_BIND_VOL("Capture Volume", 0);
  2265. static struct snd_kcontrol_new via_bind_cap_sw_ctl =
  2266. HDA_BIND_SW("Capture Switch", 0);
  2267. static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
  2268. struct hda_ctl_ops *ops)
  2269. {
  2270. struct hda_bind_ctls *ctl;
  2271. int i;
  2272. ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
  2273. if (!ctl)
  2274. return -ENOMEM;
  2275. ctl->ops = ops;
  2276. for (i = 0; i < spec->num_adc_nids; i++)
  2277. ctl->values[i] =
  2278. HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
  2279. *ctl_ret = ctl;
  2280. return 0;
  2281. }
  2282. /* create capture and input-src controls for dynamic ADC-switch case */
  2283. static int create_dyn_adc_ctls(struct hda_codec *codec)
  2284. {
  2285. struct via_spec *spec = codec->spec;
  2286. struct snd_kcontrol_new *knew;
  2287. int err;
  2288. /* set up the bind capture ctls */
  2289. err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
  2290. if (err < 0)
  2291. return err;
  2292. err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
  2293. if (err < 0)
  2294. return err;
  2295. /* create capture mixer elements */
  2296. knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
  2297. if (!knew)
  2298. return -ENOMEM;
  2299. knew->private_value = (long)spec->bind_cap_vol;
  2300. knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
  2301. if (!knew)
  2302. return -ENOMEM;
  2303. knew->private_value = (long)spec->bind_cap_sw;
  2304. /* input-source control */
  2305. err = create_input_src_ctls(codec, 1);
  2306. if (err < 0)
  2307. return err;
  2308. return 0;
  2309. }
  2310. /* parse and create capture-related stuff */
  2311. static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
  2312. {
  2313. struct via_spec *spec = codec->spec;
  2314. int err;
  2315. err = parse_analog_inputs(codec);
  2316. if (err < 0)
  2317. return err;
  2318. if (spec->dyn_adc_switch)
  2319. err = create_dyn_adc_ctls(codec);
  2320. else
  2321. err = create_multi_adc_ctls(codec);
  2322. if (err < 0)
  2323. return err;
  2324. err = create_loopback_ctls(codec);
  2325. if (err < 0)
  2326. return err;
  2327. err = create_mic_boost_ctls(codec);
  2328. if (err < 0)
  2329. return err;
  2330. return 0;
  2331. }
  2332. static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
  2333. {
  2334. unsigned int def_conf;
  2335. unsigned char seqassoc;
  2336. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  2337. seqassoc = (unsigned char) get_defcfg_association(def_conf);
  2338. seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
  2339. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
  2340. && (seqassoc == 0xf0 || seqassoc == 0xff)) {
  2341. def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
  2342. snd_hda_codec_set_pincfg(codec, nid, def_conf);
  2343. }
  2344. return;
  2345. }
  2346. static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
  2347. struct snd_ctl_elem_value *ucontrol)
  2348. {
  2349. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2350. struct via_spec *spec = codec->spec;
  2351. if (spec->codec_type != VT1708)
  2352. return 0;
  2353. ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
  2354. return 0;
  2355. }
  2356. static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
  2357. struct snd_ctl_elem_value *ucontrol)
  2358. {
  2359. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2360. struct via_spec *spec = codec->spec;
  2361. int val;
  2362. if (spec->codec_type != VT1708)
  2363. return 0;
  2364. val = !!ucontrol->value.integer.value[0];
  2365. if (spec->vt1708_jack_detect == val)
  2366. return 0;
  2367. spec->vt1708_jack_detect = val;
  2368. if (spec->vt1708_jack_detect &&
  2369. snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) {
  2370. mute_aa_path(codec, 1);
  2371. notify_aa_path_ctls(codec);
  2372. }
  2373. via_hp_automute(codec);
  2374. vt1708_update_hp_work(spec);
  2375. return 1;
  2376. }
  2377. static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
  2378. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2379. .name = "Jack Detect",
  2380. .count = 1,
  2381. .info = snd_ctl_boolean_mono_info,
  2382. .get = vt1708_jack_detect_get,
  2383. .put = vt1708_jack_detect_put,
  2384. };
  2385. static void fill_dig_outs(struct hda_codec *codec);
  2386. static void fill_dig_in(struct hda_codec *codec);
  2387. static int via_parse_auto_config(struct hda_codec *codec)
  2388. {
  2389. struct via_spec *spec = codec->spec;
  2390. int err;
  2391. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2392. if (err < 0)
  2393. return err;
  2394. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2395. return -EINVAL;
  2396. err = via_auto_create_multi_out_ctls(codec);
  2397. if (err < 0)
  2398. return err;
  2399. err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
  2400. if (err < 0)
  2401. return err;
  2402. err = via_auto_create_speaker_ctls(codec);
  2403. if (err < 0)
  2404. return err;
  2405. err = via_auto_create_loopback_switch(codec);
  2406. if (err < 0)
  2407. return err;
  2408. err = via_auto_create_analog_input_ctls(codec);
  2409. if (err < 0)
  2410. return err;
  2411. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2412. fill_dig_outs(codec);
  2413. fill_dig_in(codec);
  2414. if (spec->kctls.list)
  2415. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2416. if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
  2417. err = via_hp_build(codec);
  2418. if (err < 0)
  2419. return err;
  2420. }
  2421. err = via_smart51_build(codec);
  2422. if (err < 0)
  2423. return err;
  2424. /* assign slave outs */
  2425. if (spec->slave_dig_outs[0])
  2426. codec->slave_dig_outs = spec->slave_dig_outs;
  2427. return 1;
  2428. }
  2429. static void via_auto_init_dig_outs(struct hda_codec *codec)
  2430. {
  2431. struct via_spec *spec = codec->spec;
  2432. if (spec->multiout.dig_out_nid)
  2433. init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
  2434. if (spec->slave_dig_outs[0])
  2435. init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
  2436. }
  2437. static void via_auto_init_dig_in(struct hda_codec *codec)
  2438. {
  2439. struct via_spec *spec = codec->spec;
  2440. if (!spec->dig_in_nid)
  2441. return;
  2442. snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN);
  2443. }
  2444. /* initialize the unsolicited events */
  2445. static void via_auto_init_unsol_event(struct hda_codec *codec)
  2446. {
  2447. struct via_spec *spec = codec->spec;
  2448. struct auto_pin_cfg *cfg = &spec->autocfg;
  2449. unsigned int ev;
  2450. int i;
  2451. if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
  2452. snd_hda_jack_detect_enable(codec, cfg->hp_pins[0],
  2453. VIA_HP_EVENT | VIA_JACK_EVENT);
  2454. if (cfg->speaker_pins[0])
  2455. ev = VIA_LINE_EVENT;
  2456. else
  2457. ev = 0;
  2458. for (i = 0; i < cfg->line_outs; i++) {
  2459. if (cfg->line_out_pins[i] &&
  2460. is_jack_detectable(codec, cfg->line_out_pins[i]))
  2461. snd_hda_jack_detect_enable(codec, cfg->line_out_pins[i],
  2462. ev | VIA_JACK_EVENT);
  2463. }
  2464. for (i = 0; i < cfg->num_inputs; i++) {
  2465. if (is_jack_detectable(codec, cfg->inputs[i].pin))
  2466. snd_hda_jack_detect_enable(codec, cfg->inputs[i].pin,
  2467. VIA_JACK_EVENT);
  2468. }
  2469. }
  2470. static int via_init(struct hda_codec *codec)
  2471. {
  2472. struct via_spec *spec = codec->spec;
  2473. int i;
  2474. for (i = 0; i < spec->num_iverbs; i++)
  2475. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  2476. /* init power states */
  2477. set_widgets_power_state(codec);
  2478. __analog_low_current_mode(codec, true);
  2479. via_auto_init_multi_out(codec);
  2480. via_auto_init_hp_out(codec);
  2481. via_auto_init_speaker_out(codec);
  2482. via_auto_init_analog_input(codec);
  2483. via_auto_init_dig_outs(codec);
  2484. via_auto_init_dig_in(codec);
  2485. via_auto_init_unsol_event(codec);
  2486. via_hp_automute(codec);
  2487. vt1708_update_hp_work(spec);
  2488. snd_hda_jack_report_sync(codec);
  2489. return 0;
  2490. }
  2491. static void vt1708_update_hp_jack_state(struct work_struct *work)
  2492. {
  2493. struct via_spec *spec = container_of(work, struct via_spec,
  2494. vt1708_hp_work.work);
  2495. if (spec->codec_type != VT1708)
  2496. return;
  2497. snd_hda_jack_set_dirty_all(spec->codec);
  2498. /* if jack state toggled */
  2499. if (spec->vt1708_hp_present
  2500. != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
  2501. spec->vt1708_hp_present ^= 1;
  2502. via_hp_automute(spec->codec);
  2503. }
  2504. if (spec->vt1708_jack_detect)
  2505. schedule_delayed_work(&spec->vt1708_hp_work,
  2506. msecs_to_jiffies(100));
  2507. }
  2508. static int get_mux_nids(struct hda_codec *codec)
  2509. {
  2510. struct via_spec *spec = codec->spec;
  2511. hda_nid_t nid, conn[8];
  2512. unsigned int type;
  2513. int i, n;
  2514. for (i = 0; i < spec->num_adc_nids; i++) {
  2515. nid = spec->adc_nids[i];
  2516. while (nid) {
  2517. type = get_wcaps_type(get_wcaps(codec, nid));
  2518. if (type == AC_WID_PIN)
  2519. break;
  2520. n = snd_hda_get_connections(codec, nid, conn,
  2521. ARRAY_SIZE(conn));
  2522. if (n <= 0)
  2523. break;
  2524. if (n > 1) {
  2525. spec->mux_nids[i] = nid;
  2526. break;
  2527. }
  2528. nid = conn[0];
  2529. }
  2530. }
  2531. return 0;
  2532. }
  2533. static int patch_vt1708(struct hda_codec *codec)
  2534. {
  2535. struct via_spec *spec;
  2536. int err;
  2537. /* create a codec specific record */
  2538. spec = via_new_spec(codec);
  2539. if (spec == NULL)
  2540. return -ENOMEM;
  2541. spec->aa_mix_nid = 0x17;
  2542. /* Add HP and CD pin config connect bit re-config action */
  2543. vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
  2544. vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
  2545. /* automatic parse from the BIOS config */
  2546. err = via_parse_auto_config(codec);
  2547. if (err < 0) {
  2548. via_free(codec);
  2549. return err;
  2550. }
  2551. /* add jack detect on/off control */
  2552. if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
  2553. return -ENOMEM;
  2554. /* disable 32bit format on VT1708 */
  2555. if (codec->vendor_id == 0x11061708)
  2556. spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
  2557. spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
  2558. codec->patch_ops = via_patch_ops;
  2559. INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
  2560. return 0;
  2561. }
  2562. static int patch_vt1709(struct hda_codec *codec)
  2563. {
  2564. struct via_spec *spec;
  2565. int err;
  2566. /* create a codec specific record */
  2567. spec = via_new_spec(codec);
  2568. if (spec == NULL)
  2569. return -ENOMEM;
  2570. spec->aa_mix_nid = 0x18;
  2571. err = via_parse_auto_config(codec);
  2572. if (err < 0) {
  2573. via_free(codec);
  2574. return err;
  2575. }
  2576. codec->patch_ops = via_patch_ops;
  2577. return 0;
  2578. }
  2579. static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
  2580. {
  2581. struct via_spec *spec = codec->spec;
  2582. int imux_is_smixer;
  2583. unsigned int parm;
  2584. int is_8ch = 0;
  2585. if ((spec->codec_type != VT1708B_4CH) &&
  2586. (codec->vendor_id != 0x11064397))
  2587. is_8ch = 1;
  2588. /* SW0 (17h) = stereo mixer */
  2589. imux_is_smixer =
  2590. (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
  2591. == ((spec->codec_type == VT1708S) ? 5 : 0));
  2592. /* inputs */
  2593. /* PW 1/2/5 (1ah/1bh/1eh) */
  2594. parm = AC_PWRST_D3;
  2595. set_pin_power_state(codec, 0x1a, &parm);
  2596. set_pin_power_state(codec, 0x1b, &parm);
  2597. set_pin_power_state(codec, 0x1e, &parm);
  2598. if (imux_is_smixer)
  2599. parm = AC_PWRST_D0;
  2600. /* SW0 (17h), AIW 0/1 (13h/14h) */
  2601. update_power_state(codec, 0x17, parm);
  2602. update_power_state(codec, 0x13, parm);
  2603. update_power_state(codec, 0x14, parm);
  2604. /* outputs */
  2605. /* PW0 (19h), SW1 (18h), AOW1 (11h) */
  2606. parm = AC_PWRST_D3;
  2607. set_pin_power_state(codec, 0x19, &parm);
  2608. if (spec->smart51_enabled)
  2609. set_pin_power_state(codec, 0x1b, &parm);
  2610. update_power_state(codec, 0x18, parm);
  2611. update_power_state(codec, 0x11, parm);
  2612. /* PW6 (22h), SW2 (26h), AOW2 (24h) */
  2613. if (is_8ch) {
  2614. parm = AC_PWRST_D3;
  2615. set_pin_power_state(codec, 0x22, &parm);
  2616. if (spec->smart51_enabled)
  2617. set_pin_power_state(codec, 0x1a, &parm);
  2618. update_power_state(codec, 0x26, parm);
  2619. update_power_state(codec, 0x24, parm);
  2620. } else if (codec->vendor_id == 0x11064397) {
  2621. /* PW7(23h), SW2(27h), AOW2(25h) */
  2622. parm = AC_PWRST_D3;
  2623. set_pin_power_state(codec, 0x23, &parm);
  2624. if (spec->smart51_enabled)
  2625. set_pin_power_state(codec, 0x1a, &parm);
  2626. update_power_state(codec, 0x27, parm);
  2627. update_power_state(codec, 0x25, parm);
  2628. }
  2629. /* PW 3/4/7 (1ch/1dh/23h) */
  2630. parm = AC_PWRST_D3;
  2631. /* force to D0 for internal Speaker */
  2632. set_pin_power_state(codec, 0x1c, &parm);
  2633. set_pin_power_state(codec, 0x1d, &parm);
  2634. if (is_8ch)
  2635. set_pin_power_state(codec, 0x23, &parm);
  2636. /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
  2637. update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
  2638. update_power_state(codec, 0x10, parm);
  2639. if (is_8ch) {
  2640. update_power_state(codec, 0x25, parm);
  2641. update_power_state(codec, 0x27, parm);
  2642. } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
  2643. update_power_state(codec, 0x25, parm);
  2644. }
  2645. static int patch_vt1708S(struct hda_codec *codec);
  2646. static int patch_vt1708B(struct hda_codec *codec)
  2647. {
  2648. struct via_spec *spec;
  2649. int err;
  2650. if (get_codec_type(codec) == VT1708BCE)
  2651. return patch_vt1708S(codec);
  2652. /* create a codec specific record */
  2653. spec = via_new_spec(codec);
  2654. if (spec == NULL)
  2655. return -ENOMEM;
  2656. spec->aa_mix_nid = 0x16;
  2657. /* automatic parse from the BIOS config */
  2658. err = via_parse_auto_config(codec);
  2659. if (err < 0) {
  2660. via_free(codec);
  2661. return err;
  2662. }
  2663. codec->patch_ops = via_patch_ops;
  2664. spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
  2665. return 0;
  2666. }
  2667. /* Patch for VT1708S */
  2668. static const struct hda_verb vt1708S_init_verbs[] = {
  2669. /* Enable Mic Boost Volume backdoor */
  2670. {0x1, 0xf98, 0x1},
  2671. /* don't bybass mixer */
  2672. {0x1, 0xf88, 0xc0},
  2673. { }
  2674. };
  2675. /* fill out digital output widgets; one for master and one for slave outputs */
  2676. static void fill_dig_outs(struct hda_codec *codec)
  2677. {
  2678. struct via_spec *spec = codec->spec;
  2679. int i;
  2680. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  2681. hda_nid_t nid;
  2682. int conn;
  2683. nid = spec->autocfg.dig_out_pins[i];
  2684. if (!nid)
  2685. continue;
  2686. conn = snd_hda_get_connections(codec, nid, &nid, 1);
  2687. if (conn < 1)
  2688. continue;
  2689. if (!spec->multiout.dig_out_nid)
  2690. spec->multiout.dig_out_nid = nid;
  2691. else {
  2692. spec->slave_dig_outs[0] = nid;
  2693. break; /* at most two dig outs */
  2694. }
  2695. }
  2696. }
  2697. static void fill_dig_in(struct hda_codec *codec)
  2698. {
  2699. struct via_spec *spec = codec->spec;
  2700. hda_nid_t dig_nid;
  2701. int i, err;
  2702. if (!spec->autocfg.dig_in_pin)
  2703. return;
  2704. dig_nid = codec->start_nid;
  2705. for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
  2706. unsigned int wcaps = get_wcaps(codec, dig_nid);
  2707. if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
  2708. continue;
  2709. if (!(wcaps & AC_WCAP_DIGITAL))
  2710. continue;
  2711. if (!(wcaps & AC_WCAP_CONN_LIST))
  2712. continue;
  2713. err = get_connection_index(codec, dig_nid,
  2714. spec->autocfg.dig_in_pin);
  2715. if (err >= 0) {
  2716. spec->dig_in_nid = dig_nid;
  2717. break;
  2718. }
  2719. }
  2720. }
  2721. static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
  2722. int offset, int num_steps, int step_size)
  2723. {
  2724. snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
  2725. (offset << AC_AMPCAP_OFFSET_SHIFT) |
  2726. (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2727. (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2728. (0 << AC_AMPCAP_MUTE_SHIFT));
  2729. }
  2730. static int patch_vt1708S(struct hda_codec *codec)
  2731. {
  2732. struct via_spec *spec;
  2733. int err;
  2734. /* create a codec specific record */
  2735. spec = via_new_spec(codec);
  2736. if (spec == NULL)
  2737. return -ENOMEM;
  2738. spec->aa_mix_nid = 0x16;
  2739. override_mic_boost(codec, 0x1a, 0, 3, 40);
  2740. override_mic_boost(codec, 0x1e, 0, 3, 40);
  2741. /* automatic parse from the BIOS config */
  2742. err = via_parse_auto_config(codec);
  2743. if (err < 0) {
  2744. via_free(codec);
  2745. return err;
  2746. }
  2747. spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
  2748. codec->patch_ops = via_patch_ops;
  2749. /* correct names for VT1708BCE */
  2750. if (get_codec_type(codec) == VT1708BCE) {
  2751. kfree(codec->chip_name);
  2752. codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
  2753. snprintf(codec->bus->card->mixername,
  2754. sizeof(codec->bus->card->mixername),
  2755. "%s %s", codec->vendor_name, codec->chip_name);
  2756. }
  2757. /* correct names for VT1705 */
  2758. if (codec->vendor_id == 0x11064397) {
  2759. kfree(codec->chip_name);
  2760. codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
  2761. snprintf(codec->bus->card->mixername,
  2762. sizeof(codec->bus->card->mixername),
  2763. "%s %s", codec->vendor_name, codec->chip_name);
  2764. }
  2765. spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
  2766. return 0;
  2767. }
  2768. /* Patch for VT1702 */
  2769. static const struct hda_verb vt1702_init_verbs[] = {
  2770. /* mixer enable */
  2771. {0x1, 0xF88, 0x3},
  2772. /* GPIO 0~2 */
  2773. {0x1, 0xF82, 0x3F},
  2774. { }
  2775. };
  2776. static void set_widgets_power_state_vt1702(struct hda_codec *codec)
  2777. {
  2778. int imux_is_smixer =
  2779. snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
  2780. unsigned int parm;
  2781. /* inputs */
  2782. /* PW 1/2/5 (14h/15h/18h) */
  2783. parm = AC_PWRST_D3;
  2784. set_pin_power_state(codec, 0x14, &parm);
  2785. set_pin_power_state(codec, 0x15, &parm);
  2786. set_pin_power_state(codec, 0x18, &parm);
  2787. if (imux_is_smixer)
  2788. parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
  2789. /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
  2790. update_power_state(codec, 0x13, parm);
  2791. update_power_state(codec, 0x12, parm);
  2792. update_power_state(codec, 0x1f, parm);
  2793. update_power_state(codec, 0x20, parm);
  2794. /* outputs */
  2795. /* PW 3/4 (16h/17h) */
  2796. parm = AC_PWRST_D3;
  2797. set_pin_power_state(codec, 0x17, &parm);
  2798. set_pin_power_state(codec, 0x16, &parm);
  2799. /* MW0 (1ah), AOW 0/1 (10h/1dh) */
  2800. update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
  2801. update_power_state(codec, 0x10, parm);
  2802. update_power_state(codec, 0x1d, parm);
  2803. }
  2804. static int patch_vt1702(struct hda_codec *codec)
  2805. {
  2806. struct via_spec *spec;
  2807. int err;
  2808. /* create a codec specific record */
  2809. spec = via_new_spec(codec);
  2810. if (spec == NULL)
  2811. return -ENOMEM;
  2812. spec->aa_mix_nid = 0x1a;
  2813. /* limit AA path volume to 0 dB */
  2814. snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
  2815. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  2816. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2817. (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2818. (1 << AC_AMPCAP_MUTE_SHIFT));
  2819. /* automatic parse from the BIOS config */
  2820. err = via_parse_auto_config(codec);
  2821. if (err < 0) {
  2822. via_free(codec);
  2823. return err;
  2824. }
  2825. spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
  2826. codec->patch_ops = via_patch_ops;
  2827. spec->set_widgets_power_state = set_widgets_power_state_vt1702;
  2828. return 0;
  2829. }
  2830. /* Patch for VT1718S */
  2831. static const struct hda_verb vt1718S_init_verbs[] = {
  2832. /* Enable MW0 adjust Gain 5 */
  2833. {0x1, 0xfb2, 0x10},
  2834. /* Enable Boost Volume backdoor */
  2835. {0x1, 0xf88, 0x8},
  2836. { }
  2837. };
  2838. static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
  2839. {
  2840. struct via_spec *spec = codec->spec;
  2841. int imux_is_smixer;
  2842. unsigned int parm, parm2;
  2843. /* MUX6 (1eh) = stereo mixer */
  2844. imux_is_smixer =
  2845. snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
  2846. /* inputs */
  2847. /* PW 5/6/7 (29h/2ah/2bh) */
  2848. parm = AC_PWRST_D3;
  2849. set_pin_power_state(codec, 0x29, &parm);
  2850. set_pin_power_state(codec, 0x2a, &parm);
  2851. set_pin_power_state(codec, 0x2b, &parm);
  2852. if (imux_is_smixer)
  2853. parm = AC_PWRST_D0;
  2854. /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
  2855. update_power_state(codec, 0x1e, parm);
  2856. update_power_state(codec, 0x1f, parm);
  2857. update_power_state(codec, 0x10, parm);
  2858. update_power_state(codec, 0x11, parm);
  2859. /* outputs */
  2860. /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
  2861. parm = AC_PWRST_D3;
  2862. set_pin_power_state(codec, 0x27, &parm);
  2863. update_power_state(codec, 0x1a, parm);
  2864. parm2 = parm; /* for pin 0x0b */
  2865. /* PW2 (26h), AOW2 (ah) */
  2866. parm = AC_PWRST_D3;
  2867. set_pin_power_state(codec, 0x26, &parm);
  2868. if (spec->smart51_enabled)
  2869. set_pin_power_state(codec, 0x2b, &parm);
  2870. update_power_state(codec, 0xa, parm);
  2871. /* PW0 (24h), AOW0 (8h) */
  2872. parm = AC_PWRST_D3;
  2873. set_pin_power_state(codec, 0x24, &parm);
  2874. if (!spec->hp_independent_mode) /* check for redirected HP */
  2875. set_pin_power_state(codec, 0x28, &parm);
  2876. update_power_state(codec, 0x8, parm);
  2877. if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3)
  2878. parm = parm2;
  2879. update_power_state(codec, 0xb, parm);
  2880. /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
  2881. update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
  2882. /* PW1 (25h), AOW1 (9h) */
  2883. parm = AC_PWRST_D3;
  2884. set_pin_power_state(codec, 0x25, &parm);
  2885. if (spec->smart51_enabled)
  2886. set_pin_power_state(codec, 0x2a, &parm);
  2887. update_power_state(codec, 0x9, parm);
  2888. if (spec->hp_independent_mode) {
  2889. /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
  2890. parm = AC_PWRST_D3;
  2891. set_pin_power_state(codec, 0x28, &parm);
  2892. update_power_state(codec, 0x1b, parm);
  2893. update_power_state(codec, 0x34, parm);
  2894. update_power_state(codec, 0xc, parm);
  2895. }
  2896. }
  2897. /* Add a connection to the primary DAC from AA-mixer for some codecs
  2898. * This isn't listed from the raw info, but the chip has a secret connection.
  2899. */
  2900. static int add_secret_dac_path(struct hda_codec *codec)
  2901. {
  2902. struct via_spec *spec = codec->spec;
  2903. int i, nums;
  2904. hda_nid_t conn[8];
  2905. hda_nid_t nid;
  2906. if (!spec->aa_mix_nid)
  2907. return 0;
  2908. nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
  2909. ARRAY_SIZE(conn) - 1);
  2910. for (i = 0; i < nums; i++) {
  2911. if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
  2912. return 0;
  2913. }
  2914. /* find the primary DAC and add to the connection list */
  2915. nid = codec->start_nid;
  2916. for (i = 0; i < codec->num_nodes; i++, nid++) {
  2917. unsigned int caps = get_wcaps(codec, nid);
  2918. if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
  2919. !(caps & AC_WCAP_DIGITAL)) {
  2920. conn[nums++] = nid;
  2921. return snd_hda_override_conn_list(codec,
  2922. spec->aa_mix_nid,
  2923. nums, conn);
  2924. }
  2925. }
  2926. return 0;
  2927. }
  2928. static int patch_vt1718S(struct hda_codec *codec)
  2929. {
  2930. struct via_spec *spec;
  2931. int err;
  2932. /* create a codec specific record */
  2933. spec = via_new_spec(codec);
  2934. if (spec == NULL)
  2935. return -ENOMEM;
  2936. spec->aa_mix_nid = 0x21;
  2937. override_mic_boost(codec, 0x2b, 0, 3, 40);
  2938. override_mic_boost(codec, 0x29, 0, 3, 40);
  2939. add_secret_dac_path(codec);
  2940. /* automatic parse from the BIOS config */
  2941. err = via_parse_auto_config(codec);
  2942. if (err < 0) {
  2943. via_free(codec);
  2944. return err;
  2945. }
  2946. spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
  2947. codec->patch_ops = via_patch_ops;
  2948. spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
  2949. return 0;
  2950. }
  2951. /* Patch for VT1716S */
  2952. static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
  2953. struct snd_ctl_elem_info *uinfo)
  2954. {
  2955. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2956. uinfo->count = 1;
  2957. uinfo->value.integer.min = 0;
  2958. uinfo->value.integer.max = 1;
  2959. return 0;
  2960. }
  2961. static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
  2962. struct snd_ctl_elem_value *ucontrol)
  2963. {
  2964. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2965. int index = 0;
  2966. index = snd_hda_codec_read(codec, 0x26, 0,
  2967. AC_VERB_GET_CONNECT_SEL, 0);
  2968. if (index != -1)
  2969. *ucontrol->value.integer.value = index;
  2970. return 0;
  2971. }
  2972. static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
  2973. struct snd_ctl_elem_value *ucontrol)
  2974. {
  2975. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2976. struct via_spec *spec = codec->spec;
  2977. int index = *ucontrol->value.integer.value;
  2978. snd_hda_codec_write(codec, 0x26, 0,
  2979. AC_VERB_SET_CONNECT_SEL, index);
  2980. spec->dmic_enabled = index;
  2981. set_widgets_power_state(codec);
  2982. return 1;
  2983. }
  2984. static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
  2985. HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
  2986. {
  2987. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2988. .name = "Digital Mic Capture Switch",
  2989. .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
  2990. .count = 1,
  2991. .info = vt1716s_dmic_info,
  2992. .get = vt1716s_dmic_get,
  2993. .put = vt1716s_dmic_put,
  2994. },
  2995. {} /* end */
  2996. };
  2997. /* mono-out mixer elements */
  2998. static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
  2999. HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
  3000. { } /* end */
  3001. };
  3002. static const struct hda_verb vt1716S_init_verbs[] = {
  3003. /* Enable Boost Volume backdoor */
  3004. {0x1, 0xf8a, 0x80},
  3005. /* don't bybass mixer */
  3006. {0x1, 0xf88, 0xc0},
  3007. /* Enable mono output */
  3008. {0x1, 0xf90, 0x08},
  3009. { }
  3010. };
  3011. static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
  3012. {
  3013. struct via_spec *spec = codec->spec;
  3014. int imux_is_smixer;
  3015. unsigned int parm;
  3016. unsigned int mono_out, present;
  3017. /* SW0 (17h) = stereo mixer */
  3018. imux_is_smixer =
  3019. (snd_hda_codec_read(codec, 0x17, 0,
  3020. AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
  3021. /* inputs */
  3022. /* PW 1/2/5 (1ah/1bh/1eh) */
  3023. parm = AC_PWRST_D3;
  3024. set_pin_power_state(codec, 0x1a, &parm);
  3025. set_pin_power_state(codec, 0x1b, &parm);
  3026. set_pin_power_state(codec, 0x1e, &parm);
  3027. if (imux_is_smixer)
  3028. parm = AC_PWRST_D0;
  3029. /* SW0 (17h), AIW0(13h) */
  3030. update_power_state(codec, 0x17, parm);
  3031. update_power_state(codec, 0x13, parm);
  3032. parm = AC_PWRST_D3;
  3033. set_pin_power_state(codec, 0x1e, &parm);
  3034. /* PW11 (22h) */
  3035. if (spec->dmic_enabled)
  3036. set_pin_power_state(codec, 0x22, &parm);
  3037. else
  3038. update_power_state(codec, 0x22, AC_PWRST_D3);
  3039. /* SW2(26h), AIW1(14h) */
  3040. update_power_state(codec, 0x26, parm);
  3041. update_power_state(codec, 0x14, parm);
  3042. /* outputs */
  3043. /* PW0 (19h), SW1 (18h), AOW1 (11h) */
  3044. parm = AC_PWRST_D3;
  3045. set_pin_power_state(codec, 0x19, &parm);
  3046. /* Smart 5.1 PW2(1bh) */
  3047. if (spec->smart51_enabled)
  3048. set_pin_power_state(codec, 0x1b, &parm);
  3049. update_power_state(codec, 0x18, parm);
  3050. update_power_state(codec, 0x11, parm);
  3051. /* PW7 (23h), SW3 (27h), AOW3 (25h) */
  3052. parm = AC_PWRST_D3;
  3053. set_pin_power_state(codec, 0x23, &parm);
  3054. /* Smart 5.1 PW1(1ah) */
  3055. if (spec->smart51_enabled)
  3056. set_pin_power_state(codec, 0x1a, &parm);
  3057. update_power_state(codec, 0x27, parm);
  3058. /* Smart 5.1 PW5(1eh) */
  3059. if (spec->smart51_enabled)
  3060. set_pin_power_state(codec, 0x1e, &parm);
  3061. update_power_state(codec, 0x25, parm);
  3062. /* Mono out */
  3063. /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
  3064. present = snd_hda_jack_detect(codec, 0x1c);
  3065. if (present)
  3066. mono_out = 0;
  3067. else {
  3068. present = snd_hda_jack_detect(codec, 0x1d);
  3069. if (!spec->hp_independent_mode && present)
  3070. mono_out = 0;
  3071. else
  3072. mono_out = 1;
  3073. }
  3074. parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
  3075. update_power_state(codec, 0x28, parm);
  3076. update_power_state(codec, 0x29, parm);
  3077. update_power_state(codec, 0x2a, parm);
  3078. /* PW 3/4 (1ch/1dh) */
  3079. parm = AC_PWRST_D3;
  3080. set_pin_power_state(codec, 0x1c, &parm);
  3081. set_pin_power_state(codec, 0x1d, &parm);
  3082. /* HP Independent Mode, power on AOW3 */
  3083. if (spec->hp_independent_mode)
  3084. update_power_state(codec, 0x25, parm);
  3085. /* force to D0 for internal Speaker */
  3086. /* MW0 (16h), AOW0 (10h) */
  3087. update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
  3088. update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
  3089. }
  3090. static int patch_vt1716S(struct hda_codec *codec)
  3091. {
  3092. struct via_spec *spec;
  3093. int err;
  3094. /* create a codec specific record */
  3095. spec = via_new_spec(codec);
  3096. if (spec == NULL)
  3097. return -ENOMEM;
  3098. spec->aa_mix_nid = 0x16;
  3099. override_mic_boost(codec, 0x1a, 0, 3, 40);
  3100. override_mic_boost(codec, 0x1e, 0, 3, 40);
  3101. /* automatic parse from the BIOS config */
  3102. err = via_parse_auto_config(codec);
  3103. if (err < 0) {
  3104. via_free(codec);
  3105. return err;
  3106. }
  3107. spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
  3108. spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
  3109. spec->num_mixers++;
  3110. spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
  3111. codec->patch_ops = via_patch_ops;
  3112. spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
  3113. return 0;
  3114. }
  3115. /* for vt2002P */
  3116. static const struct hda_verb vt2002P_init_verbs[] = {
  3117. /* Class-D speaker related verbs */
  3118. {0x1, 0xfe0, 0x4},
  3119. {0x1, 0xfe9, 0x80},
  3120. {0x1, 0xfe2, 0x22},
  3121. /* Enable Boost Volume backdoor */
  3122. {0x1, 0xfb9, 0x24},
  3123. /* Enable AOW0 to MW9 */
  3124. {0x1, 0xfb8, 0x88},
  3125. { }
  3126. };
  3127. static const struct hda_verb vt1802_init_verbs[] = {
  3128. /* Enable Boost Volume backdoor */
  3129. {0x1, 0xfb9, 0x24},
  3130. /* Enable AOW0 to MW9 */
  3131. {0x1, 0xfb8, 0x88},
  3132. { }
  3133. };
  3134. static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
  3135. {
  3136. struct via_spec *spec = codec->spec;
  3137. int imux_is_smixer;
  3138. unsigned int parm;
  3139. unsigned int present;
  3140. /* MUX9 (1eh) = stereo mixer */
  3141. imux_is_smixer =
  3142. snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
  3143. /* inputs */
  3144. /* PW 5/6/7 (29h/2ah/2bh) */
  3145. parm = AC_PWRST_D3;
  3146. set_pin_power_state(codec, 0x29, &parm);
  3147. set_pin_power_state(codec, 0x2a, &parm);
  3148. set_pin_power_state(codec, 0x2b, &parm);
  3149. parm = AC_PWRST_D0;
  3150. /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
  3151. update_power_state(codec, 0x1e, parm);
  3152. update_power_state(codec, 0x1f, parm);
  3153. update_power_state(codec, 0x10, parm);
  3154. update_power_state(codec, 0x11, parm);
  3155. /* outputs */
  3156. /* AOW0 (8h)*/
  3157. update_power_state(codec, 0x8, parm);
  3158. if (spec->codec_type == VT1802) {
  3159. /* PW4 (28h), MW4 (18h), MUX4(38h) */
  3160. parm = AC_PWRST_D3;
  3161. set_pin_power_state(codec, 0x28, &parm);
  3162. update_power_state(codec, 0x18, parm);
  3163. update_power_state(codec, 0x38, parm);
  3164. } else {
  3165. /* PW4 (26h), MW4 (1ch), MUX4(37h) */
  3166. parm = AC_PWRST_D3;
  3167. set_pin_power_state(codec, 0x26, &parm);
  3168. update_power_state(codec, 0x1c, parm);
  3169. update_power_state(codec, 0x37, parm);
  3170. }
  3171. if (spec->codec_type == VT1802) {
  3172. /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
  3173. parm = AC_PWRST_D3;
  3174. set_pin_power_state(codec, 0x25, &parm);
  3175. update_power_state(codec, 0x15, parm);
  3176. update_power_state(codec, 0x35, parm);
  3177. } else {
  3178. /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
  3179. parm = AC_PWRST_D3;
  3180. set_pin_power_state(codec, 0x25, &parm);
  3181. update_power_state(codec, 0x19, parm);
  3182. update_power_state(codec, 0x35, parm);
  3183. }
  3184. if (spec->hp_independent_mode)
  3185. update_power_state(codec, 0x9, AC_PWRST_D0);
  3186. /* Class-D */
  3187. /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
  3188. present = snd_hda_jack_detect(codec, 0x25);
  3189. parm = AC_PWRST_D3;
  3190. set_pin_power_state(codec, 0x24, &parm);
  3191. parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
  3192. if (spec->codec_type == VT1802)
  3193. update_power_state(codec, 0x14, parm);
  3194. else
  3195. update_power_state(codec, 0x18, parm);
  3196. update_power_state(codec, 0x34, parm);
  3197. /* Mono Out */
  3198. present = snd_hda_jack_detect(codec, 0x26);
  3199. parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
  3200. if (spec->codec_type == VT1802) {
  3201. /* PW15 (33h), MW8(1ch), MUX8(3ch) */
  3202. update_power_state(codec, 0x33, parm);
  3203. update_power_state(codec, 0x1c, parm);
  3204. update_power_state(codec, 0x3c, parm);
  3205. } else {
  3206. /* PW15 (31h), MW8(17h), MUX8(3bh) */
  3207. update_power_state(codec, 0x31, parm);
  3208. update_power_state(codec, 0x17, parm);
  3209. update_power_state(codec, 0x3b, parm);
  3210. }
  3211. /* MW9 (21h) */
  3212. if (imux_is_smixer || !is_aa_path_mute(codec))
  3213. update_power_state(codec, 0x21, AC_PWRST_D0);
  3214. else
  3215. update_power_state(codec, 0x21, AC_PWRST_D3);
  3216. }
  3217. /* patch for vt2002P */
  3218. static int patch_vt2002P(struct hda_codec *codec)
  3219. {
  3220. struct via_spec *spec;
  3221. int err;
  3222. /* create a codec specific record */
  3223. spec = via_new_spec(codec);
  3224. if (spec == NULL)
  3225. return -ENOMEM;
  3226. spec->aa_mix_nid = 0x21;
  3227. override_mic_boost(codec, 0x2b, 0, 3, 40);
  3228. override_mic_boost(codec, 0x29, 0, 3, 40);
  3229. add_secret_dac_path(codec);
  3230. /* automatic parse from the BIOS config */
  3231. err = via_parse_auto_config(codec);
  3232. if (err < 0) {
  3233. via_free(codec);
  3234. return err;
  3235. }
  3236. if (spec->codec_type == VT1802)
  3237. spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
  3238. else
  3239. spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
  3240. codec->patch_ops = via_patch_ops;
  3241. spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
  3242. return 0;
  3243. }
  3244. /* for vt1812 */
  3245. static const struct hda_verb vt1812_init_verbs[] = {
  3246. /* Enable Boost Volume backdoor */
  3247. {0x1, 0xfb9, 0x24},
  3248. /* Enable AOW0 to MW9 */
  3249. {0x1, 0xfb8, 0xa8},
  3250. { }
  3251. };
  3252. static void set_widgets_power_state_vt1812(struct hda_codec *codec)
  3253. {
  3254. struct via_spec *spec = codec->spec;
  3255. unsigned int parm;
  3256. unsigned int present;
  3257. /* inputs */
  3258. /* PW 5/6/7 (29h/2ah/2bh) */
  3259. parm = AC_PWRST_D3;
  3260. set_pin_power_state(codec, 0x29, &parm);
  3261. set_pin_power_state(codec, 0x2a, &parm);
  3262. set_pin_power_state(codec, 0x2b, &parm);
  3263. parm = AC_PWRST_D0;
  3264. /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
  3265. update_power_state(codec, 0x1e, parm);
  3266. update_power_state(codec, 0x1f, parm);
  3267. update_power_state(codec, 0x10, parm);
  3268. update_power_state(codec, 0x11, parm);
  3269. /* outputs */
  3270. /* AOW0 (8h)*/
  3271. update_power_state(codec, 0x8, AC_PWRST_D0);
  3272. /* PW4 (28h), MW4 (18h), MUX4(38h) */
  3273. parm = AC_PWRST_D3;
  3274. set_pin_power_state(codec, 0x28, &parm);
  3275. update_power_state(codec, 0x18, parm);
  3276. update_power_state(codec, 0x38, parm);
  3277. /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
  3278. parm = AC_PWRST_D3;
  3279. set_pin_power_state(codec, 0x25, &parm);
  3280. update_power_state(codec, 0x15, parm);
  3281. update_power_state(codec, 0x35, parm);
  3282. if (spec->hp_independent_mode)
  3283. update_power_state(codec, 0x9, AC_PWRST_D0);
  3284. /* Internal Speaker */
  3285. /* PW0 (24h), MW0(14h), MUX0(34h) */
  3286. present = snd_hda_jack_detect(codec, 0x25);
  3287. parm = AC_PWRST_D3;
  3288. set_pin_power_state(codec, 0x24, &parm);
  3289. if (present) {
  3290. update_power_state(codec, 0x14, AC_PWRST_D3);
  3291. update_power_state(codec, 0x34, AC_PWRST_D3);
  3292. } else {
  3293. update_power_state(codec, 0x14, AC_PWRST_D0);
  3294. update_power_state(codec, 0x34, AC_PWRST_D0);
  3295. }
  3296. /* Mono Out */
  3297. /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
  3298. present = snd_hda_jack_detect(codec, 0x28);
  3299. parm = AC_PWRST_D3;
  3300. set_pin_power_state(codec, 0x31, &parm);
  3301. if (present) {
  3302. update_power_state(codec, 0x1c, AC_PWRST_D3);
  3303. update_power_state(codec, 0x3c, AC_PWRST_D3);
  3304. update_power_state(codec, 0x3e, AC_PWRST_D3);
  3305. } else {
  3306. update_power_state(codec, 0x1c, AC_PWRST_D0);
  3307. update_power_state(codec, 0x3c, AC_PWRST_D0);
  3308. update_power_state(codec, 0x3e, AC_PWRST_D0);
  3309. }
  3310. /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
  3311. parm = AC_PWRST_D3;
  3312. set_pin_power_state(codec, 0x33, &parm);
  3313. update_power_state(codec, 0x1d, parm);
  3314. update_power_state(codec, 0x3d, parm);
  3315. }
  3316. /* patch for vt1812 */
  3317. static int patch_vt1812(struct hda_codec *codec)
  3318. {
  3319. struct via_spec *spec;
  3320. int err;
  3321. /* create a codec specific record */
  3322. spec = via_new_spec(codec);
  3323. if (spec == NULL)
  3324. return -ENOMEM;
  3325. spec->aa_mix_nid = 0x21;
  3326. override_mic_boost(codec, 0x2b, 0, 3, 40);
  3327. override_mic_boost(codec, 0x29, 0, 3, 40);
  3328. add_secret_dac_path(codec);
  3329. /* automatic parse from the BIOS config */
  3330. err = via_parse_auto_config(codec);
  3331. if (err < 0) {
  3332. via_free(codec);
  3333. return err;
  3334. }
  3335. spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
  3336. codec->patch_ops = via_patch_ops;
  3337. spec->set_widgets_power_state = set_widgets_power_state_vt1812;
  3338. return 0;
  3339. }
  3340. /*
  3341. * patch entries
  3342. */
  3343. static const struct hda_codec_preset snd_hda_preset_via[] = {
  3344. { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
  3345. { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
  3346. { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
  3347. { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
  3348. { .id = 0x1106e710, .name = "VT1709 10-Ch",
  3349. .patch = patch_vt1709},
  3350. { .id = 0x1106e711, .name = "VT1709 10-Ch",
  3351. .patch = patch_vt1709},
  3352. { .id = 0x1106e712, .name = "VT1709 10-Ch",
  3353. .patch = patch_vt1709},
  3354. { .id = 0x1106e713, .name = "VT1709 10-Ch",
  3355. .patch = patch_vt1709},
  3356. { .id = 0x1106e714, .name = "VT1709 6-Ch",
  3357. .patch = patch_vt1709},
  3358. { .id = 0x1106e715, .name = "VT1709 6-Ch",
  3359. .patch = patch_vt1709},
  3360. { .id = 0x1106e716, .name = "VT1709 6-Ch",
  3361. .patch = patch_vt1709},
  3362. { .id = 0x1106e717, .name = "VT1709 6-Ch",
  3363. .patch = patch_vt1709},
  3364. { .id = 0x1106e720, .name = "VT1708B 8-Ch",
  3365. .patch = patch_vt1708B},
  3366. { .id = 0x1106e721, .name = "VT1708B 8-Ch",
  3367. .patch = patch_vt1708B},
  3368. { .id = 0x1106e722, .name = "VT1708B 8-Ch",
  3369. .patch = patch_vt1708B},
  3370. { .id = 0x1106e723, .name = "VT1708B 8-Ch",
  3371. .patch = patch_vt1708B},
  3372. { .id = 0x1106e724, .name = "VT1708B 4-Ch",
  3373. .patch = patch_vt1708B},
  3374. { .id = 0x1106e725, .name = "VT1708B 4-Ch",
  3375. .patch = patch_vt1708B},
  3376. { .id = 0x1106e726, .name = "VT1708B 4-Ch",
  3377. .patch = patch_vt1708B},
  3378. { .id = 0x1106e727, .name = "VT1708B 4-Ch",
  3379. .patch = patch_vt1708B},
  3380. { .id = 0x11060397, .name = "VT1708S",
  3381. .patch = patch_vt1708S},
  3382. { .id = 0x11061397, .name = "VT1708S",
  3383. .patch = patch_vt1708S},
  3384. { .id = 0x11062397, .name = "VT1708S",
  3385. .patch = patch_vt1708S},
  3386. { .id = 0x11063397, .name = "VT1708S",
  3387. .patch = patch_vt1708S},
  3388. { .id = 0x11064397, .name = "VT1705",
  3389. .patch = patch_vt1708S},
  3390. { .id = 0x11065397, .name = "VT1708S",
  3391. .patch = patch_vt1708S},
  3392. { .id = 0x11066397, .name = "VT1708S",
  3393. .patch = patch_vt1708S},
  3394. { .id = 0x11067397, .name = "VT1708S",
  3395. .patch = patch_vt1708S},
  3396. { .id = 0x11060398, .name = "VT1702",
  3397. .patch = patch_vt1702},
  3398. { .id = 0x11061398, .name = "VT1702",
  3399. .patch = patch_vt1702},
  3400. { .id = 0x11062398, .name = "VT1702",
  3401. .patch = patch_vt1702},
  3402. { .id = 0x11063398, .name = "VT1702",
  3403. .patch = patch_vt1702},
  3404. { .id = 0x11064398, .name = "VT1702",
  3405. .patch = patch_vt1702},
  3406. { .id = 0x11065398, .name = "VT1702",
  3407. .patch = patch_vt1702},
  3408. { .id = 0x11066398, .name = "VT1702",
  3409. .patch = patch_vt1702},
  3410. { .id = 0x11067398, .name = "VT1702",
  3411. .patch = patch_vt1702},
  3412. { .id = 0x11060428, .name = "VT1718S",
  3413. .patch = patch_vt1718S},
  3414. { .id = 0x11064428, .name = "VT1718S",
  3415. .patch = patch_vt1718S},
  3416. { .id = 0x11060441, .name = "VT2020",
  3417. .patch = patch_vt1718S},
  3418. { .id = 0x11064441, .name = "VT1828S",
  3419. .patch = patch_vt1718S},
  3420. { .id = 0x11060433, .name = "VT1716S",
  3421. .patch = patch_vt1716S},
  3422. { .id = 0x1106a721, .name = "VT1716S",
  3423. .patch = patch_vt1716S},
  3424. { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
  3425. { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
  3426. { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
  3427. { .id = 0x11060440, .name = "VT1818S",
  3428. .patch = patch_vt1708S},
  3429. { .id = 0x11060446, .name = "VT1802",
  3430. .patch = patch_vt2002P},
  3431. { .id = 0x11068446, .name = "VT1802",
  3432. .patch = patch_vt2002P},
  3433. {} /* terminator */
  3434. };
  3435. MODULE_ALIAS("snd-hda-codec-id:1106*");
  3436. static struct hda_codec_preset_list via_list = {
  3437. .preset = snd_hda_preset_via,
  3438. .owner = THIS_MODULE,
  3439. };
  3440. MODULE_LICENSE("GPL");
  3441. MODULE_DESCRIPTION("VIA HD-audio codec");
  3442. static int __init patch_via_init(void)
  3443. {
  3444. return snd_hda_add_codec_preset(&via_list);
  3445. }
  3446. static void __exit patch_via_exit(void)
  3447. {
  3448. snd_hda_delete_codec_preset(&via_list);
  3449. }
  3450. module_init(patch_via_init)
  3451. module_exit(patch_via_exit)