patch_cmedia.c 21 KB

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