patch_via.c 106 KB

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