patch_via.c 38 KB

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