patch_via.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
  5. *
  6. * (C) 2006-2009 VIA Technology, Inc.
  7. * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
  8. *
  9. * This driver is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This driver is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
  24. /* */
  25. /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
  26. /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
  27. /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
  28. /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
  29. /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
  30. /* 2007-09-17 Lydia Wang Add VT1708B codec support */
  31. /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
  32. /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
  33. /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
  34. /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
  35. /* 2008-04-09 Lydia Wang Add Independent HP feature */
  36. /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
  37. /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
  38. /* 2009-02-16 Logan Li Add support for VT1718S */
  39. /* 2009-03-13 Logan Li Add support for VT1716S */
  40. /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
  41. /* 2009-07-08 Lydia Wang Add support for VT2002P */
  42. /* 2009-07-21 Lydia Wang Add support for VT1812 */
  43. /* 2009-09-19 Lydia Wang Add support for VT1818S */
  44. /* */
  45. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  46. #include <linux/init.h>
  47. #include <linux/delay.h>
  48. #include <linux/slab.h>
  49. #include <linux/module.h>
  50. #include <sound/core.h>
  51. #include <sound/asoundef.h>
  52. #include "hda_codec.h"
  53. #include "hda_local.h"
  54. #include "hda_auto_parser.h"
  55. #include "hda_jack.h"
  56. #include "hda_generic.h"
  57. /* Pin Widget NID */
  58. #define VT1708_HP_PIN_NID 0x20
  59. #define VT1708_CD_PIN_NID 0x24
  60. enum VIA_HDA_CODEC {
  61. UNKNOWN = -1,
  62. VT1708,
  63. VT1709_10CH,
  64. VT1709_6CH,
  65. VT1708B_8CH,
  66. VT1708B_4CH,
  67. VT1708S,
  68. VT1708BCE,
  69. VT1702,
  70. VT1718S,
  71. VT1716S,
  72. VT2002P,
  73. VT1812,
  74. VT1802,
  75. VT1705CF,
  76. VT1808,
  77. CODEC_TYPES,
  78. };
  79. #define VT2002P_COMPATIBLE(spec) \
  80. ((spec)->codec_type == VT2002P ||\
  81. (spec)->codec_type == VT1812 ||\
  82. (spec)->codec_type == VT1802)
  83. struct via_spec {
  84. struct hda_gen_spec gen;
  85. /* codec parameterization */
  86. const struct snd_kcontrol_new *mixers[6];
  87. unsigned int num_mixers;
  88. const struct hda_verb *init_verbs[5];
  89. unsigned int num_iverbs;
  90. /* HP mode source */
  91. unsigned int dmic_enabled;
  92. unsigned int no_pin_power_ctl;
  93. enum VIA_HDA_CODEC codec_type;
  94. /* analog low-power control */
  95. bool alc_mode;
  96. /* work to check hp jack state */
  97. int hp_work_active;
  98. int vt1708_jack_detect;
  99. void (*set_widgets_power_state)(struct hda_codec *codec);
  100. unsigned int dac_stream_tag[4];
  101. };
  102. static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
  103. static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
  104. struct hda_codec *codec,
  105. struct snd_pcm_substream *substream,
  106. int action);
  107. static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl);
  108. static struct via_spec *via_new_spec(struct hda_codec *codec)
  109. {
  110. struct via_spec *spec;
  111. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  112. if (spec == NULL)
  113. return NULL;
  114. codec->spec = spec;
  115. snd_hda_gen_spec_init(&spec->gen);
  116. spec->codec_type = get_codec_type(codec);
  117. /* VT1708BCE & VT1708S are almost same */
  118. if (spec->codec_type == VT1708BCE)
  119. spec->codec_type = VT1708S;
  120. spec->no_pin_power_ctl = 1;
  121. spec->gen.indep_hp = 1;
  122. spec->gen.pcm_playback_hook = via_playback_pcm_hook;
  123. return spec;
  124. }
  125. static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
  126. {
  127. u32 vendor_id = codec->vendor_id;
  128. u16 ven_id = vendor_id >> 16;
  129. u16 dev_id = vendor_id & 0xffff;
  130. enum VIA_HDA_CODEC codec_type;
  131. /* get codec type */
  132. if (ven_id != 0x1106)
  133. codec_type = UNKNOWN;
  134. else if (dev_id >= 0x1708 && dev_id <= 0x170b)
  135. codec_type = VT1708;
  136. else if (dev_id >= 0xe710 && dev_id <= 0xe713)
  137. codec_type = VT1709_10CH;
  138. else if (dev_id >= 0xe714 && dev_id <= 0xe717)
  139. codec_type = VT1709_6CH;
  140. else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
  141. codec_type = VT1708B_8CH;
  142. if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
  143. codec_type = VT1708BCE;
  144. } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
  145. codec_type = VT1708B_4CH;
  146. else if ((dev_id & 0xfff) == 0x397
  147. && (dev_id >> 12) < 8)
  148. codec_type = VT1708S;
  149. else if ((dev_id & 0xfff) == 0x398
  150. && (dev_id >> 12) < 8)
  151. codec_type = VT1702;
  152. else if ((dev_id & 0xfff) == 0x428
  153. && (dev_id >> 12) < 8)
  154. codec_type = VT1718S;
  155. else if (dev_id == 0x0433 || dev_id == 0xa721)
  156. codec_type = VT1716S;
  157. else if (dev_id == 0x0441 || dev_id == 0x4441)
  158. codec_type = VT1718S;
  159. else if (dev_id == 0x0438 || dev_id == 0x4438)
  160. codec_type = VT2002P;
  161. else if (dev_id == 0x0448)
  162. codec_type = VT1812;
  163. else if (dev_id == 0x0440)
  164. codec_type = VT1708S;
  165. else if ((dev_id & 0xfff) == 0x446)
  166. codec_type = VT1802;
  167. else if (dev_id == 0x4760)
  168. codec_type = VT1705CF;
  169. else if (dev_id == 0x4761 || dev_id == 0x4762)
  170. codec_type = VT1808;
  171. else
  172. codec_type = UNKNOWN;
  173. return codec_type;
  174. };
  175. static void analog_low_current_mode(struct hda_codec *codec);
  176. static bool is_aa_path_mute(struct hda_codec *codec);
  177. #define hp_detect_with_aa(codec) \
  178. (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
  179. !is_aa_path_mute(codec))
  180. static void vt1708_stop_hp_work(struct hda_codec *codec)
  181. {
  182. struct via_spec *spec = codec->spec;
  183. if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
  184. return;
  185. if (spec->hp_work_active) {
  186. snd_hda_codec_write(codec, 0x1, 0, 0xf81, 1);
  187. cancel_delayed_work_sync(&codec->jackpoll_work);
  188. spec->hp_work_active = false;
  189. codec->jackpoll_interval = 0;
  190. }
  191. }
  192. static void vt1708_update_hp_work(struct hda_codec *codec)
  193. {
  194. struct via_spec *spec = codec->spec;
  195. if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
  196. return;
  197. if (spec->vt1708_jack_detect) {
  198. if (!spec->hp_work_active) {
  199. codec->jackpoll_interval = msecs_to_jiffies(100);
  200. snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0);
  201. queue_delayed_work(codec->bus->workq,
  202. &codec->jackpoll_work, 0);
  203. spec->hp_work_active = true;
  204. }
  205. } else if (!hp_detect_with_aa(codec))
  206. vt1708_stop_hp_work(codec);
  207. }
  208. static void set_widgets_power_state(struct hda_codec *codec)
  209. {
  210. struct via_spec *spec = codec->spec;
  211. if (spec->set_widgets_power_state)
  212. spec->set_widgets_power_state(codec);
  213. }
  214. static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
  215. unsigned int parm)
  216. {
  217. if (snd_hda_check_power_state(codec, nid, parm))
  218. return;
  219. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
  220. }
  221. static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
  222. unsigned int parm, unsigned int index)
  223. {
  224. struct via_spec *spec = codec->spec;
  225. unsigned int format;
  226. if (snd_hda_check_power_state(codec, nid, parm))
  227. return;
  228. format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
  229. if (format && (spec->dac_stream_tag[index] != format))
  230. spec->dac_stream_tag[index] = format;
  231. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
  232. if (parm == AC_PWRST_D0) {
  233. format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
  234. if (!format && (spec->dac_stream_tag[index] != format))
  235. snd_hda_codec_write(codec, nid, 0,
  236. AC_VERB_SET_CHANNEL_STREAMID,
  237. spec->dac_stream_tag[index]);
  238. }
  239. }
  240. static bool smart51_enabled(struct hda_codec *codec)
  241. {
  242. struct via_spec *spec = codec->spec;
  243. return spec->gen.ext_channel_count > 2;
  244. }
  245. static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
  246. {
  247. struct via_spec *spec = codec->spec;
  248. int i;
  249. for (i = 0; i < spec->gen.multi_ios; i++)
  250. if (spec->gen.multi_io[i].pin == pin)
  251. return true;
  252. return false;
  253. }
  254. static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
  255. unsigned int *affected_parm)
  256. {
  257. unsigned parm;
  258. unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
  259. unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
  260. >> AC_DEFCFG_MISC_SHIFT
  261. & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
  262. struct via_spec *spec = codec->spec;
  263. unsigned present = 0;
  264. no_presence |= spec->no_pin_power_ctl;
  265. if (!no_presence)
  266. present = snd_hda_jack_detect(codec, nid);
  267. if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
  268. || ((no_presence || present)
  269. && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
  270. *affected_parm = AC_PWRST_D0; /* if it's connected */
  271. parm = AC_PWRST_D0;
  272. } else
  273. parm = AC_PWRST_D3;
  274. update_power_state(codec, nid, parm);
  275. }
  276. static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
  277. struct snd_ctl_elem_info *uinfo)
  278. {
  279. return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
  280. }
  281. static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
  282. struct snd_ctl_elem_value *ucontrol)
  283. {
  284. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  285. struct via_spec *spec = codec->spec;
  286. ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
  287. return 0;
  288. }
  289. static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
  290. struct snd_ctl_elem_value *ucontrol)
  291. {
  292. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  293. struct via_spec *spec = codec->spec;
  294. unsigned int val = !ucontrol->value.enumerated.item[0];
  295. if (val == spec->no_pin_power_ctl)
  296. return 0;
  297. spec->no_pin_power_ctl = val;
  298. set_widgets_power_state(codec);
  299. analog_low_current_mode(codec);
  300. return 1;
  301. }
  302. static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
  303. {
  304. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  305. .name = "Dynamic Power-Control",
  306. .info = via_pin_power_ctl_info,
  307. .get = via_pin_power_ctl_get,
  308. .put = via_pin_power_ctl_put,
  309. },
  310. {} /* terminator */
  311. };
  312. /* check AA path's mute status */
  313. static bool is_aa_path_mute(struct hda_codec *codec)
  314. {
  315. struct via_spec *spec = codec->spec;
  316. const struct hda_amp_list *p;
  317. int ch, v;
  318. p = spec->gen.loopback.amplist;
  319. if (!p)
  320. return true;
  321. for (; p->nid; p++) {
  322. for (ch = 0; ch < 2; ch++) {
  323. v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
  324. p->idx);
  325. if (!(v & HDA_AMP_MUTE) && v > 0)
  326. return false;
  327. }
  328. }
  329. return true;
  330. }
  331. /* enter/exit analog low-current mode */
  332. static void __analog_low_current_mode(struct hda_codec *codec, bool force)
  333. {
  334. struct via_spec *spec = codec->spec;
  335. bool enable;
  336. unsigned int verb, parm;
  337. if (spec->no_pin_power_ctl)
  338. enable = false;
  339. else
  340. enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
  341. if (enable == spec->alc_mode && !force)
  342. return;
  343. spec->alc_mode = enable;
  344. /* decide low current mode's verb & parameter */
  345. switch (spec->codec_type) {
  346. case VT1708B_8CH:
  347. case VT1708B_4CH:
  348. verb = 0xf70;
  349. parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
  350. break;
  351. case VT1708S:
  352. case VT1718S:
  353. case VT1716S:
  354. verb = 0xf73;
  355. parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
  356. break;
  357. case VT1702:
  358. verb = 0xf73;
  359. parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
  360. break;
  361. case VT2002P:
  362. case VT1812:
  363. case VT1802:
  364. verb = 0xf93;
  365. parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
  366. break;
  367. case VT1705CF:
  368. case VT1808:
  369. verb = 0xf82;
  370. parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
  371. break;
  372. default:
  373. return; /* other codecs are not supported */
  374. }
  375. /* send verb */
  376. snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
  377. }
  378. static void analog_low_current_mode(struct hda_codec *codec)
  379. {
  380. return __analog_low_current_mode(codec, false);
  381. }
  382. static int via_build_controls(struct hda_codec *codec)
  383. {
  384. struct via_spec *spec = codec->spec;
  385. int err, i;
  386. err = snd_hda_gen_build_controls(codec);
  387. if (err < 0)
  388. return err;
  389. if (spec->set_widgets_power_state)
  390. spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
  391. for (i = 0; i < spec->num_mixers; i++) {
  392. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  393. if (err < 0)
  394. return err;
  395. }
  396. return 0;
  397. }
  398. static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
  399. struct hda_codec *codec,
  400. struct snd_pcm_substream *substream,
  401. int action)
  402. {
  403. analog_low_current_mode(codec);
  404. vt1708_update_hp_work(codec);
  405. }
  406. static void via_free(struct hda_codec *codec)
  407. {
  408. struct via_spec *spec = codec->spec;
  409. if (!spec)
  410. return;
  411. vt1708_stop_hp_work(codec);
  412. snd_hda_gen_spec_free(&spec->gen);
  413. kfree(spec);
  414. }
  415. #ifdef CONFIG_PM
  416. static int via_suspend(struct hda_codec *codec)
  417. {
  418. struct via_spec *spec = codec->spec;
  419. vt1708_stop_hp_work(codec);
  420. if (spec->codec_type == VT1802) {
  421. /* Fix pop noise on headphones */
  422. int i;
  423. for (i = 0; i < spec->gen.autocfg.hp_outs; i++)
  424. snd_hda_set_pin_ctl(codec, spec->gen.autocfg.hp_pins[i], 0);
  425. }
  426. return 0;
  427. }
  428. #endif
  429. #ifdef CONFIG_PM
  430. static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  431. {
  432. struct via_spec *spec = codec->spec;
  433. set_widgets_power_state(codec);
  434. analog_low_current_mode(codec);
  435. vt1708_update_hp_work(codec);
  436. return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
  437. }
  438. #endif
  439. /*
  440. */
  441. static int via_init(struct hda_codec *codec);
  442. static const struct hda_codec_ops via_patch_ops = {
  443. .build_controls = via_build_controls,
  444. .build_pcms = snd_hda_gen_build_pcms,
  445. .init = via_init,
  446. .free = via_free,
  447. .unsol_event = snd_hda_jack_unsol_event,
  448. #ifdef CONFIG_PM
  449. .suspend = via_suspend,
  450. .check_power_status = via_check_power_status,
  451. #endif
  452. };
  453. static const struct hda_verb vt1708_init_verbs[] = {
  454. /* power down jack detect function */
  455. {0x1, 0xf81, 0x1},
  456. { }
  457. };
  458. static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
  459. {
  460. unsigned int def_conf;
  461. unsigned char seqassoc;
  462. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  463. seqassoc = (unsigned char) get_defcfg_association(def_conf);
  464. seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
  465. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
  466. && (seqassoc == 0xf0 || seqassoc == 0xff)) {
  467. def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
  468. snd_hda_codec_set_pincfg(codec, nid, def_conf);
  469. }
  470. return;
  471. }
  472. static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
  473. struct snd_ctl_elem_value *ucontrol)
  474. {
  475. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  476. struct via_spec *spec = codec->spec;
  477. if (spec->codec_type != VT1708)
  478. return 0;
  479. ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
  480. return 0;
  481. }
  482. static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
  483. struct snd_ctl_elem_value *ucontrol)
  484. {
  485. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  486. struct via_spec *spec = codec->spec;
  487. int val;
  488. if (spec->codec_type != VT1708)
  489. return 0;
  490. val = !!ucontrol->value.integer.value[0];
  491. if (spec->vt1708_jack_detect == val)
  492. return 0;
  493. spec->vt1708_jack_detect = val;
  494. vt1708_update_hp_work(codec);
  495. return 1;
  496. }
  497. static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
  498. {
  499. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  500. .name = "Jack Detect",
  501. .count = 1,
  502. .info = snd_ctl_boolean_mono_info,
  503. .get = vt1708_jack_detect_get,
  504. .put = vt1708_jack_detect_put,
  505. },
  506. {} /* terminator */
  507. };
  508. static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
  509. {
  510. set_widgets_power_state(codec);
  511. snd_hda_gen_hp_automute(codec, tbl);
  512. }
  513. static void via_line_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
  514. {
  515. set_widgets_power_state(codec);
  516. snd_hda_gen_line_automute(codec, tbl);
  517. }
  518. static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
  519. {
  520. set_widgets_power_state(codec);
  521. }
  522. #define VIA_JACK_EVENT (HDA_GEN_LAST_EVENT + 1)
  523. static void via_set_jack_unsol_events(struct hda_codec *codec)
  524. {
  525. struct via_spec *spec = codec->spec;
  526. struct auto_pin_cfg *cfg = &spec->gen.autocfg;
  527. hda_nid_t pin;
  528. int i;
  529. spec->gen.hp_automute_hook = via_hp_automute;
  530. if (cfg->speaker_pins[0])
  531. spec->gen.line_automute_hook = via_line_automute;
  532. for (i = 0; i < cfg->line_outs; i++) {
  533. pin = cfg->line_out_pins[i];
  534. if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
  535. is_jack_detectable(codec, pin))
  536. snd_hda_jack_detect_enable_callback(codec, pin,
  537. VIA_JACK_EVENT,
  538. via_jack_powerstate_event);
  539. }
  540. for (i = 0; i < cfg->num_inputs; i++) {
  541. pin = cfg->line_out_pins[i];
  542. if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
  543. is_jack_detectable(codec, pin))
  544. snd_hda_jack_detect_enable_callback(codec, pin,
  545. VIA_JACK_EVENT,
  546. via_jack_powerstate_event);
  547. }
  548. }
  549. static int via_parse_auto_config(struct hda_codec *codec)
  550. {
  551. struct via_spec *spec = codec->spec;
  552. int err;
  553. err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
  554. if (err < 0)
  555. return err;
  556. err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
  557. if (err < 0)
  558. return err;
  559. via_set_jack_unsol_events(codec);
  560. return 0;
  561. }
  562. static int via_init(struct hda_codec *codec)
  563. {
  564. struct via_spec *spec = codec->spec;
  565. int i;
  566. for (i = 0; i < spec->num_iverbs; i++)
  567. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  568. /* init power states */
  569. set_widgets_power_state(codec);
  570. __analog_low_current_mode(codec, true);
  571. snd_hda_gen_init(codec);
  572. vt1708_update_hp_work(codec);
  573. return 0;
  574. }
  575. static int vt1708_build_controls(struct hda_codec *codec)
  576. {
  577. /* In order not to create "Phantom Jack" controls,
  578. temporary enable jackpoll */
  579. int err;
  580. int old_interval = codec->jackpoll_interval;
  581. codec->jackpoll_interval = msecs_to_jiffies(100);
  582. err = via_build_controls(codec);
  583. codec->jackpoll_interval = old_interval;
  584. return err;
  585. }
  586. static int vt1708_build_pcms(struct hda_codec *codec)
  587. {
  588. struct via_spec *spec = codec->spec;
  589. int i, err;
  590. err = snd_hda_gen_build_pcms(codec);
  591. if (err < 0 || codec->vendor_id != 0x11061708)
  592. return err;
  593. /* We got noisy outputs on the right channel on VT1708 when
  594. * 24bit samples are used. Until any workaround is found,
  595. * disable the 24bit format, so far.
  596. */
  597. for (i = 0; i < codec->num_pcms; i++) {
  598. struct hda_pcm *info = &spec->gen.pcm_rec[i];
  599. if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
  600. info->pcm_type != HDA_PCM_TYPE_AUDIO)
  601. continue;
  602. info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats =
  603. SNDRV_PCM_FMTBIT_S16_LE;
  604. }
  605. return 0;
  606. }
  607. static int patch_vt1708(struct hda_codec *codec)
  608. {
  609. struct via_spec *spec;
  610. int err;
  611. /* create a codec specific record */
  612. spec = via_new_spec(codec);
  613. if (spec == NULL)
  614. return -ENOMEM;
  615. spec->gen.mixer_nid = 0x17;
  616. /* set jackpoll_interval while parsing the codec */
  617. codec->jackpoll_interval = msecs_to_jiffies(100);
  618. spec->vt1708_jack_detect = 1;
  619. /* don't support the input jack switching due to lack of unsol event */
  620. /* (it may work with polling, though, but it needs testing) */
  621. spec->gen.suppress_auto_mic = 1;
  622. /* Add HP and CD pin config connect bit re-config action */
  623. vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
  624. vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
  625. /* automatic parse from the BIOS config */
  626. err = via_parse_auto_config(codec);
  627. if (err < 0) {
  628. via_free(codec);
  629. return err;
  630. }
  631. /* add jack detect on/off control */
  632. spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
  633. spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
  634. codec->patch_ops = via_patch_ops;
  635. codec->patch_ops.build_controls = vt1708_build_controls;
  636. codec->patch_ops.build_pcms = vt1708_build_pcms;
  637. /* clear jackpoll_interval again; it's set dynamically */
  638. codec->jackpoll_interval = 0;
  639. return 0;
  640. }
  641. static int patch_vt1709(struct hda_codec *codec)
  642. {
  643. struct via_spec *spec;
  644. int err;
  645. /* create a codec specific record */
  646. spec = via_new_spec(codec);
  647. if (spec == NULL)
  648. return -ENOMEM;
  649. spec->gen.mixer_nid = 0x18;
  650. err = via_parse_auto_config(codec);
  651. if (err < 0) {
  652. via_free(codec);
  653. return err;
  654. }
  655. codec->patch_ops = via_patch_ops;
  656. return 0;
  657. }
  658. static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
  659. {
  660. struct via_spec *spec = codec->spec;
  661. int imux_is_smixer;
  662. unsigned int parm;
  663. int is_8ch = 0;
  664. if ((spec->codec_type != VT1708B_4CH) &&
  665. (codec->vendor_id != 0x11064397))
  666. is_8ch = 1;
  667. /* SW0 (17h) = stereo mixer */
  668. imux_is_smixer =
  669. (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
  670. == ((spec->codec_type == VT1708S) ? 5 : 0));
  671. /* inputs */
  672. /* PW 1/2/5 (1ah/1bh/1eh) */
  673. parm = AC_PWRST_D3;
  674. set_pin_power_state(codec, 0x1a, &parm);
  675. set_pin_power_state(codec, 0x1b, &parm);
  676. set_pin_power_state(codec, 0x1e, &parm);
  677. if (imux_is_smixer)
  678. parm = AC_PWRST_D0;
  679. /* SW0 (17h), AIW 0/1 (13h/14h) */
  680. update_power_state(codec, 0x17, parm);
  681. update_power_state(codec, 0x13, parm);
  682. update_power_state(codec, 0x14, parm);
  683. /* outputs */
  684. /* PW0 (19h), SW1 (18h), AOW1 (11h) */
  685. parm = AC_PWRST_D3;
  686. set_pin_power_state(codec, 0x19, &parm);
  687. if (smart51_enabled(codec))
  688. set_pin_power_state(codec, 0x1b, &parm);
  689. update_power_state(codec, 0x18, parm);
  690. update_power_state(codec, 0x11, parm);
  691. /* PW6 (22h), SW2 (26h), AOW2 (24h) */
  692. if (is_8ch) {
  693. parm = AC_PWRST_D3;
  694. set_pin_power_state(codec, 0x22, &parm);
  695. if (smart51_enabled(codec))
  696. set_pin_power_state(codec, 0x1a, &parm);
  697. update_power_state(codec, 0x26, parm);
  698. update_power_state(codec, 0x24, parm);
  699. } else if (codec->vendor_id == 0x11064397) {
  700. /* PW7(23h), SW2(27h), AOW2(25h) */
  701. parm = AC_PWRST_D3;
  702. set_pin_power_state(codec, 0x23, &parm);
  703. if (smart51_enabled(codec))
  704. set_pin_power_state(codec, 0x1a, &parm);
  705. update_power_state(codec, 0x27, parm);
  706. update_power_state(codec, 0x25, parm);
  707. }
  708. /* PW 3/4/7 (1ch/1dh/23h) */
  709. parm = AC_PWRST_D3;
  710. /* force to D0 for internal Speaker */
  711. set_pin_power_state(codec, 0x1c, &parm);
  712. set_pin_power_state(codec, 0x1d, &parm);
  713. if (is_8ch)
  714. set_pin_power_state(codec, 0x23, &parm);
  715. /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
  716. update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
  717. update_power_state(codec, 0x10, parm);
  718. if (is_8ch) {
  719. update_power_state(codec, 0x25, parm);
  720. update_power_state(codec, 0x27, parm);
  721. } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
  722. update_power_state(codec, 0x25, parm);
  723. }
  724. static int patch_vt1708S(struct hda_codec *codec);
  725. static int patch_vt1708B(struct hda_codec *codec)
  726. {
  727. struct via_spec *spec;
  728. int err;
  729. if (get_codec_type(codec) == VT1708BCE)
  730. return patch_vt1708S(codec);
  731. /* create a codec specific record */
  732. spec = via_new_spec(codec);
  733. if (spec == NULL)
  734. return -ENOMEM;
  735. spec->gen.mixer_nid = 0x16;
  736. /* automatic parse from the BIOS config */
  737. err = via_parse_auto_config(codec);
  738. if (err < 0) {
  739. via_free(codec);
  740. return err;
  741. }
  742. codec->patch_ops = via_patch_ops;
  743. spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
  744. return 0;
  745. }
  746. /* Patch for VT1708S */
  747. static const struct hda_verb vt1708S_init_verbs[] = {
  748. /* Enable Mic Boost Volume backdoor */
  749. {0x1, 0xf98, 0x1},
  750. /* don't bybass mixer */
  751. {0x1, 0xf88, 0xc0},
  752. { }
  753. };
  754. static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
  755. int offset, int num_steps, int step_size)
  756. {
  757. snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
  758. (offset << AC_AMPCAP_OFFSET_SHIFT) |
  759. (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
  760. (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
  761. (0 << AC_AMPCAP_MUTE_SHIFT));
  762. }
  763. static int patch_vt1708S(struct hda_codec *codec)
  764. {
  765. struct via_spec *spec;
  766. int err;
  767. /* create a codec specific record */
  768. spec = via_new_spec(codec);
  769. if (spec == NULL)
  770. return -ENOMEM;
  771. spec->gen.mixer_nid = 0x16;
  772. override_mic_boost(codec, 0x1a, 0, 3, 40);
  773. override_mic_boost(codec, 0x1e, 0, 3, 40);
  774. /* correct names for VT1708BCE */
  775. if (get_codec_type(codec) == VT1708BCE) {
  776. kfree(codec->chip_name);
  777. codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
  778. snprintf(codec->bus->card->mixername,
  779. sizeof(codec->bus->card->mixername),
  780. "%s %s", codec->vendor_name, codec->chip_name);
  781. }
  782. /* correct names for VT1705 */
  783. if (codec->vendor_id == 0x11064397) {
  784. kfree(codec->chip_name);
  785. codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
  786. snprintf(codec->bus->card->mixername,
  787. sizeof(codec->bus->card->mixername),
  788. "%s %s", codec->vendor_name, codec->chip_name);
  789. }
  790. /* automatic parse from the BIOS config */
  791. err = via_parse_auto_config(codec);
  792. if (err < 0) {
  793. via_free(codec);
  794. return err;
  795. }
  796. spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
  797. codec->patch_ops = via_patch_ops;
  798. spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
  799. return 0;
  800. }
  801. /* Patch for VT1702 */
  802. static const struct hda_verb vt1702_init_verbs[] = {
  803. /* mixer enable */
  804. {0x1, 0xF88, 0x3},
  805. /* GPIO 0~2 */
  806. {0x1, 0xF82, 0x3F},
  807. { }
  808. };
  809. static void set_widgets_power_state_vt1702(struct hda_codec *codec)
  810. {
  811. int imux_is_smixer =
  812. snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
  813. unsigned int parm;
  814. /* inputs */
  815. /* PW 1/2/5 (14h/15h/18h) */
  816. parm = AC_PWRST_D3;
  817. set_pin_power_state(codec, 0x14, &parm);
  818. set_pin_power_state(codec, 0x15, &parm);
  819. set_pin_power_state(codec, 0x18, &parm);
  820. if (imux_is_smixer)
  821. parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
  822. /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
  823. update_power_state(codec, 0x13, parm);
  824. update_power_state(codec, 0x12, parm);
  825. update_power_state(codec, 0x1f, parm);
  826. update_power_state(codec, 0x20, parm);
  827. /* outputs */
  828. /* PW 3/4 (16h/17h) */
  829. parm = AC_PWRST_D3;
  830. set_pin_power_state(codec, 0x17, &parm);
  831. set_pin_power_state(codec, 0x16, &parm);
  832. /* MW0 (1ah), AOW 0/1 (10h/1dh) */
  833. update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
  834. update_power_state(codec, 0x10, parm);
  835. update_power_state(codec, 0x1d, parm);
  836. }
  837. static int patch_vt1702(struct hda_codec *codec)
  838. {
  839. struct via_spec *spec;
  840. int err;
  841. /* create a codec specific record */
  842. spec = via_new_spec(codec);
  843. if (spec == NULL)
  844. return -ENOMEM;
  845. spec->gen.mixer_nid = 0x1a;
  846. /* limit AA path volume to 0 dB */
  847. snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
  848. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  849. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  850. (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  851. (1 << AC_AMPCAP_MUTE_SHIFT));
  852. /* automatic parse from the BIOS config */
  853. err = via_parse_auto_config(codec);
  854. if (err < 0) {
  855. via_free(codec);
  856. return err;
  857. }
  858. spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
  859. codec->patch_ops = via_patch_ops;
  860. spec->set_widgets_power_state = set_widgets_power_state_vt1702;
  861. return 0;
  862. }
  863. /* Patch for VT1718S */
  864. static const struct hda_verb vt1718S_init_verbs[] = {
  865. /* Enable MW0 adjust Gain 5 */
  866. {0x1, 0xfb2, 0x10},
  867. /* Enable Boost Volume backdoor */
  868. {0x1, 0xf88, 0x8},
  869. { }
  870. };
  871. static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
  872. {
  873. struct via_spec *spec = codec->spec;
  874. int imux_is_smixer;
  875. unsigned int parm, parm2;
  876. /* MUX6 (1eh) = stereo mixer */
  877. imux_is_smixer =
  878. snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
  879. /* inputs */
  880. /* PW 5/6/7 (29h/2ah/2bh) */
  881. parm = AC_PWRST_D3;
  882. set_pin_power_state(codec, 0x29, &parm);
  883. set_pin_power_state(codec, 0x2a, &parm);
  884. set_pin_power_state(codec, 0x2b, &parm);
  885. if (imux_is_smixer)
  886. parm = AC_PWRST_D0;
  887. /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
  888. update_power_state(codec, 0x1e, parm);
  889. update_power_state(codec, 0x1f, parm);
  890. update_power_state(codec, 0x10, parm);
  891. update_power_state(codec, 0x11, parm);
  892. /* outputs */
  893. /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
  894. parm = AC_PWRST_D3;
  895. set_pin_power_state(codec, 0x27, &parm);
  896. update_power_state(codec, 0x1a, parm);
  897. parm2 = parm; /* for pin 0x0b */
  898. /* PW2 (26h), AOW2 (ah) */
  899. parm = AC_PWRST_D3;
  900. set_pin_power_state(codec, 0x26, &parm);
  901. if (smart51_enabled(codec))
  902. set_pin_power_state(codec, 0x2b, &parm);
  903. update_power_state(codec, 0xa, parm);
  904. /* PW0 (24h), AOW0 (8h) */
  905. parm = AC_PWRST_D3;
  906. set_pin_power_state(codec, 0x24, &parm);
  907. if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
  908. set_pin_power_state(codec, 0x28, &parm);
  909. update_power_state(codec, 0x8, parm);
  910. if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
  911. parm = parm2;
  912. update_power_state(codec, 0xb, parm);
  913. /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
  914. update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
  915. /* PW1 (25h), AOW1 (9h) */
  916. parm = AC_PWRST_D3;
  917. set_pin_power_state(codec, 0x25, &parm);
  918. if (smart51_enabled(codec))
  919. set_pin_power_state(codec, 0x2a, &parm);
  920. update_power_state(codec, 0x9, parm);
  921. if (spec->gen.indep_hp_enabled) {
  922. /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
  923. parm = AC_PWRST_D3;
  924. set_pin_power_state(codec, 0x28, &parm);
  925. update_power_state(codec, 0x1b, parm);
  926. update_power_state(codec, 0x34, parm);
  927. update_power_state(codec, 0xc, parm);
  928. }
  929. }
  930. /* Add a connection to the primary DAC from AA-mixer for some codecs
  931. * This isn't listed from the raw info, but the chip has a secret connection.
  932. */
  933. static int add_secret_dac_path(struct hda_codec *codec)
  934. {
  935. struct via_spec *spec = codec->spec;
  936. int i, nums;
  937. hda_nid_t conn[8];
  938. hda_nid_t nid;
  939. if (!spec->gen.mixer_nid)
  940. return 0;
  941. nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn,
  942. ARRAY_SIZE(conn) - 1);
  943. for (i = 0; i < nums; i++) {
  944. if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
  945. return 0;
  946. }
  947. /* find the primary DAC and add to the connection list */
  948. nid = codec->start_nid;
  949. for (i = 0; i < codec->num_nodes; i++, nid++) {
  950. unsigned int caps = get_wcaps(codec, nid);
  951. if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
  952. !(caps & AC_WCAP_DIGITAL)) {
  953. conn[nums++] = nid;
  954. return snd_hda_override_conn_list(codec,
  955. spec->gen.mixer_nid,
  956. nums, conn);
  957. }
  958. }
  959. return 0;
  960. }
  961. static int patch_vt1718S(struct hda_codec *codec)
  962. {
  963. struct via_spec *spec;
  964. int err;
  965. /* create a codec specific record */
  966. spec = via_new_spec(codec);
  967. if (spec == NULL)
  968. return -ENOMEM;
  969. spec->gen.mixer_nid = 0x21;
  970. override_mic_boost(codec, 0x2b, 0, 3, 40);
  971. override_mic_boost(codec, 0x29, 0, 3, 40);
  972. add_secret_dac_path(codec);
  973. /* automatic parse from the BIOS config */
  974. err = via_parse_auto_config(codec);
  975. if (err < 0) {
  976. via_free(codec);
  977. return err;
  978. }
  979. spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
  980. codec->patch_ops = via_patch_ops;
  981. spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
  982. return 0;
  983. }
  984. /* Patch for VT1716S */
  985. static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
  986. struct snd_ctl_elem_info *uinfo)
  987. {
  988. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  989. uinfo->count = 1;
  990. uinfo->value.integer.min = 0;
  991. uinfo->value.integer.max = 1;
  992. return 0;
  993. }
  994. static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
  995. struct snd_ctl_elem_value *ucontrol)
  996. {
  997. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  998. int index = 0;
  999. index = snd_hda_codec_read(codec, 0x26, 0,
  1000. AC_VERB_GET_CONNECT_SEL, 0);
  1001. if (index != -1)
  1002. *ucontrol->value.integer.value = index;
  1003. return 0;
  1004. }
  1005. static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
  1006. struct snd_ctl_elem_value *ucontrol)
  1007. {
  1008. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1009. struct via_spec *spec = codec->spec;
  1010. int index = *ucontrol->value.integer.value;
  1011. snd_hda_codec_write(codec, 0x26, 0,
  1012. AC_VERB_SET_CONNECT_SEL, index);
  1013. spec->dmic_enabled = index;
  1014. set_widgets_power_state(codec);
  1015. return 1;
  1016. }
  1017. static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
  1018. HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
  1019. {
  1020. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1021. .name = "Digital Mic Capture Switch",
  1022. .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
  1023. .count = 1,
  1024. .info = vt1716s_dmic_info,
  1025. .get = vt1716s_dmic_get,
  1026. .put = vt1716s_dmic_put,
  1027. },
  1028. {} /* end */
  1029. };
  1030. /* mono-out mixer elements */
  1031. static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
  1032. HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
  1033. { } /* end */
  1034. };
  1035. static const struct hda_verb vt1716S_init_verbs[] = {
  1036. /* Enable Boost Volume backdoor */
  1037. {0x1, 0xf8a, 0x80},
  1038. /* don't bybass mixer */
  1039. {0x1, 0xf88, 0xc0},
  1040. /* Enable mono output */
  1041. {0x1, 0xf90, 0x08},
  1042. { }
  1043. };
  1044. static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
  1045. {
  1046. struct via_spec *spec = codec->spec;
  1047. int imux_is_smixer;
  1048. unsigned int parm;
  1049. unsigned int mono_out, present;
  1050. /* SW0 (17h) = stereo mixer */
  1051. imux_is_smixer =
  1052. (snd_hda_codec_read(codec, 0x17, 0,
  1053. AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
  1054. /* inputs */
  1055. /* PW 1/2/5 (1ah/1bh/1eh) */
  1056. parm = AC_PWRST_D3;
  1057. set_pin_power_state(codec, 0x1a, &parm);
  1058. set_pin_power_state(codec, 0x1b, &parm);
  1059. set_pin_power_state(codec, 0x1e, &parm);
  1060. if (imux_is_smixer)
  1061. parm = AC_PWRST_D0;
  1062. /* SW0 (17h), AIW0(13h) */
  1063. update_power_state(codec, 0x17, parm);
  1064. update_power_state(codec, 0x13, parm);
  1065. parm = AC_PWRST_D3;
  1066. set_pin_power_state(codec, 0x1e, &parm);
  1067. /* PW11 (22h) */
  1068. if (spec->dmic_enabled)
  1069. set_pin_power_state(codec, 0x22, &parm);
  1070. else
  1071. update_power_state(codec, 0x22, AC_PWRST_D3);
  1072. /* SW2(26h), AIW1(14h) */
  1073. update_power_state(codec, 0x26, parm);
  1074. update_power_state(codec, 0x14, parm);
  1075. /* outputs */
  1076. /* PW0 (19h), SW1 (18h), AOW1 (11h) */
  1077. parm = AC_PWRST_D3;
  1078. set_pin_power_state(codec, 0x19, &parm);
  1079. /* Smart 5.1 PW2(1bh) */
  1080. if (smart51_enabled(codec))
  1081. set_pin_power_state(codec, 0x1b, &parm);
  1082. update_power_state(codec, 0x18, parm);
  1083. update_power_state(codec, 0x11, parm);
  1084. /* PW7 (23h), SW3 (27h), AOW3 (25h) */
  1085. parm = AC_PWRST_D3;
  1086. set_pin_power_state(codec, 0x23, &parm);
  1087. /* Smart 5.1 PW1(1ah) */
  1088. if (smart51_enabled(codec))
  1089. set_pin_power_state(codec, 0x1a, &parm);
  1090. update_power_state(codec, 0x27, parm);
  1091. /* Smart 5.1 PW5(1eh) */
  1092. if (smart51_enabled(codec))
  1093. set_pin_power_state(codec, 0x1e, &parm);
  1094. update_power_state(codec, 0x25, parm);
  1095. /* Mono out */
  1096. /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
  1097. present = snd_hda_jack_detect(codec, 0x1c);
  1098. if (present)
  1099. mono_out = 0;
  1100. else {
  1101. present = snd_hda_jack_detect(codec, 0x1d);
  1102. if (!spec->gen.indep_hp_enabled && present)
  1103. mono_out = 0;
  1104. else
  1105. mono_out = 1;
  1106. }
  1107. parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
  1108. update_power_state(codec, 0x28, parm);
  1109. update_power_state(codec, 0x29, parm);
  1110. update_power_state(codec, 0x2a, parm);
  1111. /* PW 3/4 (1ch/1dh) */
  1112. parm = AC_PWRST_D3;
  1113. set_pin_power_state(codec, 0x1c, &parm);
  1114. set_pin_power_state(codec, 0x1d, &parm);
  1115. /* HP Independent Mode, power on AOW3 */
  1116. if (spec->gen.indep_hp_enabled)
  1117. update_power_state(codec, 0x25, parm);
  1118. /* force to D0 for internal Speaker */
  1119. /* MW0 (16h), AOW0 (10h) */
  1120. update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
  1121. update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
  1122. }
  1123. static int patch_vt1716S(struct hda_codec *codec)
  1124. {
  1125. struct via_spec *spec;
  1126. int err;
  1127. /* create a codec specific record */
  1128. spec = via_new_spec(codec);
  1129. if (spec == NULL)
  1130. return -ENOMEM;
  1131. spec->gen.mixer_nid = 0x16;
  1132. override_mic_boost(codec, 0x1a, 0, 3, 40);
  1133. override_mic_boost(codec, 0x1e, 0, 3, 40);
  1134. /* automatic parse from the BIOS config */
  1135. err = via_parse_auto_config(codec);
  1136. if (err < 0) {
  1137. via_free(codec);
  1138. return err;
  1139. }
  1140. spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
  1141. spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer;
  1142. spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
  1143. codec->patch_ops = via_patch_ops;
  1144. spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
  1145. return 0;
  1146. }
  1147. /* for vt2002P */
  1148. static const struct hda_verb vt2002P_init_verbs[] = {
  1149. /* Class-D speaker related verbs */
  1150. {0x1, 0xfe0, 0x4},
  1151. {0x1, 0xfe9, 0x80},
  1152. {0x1, 0xfe2, 0x22},
  1153. /* Enable Boost Volume backdoor */
  1154. {0x1, 0xfb9, 0x24},
  1155. /* Enable AOW0 to MW9 */
  1156. {0x1, 0xfb8, 0x88},
  1157. { }
  1158. };
  1159. static const struct hda_verb vt1802_init_verbs[] = {
  1160. /* Enable Boost Volume backdoor */
  1161. {0x1, 0xfb9, 0x24},
  1162. /* Enable AOW0 to MW9 */
  1163. {0x1, 0xfb8, 0x88},
  1164. { }
  1165. };
  1166. static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
  1167. {
  1168. struct via_spec *spec = codec->spec;
  1169. int imux_is_smixer;
  1170. unsigned int parm;
  1171. unsigned int present;
  1172. /* MUX9 (1eh) = stereo mixer */
  1173. imux_is_smixer =
  1174. snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
  1175. /* inputs */
  1176. /* PW 5/6/7 (29h/2ah/2bh) */
  1177. parm = AC_PWRST_D3;
  1178. set_pin_power_state(codec, 0x29, &parm);
  1179. set_pin_power_state(codec, 0x2a, &parm);
  1180. set_pin_power_state(codec, 0x2b, &parm);
  1181. parm = AC_PWRST_D0;
  1182. /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
  1183. update_power_state(codec, 0x1e, parm);
  1184. update_power_state(codec, 0x1f, parm);
  1185. update_power_state(codec, 0x10, parm);
  1186. update_power_state(codec, 0x11, parm);
  1187. /* outputs */
  1188. /* AOW0 (8h)*/
  1189. update_power_state(codec, 0x8, parm);
  1190. if (spec->codec_type == VT1802) {
  1191. /* PW4 (28h), MW4 (18h), MUX4(38h) */
  1192. parm = AC_PWRST_D3;
  1193. set_pin_power_state(codec, 0x28, &parm);
  1194. update_power_state(codec, 0x18, parm);
  1195. update_power_state(codec, 0x38, parm);
  1196. } else {
  1197. /* PW4 (26h), MW4 (1ch), MUX4(37h) */
  1198. parm = AC_PWRST_D3;
  1199. set_pin_power_state(codec, 0x26, &parm);
  1200. update_power_state(codec, 0x1c, parm);
  1201. update_power_state(codec, 0x37, parm);
  1202. }
  1203. if (spec->codec_type == VT1802) {
  1204. /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
  1205. parm = AC_PWRST_D3;
  1206. set_pin_power_state(codec, 0x25, &parm);
  1207. update_power_state(codec, 0x15, parm);
  1208. update_power_state(codec, 0x35, parm);
  1209. } else {
  1210. /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
  1211. parm = AC_PWRST_D3;
  1212. set_pin_power_state(codec, 0x25, &parm);
  1213. update_power_state(codec, 0x19, parm);
  1214. update_power_state(codec, 0x35, parm);
  1215. }
  1216. if (spec->gen.indep_hp_enabled)
  1217. update_power_state(codec, 0x9, AC_PWRST_D0);
  1218. /* Class-D */
  1219. /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
  1220. present = snd_hda_jack_detect(codec, 0x25);
  1221. parm = AC_PWRST_D3;
  1222. set_pin_power_state(codec, 0x24, &parm);
  1223. parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
  1224. if (spec->codec_type == VT1802)
  1225. update_power_state(codec, 0x14, parm);
  1226. else
  1227. update_power_state(codec, 0x18, parm);
  1228. update_power_state(codec, 0x34, parm);
  1229. /* Mono Out */
  1230. present = snd_hda_jack_detect(codec, 0x26);
  1231. parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
  1232. if (spec->codec_type == VT1802) {
  1233. /* PW15 (33h), MW8(1ch), MUX8(3ch) */
  1234. update_power_state(codec, 0x33, parm);
  1235. update_power_state(codec, 0x1c, parm);
  1236. update_power_state(codec, 0x3c, parm);
  1237. } else {
  1238. /* PW15 (31h), MW8(17h), MUX8(3bh) */
  1239. update_power_state(codec, 0x31, parm);
  1240. update_power_state(codec, 0x17, parm);
  1241. update_power_state(codec, 0x3b, parm);
  1242. }
  1243. /* MW9 (21h) */
  1244. if (imux_is_smixer || !is_aa_path_mute(codec))
  1245. update_power_state(codec, 0x21, AC_PWRST_D0);
  1246. else
  1247. update_power_state(codec, 0x21, AC_PWRST_D3);
  1248. }
  1249. /*
  1250. * pin fix-up
  1251. */
  1252. enum {
  1253. VIA_FIXUP_INTMIC_BOOST,
  1254. VIA_FIXUP_ASUS_G75,
  1255. };
  1256. static void via_fixup_intmic_boost(struct hda_codec *codec,
  1257. const struct hda_fixup *fix, int action)
  1258. {
  1259. if (action == HDA_FIXUP_ACT_PRE_PROBE)
  1260. override_mic_boost(codec, 0x30, 0, 2, 40);
  1261. }
  1262. static const struct hda_fixup via_fixups[] = {
  1263. [VIA_FIXUP_INTMIC_BOOST] = {
  1264. .type = HDA_FIXUP_FUNC,
  1265. .v.func = via_fixup_intmic_boost,
  1266. },
  1267. [VIA_FIXUP_ASUS_G75] = {
  1268. .type = HDA_FIXUP_PINS,
  1269. .v.pins = (const struct hda_pintbl[]) {
  1270. /* set 0x24 and 0x33 as speakers */
  1271. { 0x24, 0x991301f0 },
  1272. { 0x33, 0x991301f1 }, /* subwoofer */
  1273. { }
  1274. }
  1275. },
  1276. };
  1277. static const struct snd_pci_quirk vt2002p_fixups[] = {
  1278. SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
  1279. SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
  1280. {}
  1281. };
  1282. /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
  1283. * Replace this with mixer NID 0x1c
  1284. */
  1285. static void fix_vt1802_connections(struct hda_codec *codec)
  1286. {
  1287. static hda_nid_t conn_24[] = { 0x14, 0x1c };
  1288. static hda_nid_t conn_33[] = { 0x1c };
  1289. snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
  1290. snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
  1291. }
  1292. /* patch for vt2002P */
  1293. static int patch_vt2002P(struct hda_codec *codec)
  1294. {
  1295. struct via_spec *spec;
  1296. int err;
  1297. /* create a codec specific record */
  1298. spec = via_new_spec(codec);
  1299. if (spec == NULL)
  1300. return -ENOMEM;
  1301. spec->gen.mixer_nid = 0x21;
  1302. override_mic_boost(codec, 0x2b, 0, 3, 40);
  1303. override_mic_boost(codec, 0x29, 0, 3, 40);
  1304. if (spec->codec_type == VT1802)
  1305. fix_vt1802_connections(codec);
  1306. add_secret_dac_path(codec);
  1307. snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
  1308. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  1309. /* automatic parse from the BIOS config */
  1310. err = via_parse_auto_config(codec);
  1311. if (err < 0) {
  1312. via_free(codec);
  1313. return err;
  1314. }
  1315. if (spec->codec_type == VT1802)
  1316. spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
  1317. else
  1318. spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
  1319. codec->patch_ops = via_patch_ops;
  1320. spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
  1321. return 0;
  1322. }
  1323. /* for vt1812 */
  1324. static const struct hda_verb vt1812_init_verbs[] = {
  1325. /* Enable Boost Volume backdoor */
  1326. {0x1, 0xfb9, 0x24},
  1327. /* Enable AOW0 to MW9 */
  1328. {0x1, 0xfb8, 0xa8},
  1329. { }
  1330. };
  1331. static void set_widgets_power_state_vt1812(struct hda_codec *codec)
  1332. {
  1333. struct via_spec *spec = codec->spec;
  1334. unsigned int parm;
  1335. unsigned int present;
  1336. /* inputs */
  1337. /* PW 5/6/7 (29h/2ah/2bh) */
  1338. parm = AC_PWRST_D3;
  1339. set_pin_power_state(codec, 0x29, &parm);
  1340. set_pin_power_state(codec, 0x2a, &parm);
  1341. set_pin_power_state(codec, 0x2b, &parm);
  1342. parm = AC_PWRST_D0;
  1343. /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
  1344. update_power_state(codec, 0x1e, parm);
  1345. update_power_state(codec, 0x1f, parm);
  1346. update_power_state(codec, 0x10, parm);
  1347. update_power_state(codec, 0x11, parm);
  1348. /* outputs */
  1349. /* AOW0 (8h)*/
  1350. update_power_state(codec, 0x8, AC_PWRST_D0);
  1351. /* PW4 (28h), MW4 (18h), MUX4(38h) */
  1352. parm = AC_PWRST_D3;
  1353. set_pin_power_state(codec, 0x28, &parm);
  1354. update_power_state(codec, 0x18, parm);
  1355. update_power_state(codec, 0x38, parm);
  1356. /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
  1357. parm = AC_PWRST_D3;
  1358. set_pin_power_state(codec, 0x25, &parm);
  1359. update_power_state(codec, 0x15, parm);
  1360. update_power_state(codec, 0x35, parm);
  1361. if (spec->gen.indep_hp_enabled)
  1362. update_power_state(codec, 0x9, AC_PWRST_D0);
  1363. /* Internal Speaker */
  1364. /* PW0 (24h), MW0(14h), MUX0(34h) */
  1365. present = snd_hda_jack_detect(codec, 0x25);
  1366. parm = AC_PWRST_D3;
  1367. set_pin_power_state(codec, 0x24, &parm);
  1368. if (present) {
  1369. update_power_state(codec, 0x14, AC_PWRST_D3);
  1370. update_power_state(codec, 0x34, AC_PWRST_D3);
  1371. } else {
  1372. update_power_state(codec, 0x14, AC_PWRST_D0);
  1373. update_power_state(codec, 0x34, AC_PWRST_D0);
  1374. }
  1375. /* Mono Out */
  1376. /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
  1377. present = snd_hda_jack_detect(codec, 0x28);
  1378. parm = AC_PWRST_D3;
  1379. set_pin_power_state(codec, 0x31, &parm);
  1380. if (present) {
  1381. update_power_state(codec, 0x1c, AC_PWRST_D3);
  1382. update_power_state(codec, 0x3c, AC_PWRST_D3);
  1383. update_power_state(codec, 0x3e, AC_PWRST_D3);
  1384. } else {
  1385. update_power_state(codec, 0x1c, AC_PWRST_D0);
  1386. update_power_state(codec, 0x3c, AC_PWRST_D0);
  1387. update_power_state(codec, 0x3e, AC_PWRST_D0);
  1388. }
  1389. /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
  1390. parm = AC_PWRST_D3;
  1391. set_pin_power_state(codec, 0x33, &parm);
  1392. update_power_state(codec, 0x1d, parm);
  1393. update_power_state(codec, 0x3d, parm);
  1394. }
  1395. /* patch for vt1812 */
  1396. static int patch_vt1812(struct hda_codec *codec)
  1397. {
  1398. struct via_spec *spec;
  1399. int err;
  1400. /* create a codec specific record */
  1401. spec = via_new_spec(codec);
  1402. if (spec == NULL)
  1403. return -ENOMEM;
  1404. spec->gen.mixer_nid = 0x21;
  1405. override_mic_boost(codec, 0x2b, 0, 3, 40);
  1406. override_mic_boost(codec, 0x29, 0, 3, 40);
  1407. add_secret_dac_path(codec);
  1408. /* automatic parse from the BIOS config */
  1409. err = via_parse_auto_config(codec);
  1410. if (err < 0) {
  1411. via_free(codec);
  1412. return err;
  1413. }
  1414. spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
  1415. codec->patch_ops = via_patch_ops;
  1416. spec->set_widgets_power_state = set_widgets_power_state_vt1812;
  1417. return 0;
  1418. }
  1419. /* patch for vt3476 */
  1420. static const struct hda_verb vt3476_init_verbs[] = {
  1421. /* Enable DMic 8/16/32K */
  1422. {0x1, 0xF7B, 0x30},
  1423. /* Enable Boost Volume backdoor */
  1424. {0x1, 0xFB9, 0x20},
  1425. /* Enable AOW-MW9 path */
  1426. {0x1, 0xFB8, 0x10},
  1427. { }
  1428. };
  1429. static void set_widgets_power_state_vt3476(struct hda_codec *codec)
  1430. {
  1431. struct via_spec *spec = codec->spec;
  1432. int imux_is_smixer;
  1433. unsigned int parm, parm2;
  1434. /* MUX10 (1eh) = stereo mixer */
  1435. imux_is_smixer =
  1436. snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
  1437. /* inputs */
  1438. /* PW 5/6/7 (29h/2ah/2bh) */
  1439. parm = AC_PWRST_D3;
  1440. set_pin_power_state(codec, 0x29, &parm);
  1441. set_pin_power_state(codec, 0x2a, &parm);
  1442. set_pin_power_state(codec, 0x2b, &parm);
  1443. if (imux_is_smixer)
  1444. parm = AC_PWRST_D0;
  1445. /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
  1446. update_power_state(codec, 0x1e, parm);
  1447. update_power_state(codec, 0x1f, parm);
  1448. update_power_state(codec, 0x10, parm);
  1449. update_power_state(codec, 0x11, parm);
  1450. /* outputs */
  1451. /* PW3 (27h), MW3(37h), AOW3 (bh) */
  1452. if (spec->codec_type == VT1705CF) {
  1453. parm = AC_PWRST_D3;
  1454. update_power_state(codec, 0x27, parm);
  1455. update_power_state(codec, 0x37, parm);
  1456. } else {
  1457. parm = AC_PWRST_D3;
  1458. set_pin_power_state(codec, 0x27, &parm);
  1459. update_power_state(codec, 0x37, parm);
  1460. }
  1461. /* PW2 (26h), MW2(36h), AOW2 (ah) */
  1462. parm = AC_PWRST_D3;
  1463. set_pin_power_state(codec, 0x26, &parm);
  1464. update_power_state(codec, 0x36, parm);
  1465. if (smart51_enabled(codec)) {
  1466. /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
  1467. set_pin_power_state(codec, 0x2b, &parm);
  1468. update_power_state(codec, 0x3b, parm);
  1469. update_power_state(codec, 0x1b, parm);
  1470. }
  1471. update_conv_power_state(codec, 0xa, parm, 2);
  1472. /* PW1 (25h), MW1(35h), AOW1 (9h) */
  1473. parm = AC_PWRST_D3;
  1474. set_pin_power_state(codec, 0x25, &parm);
  1475. update_power_state(codec, 0x35, parm);
  1476. if (smart51_enabled(codec)) {
  1477. /* PW6(2ah), MW6(3ah), MUX6(1ah) */
  1478. set_pin_power_state(codec, 0x2a, &parm);
  1479. update_power_state(codec, 0x3a, parm);
  1480. update_power_state(codec, 0x1a, parm);
  1481. }
  1482. update_conv_power_state(codec, 0x9, parm, 1);
  1483. /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
  1484. parm = AC_PWRST_D3;
  1485. set_pin_power_state(codec, 0x28, &parm);
  1486. update_power_state(codec, 0x38, parm);
  1487. update_power_state(codec, 0x18, parm);
  1488. if (spec->gen.indep_hp_enabled)
  1489. update_conv_power_state(codec, 0xb, parm, 3);
  1490. parm2 = parm; /* for pin 0x0b */
  1491. /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
  1492. parm = AC_PWRST_D3;
  1493. set_pin_power_state(codec, 0x24, &parm);
  1494. update_power_state(codec, 0x34, parm);
  1495. if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
  1496. parm = parm2;
  1497. update_conv_power_state(codec, 0x8, parm, 0);
  1498. /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
  1499. update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
  1500. }
  1501. static int patch_vt3476(struct hda_codec *codec)
  1502. {
  1503. struct via_spec *spec;
  1504. int err;
  1505. /* create a codec specific record */
  1506. spec = via_new_spec(codec);
  1507. if (spec == NULL)
  1508. return -ENOMEM;
  1509. spec->gen.mixer_nid = 0x3f;
  1510. add_secret_dac_path(codec);
  1511. /* automatic parse from the BIOS config */
  1512. err = via_parse_auto_config(codec);
  1513. if (err < 0) {
  1514. via_free(codec);
  1515. return err;
  1516. }
  1517. spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
  1518. codec->patch_ops = via_patch_ops;
  1519. spec->set_widgets_power_state = set_widgets_power_state_vt3476;
  1520. return 0;
  1521. }
  1522. /*
  1523. * patch entries
  1524. */
  1525. static const struct hda_codec_preset snd_hda_preset_via[] = {
  1526. { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
  1527. { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
  1528. { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
  1529. { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
  1530. { .id = 0x1106e710, .name = "VT1709 10-Ch",
  1531. .patch = patch_vt1709},
  1532. { .id = 0x1106e711, .name = "VT1709 10-Ch",
  1533. .patch = patch_vt1709},
  1534. { .id = 0x1106e712, .name = "VT1709 10-Ch",
  1535. .patch = patch_vt1709},
  1536. { .id = 0x1106e713, .name = "VT1709 10-Ch",
  1537. .patch = patch_vt1709},
  1538. { .id = 0x1106e714, .name = "VT1709 6-Ch",
  1539. .patch = patch_vt1709},
  1540. { .id = 0x1106e715, .name = "VT1709 6-Ch",
  1541. .patch = patch_vt1709},
  1542. { .id = 0x1106e716, .name = "VT1709 6-Ch",
  1543. .patch = patch_vt1709},
  1544. { .id = 0x1106e717, .name = "VT1709 6-Ch",
  1545. .patch = patch_vt1709},
  1546. { .id = 0x1106e720, .name = "VT1708B 8-Ch",
  1547. .patch = patch_vt1708B},
  1548. { .id = 0x1106e721, .name = "VT1708B 8-Ch",
  1549. .patch = patch_vt1708B},
  1550. { .id = 0x1106e722, .name = "VT1708B 8-Ch",
  1551. .patch = patch_vt1708B},
  1552. { .id = 0x1106e723, .name = "VT1708B 8-Ch",
  1553. .patch = patch_vt1708B},
  1554. { .id = 0x1106e724, .name = "VT1708B 4-Ch",
  1555. .patch = patch_vt1708B},
  1556. { .id = 0x1106e725, .name = "VT1708B 4-Ch",
  1557. .patch = patch_vt1708B},
  1558. { .id = 0x1106e726, .name = "VT1708B 4-Ch",
  1559. .patch = patch_vt1708B},
  1560. { .id = 0x1106e727, .name = "VT1708B 4-Ch",
  1561. .patch = patch_vt1708B},
  1562. { .id = 0x11060397, .name = "VT1708S",
  1563. .patch = patch_vt1708S},
  1564. { .id = 0x11061397, .name = "VT1708S",
  1565. .patch = patch_vt1708S},
  1566. { .id = 0x11062397, .name = "VT1708S",
  1567. .patch = patch_vt1708S},
  1568. { .id = 0x11063397, .name = "VT1708S",
  1569. .patch = patch_vt1708S},
  1570. { .id = 0x11064397, .name = "VT1705",
  1571. .patch = patch_vt1708S},
  1572. { .id = 0x11065397, .name = "VT1708S",
  1573. .patch = patch_vt1708S},
  1574. { .id = 0x11066397, .name = "VT1708S",
  1575. .patch = patch_vt1708S},
  1576. { .id = 0x11067397, .name = "VT1708S",
  1577. .patch = patch_vt1708S},
  1578. { .id = 0x11060398, .name = "VT1702",
  1579. .patch = patch_vt1702},
  1580. { .id = 0x11061398, .name = "VT1702",
  1581. .patch = patch_vt1702},
  1582. { .id = 0x11062398, .name = "VT1702",
  1583. .patch = patch_vt1702},
  1584. { .id = 0x11063398, .name = "VT1702",
  1585. .patch = patch_vt1702},
  1586. { .id = 0x11064398, .name = "VT1702",
  1587. .patch = patch_vt1702},
  1588. { .id = 0x11065398, .name = "VT1702",
  1589. .patch = patch_vt1702},
  1590. { .id = 0x11066398, .name = "VT1702",
  1591. .patch = patch_vt1702},
  1592. { .id = 0x11067398, .name = "VT1702",
  1593. .patch = patch_vt1702},
  1594. { .id = 0x11060428, .name = "VT1718S",
  1595. .patch = patch_vt1718S},
  1596. { .id = 0x11064428, .name = "VT1718S",
  1597. .patch = patch_vt1718S},
  1598. { .id = 0x11060441, .name = "VT2020",
  1599. .patch = patch_vt1718S},
  1600. { .id = 0x11064441, .name = "VT1828S",
  1601. .patch = patch_vt1718S},
  1602. { .id = 0x11060433, .name = "VT1716S",
  1603. .patch = patch_vt1716S},
  1604. { .id = 0x1106a721, .name = "VT1716S",
  1605. .patch = patch_vt1716S},
  1606. { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
  1607. { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
  1608. { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
  1609. { .id = 0x11060440, .name = "VT1818S",
  1610. .patch = patch_vt1708S},
  1611. { .id = 0x11060446, .name = "VT1802",
  1612. .patch = patch_vt2002P},
  1613. { .id = 0x11068446, .name = "VT1802",
  1614. .patch = patch_vt2002P},
  1615. { .id = 0x11064760, .name = "VT1705CF",
  1616. .patch = patch_vt3476},
  1617. { .id = 0x11064761, .name = "VT1708SCE",
  1618. .patch = patch_vt3476},
  1619. { .id = 0x11064762, .name = "VT1808",
  1620. .patch = patch_vt3476},
  1621. {} /* terminator */
  1622. };
  1623. MODULE_ALIAS("snd-hda-codec-id:1106*");
  1624. static struct hda_codec_preset_list via_list = {
  1625. .preset = snd_hda_preset_via,
  1626. .owner = THIS_MODULE,
  1627. };
  1628. MODULE_LICENSE("GPL");
  1629. MODULE_DESCRIPTION("VIA HD-audio codec");
  1630. static int __init patch_via_init(void)
  1631. {
  1632. return snd_hda_add_codec_preset(&via_list);
  1633. }
  1634. static void __exit patch_via_exit(void)
  1635. {
  1636. snd_hda_delete_codec_preset(&via_list);
  1637. }
  1638. module_init(patch_via_init)
  1639. module_exit(patch_via_exit)