patch_via.c 106 KB

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