patch_via.c 106 KB

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