patch_via.c 106 KB

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