patch_via.c 104 KB

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