patch_via.c 51 KB

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