patch_cmedia.c 19 KB

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