patch_via.c 109 KB

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