patch_via.c 104 KB

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