patch_via.c 90 KB

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