patch_via.c 105 KB

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