patch_via.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for VIA VT1708 codec
  5. *
  6. * Copyright (c) 2006 Lydia Wang <lydiawang@viatech.com>
  7. * 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. /* */
  30. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  31. #include <sound/driver.h>
  32. #include <linux/init.h>
  33. #include <linux/delay.h>
  34. #include <linux/slab.h>
  35. #include <sound/core.h>
  36. #include "hda_codec.h"
  37. #include "hda_local.h"
  38. /* amp values */
  39. #define AMP_VAL_IDX_SHIFT 19
  40. #define AMP_VAL_IDX_MASK (0x0f<<19)
  41. #define NUM_CONTROL_ALLOC 32
  42. #define NUM_VERB_ALLOC 32
  43. /* Pin Widget NID */
  44. #define VT1708_HP_NID 0x13
  45. #define VT1708_DIGOUT_NID 0x14
  46. #define VT1708_DIGIN_NID 0x16
  47. #define VT1709_HP_DAC_NID 0x28
  48. #define VT1709_DIGOUT_NID 0x13
  49. #define VT1709_DIGIN_NID 0x17
  50. #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
  51. #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
  52. #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
  53. enum {
  54. VIA_CTL_WIDGET_VOL,
  55. VIA_CTL_WIDGET_MUTE,
  56. };
  57. enum {
  58. AUTO_SEQ_FRONT,
  59. AUTO_SEQ_SURROUND,
  60. AUTO_SEQ_CENLFE,
  61. AUTO_SEQ_SIDE
  62. };
  63. static struct snd_kcontrol_new vt1708_control_templates[] = {
  64. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  65. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  66. };
  67. struct via_spec {
  68. /* codec parameterization */
  69. struct snd_kcontrol_new *mixers[3];
  70. unsigned int num_mixers;
  71. struct hda_verb *init_verbs;
  72. char *stream_name_analog;
  73. struct hda_pcm_stream *stream_analog_playback;
  74. struct hda_pcm_stream *stream_analog_capture;
  75. char *stream_name_digital;
  76. struct hda_pcm_stream *stream_digital_playback;
  77. struct hda_pcm_stream *stream_digital_capture;
  78. /* playback */
  79. struct hda_multi_out multiout;
  80. /* capture */
  81. unsigned int num_adc_nids;
  82. hda_nid_t *adc_nids;
  83. hda_nid_t dig_in_nid;
  84. /* capture source */
  85. const struct hda_input_mux *input_mux;
  86. unsigned int cur_mux[3];
  87. /* PCM information */
  88. struct hda_pcm pcm_rec[2];
  89. /* dynamic controls, init_verbs and input_mux */
  90. struct auto_pin_cfg autocfg;
  91. unsigned int num_kctl_alloc, num_kctl_used;
  92. struct snd_kcontrol_new *kctl_alloc;
  93. struct hda_input_mux private_imux;
  94. hda_nid_t private_dac_nids[4];
  95. };
  96. static hda_nid_t vt1708_adc_nids[2] = {
  97. /* ADC1-2 */
  98. 0x15, 0x27
  99. };
  100. static hda_nid_t vt1709_adc_nids[3] = {
  101. /* ADC1-2 */
  102. 0x14, 0x15, 0x16
  103. };
  104. /* add dynamic controls */
  105. static int via_add_control(struct via_spec *spec, int type, const char *name,
  106. unsigned long val)
  107. {
  108. struct snd_kcontrol_new *knew;
  109. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  110. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  111. /* array + terminator */
  112. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
  113. if (!knew)
  114. return -ENOMEM;
  115. if (spec->kctl_alloc) {
  116. memcpy(knew, spec->kctl_alloc,
  117. sizeof(*knew) * spec->num_kctl_alloc);
  118. kfree(spec->kctl_alloc);
  119. }
  120. spec->kctl_alloc = knew;
  121. spec->num_kctl_alloc = num;
  122. }
  123. knew = &spec->kctl_alloc[spec->num_kctl_used];
  124. *knew = vt1708_control_templates[type];
  125. knew->name = kstrdup(name, GFP_KERNEL);
  126. if (!knew->name)
  127. return -ENOMEM;
  128. knew->private_value = val;
  129. spec->num_kctl_used++;
  130. return 0;
  131. }
  132. /* create input playback/capture controls for the given pin */
  133. static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
  134. const char *ctlname, int idx, int mix_nid)
  135. {
  136. char name[32];
  137. int err;
  138. sprintf(name, "%s Playback Volume", ctlname);
  139. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  140. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  141. if (err < 0)
  142. return err;
  143. sprintf(name, "%s Playback Switch", ctlname);
  144. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  145. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  146. if (err < 0)
  147. return err;
  148. return 0;
  149. }
  150. static void via_auto_set_output_and_unmute(struct hda_codec *codec,
  151. hda_nid_t nid, int pin_type,
  152. int dac_idx)
  153. {
  154. /* set as output */
  155. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  156. pin_type);
  157. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  158. AMP_OUT_UNMUTE);
  159. }
  160. static void via_auto_init_multi_out(struct hda_codec *codec)
  161. {
  162. struct via_spec *spec = codec->spec;
  163. int i;
  164. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  165. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  166. if (nid)
  167. via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
  168. }
  169. }
  170. static void via_auto_init_hp_out(struct hda_codec *codec)
  171. {
  172. struct via_spec *spec = codec->spec;
  173. hda_nid_t pin;
  174. pin = spec->autocfg.hp_pins[0];
  175. if (pin) /* connect to front */
  176. via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
  177. }
  178. static void via_auto_init_analog_input(struct hda_codec *codec)
  179. {
  180. struct via_spec *spec = codec->spec;
  181. int i;
  182. for (i = 0; i < AUTO_PIN_LAST; i++) {
  183. hda_nid_t nid = spec->autocfg.input_pins[i];
  184. snd_hda_codec_write(codec, nid, 0,
  185. AC_VERB_SET_PIN_WIDGET_CONTROL,
  186. (i <= AUTO_PIN_FRONT_MIC ?
  187. PIN_VREF50 : PIN_IN));
  188. }
  189. }
  190. /*
  191. * input MUX handling
  192. */
  193. static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
  194. struct snd_ctl_elem_info *uinfo)
  195. {
  196. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  197. struct via_spec *spec = codec->spec;
  198. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  199. }
  200. static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
  201. struct snd_ctl_elem_value *ucontrol)
  202. {
  203. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  204. struct via_spec *spec = codec->spec;
  205. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  206. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  207. return 0;
  208. }
  209. static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
  210. struct snd_ctl_elem_value *ucontrol)
  211. {
  212. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  213. struct via_spec *spec = codec->spec;
  214. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  215. unsigned int vendor_id = codec->vendor_id;
  216. /* AIW0 lydia 060801 add for correct sw0 input select */
  217. if (IS_VT1708_VENDORID(vendor_id) && (adc_idx == 0))
  218. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  219. 0x18, &spec->cur_mux[adc_idx]);
  220. else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
  221. IS_VT1709_6CH_VENDORID(vendor_id)) && (adc_idx == 0) )
  222. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  223. 0x19, &spec->cur_mux[adc_idx]);
  224. else
  225. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  226. spec->adc_nids[adc_idx],
  227. &spec->cur_mux[adc_idx]);
  228. }
  229. /* capture mixer elements */
  230. static struct snd_kcontrol_new vt1708_capture_mixer[] = {
  231. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
  232. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
  233. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
  234. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
  235. {
  236. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  237. /* The multiple "Capture Source" controls confuse alsamixer
  238. * So call somewhat different..
  239. * FIXME: the controls appear in the "playback" view!
  240. */
  241. /* .name = "Capture Source", */
  242. .name = "Input Source",
  243. .count = 1,
  244. .info = via_mux_enum_info,
  245. .get = via_mux_enum_get,
  246. .put = via_mux_enum_put,
  247. },
  248. { } /* end */
  249. };
  250. /*
  251. * generic initialization of ADC, input mixers and output mixers
  252. */
  253. static struct hda_verb vt1708_volume_init_verbs[] = {
  254. /*
  255. * Unmute ADC0-1 and set the default input to mic-in
  256. */
  257. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  258. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  259. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  260. * mixer widget
  261. */
  262. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  263. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  264. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  265. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  266. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  267. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  268. /*
  269. * Set up output mixers (0x19 - 0x1b)
  270. */
  271. /* set vol=0 to output mixers */
  272. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  273. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  274. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  275. /* Setup default input to PW4 */
  276. {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
  277. /* Set mic as default input of sw0 */
  278. {0x18, AC_VERB_SET_CONNECT_SEL, 0x2},
  279. /* PW9 Output enable */
  280. {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  281. };
  282. static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
  283. struct hda_codec *codec,
  284. struct snd_pcm_substream *substream)
  285. {
  286. struct via_spec *spec = codec->spec;
  287. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  288. }
  289. static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  290. struct hda_codec *codec,
  291. unsigned int stream_tag,
  292. unsigned int format,
  293. struct snd_pcm_substream *substream)
  294. {
  295. struct via_spec *spec = codec->spec;
  296. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  297. stream_tag, format, substream);
  298. }
  299. static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  300. struct hda_codec *codec,
  301. struct snd_pcm_substream *substream)
  302. {
  303. struct via_spec *spec = codec->spec;
  304. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  305. }
  306. /*
  307. * Digital out
  308. */
  309. static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  310. struct hda_codec *codec,
  311. struct snd_pcm_substream *substream)
  312. {
  313. struct via_spec *spec = codec->spec;
  314. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  315. }
  316. static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  317. struct hda_codec *codec,
  318. struct snd_pcm_substream *substream)
  319. {
  320. struct via_spec *spec = codec->spec;
  321. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  322. }
  323. static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  324. struct hda_codec *codec,
  325. unsigned int stream_tag,
  326. unsigned int format,
  327. struct snd_pcm_substream *substream)
  328. {
  329. struct via_spec *spec = codec->spec;
  330. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  331. stream_tag, format, substream);
  332. }
  333. /*
  334. * Analog capture
  335. */
  336. static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  337. struct hda_codec *codec,
  338. unsigned int stream_tag,
  339. unsigned int format,
  340. struct snd_pcm_substream *substream)
  341. {
  342. struct via_spec *spec = codec->spec;
  343. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  344. stream_tag, 0, format);
  345. return 0;
  346. }
  347. static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  348. struct hda_codec *codec,
  349. struct snd_pcm_substream *substream)
  350. {
  351. struct via_spec *spec = codec->spec;
  352. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  353. 0, 0, 0);
  354. return 0;
  355. }
  356. static struct hda_pcm_stream vt1708_pcm_analog_playback = {
  357. .substreams = 1,
  358. .channels_min = 2,
  359. .channels_max = 8,
  360. .nid = 0x10, /* NID to query formats and rates */
  361. .ops = {
  362. .open = via_playback_pcm_open,
  363. .prepare = via_playback_pcm_prepare,
  364. .cleanup = via_playback_pcm_cleanup
  365. },
  366. };
  367. static struct hda_pcm_stream vt1708_pcm_analog_capture = {
  368. .substreams = 2,
  369. .channels_min = 2,
  370. .channels_max = 2,
  371. .nid = 0x15, /* NID to query formats and rates */
  372. .ops = {
  373. .prepare = via_capture_pcm_prepare,
  374. .cleanup = via_capture_pcm_cleanup
  375. },
  376. };
  377. static struct hda_pcm_stream vt1708_pcm_digital_playback = {
  378. .substreams = 1,
  379. .channels_min = 2,
  380. .channels_max = 2,
  381. /* NID is set in via_build_pcms */
  382. .ops = {
  383. .open = via_dig_playback_pcm_open,
  384. .close = via_dig_playback_pcm_close,
  385. .prepare = via_dig_playback_pcm_prepare
  386. },
  387. };
  388. static struct hda_pcm_stream vt1708_pcm_digital_capture = {
  389. .substreams = 1,
  390. .channels_min = 2,
  391. .channels_max = 2,
  392. };
  393. static int via_build_controls(struct hda_codec *codec)
  394. {
  395. struct via_spec *spec = codec->spec;
  396. int err;
  397. int i;
  398. for (i = 0; i < spec->num_mixers; i++) {
  399. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  400. if (err < 0)
  401. return err;
  402. }
  403. if (spec->multiout.dig_out_nid) {
  404. err = snd_hda_create_spdif_out_ctls(codec,
  405. spec->multiout.dig_out_nid);
  406. if (err < 0)
  407. return err;
  408. }
  409. if (spec->dig_in_nid) {
  410. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  411. if (err < 0)
  412. return err;
  413. }
  414. return 0;
  415. }
  416. static int via_build_pcms(struct hda_codec *codec)
  417. {
  418. struct via_spec *spec = codec->spec;
  419. struct hda_pcm *info = spec->pcm_rec;
  420. codec->num_pcms = 1;
  421. codec->pcm_info = info;
  422. info->name = spec->stream_name_analog;
  423. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
  424. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  425. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
  426. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  427. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  428. spec->multiout.max_channels;
  429. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  430. codec->num_pcms++;
  431. info++;
  432. info->name = spec->stream_name_digital;
  433. if (spec->multiout.dig_out_nid) {
  434. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  435. *(spec->stream_digital_playback);
  436. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  437. spec->multiout.dig_out_nid;
  438. }
  439. if (spec->dig_in_nid) {
  440. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  441. *(spec->stream_digital_capture);
  442. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  443. spec->dig_in_nid;
  444. }
  445. }
  446. return 0;
  447. }
  448. static void via_free(struct hda_codec *codec)
  449. {
  450. struct via_spec *spec = codec->spec;
  451. unsigned int i;
  452. if (!spec)
  453. return;
  454. if (spec->kctl_alloc) {
  455. for (i = 0; i < spec->num_kctl_used; i++)
  456. kfree(spec->kctl_alloc[i].name);
  457. kfree(spec->kctl_alloc);
  458. }
  459. kfree(codec->spec);
  460. }
  461. static int via_init(struct hda_codec *codec)
  462. {
  463. struct via_spec *spec = codec->spec;
  464. snd_hda_sequence_write(codec, spec->init_verbs);
  465. return 0;
  466. }
  467. /*
  468. */
  469. static struct hda_codec_ops via_patch_ops = {
  470. .build_controls = via_build_controls,
  471. .build_pcms = via_build_pcms,
  472. .init = via_init,
  473. .free = via_free,
  474. };
  475. /* fill in the dac_nids table from the parsed pin configuration */
  476. static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
  477. const struct auto_pin_cfg *cfg)
  478. {
  479. int i;
  480. hda_nid_t nid;
  481. spec->multiout.num_dacs = cfg->line_outs;
  482. spec->multiout.dac_nids = spec->private_dac_nids;
  483. for(i = 0; i < 4; i++) {
  484. nid = cfg->line_out_pins[i];
  485. if (nid) {
  486. /* config dac list */
  487. switch (i) {
  488. case AUTO_SEQ_FRONT:
  489. spec->multiout.dac_nids[i] = 0x10;
  490. break;
  491. case AUTO_SEQ_CENLFE:
  492. spec->multiout.dac_nids[i] = 0x12;
  493. break;
  494. case AUTO_SEQ_SURROUND:
  495. spec->multiout.dac_nids[i] = 0x13;
  496. break;
  497. case AUTO_SEQ_SIDE:
  498. spec->multiout.dac_nids[i] = 0x11;
  499. break;
  500. }
  501. }
  502. }
  503. return 0;
  504. }
  505. /* add playback controls from the parsed DAC table */
  506. static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
  507. const struct auto_pin_cfg *cfg)
  508. {
  509. char name[32];
  510. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  511. hda_nid_t nid, nid_vol = 0;
  512. int i, err;
  513. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  514. nid = cfg->line_out_pins[i];
  515. if (!nid)
  516. continue;
  517. if (i != AUTO_SEQ_FRONT)
  518. nid_vol = 0x1b - i + 1;
  519. if (i == AUTO_SEQ_CENLFE) {
  520. /* Center/LFE */
  521. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  522. "Center Playback Volume",
  523. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
  524. if (err < 0)
  525. return err;
  526. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  527. "LFE Playback Volume",
  528. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
  529. if (err < 0)
  530. return err;
  531. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  532. "Center Playback Switch",
  533. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
  534. if (err < 0)
  535. return err;
  536. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  537. "LFE Playback Switch",
  538. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
  539. if (err < 0)
  540. return err;
  541. } else if (i == AUTO_SEQ_FRONT){
  542. /* add control to mixer index 0 */
  543. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  544. "Master Front Playback Volume",
  545. HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT));
  546. if (err < 0)
  547. return err;
  548. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  549. "Master Front Playback Switch",
  550. HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT));
  551. if (err < 0)
  552. return err;
  553. /* add control to PW3 */
  554. sprintf(name, "%s Playback Volume", chname[i]);
  555. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  556. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
  557. if (err < 0)
  558. return err;
  559. sprintf(name, "%s Playback Switch", chname[i]);
  560. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  561. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
  562. if (err < 0)
  563. return err;
  564. } else {
  565. sprintf(name, "%s Playback Volume", chname[i]);
  566. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  567. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
  568. if (err < 0)
  569. return err;
  570. sprintf(name, "%s Playback Switch", chname[i]);
  571. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  572. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
  573. if (err < 0)
  574. return err;
  575. }
  576. }
  577. return 0;
  578. }
  579. static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  580. {
  581. int err;
  582. if (!pin)
  583. return 0;
  584. spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
  585. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  586. "Headphone Playback Volume",
  587. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  588. if (err < 0)
  589. return err;
  590. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  591. "Headphone Playback Switch",
  592. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  593. if (err < 0)
  594. return err;
  595. return 0;
  596. }
  597. /* create playback/capture controls for input pins */
  598. static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
  599. const struct auto_pin_cfg *cfg)
  600. {
  601. static char *labels[] = {
  602. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  603. };
  604. struct hda_input_mux *imux = &spec->private_imux;
  605. int i, err, idx = 0;
  606. /* for internal loopback recording select */
  607. imux->items[imux->num_items].label = "Stereo Mixer";
  608. imux->items[imux->num_items].index = idx;
  609. imux->num_items++;
  610. for (i = 0; i < AUTO_PIN_LAST; i++) {
  611. if (!cfg->input_pins[i])
  612. continue;
  613. switch (cfg->input_pins[i]) {
  614. case 0x1d: /* Mic */
  615. idx = 2;
  616. break;
  617. case 0x1e: /* Line In */
  618. idx = 3;
  619. break;
  620. case 0x21: /* Front Mic */
  621. idx = 4;
  622. break;
  623. case 0x24: /* CD */
  624. idx = 1;
  625. break;
  626. }
  627. err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
  628. idx, 0x17);
  629. if (err < 0)
  630. return err;
  631. imux->items[imux->num_items].label = labels[i];
  632. imux->items[imux->num_items].index = idx;
  633. imux->num_items++;
  634. }
  635. return 0;
  636. }
  637. static int vt1708_parse_auto_config(struct hda_codec *codec)
  638. {
  639. struct via_spec *spec = codec->spec;
  640. int err;
  641. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  642. if (err < 0)
  643. return err;
  644. err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
  645. if (err < 0)
  646. return err;
  647. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  648. return 0; /* can't find valid BIOS pin config */
  649. err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
  650. if (err < 0)
  651. return err;
  652. err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  653. if (err < 0)
  654. return err;
  655. err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
  656. if (err < 0)
  657. return err;
  658. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  659. if (spec->autocfg.dig_out_pin)
  660. spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
  661. if (spec->autocfg.dig_in_pin)
  662. spec->dig_in_nid = VT1708_DIGIN_NID;
  663. if (spec->kctl_alloc)
  664. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  665. spec->init_verbs = vt1708_volume_init_verbs;
  666. spec->input_mux = &spec->private_imux;
  667. return 1;
  668. }
  669. /* init callback for auto-configuration model -- overriding the default init */
  670. static int via_auto_init(struct hda_codec *codec)
  671. {
  672. via_init(codec);
  673. via_auto_init_multi_out(codec);
  674. via_auto_init_hp_out(codec);
  675. via_auto_init_analog_input(codec);
  676. return 0;
  677. }
  678. static int patch_vt1708(struct hda_codec *codec)
  679. {
  680. struct via_spec *spec;
  681. int err;
  682. /* create a codec specific record */
  683. spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
  684. if (spec == NULL)
  685. return -ENOMEM;
  686. codec->spec = spec;
  687. /* automatic parse from the BIOS config */
  688. err = vt1708_parse_auto_config(codec);
  689. if (err < 0) {
  690. via_free(codec);
  691. return err;
  692. } else if (!err) {
  693. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  694. "from BIOS. Using genenic mode...\n");
  695. }
  696. spec->stream_name_analog = "VT1708 Analog";
  697. spec->stream_analog_playback = &vt1708_pcm_analog_playback;
  698. spec->stream_analog_capture = &vt1708_pcm_analog_capture;
  699. spec->stream_name_digital = "VT1708 Digital";
  700. spec->stream_digital_playback = &vt1708_pcm_digital_playback;
  701. spec->stream_digital_capture = &vt1708_pcm_digital_capture;
  702. if (!spec->adc_nids && spec->input_mux) {
  703. spec->adc_nids = vt1708_adc_nids;
  704. spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
  705. spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
  706. spec->num_mixers++;
  707. }
  708. codec->patch_ops = via_patch_ops;
  709. codec->patch_ops.init = via_auto_init;
  710. return 0;
  711. }
  712. /* capture mixer elements */
  713. static struct snd_kcontrol_new vt1709_capture_mixer[] = {
  714. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
  715. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
  716. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
  717. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
  718. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
  719. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
  720. {
  721. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  722. /* The multiple "Capture Source" controls confuse alsamixer
  723. * So call somewhat different..
  724. * FIXME: the controls appear in the "playback" view!
  725. */
  726. /* .name = "Capture Source", */
  727. .name = "Input Source",
  728. .count = 1,
  729. .info = via_mux_enum_info,
  730. .get = via_mux_enum_get,
  731. .put = via_mux_enum_put,
  732. },
  733. { } /* end */
  734. };
  735. /*
  736. * generic initialization of ADC, input mixers and output mixers
  737. */
  738. static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
  739. /*
  740. * Unmute ADC0-2 and set the default input to mic-in
  741. */
  742. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  743. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  744. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  745. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  746. * mixer widget
  747. */
  748. /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  749. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  750. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  751. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  752. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  753. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  754. /*
  755. * Set up output selector (0x1a, 0x1b, 0x29)
  756. */
  757. /* set vol=0 to output mixers */
  758. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  759. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  760. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  761. /*
  762. * Unmute PW3 and PW4
  763. */
  764. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  765. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  766. /* Set input of PW4 as AOW4 */
  767. {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
  768. /* Set mic as default input of sw0 */
  769. {0x19, AC_VERB_SET_CONNECT_SEL, 0x2},
  770. /* PW9 Output enable */
  771. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  772. { }
  773. };
  774. static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
  775. .substreams = 1,
  776. .channels_min = 2,
  777. .channels_max = 10,
  778. .nid = 0x10, /* NID to query formats and rates */
  779. .ops = {
  780. .open = via_playback_pcm_open,
  781. .prepare = via_playback_pcm_prepare,
  782. .cleanup = via_playback_pcm_cleanup
  783. },
  784. };
  785. static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
  786. .substreams = 1,
  787. .channels_min = 2,
  788. .channels_max = 6,
  789. .nid = 0x10, /* NID to query formats and rates */
  790. .ops = {
  791. .open = via_playback_pcm_open,
  792. .prepare = via_playback_pcm_prepare,
  793. .cleanup = via_playback_pcm_cleanup
  794. },
  795. };
  796. static struct hda_pcm_stream vt1709_pcm_analog_capture = {
  797. .substreams = 2,
  798. .channels_min = 2,
  799. .channels_max = 2,
  800. .nid = 0x14, /* NID to query formats and rates */
  801. .ops = {
  802. .prepare = via_capture_pcm_prepare,
  803. .cleanup = via_capture_pcm_cleanup
  804. },
  805. };
  806. static struct hda_pcm_stream vt1709_pcm_digital_playback = {
  807. .substreams = 1,
  808. .channels_min = 2,
  809. .channels_max = 2,
  810. /* NID is set in via_build_pcms */
  811. .ops = {
  812. .open = via_dig_playback_pcm_open,
  813. .close = via_dig_playback_pcm_close
  814. },
  815. };
  816. static struct hda_pcm_stream vt1709_pcm_digital_capture = {
  817. .substreams = 1,
  818. .channels_min = 2,
  819. .channels_max = 2,
  820. };
  821. static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
  822. const struct auto_pin_cfg *cfg)
  823. {
  824. int i;
  825. hda_nid_t nid;
  826. if (cfg->line_outs == 4) /* 10 channels */
  827. spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
  828. else if (cfg->line_outs == 3) /* 6 channels */
  829. spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
  830. spec->multiout.dac_nids = spec->private_dac_nids;
  831. if (cfg->line_outs == 4) { /* 10 channels */
  832. for (i = 0; i < cfg->line_outs; i++) {
  833. nid = cfg->line_out_pins[i];
  834. if (nid) {
  835. /* config dac list */
  836. switch (i) {
  837. case AUTO_SEQ_FRONT:
  838. /* AOW0 */
  839. spec->multiout.dac_nids[i] = 0x10;
  840. break;
  841. case AUTO_SEQ_CENLFE:
  842. /* AOW2 */
  843. spec->multiout.dac_nids[i] = 0x12;
  844. break;
  845. case AUTO_SEQ_SURROUND:
  846. /* AOW3 */
  847. spec->multiout.dac_nids[i] = 0x27;
  848. break;
  849. case AUTO_SEQ_SIDE:
  850. /* AOW1 */
  851. spec->multiout.dac_nids[i] = 0x11;
  852. break;
  853. default:
  854. break;
  855. }
  856. }
  857. }
  858. spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
  859. } else if (cfg->line_outs == 3) { /* 6 channels */
  860. for(i = 0; i < cfg->line_outs; i++) {
  861. nid = cfg->line_out_pins[i];
  862. if (nid) {
  863. /* config dac list */
  864. switch(i) {
  865. case AUTO_SEQ_FRONT:
  866. /* AOW0 */
  867. spec->multiout.dac_nids[i] = 0x10;
  868. break;
  869. case AUTO_SEQ_CENLFE:
  870. /* AOW2 */
  871. spec->multiout.dac_nids[i] = 0x12;
  872. break;
  873. case AUTO_SEQ_SURROUND:
  874. /* AOW1 */
  875. spec->multiout.dac_nids[i] = 0x11;
  876. break;
  877. default:
  878. break;
  879. }
  880. }
  881. }
  882. }
  883. return 0;
  884. }
  885. /* add playback controls from the parsed DAC table */
  886. static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
  887. const struct auto_pin_cfg *cfg)
  888. {
  889. char name[32];
  890. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  891. hda_nid_t nid = 0;
  892. int i, err;
  893. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  894. nid = cfg->line_out_pins[i];
  895. if (!nid)
  896. continue;
  897. if (i == AUTO_SEQ_CENLFE) {
  898. /* Center/LFE */
  899. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  900. "Center Playback Volume",
  901. HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, HDA_OUTPUT));
  902. if (err < 0)
  903. return err;
  904. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  905. "LFE Playback Volume",
  906. HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, HDA_OUTPUT));
  907. if (err < 0)
  908. return err;
  909. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  910. "Center Playback Switch",
  911. HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, HDA_OUTPUT));
  912. if (err < 0)
  913. return err;
  914. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  915. "LFE Playback Switch",
  916. HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, HDA_OUTPUT));
  917. if (err < 0)
  918. return err;
  919. } else if (i == AUTO_SEQ_FRONT){
  920. /* add control to mixer index 0 */
  921. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  922. "Master Front Playback Volume",
  923. HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT));
  924. if (err < 0)
  925. return err;
  926. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  927. "Master Front Playback Switch",
  928. HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT));
  929. if (err < 0)
  930. return err;
  931. /* add control to PW3 */
  932. sprintf(name, "%s Playback Volume", chname[i]);
  933. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  934. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
  935. if (err < 0)
  936. return err;
  937. sprintf(name, "%s Playback Switch", chname[i]);
  938. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  939. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
  940. if (err < 0)
  941. return err;
  942. } else if (i == AUTO_SEQ_SURROUND) {
  943. sprintf(name, "%s Playback Volume", chname[i]);
  944. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  945. HDA_COMPOSE_AMP_VAL(0x29, 3, 0, HDA_OUTPUT));
  946. if (err < 0)
  947. return err;
  948. sprintf(name, "%s Playback Switch", chname[i]);
  949. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  950. HDA_COMPOSE_AMP_VAL(0x29, 3, 0, HDA_OUTPUT));
  951. if (err < 0)
  952. return err;
  953. } else if (i == AUTO_SEQ_SIDE) {
  954. sprintf(name, "%s Playback Volume", chname[i]);
  955. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  956. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT));
  957. if (err < 0)
  958. return err;
  959. sprintf(name, "%s Playback Switch", chname[i]);
  960. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  961. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT));
  962. if (err < 0)
  963. return err;
  964. }
  965. }
  966. return 0;
  967. }
  968. static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  969. {
  970. int err;
  971. if (!pin)
  972. return 0;
  973. if (spec->multiout.num_dacs == 5) /* 10 channels */
  974. spec->multiout.hp_nid = VT1709_HP_DAC_NID;
  975. else if (spec->multiout.num_dacs == 3) /* 6 channels */
  976. spec->multiout.hp_nid = 0;
  977. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  978. "Headphone Playback Volume",
  979. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  980. if (err < 0)
  981. return err;
  982. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  983. "Headphone Playback Switch",
  984. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  985. if (err < 0)
  986. return err;
  987. return 0;
  988. }
  989. /* create playback/capture controls for input pins */
  990. static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
  991. const struct auto_pin_cfg *cfg)
  992. {
  993. static char *labels[] = {
  994. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  995. };
  996. struct hda_input_mux *imux = &spec->private_imux;
  997. int i, err, idx = 0;
  998. /* for internal loopback recording select */
  999. imux->items[imux->num_items].label = "Stereo Mixer";
  1000. imux->items[imux->num_items].index = idx;
  1001. imux->num_items++;
  1002. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1003. if (!cfg->input_pins[i])
  1004. continue;
  1005. switch (cfg->input_pins[i]) {
  1006. case 0x1d: /* Mic */
  1007. idx = 2;
  1008. break;
  1009. case 0x1e: /* Line In */
  1010. idx = 3;
  1011. break;
  1012. case 0x21: /* Front Mic */
  1013. idx = 4;
  1014. break;
  1015. case 0x23: /* CD */
  1016. idx = 1;
  1017. break;
  1018. }
  1019. err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
  1020. idx, 0x18);
  1021. if (err < 0)
  1022. return err;
  1023. imux->items[imux->num_items].label = labels[i];
  1024. imux->items[imux->num_items].index = idx;
  1025. imux->num_items++;
  1026. }
  1027. return 0;
  1028. }
  1029. static int vt1709_parse_auto_config(struct hda_codec *codec)
  1030. {
  1031. struct via_spec *spec = codec->spec;
  1032. int err;
  1033. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  1034. if (err < 0)
  1035. return err;
  1036. err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
  1037. if (err < 0)
  1038. return err;
  1039. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  1040. return 0; /* can't find valid BIOS pin config */
  1041. err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
  1042. if (err < 0)
  1043. return err;
  1044. err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  1045. if (err < 0)
  1046. return err;
  1047. err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
  1048. if (err < 0)
  1049. return err;
  1050. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1051. if (spec->autocfg.dig_out_pin)
  1052. spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
  1053. if (spec->autocfg.dig_in_pin)
  1054. spec->dig_in_nid = VT1709_DIGIN_NID;
  1055. if (spec->kctl_alloc)
  1056. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1057. spec->input_mux = &spec->private_imux;
  1058. return 1;
  1059. }
  1060. static int patch_vt1709_10ch(struct hda_codec *codec)
  1061. {
  1062. struct via_spec *spec;
  1063. int err;
  1064. /* create a codec specific record */
  1065. spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
  1066. if (spec == NULL)
  1067. return -ENOMEM;
  1068. codec->spec = spec;
  1069. err = vt1709_parse_auto_config(codec);
  1070. if (err < 0) {
  1071. via_free(codec);
  1072. return err;
  1073. } else if (!err) {
  1074. printk(KERN_INFO "hda_codec: Cannot set up configuration. "
  1075. "Using genenic mode...\n");
  1076. }
  1077. spec->init_verbs = vt1709_10ch_volume_init_verbs;
  1078. spec->stream_name_analog = "VT1709 Analog";
  1079. spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
  1080. spec->stream_analog_capture = &vt1709_pcm_analog_capture;
  1081. spec->stream_name_digital = "VT1709 Digital";
  1082. spec->stream_digital_playback = &vt1709_pcm_digital_playback;
  1083. spec->stream_digital_capture = &vt1709_pcm_digital_capture;
  1084. if (!spec->adc_nids && spec->input_mux) {
  1085. spec->adc_nids = vt1709_adc_nids;
  1086. spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
  1087. spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
  1088. spec->num_mixers++;
  1089. }
  1090. codec->patch_ops = via_patch_ops;
  1091. codec->patch_ops.init = via_auto_init;
  1092. return 0;
  1093. }
  1094. /*
  1095. * generic initialization of ADC, input mixers and output mixers
  1096. */
  1097. static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
  1098. /*
  1099. * Unmute ADC0-2 and set the default input to mic-in
  1100. */
  1101. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1102. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1103. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1104. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  1105. * mixer widget
  1106. */
  1107. /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  1108. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1109. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1110. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  1111. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  1112. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  1113. /*
  1114. * Set up output selector (0x1a, 0x1b, 0x29)
  1115. */
  1116. /* set vol=0 to output mixers */
  1117. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1118. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1119. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1120. /*
  1121. * Unmute PW3 and PW4
  1122. */
  1123. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1124. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1125. /* Set input of PW4 as MW0 */
  1126. {0x20, AC_VERB_SET_CONNECT_SEL, 0},
  1127. /* Set mic as default input of sw0 */
  1128. {0x19, AC_VERB_SET_CONNECT_SEL, 0x2},
  1129. /* PW9 Output enable */
  1130. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  1131. { }
  1132. };
  1133. static int patch_vt1709_6ch(struct hda_codec *codec)
  1134. {
  1135. struct via_spec *spec;
  1136. int err;
  1137. /* create a codec specific record */
  1138. spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
  1139. if (spec == NULL)
  1140. return -ENOMEM;
  1141. codec->spec = spec;
  1142. err = vt1709_parse_auto_config(codec);
  1143. if (err < 0) {
  1144. via_free(codec);
  1145. return err;
  1146. } else if (!err) {
  1147. printk(KERN_INFO "hda_codec: Cannot set up configuration. "
  1148. "Using genenic mode...\n");
  1149. }
  1150. spec->init_verbs = vt1709_6ch_volume_init_verbs;
  1151. spec->stream_name_analog = "VT1709 Analog";
  1152. spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
  1153. spec->stream_analog_capture = &vt1709_pcm_analog_capture;
  1154. spec->stream_name_digital = "VT1709 Digital";
  1155. spec->stream_digital_playback = &vt1709_pcm_digital_playback;
  1156. spec->stream_digital_capture = &vt1709_pcm_digital_capture;
  1157. if (!spec->adc_nids && spec->input_mux) {
  1158. spec->adc_nids = vt1709_adc_nids;
  1159. spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
  1160. spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
  1161. spec->num_mixers++;
  1162. }
  1163. codec->patch_ops = via_patch_ops;
  1164. codec->patch_ops.init = via_auto_init;
  1165. return 0;
  1166. }
  1167. /*
  1168. * patch entries
  1169. */
  1170. struct hda_codec_preset snd_hda_preset_via[] = {
  1171. { .id = 0x11061708, .name = "VIA VT1708", .patch = patch_vt1708},
  1172. { .id = 0x11061709, .name = "VIA VT1708", .patch = patch_vt1708},
  1173. { .id = 0x1106170A, .name = "VIA VT1708", .patch = patch_vt1708},
  1174. { .id = 0x1106170B, .name = "VIA VT1708", .patch = patch_vt1708},
  1175. { .id = 0x1106E710, .name = "VIA VT1709 10-Ch", .patch = patch_vt1709_10ch},
  1176. { .id = 0x1106E711, .name = "VIA VT1709 10-Ch", .patch = patch_vt1709_10ch},
  1177. { .id = 0x1106E712, .name = "VIA VT1709 10-Ch", .patch = patch_vt1709_10ch},
  1178. { .id = 0x1106E713, .name = "VIA VT1709 10-Ch", .patch = patch_vt1709_10ch},
  1179. { .id = 0x1106E714, .name = "VIA VT1709 6-Ch", .patch = patch_vt1709_6ch},
  1180. { .id = 0x1106E715, .name = "VIA VT1709 6-Ch", .patch = patch_vt1709_6ch},
  1181. { .id = 0x1106E716, .name = "VIA VT1709 6-Ch", .patch = patch_vt1709_6ch},
  1182. { .id = 0x1106E717, .name = "VIA VT1709 6-Ch", .patch = patch_vt1709_6ch},
  1183. {} /* terminator */
  1184. };