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