patch_cmedia.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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 <sound/driver.h>
  24. #include <linux/init.h>
  25. #include <linux/delay.h>
  26. #include <linux/slab.h>
  27. #include <linux/pci.h>
  28. #include <sound/core.h>
  29. #include "hda_codec.h"
  30. #include "hda_local.h"
  31. /* board config type */
  32. enum {
  33. CMI_MINIMAL, /* back 3-jack */
  34. CMI_MIN_FP, /* back 3-jack + front-panel 2-jack */
  35. CMI_FULL, /* back 6-jack + front-panel 2-jack */
  36. CMI_FULL_DIG, /* back 6-jack + front-panel 2-jack + digital I/O */
  37. CMI_ALLOUT, /* back 5-jack + front-panel 2-jack + digital out */
  38. };
  39. struct cmi_spec {
  40. int board_config;
  41. unsigned int surr_switch: 1; /* switchable line,mic */
  42. unsigned int no_line_in: 1; /* no line-in (5-jack) */
  43. unsigned int front_panel: 1; /* has front-panel 2-jack */
  44. /* playback */
  45. struct hda_multi_out multiout;
  46. /* capture */
  47. hda_nid_t *adc_nids;
  48. hda_nid_t dig_in_nid;
  49. /* capture source */
  50. const struct hda_input_mux *input_mux;
  51. unsigned int cur_mux[2];
  52. /* channel mode */
  53. unsigned int num_ch_modes;
  54. unsigned int cur_ch_mode;
  55. const struct cmi_channel_mode *channel_modes;
  56. struct hda_pcm pcm_rec[2]; /* PCM information */
  57. };
  58. /*
  59. * input MUX
  60. */
  61. static int cmi_mux_enum_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  62. {
  63. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  64. struct cmi_spec *spec = codec->spec;
  65. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  66. }
  67. static int cmi_mux_enum_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  68. {
  69. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  70. struct cmi_spec *spec = codec->spec;
  71. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  72. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  73. return 0;
  74. }
  75. static int cmi_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  76. {
  77. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  78. struct cmi_spec *spec = codec->spec;
  79. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  80. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  81. spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);
  82. }
  83. /*
  84. * shared line-in, mic for surrounds
  85. */
  86. /* 3-stack / 2 channel */
  87. static struct hda_verb cmi9880_ch2_init[] = {
  88. /* set line-in PIN for input */
  89. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  90. /* set mic PIN for input, also enable vref */
  91. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  92. /* route front PCM (DAC1) to HP */
  93. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
  94. {}
  95. };
  96. /* 3-stack / 6 channel */
  97. static struct hda_verb cmi9880_ch6_init[] = {
  98. /* set line-in PIN for output */
  99. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  100. /* set mic PIN for output */
  101. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  102. /* route front PCM (DAC1) to HP */
  103. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
  104. {}
  105. };
  106. /* 3-stack+front / 8 channel */
  107. static struct hda_verb cmi9880_ch8_init[] = {
  108. /* set line-in PIN for output */
  109. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  110. /* set mic PIN for output */
  111. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  112. /* route rear-surround PCM (DAC4) to HP */
  113. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x03 },
  114. {}
  115. };
  116. struct cmi_channel_mode {
  117. unsigned int channels;
  118. const struct hda_verb *sequence;
  119. };
  120. static struct cmi_channel_mode cmi9880_channel_modes[3] = {
  121. { 2, cmi9880_ch2_init },
  122. { 6, cmi9880_ch6_init },
  123. { 8, cmi9880_ch8_init },
  124. };
  125. static int cmi_ch_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  126. {
  127. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  128. struct cmi_spec *spec = codec->spec;
  129. snd_assert(spec->channel_modes, return -EINVAL);
  130. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  131. uinfo->count = 1;
  132. uinfo->value.enumerated.items = spec->num_ch_modes;
  133. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  134. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  135. sprintf(uinfo->value.enumerated.name, "%dch",
  136. spec->channel_modes[uinfo->value.enumerated.item].channels);
  137. return 0;
  138. }
  139. static int cmi_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  140. {
  141. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  142. struct cmi_spec *spec = codec->spec;
  143. ucontrol->value.enumerated.item[0] = spec->cur_ch_mode;
  144. return 0;
  145. }
  146. static int cmi_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  147. {
  148. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  149. struct cmi_spec *spec = codec->spec;
  150. snd_assert(spec->channel_modes, return -EINVAL);
  151. if (ucontrol->value.enumerated.item[0] >= spec->num_ch_modes)
  152. ucontrol->value.enumerated.item[0] = spec->num_ch_modes;
  153. if (ucontrol->value.enumerated.item[0] == spec->cur_ch_mode &&
  154. ! codec->in_resume)
  155. return 0;
  156. spec->cur_ch_mode = ucontrol->value.enumerated.item[0];
  157. snd_hda_sequence_write(codec, spec->channel_modes[spec->cur_ch_mode].sequence);
  158. spec->multiout.max_channels = spec->channel_modes[spec->cur_ch_mode].channels;
  159. return 1;
  160. }
  161. /*
  162. */
  163. static snd_kcontrol_new_t cmi9880_basic_mixer[] = {
  164. /* CMI9880 has no playback volumes! */
  165. HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), /* front */
  166. HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0x0, HDA_OUTPUT),
  167. HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
  168. HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
  169. HDA_CODEC_MUTE("Side Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  170. {
  171. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  172. /* The multiple "Capture Source" controls confuse alsamixer
  173. * So call somewhat different..
  174. * FIXME: the controls appear in the "playback" view!
  175. */
  176. /* .name = "Capture Source", */
  177. .name = "Input Source",
  178. .count = 2,
  179. .info = cmi_mux_enum_info,
  180. .get = cmi_mux_enum_get,
  181. .put = cmi_mux_enum_put,
  182. },
  183. HDA_CODEC_VOLUME("Capture Volume", 0x08, 0, HDA_INPUT),
  184. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT),
  185. HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT),
  186. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT),
  187. HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x23, 0, HDA_OUTPUT),
  188. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x23, 0, HDA_OUTPUT),
  189. { } /* end */
  190. };
  191. /*
  192. * shared I/O pins
  193. */
  194. static snd_kcontrol_new_t cmi9880_ch_mode_mixer[] = {
  195. {
  196. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  197. .name = "Channel Mode",
  198. .info = cmi_ch_mode_info,
  199. .get = cmi_ch_mode_get,
  200. .put = cmi_ch_mode_put,
  201. },
  202. { } /* end */
  203. };
  204. /* AUD-in selections:
  205. * 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x1f 0x20
  206. */
  207. static struct hda_input_mux cmi9880_basic_mux = {
  208. .num_items = 4,
  209. .items = {
  210. { "Front Mic", 0x5 },
  211. { "Rear Mic", 0x2 },
  212. { "Line", 0x1 },
  213. { "CD", 0x7 },
  214. }
  215. };
  216. static struct hda_input_mux cmi9880_no_line_mux = {
  217. .num_items = 3,
  218. .items = {
  219. { "Front Mic", 0x5 },
  220. { "Rear Mic", 0x2 },
  221. { "CD", 0x7 },
  222. }
  223. };
  224. /* front, rear, clfe, rear_surr */
  225. static hda_nid_t cmi9880_dac_nids[4] = {
  226. 0x03, 0x04, 0x05, 0x06
  227. };
  228. /* ADC0, ADC1 */
  229. static hda_nid_t cmi9880_adc_nids[2] = {
  230. 0x08, 0x09
  231. };
  232. #define CMI_DIG_OUT_NID 0x07
  233. #define CMI_DIG_IN_NID 0x0a
  234. /*
  235. */
  236. static struct hda_verb cmi9880_basic_init[] = {
  237. /* port-D for line out (rear panel) */
  238. { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  239. /* port-E for HP out (front panel) */
  240. { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  241. /* route front PCM to HP */
  242. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
  243. /* port-A for surround (rear panel) */
  244. { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  245. /* port-G for CLFE (rear panel) */
  246. { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  247. /* port-H for side (rear panel) */
  248. { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  249. /* port-C for line-in (rear panel) */
  250. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  251. /* port-B for mic-in (rear panel) with vref */
  252. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  253. /* port-F for mic-in (front panel) with vref */
  254. { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  255. /* CD-in */
  256. { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  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 struct hda_verb cmi9880_allout_init[] = {
  263. /* port-D for line out (rear panel) */
  264. { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  265. /* port-E for HP out (front panel) */
  266. { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  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, 0xc0 },
  271. /* port-G for CLFE (rear panel) */
  272. { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  273. /* port-C for surround (rear panel) */
  274. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  275. /* port-B for mic-in (rear panel) with vref */
  276. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  277. /* port-F for mic-in (front panel) with vref */
  278. { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  279. /* CD-in */
  280. { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  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. int err;
  292. err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer);
  293. if (err < 0)
  294. return err;
  295. if (spec->surr_switch) {
  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, spec->multiout.dig_out_nid);
  302. if (err < 0)
  303. return err;
  304. }
  305. if (spec->dig_in_nid) {
  306. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  307. if (err < 0)
  308. return err;
  309. }
  310. return 0;
  311. }
  312. static int cmi9880_init(struct hda_codec *codec)
  313. {
  314. struct cmi_spec *spec = codec->spec;
  315. if (spec->board_config == CMI_ALLOUT)
  316. snd_hda_sequence_write(codec, cmi9880_allout_init);
  317. else
  318. snd_hda_sequence_write(codec, cmi9880_basic_init);
  319. return 0;
  320. }
  321. #ifdef CONFIG_PM
  322. /*
  323. * resume
  324. */
  325. static int cmi9880_resume(struct hda_codec *codec)
  326. {
  327. struct cmi_spec *spec = codec->spec;
  328. cmi9880_init(codec);
  329. snd_hda_resume_ctls(codec, cmi9880_basic_mixer);
  330. if (spec->surr_switch)
  331. snd_hda_resume_ctls(codec, cmi9880_ch_mode_mixer);
  332. if (spec->multiout.dig_out_nid)
  333. snd_hda_resume_spdif_out(codec);
  334. if (spec->dig_in_nid)
  335. snd_hda_resume_spdif_in(codec);
  336. return 0;
  337. }
  338. #endif
  339. /*
  340. * Analog playback callbacks
  341. */
  342. static int cmi9880_playback_pcm_open(struct hda_pcm_stream *hinfo,
  343. struct hda_codec *codec,
  344. snd_pcm_substream_t *substream)
  345. {
  346. struct cmi_spec *spec = codec->spec;
  347. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  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. snd_pcm_substream_t *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. snd_pcm_substream_t *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. snd_pcm_substream_t *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. snd_pcm_substream_t *substream)
  379. {
  380. struct cmi_spec *spec = codec->spec;
  381. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  382. }
  383. /*
  384. * Analog capture
  385. */
  386. static int cmi9880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  387. struct hda_codec *codec,
  388. unsigned int stream_tag,
  389. unsigned int format,
  390. snd_pcm_substream_t *substream)
  391. {
  392. struct cmi_spec *spec = codec->spec;
  393. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  394. stream_tag, 0, format);
  395. return 0;
  396. }
  397. static int cmi9880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  398. struct hda_codec *codec,
  399. snd_pcm_substream_t *substream)
  400. {
  401. struct cmi_spec *spec = codec->spec;
  402. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
  403. return 0;
  404. }
  405. /*
  406. */
  407. static struct hda_pcm_stream cmi9880_pcm_analog_playback = {
  408. .substreams = 1,
  409. .channels_min = 2,
  410. .channels_max = 8,
  411. .nid = 0x03, /* NID to query formats and rates */
  412. .ops = {
  413. .open = cmi9880_playback_pcm_open,
  414. .prepare = cmi9880_playback_pcm_prepare,
  415. .cleanup = cmi9880_playback_pcm_cleanup
  416. },
  417. };
  418. static struct hda_pcm_stream cmi9880_pcm_analog_capture = {
  419. .substreams = 2,
  420. .channels_min = 2,
  421. .channels_max = 2,
  422. .nid = 0x08, /* NID to query formats and rates */
  423. .ops = {
  424. .prepare = cmi9880_capture_pcm_prepare,
  425. .cleanup = cmi9880_capture_pcm_cleanup
  426. },
  427. };
  428. static struct hda_pcm_stream cmi9880_pcm_digital_playback = {
  429. .substreams = 1,
  430. .channels_min = 2,
  431. .channels_max = 2,
  432. /* NID is set in cmi9880_build_pcms */
  433. .ops = {
  434. .open = cmi9880_dig_playback_pcm_open,
  435. .close = cmi9880_dig_playback_pcm_close
  436. },
  437. };
  438. static struct hda_pcm_stream cmi9880_pcm_digital_capture = {
  439. .substreams = 1,
  440. .channels_min = 2,
  441. .channels_max = 2,
  442. /* NID is set in cmi9880_build_pcms */
  443. };
  444. static int cmi9880_build_pcms(struct hda_codec *codec)
  445. {
  446. struct cmi_spec *spec = codec->spec;
  447. struct hda_pcm *info = spec->pcm_rec;
  448. codec->num_pcms = 1;
  449. codec->pcm_info = info;
  450. info->name = "CMI9880";
  451. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_analog_playback;
  452. info->stream[SNDRV_PCM_STREAM_CAPTURE] = cmi9880_pcm_analog_capture;
  453. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  454. codec->num_pcms++;
  455. info++;
  456. info->name = "CMI9880 Digital";
  457. if (spec->multiout.dig_out_nid) {
  458. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback;
  459. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  460. }
  461. if (spec->dig_in_nid) {
  462. info->stream[SNDRV_PCM_STREAM_CAPTURE] = cmi9880_pcm_digital_capture;
  463. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  464. }
  465. }
  466. return 0;
  467. }
  468. static void cmi9880_free(struct hda_codec *codec)
  469. {
  470. kfree(codec->spec);
  471. }
  472. /*
  473. */
  474. static struct hda_board_config cmi9880_cfg_tbl[] = {
  475. { .modelname = "minimal", .config = CMI_MINIMAL },
  476. { .modelname = "min_fp", .config = CMI_MIN_FP },
  477. { .modelname = "full", .config = CMI_FULL },
  478. { .modelname = "full_dig", .config = CMI_FULL_DIG },
  479. { .modelname = "allout", .config = CMI_ALLOUT },
  480. {} /* terminator */
  481. };
  482. static struct hda_codec_ops cmi9880_patch_ops = {
  483. .build_controls = cmi9880_build_controls,
  484. .build_pcms = cmi9880_build_pcms,
  485. .init = cmi9880_init,
  486. .free = cmi9880_free,
  487. #ifdef CONFIG_PM
  488. .resume = cmi9880_resume,
  489. #endif
  490. };
  491. static int patch_cmi9880(struct hda_codec *codec)
  492. {
  493. struct cmi_spec *spec;
  494. spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
  495. if (spec == NULL)
  496. return -ENOMEM;
  497. codec->spec = spec;
  498. spec->board_config = snd_hda_check_board_config(codec, cmi9880_cfg_tbl);
  499. if (spec->board_config < 0) {
  500. snd_printd(KERN_INFO "hda_codec: Unknown model for CMI9880\n");
  501. spec->board_config = CMI_FULL_DIG; /* try everything */
  502. }
  503. switch (spec->board_config) {
  504. case CMI_MINIMAL:
  505. case CMI_MIN_FP:
  506. spec->surr_switch = 1;
  507. if (spec->board_config == CMI_MINIMAL)
  508. spec->num_ch_modes = 2;
  509. else {
  510. spec->front_panel = 1;
  511. spec->num_ch_modes = 3;
  512. }
  513. spec->channel_modes = cmi9880_channel_modes;
  514. spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
  515. spec->input_mux = &cmi9880_basic_mux;
  516. break;
  517. case CMI_FULL:
  518. case CMI_FULL_DIG:
  519. spec->front_panel = 1;
  520. spec->multiout.max_channels = 8;
  521. spec->input_mux = &cmi9880_basic_mux;
  522. if (spec->board_config == CMI_FULL_DIG) {
  523. spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
  524. spec->dig_in_nid = CMI_DIG_IN_NID;
  525. }
  526. break;
  527. case CMI_ALLOUT:
  528. spec->front_panel = 1;
  529. spec->multiout.max_channels = 8;
  530. spec->no_line_in = 1;
  531. spec->input_mux = &cmi9880_no_line_mux;
  532. spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
  533. break;
  534. }
  535. spec->multiout.num_dacs = 4;
  536. spec->multiout.dac_nids = cmi9880_dac_nids;
  537. spec->adc_nids = cmi9880_adc_nids;
  538. codec->patch_ops = cmi9880_patch_ops;
  539. return 0;
  540. }
  541. /*
  542. * patch entries
  543. */
  544. struct hda_codec_preset snd_hda_preset_cmedia[] = {
  545. { .id = 0x13f69880, .name = "CMI9880", .patch = patch_cmi9880 },
  546. { .id = 0x434d4980, .name = "CMI9880", .patch = patch_cmi9880 },
  547. {} /* terminator */
  548. };