patch_cmedia.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for C-Media CMI9880
  5. *
  6. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  7. *
  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. #include <linux/init.h>
  24. #include <linux/slab.h>
  25. #include <linux/module.h>
  26. #include <sound/core.h>
  27. #include "hda_codec.h"
  28. #include "hda_local.h"
  29. #include "hda_auto_parser.h"
  30. #include "hda_jack.h"
  31. #include "hda_generic.h"
  32. #undef ENABLE_CMI_STATIC_QUIRKS
  33. #ifdef ENABLE_CMI_STATIC_QUIRKS
  34. #define NUM_PINS 11
  35. /* board config type */
  36. enum {
  37. CMI_MINIMAL, /* back 3-jack */
  38. CMI_MIN_FP, /* back 3-jack + front-panel 2-jack */
  39. CMI_FULL, /* back 6-jack + front-panel 2-jack */
  40. CMI_FULL_DIG, /* back 6-jack + front-panel 2-jack + digital I/O */
  41. CMI_ALLOUT, /* back 5-jack + front-panel 2-jack + digital out */
  42. CMI_AUTO, /* let driver guess it */
  43. CMI_MODELS
  44. };
  45. #endif /* ENABLE_CMI_STATIC_QUIRKS */
  46. struct cmi_spec {
  47. struct hda_gen_spec gen;
  48. #ifdef ENABLE_CMI_STATIC_QUIRKS
  49. /* below are only for static models */
  50. int board_config;
  51. unsigned int no_line_in: 1; /* no line-in (5-jack) */
  52. unsigned int front_panel: 1; /* has front-panel 2-jack */
  53. /* playback */
  54. struct hda_multi_out multiout;
  55. hda_nid_t dac_nids[AUTO_CFG_MAX_OUTS]; /* NID for each DAC */
  56. int num_dacs;
  57. /* capture */
  58. const hda_nid_t *adc_nids;
  59. hda_nid_t dig_in_nid;
  60. /* capture source */
  61. const struct hda_input_mux *input_mux;
  62. unsigned int cur_mux[2];
  63. /* channel mode */
  64. int num_channel_modes;
  65. const struct hda_channel_mode *channel_modes;
  66. struct hda_pcm pcm_rec[2]; /* PCM information */
  67. /* pin default configuration */
  68. hda_nid_t pin_nid[NUM_PINS];
  69. unsigned int def_conf[NUM_PINS];
  70. unsigned int pin_def_confs;
  71. /* multichannel pins */
  72. struct hda_verb multi_init[9]; /* 2 verbs for each pin + terminator */
  73. #endif /* ENABLE_CMI_STATIC_QUIRKS */
  74. };
  75. #ifdef ENABLE_CMI_STATIC_QUIRKS
  76. /*
  77. * input MUX
  78. */
  79. static int cmi_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  80. {
  81. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  82. struct cmi_spec *spec = codec->spec;
  83. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  84. }
  85. static int cmi_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  86. {
  87. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  88. struct cmi_spec *spec = codec->spec;
  89. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  90. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  91. return 0;
  92. }
  93. static int cmi_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  94. {
  95. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  96. struct cmi_spec *spec = codec->spec;
  97. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  98. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  99. spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);
  100. }
  101. /*
  102. * shared line-in, mic for surrounds
  103. */
  104. /* 3-stack / 2 channel */
  105. static const struct hda_verb cmi9880_ch2_init[] = {
  106. /* set line-in PIN for input */
  107. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  108. /* set mic PIN for input, also enable vref */
  109. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  110. /* route front PCM (DAC1) to HP */
  111. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
  112. {}
  113. };
  114. /* 3-stack / 6 channel */
  115. static const struct hda_verb cmi9880_ch6_init[] = {
  116. /* set line-in PIN for output */
  117. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  118. /* set mic PIN for output */
  119. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  120. /* route front PCM (DAC1) to HP */
  121. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
  122. {}
  123. };
  124. /* 3-stack+front / 8 channel */
  125. static const struct hda_verb cmi9880_ch8_init[] = {
  126. /* set line-in PIN for output */
  127. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  128. /* set mic PIN for output */
  129. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  130. /* route rear-surround PCM (DAC4) to HP */
  131. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x03 },
  132. {}
  133. };
  134. static const struct hda_channel_mode cmi9880_channel_modes[3] = {
  135. { 2, cmi9880_ch2_init },
  136. { 6, cmi9880_ch6_init },
  137. { 8, cmi9880_ch8_init },
  138. };
  139. static int cmi_ch_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  140. {
  141. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  142. struct cmi_spec *spec = codec->spec;
  143. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_modes,
  144. spec->num_channel_modes);
  145. }
  146. static int cmi_ch_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  147. {
  148. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  149. struct cmi_spec *spec = codec->spec;
  150. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_modes,
  151. spec->num_channel_modes, spec->multiout.max_channels);
  152. }
  153. static int cmi_ch_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  154. {
  155. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  156. struct cmi_spec *spec = codec->spec;
  157. return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_modes,
  158. spec->num_channel_modes, &spec->multiout.max_channels);
  159. }
  160. /*
  161. */
  162. static const struct snd_kcontrol_new cmi9880_basic_mixer[] = {
  163. /* CMI9880 has no playback volumes! */
  164. HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), /* front */
  165. HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0x0, HDA_OUTPUT),
  166. HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
  167. HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
  168. HDA_CODEC_MUTE("Side Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  169. {
  170. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  171. /* The multiple "Capture Source" controls confuse alsamixer
  172. * So call somewhat different..
  173. */
  174. /* .name = "Capture Source", */
  175. .name = "Input Source",
  176. .count = 2,
  177. .info = cmi_mux_enum_info,
  178. .get = cmi_mux_enum_get,
  179. .put = cmi_mux_enum_put,
  180. },
  181. HDA_CODEC_VOLUME("Capture Volume", 0x08, 0, HDA_INPUT),
  182. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT),
  183. HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT),
  184. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT),
  185. HDA_CODEC_VOLUME("Beep Playback Volume", 0x23, 0, HDA_OUTPUT),
  186. HDA_CODEC_MUTE("Beep Playback Switch", 0x23, 0, HDA_OUTPUT),
  187. { } /* end */
  188. };
  189. /*
  190. * shared I/O pins
  191. */
  192. static const struct snd_kcontrol_new cmi9880_ch_mode_mixer[] = {
  193. {
  194. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  195. .name = "Channel Mode",
  196. .info = cmi_ch_mode_info,
  197. .get = cmi_ch_mode_get,
  198. .put = cmi_ch_mode_put,
  199. },
  200. { } /* end */
  201. };
  202. /* AUD-in selections:
  203. * 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x1f 0x20
  204. */
  205. static const struct hda_input_mux cmi9880_basic_mux = {
  206. .num_items = 4,
  207. .items = {
  208. { "Front Mic", 0x5 },
  209. { "Rear Mic", 0x2 },
  210. { "Line", 0x1 },
  211. { "CD", 0x7 },
  212. }
  213. };
  214. static const struct hda_input_mux cmi9880_no_line_mux = {
  215. .num_items = 3,
  216. .items = {
  217. { "Front Mic", 0x5 },
  218. { "Rear Mic", 0x2 },
  219. { "CD", 0x7 },
  220. }
  221. };
  222. /* front, rear, clfe, rear_surr */
  223. static const hda_nid_t cmi9880_dac_nids[4] = {
  224. 0x03, 0x04, 0x05, 0x06
  225. };
  226. /* ADC0, ADC1 */
  227. static const hda_nid_t cmi9880_adc_nids[2] = {
  228. 0x08, 0x09
  229. };
  230. #define CMI_DIG_OUT_NID 0x07
  231. #define CMI_DIG_IN_NID 0x0a
  232. /*
  233. */
  234. static const struct hda_verb cmi9880_basic_init[] = {
  235. /* port-D for line out (rear panel) */
  236. { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  237. /* port-E for HP out (front panel) */
  238. { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  239. /* route front PCM to HP */
  240. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
  241. /* port-A for surround (rear panel) */
  242. { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  243. /* port-G for CLFE (rear panel) */
  244. { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  245. { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 },
  246. /* port-H for side (rear panel) */
  247. { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  248. { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 },
  249. /* port-C for line-in (rear panel) */
  250. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  251. /* port-B for mic-in (rear panel) with vref */
  252. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  253. /* port-F for mic-in (front panel) with vref */
  254. { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  255. /* CD-in */
  256. { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  257. /* route front mic to ADC1/2 */
  258. { 0x08, AC_VERB_SET_CONNECT_SEL, 0x05 },
  259. { 0x09, AC_VERB_SET_CONNECT_SEL, 0x05 },
  260. {} /* terminator */
  261. };
  262. static const struct hda_verb cmi9880_allout_init[] = {
  263. /* port-D for line out (rear panel) */
  264. { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  265. /* port-E for HP out (front panel) */
  266. { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  267. /* route front PCM to HP */
  268. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
  269. /* port-A for side (rear panel) */
  270. { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  271. /* port-G for CLFE (rear panel) */
  272. { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  273. { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 },
  274. /* port-H for side (rear panel) */
  275. { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  276. { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 },
  277. /* port-C for surround (rear panel) */
  278. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  279. /* port-B for mic-in (rear panel) with vref */
  280. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  281. /* port-F for mic-in (front panel) with vref */
  282. { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  283. /* CD-in */
  284. { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  285. /* route front mic to ADC1/2 */
  286. { 0x08, AC_VERB_SET_CONNECT_SEL, 0x05 },
  287. { 0x09, AC_VERB_SET_CONNECT_SEL, 0x05 },
  288. {} /* terminator */
  289. };
  290. /*
  291. */
  292. static int cmi9880_build_controls(struct hda_codec *codec)
  293. {
  294. struct cmi_spec *spec = codec->spec;
  295. struct snd_kcontrol *kctl;
  296. int i, err;
  297. err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer);
  298. if (err < 0)
  299. return err;
  300. if (spec->channel_modes) {
  301. err = snd_hda_add_new_ctls(codec, cmi9880_ch_mode_mixer);
  302. if (err < 0)
  303. return err;
  304. }
  305. if (spec->multiout.dig_out_nid) {
  306. err = snd_hda_create_spdif_out_ctls(codec,
  307. spec->multiout.dig_out_nid,
  308. spec->multiout.dig_out_nid);
  309. if (err < 0)
  310. return err;
  311. err = snd_hda_create_spdif_share_sw(codec,
  312. &spec->multiout);
  313. if (err < 0)
  314. return err;
  315. spec->multiout.share_spdif = 1;
  316. }
  317. if (spec->dig_in_nid) {
  318. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  319. if (err < 0)
  320. return err;
  321. }
  322. /* assign Capture Source enums to NID */
  323. kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
  324. for (i = 0; kctl && i < kctl->count; i++) {
  325. err = snd_hda_add_nid(codec, kctl, i, spec->adc_nids[i]);
  326. if (err < 0)
  327. return err;
  328. }
  329. return 0;
  330. }
  331. static int cmi9880_init(struct hda_codec *codec)
  332. {
  333. struct cmi_spec *spec = codec->spec;
  334. if (spec->board_config == CMI_ALLOUT)
  335. snd_hda_sequence_write(codec, cmi9880_allout_init);
  336. else
  337. snd_hda_sequence_write(codec, cmi9880_basic_init);
  338. if (spec->board_config == CMI_AUTO)
  339. snd_hda_sequence_write(codec, spec->multi_init);
  340. return 0;
  341. }
  342. /*
  343. * Analog playback callbacks
  344. */
  345. static int cmi9880_playback_pcm_open(struct hda_pcm_stream *hinfo,
  346. struct hda_codec *codec,
  347. struct snd_pcm_substream *substream)
  348. {
  349. struct cmi_spec *spec = codec->spec;
  350. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  351. hinfo);
  352. }
  353. static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  354. struct hda_codec *codec,
  355. unsigned int stream_tag,
  356. unsigned int format,
  357. struct snd_pcm_substream *substream)
  358. {
  359. struct cmi_spec *spec = codec->spec;
  360. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
  361. format, substream);
  362. }
  363. static int cmi9880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  364. struct hda_codec *codec,
  365. struct snd_pcm_substream *substream)
  366. {
  367. struct cmi_spec *spec = codec->spec;
  368. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  369. }
  370. /*
  371. * Digital out
  372. */
  373. static int cmi9880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  374. struct hda_codec *codec,
  375. struct snd_pcm_substream *substream)
  376. {
  377. struct cmi_spec *spec = codec->spec;
  378. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  379. }
  380. static int cmi9880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  381. struct hda_codec *codec,
  382. struct snd_pcm_substream *substream)
  383. {
  384. struct cmi_spec *spec = codec->spec;
  385. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  386. }
  387. static int cmi9880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  388. struct hda_codec *codec,
  389. unsigned int stream_tag,
  390. unsigned int format,
  391. struct snd_pcm_substream *substream)
  392. {
  393. struct cmi_spec *spec = codec->spec;
  394. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
  395. format, substream);
  396. }
  397. /*
  398. * Analog capture
  399. */
  400. static int cmi9880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  401. struct hda_codec *codec,
  402. unsigned int stream_tag,
  403. unsigned int format,
  404. struct snd_pcm_substream *substream)
  405. {
  406. struct cmi_spec *spec = codec->spec;
  407. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  408. stream_tag, 0, format);
  409. return 0;
  410. }
  411. static int cmi9880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  412. struct hda_codec *codec,
  413. struct snd_pcm_substream *substream)
  414. {
  415. struct cmi_spec *spec = codec->spec;
  416. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  417. return 0;
  418. }
  419. /*
  420. */
  421. static const struct hda_pcm_stream cmi9880_pcm_analog_playback = {
  422. .substreams = 1,
  423. .channels_min = 2,
  424. .channels_max = 8,
  425. .nid = 0x03, /* NID to query formats and rates */
  426. .ops = {
  427. .open = cmi9880_playback_pcm_open,
  428. .prepare = cmi9880_playback_pcm_prepare,
  429. .cleanup = cmi9880_playback_pcm_cleanup
  430. },
  431. };
  432. static const struct hda_pcm_stream cmi9880_pcm_analog_capture = {
  433. .substreams = 2,
  434. .channels_min = 2,
  435. .channels_max = 2,
  436. .nid = 0x08, /* NID to query formats and rates */
  437. .ops = {
  438. .prepare = cmi9880_capture_pcm_prepare,
  439. .cleanup = cmi9880_capture_pcm_cleanup
  440. },
  441. };
  442. static const struct hda_pcm_stream cmi9880_pcm_digital_playback = {
  443. .substreams = 1,
  444. .channels_min = 2,
  445. .channels_max = 2,
  446. /* NID is set in cmi9880_build_pcms */
  447. .ops = {
  448. .open = cmi9880_dig_playback_pcm_open,
  449. .close = cmi9880_dig_playback_pcm_close,
  450. .prepare = cmi9880_dig_playback_pcm_prepare
  451. },
  452. };
  453. static const struct hda_pcm_stream cmi9880_pcm_digital_capture = {
  454. .substreams = 1,
  455. .channels_min = 2,
  456. .channels_max = 2,
  457. /* NID is set in cmi9880_build_pcms */
  458. };
  459. static int cmi9880_build_pcms(struct hda_codec *codec)
  460. {
  461. struct cmi_spec *spec = codec->spec;
  462. struct hda_pcm *info = spec->pcm_rec;
  463. codec->num_pcms = 1;
  464. codec->pcm_info = info;
  465. info->name = "CMI9880";
  466. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_analog_playback;
  467. info->stream[SNDRV_PCM_STREAM_CAPTURE] = cmi9880_pcm_analog_capture;
  468. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  469. codec->num_pcms++;
  470. info++;
  471. info->name = "CMI9880 Digital";
  472. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  473. if (spec->multiout.dig_out_nid) {
  474. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback;
  475. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  476. }
  477. if (spec->dig_in_nid) {
  478. info->stream[SNDRV_PCM_STREAM_CAPTURE] = cmi9880_pcm_digital_capture;
  479. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  480. }
  481. }
  482. return 0;
  483. }
  484. static void cmi9880_free(struct hda_codec *codec)
  485. {
  486. kfree(codec->spec);
  487. }
  488. /*
  489. */
  490. static const char * const cmi9880_models[CMI_MODELS] = {
  491. [CMI_MINIMAL] = "minimal",
  492. [CMI_MIN_FP] = "min_fp",
  493. [CMI_FULL] = "full",
  494. [CMI_FULL_DIG] = "full_dig",
  495. [CMI_ALLOUT] = "allout",
  496. [CMI_AUTO] = "auto",
  497. };
  498. static const struct snd_pci_quirk cmi9880_cfg_tbl[] = {
  499. SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", CMI_FULL_DIG),
  500. SND_PCI_QUIRK(0x1854, 0x002b, "LG LS75", CMI_MINIMAL),
  501. SND_PCI_QUIRK(0x1854, 0x0032, "LG", CMI_FULL_DIG),
  502. {} /* terminator */
  503. };
  504. static const struct hda_codec_ops cmi9880_patch_ops = {
  505. .build_controls = cmi9880_build_controls,
  506. .build_pcms = cmi9880_build_pcms,
  507. .init = cmi9880_init,
  508. .free = cmi9880_free,
  509. };
  510. #endif /* ENABLE_CMI_STATIC_QUIRKS */
  511. /*
  512. * stuff for auto-parser
  513. */
  514. static const struct hda_codec_ops cmi_auto_patch_ops = {
  515. .build_controls = snd_hda_gen_build_controls,
  516. .build_pcms = snd_hda_gen_build_pcms,
  517. .init = snd_hda_gen_init,
  518. .free = snd_hda_gen_free,
  519. .unsol_event = snd_hda_jack_unsol_event,
  520. };
  521. static int cmi_parse_auto_config(struct hda_codec *codec)
  522. {
  523. struct cmi_spec *spec = codec->spec;
  524. struct auto_pin_cfg *cfg = &spec->gen.autocfg;
  525. int err;
  526. snd_hda_gen_spec_init(&spec->gen);
  527. err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
  528. if (err < 0)
  529. goto error;
  530. err = snd_hda_gen_parse_auto_config(codec, cfg);
  531. if (err < 0)
  532. goto error;
  533. codec->patch_ops = cmi_auto_patch_ops;
  534. return 0;
  535. error:
  536. snd_hda_gen_free(codec);
  537. return err;
  538. }
  539. static int patch_cmi9880(struct hda_codec *codec)
  540. {
  541. struct cmi_spec *spec;
  542. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  543. if (spec == NULL)
  544. return -ENOMEM;
  545. codec->spec = spec;
  546. #ifdef ENABLE_CMI_STATIC_QUIRKS
  547. spec->board_config = snd_hda_check_board_config(codec, CMI_MODELS,
  548. cmi9880_models,
  549. cmi9880_cfg_tbl);
  550. if (spec->board_config < 0) {
  551. codec_dbg(codec, "%s: BIOS auto-probing.\n",
  552. codec->chip_name);
  553. spec->board_config = CMI_AUTO; /* try everything */
  554. }
  555. if (spec->board_config == CMI_AUTO)
  556. return cmi_parse_auto_config(codec);
  557. /* copy default DAC NIDs */
  558. memcpy(spec->dac_nids, cmi9880_dac_nids, sizeof(spec->dac_nids));
  559. spec->num_dacs = 4;
  560. switch (spec->board_config) {
  561. case CMI_MINIMAL:
  562. case CMI_MIN_FP:
  563. spec->channel_modes = cmi9880_channel_modes;
  564. if (spec->board_config == CMI_MINIMAL)
  565. spec->num_channel_modes = 2;
  566. else {
  567. spec->front_panel = 1;
  568. spec->num_channel_modes = 3;
  569. }
  570. spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
  571. spec->input_mux = &cmi9880_basic_mux;
  572. break;
  573. case CMI_FULL:
  574. case CMI_FULL_DIG:
  575. spec->front_panel = 1;
  576. spec->multiout.max_channels = 8;
  577. spec->input_mux = &cmi9880_basic_mux;
  578. if (spec->board_config == CMI_FULL_DIG) {
  579. spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
  580. spec->dig_in_nid = CMI_DIG_IN_NID;
  581. }
  582. break;
  583. case CMI_ALLOUT:
  584. default:
  585. spec->front_panel = 1;
  586. spec->multiout.max_channels = 8;
  587. spec->no_line_in = 1;
  588. spec->input_mux = &cmi9880_no_line_mux;
  589. spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
  590. break;
  591. }
  592. spec->multiout.num_dacs = spec->num_dacs;
  593. spec->multiout.dac_nids = spec->dac_nids;
  594. spec->adc_nids = cmi9880_adc_nids;
  595. codec->patch_ops = cmi9880_patch_ops;
  596. return 0;
  597. #else
  598. return cmi_parse_auto_config(codec);
  599. #endif
  600. }
  601. /*
  602. * patch entries
  603. */
  604. static const struct hda_codec_preset snd_hda_preset_cmedia[] = {
  605. { .id = 0x13f69880, .name = "CMI9880", .patch = patch_cmi9880 },
  606. { .id = 0x434d4980, .name = "CMI9880", .patch = patch_cmi9880 },
  607. {} /* terminator */
  608. };
  609. MODULE_ALIAS("snd-hda-codec-id:13f69880");
  610. MODULE_ALIAS("snd-hda-codec-id:434d4980");
  611. MODULE_LICENSE("GPL");
  612. MODULE_DESCRIPTION("C-Media HD-audio codec");
  613. static struct hda_codec_preset_list cmedia_list = {
  614. .preset = snd_hda_preset_cmedia,
  615. .owner = THIS_MODULE,
  616. };
  617. static int __init patch_cmedia_init(void)
  618. {
  619. return snd_hda_add_codec_preset(&cmedia_list);
  620. }
  621. static void __exit patch_cmedia_exit(void)
  622. {
  623. snd_hda_delete_codec_preset(&cmedia_list);
  624. }
  625. module_init(patch_cmedia_init)
  626. module_exit(patch_cmedia_exit)