patch_via.c 103 KB

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