au88x0_pcm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU Library General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /*
  17. * Vortex PCM ALSA driver.
  18. *
  19. * Supports ADB and WT DMA. Unfortunately, WT channels do not run yet.
  20. * It remains stuck,and DMA transfers do not happen.
  21. */
  22. #include <sound/asoundef.h>
  23. #include <linux/time.h>
  24. #include <sound/core.h>
  25. #include <sound/pcm.h>
  26. #include <sound/pcm_params.h>
  27. #include "au88x0.h"
  28. #define VORTEX_PCM_TYPE(x) (x->name[40])
  29. /* hardware definition */
  30. static struct snd_pcm_hardware snd_vortex_playback_hw_adb = {
  31. .info =
  32. (SNDRV_PCM_INFO_MMAP | /* SNDRV_PCM_INFO_RESUME | */
  33. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_INTERLEAVED |
  34. SNDRV_PCM_INFO_MMAP_VALID),
  35. .formats =
  36. SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U8 |
  37. SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW,
  38. .rates = SNDRV_PCM_RATE_CONTINUOUS,
  39. .rate_min = 5000,
  40. .rate_max = 48000,
  41. .channels_min = 1,
  42. .channels_max = 2,
  43. .buffer_bytes_max = 0x10000,
  44. .period_bytes_min = 0x1,
  45. .period_bytes_max = 0x1000,
  46. .periods_min = 2,
  47. .periods_max = 32,
  48. };
  49. #ifndef CHIP_AU8820
  50. static struct snd_pcm_hardware snd_vortex_playback_hw_a3d = {
  51. .info =
  52. (SNDRV_PCM_INFO_MMAP | /* SNDRV_PCM_INFO_RESUME | */
  53. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_INTERLEAVED |
  54. SNDRV_PCM_INFO_MMAP_VALID),
  55. .formats =
  56. SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U8 |
  57. SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW,
  58. .rates = SNDRV_PCM_RATE_CONTINUOUS,
  59. .rate_min = 5000,
  60. .rate_max = 48000,
  61. .channels_min = 1,
  62. .channels_max = 1,
  63. .buffer_bytes_max = 0x10000,
  64. .period_bytes_min = 0x100,
  65. .period_bytes_max = 0x1000,
  66. .periods_min = 2,
  67. .periods_max = 64,
  68. };
  69. #endif
  70. static struct snd_pcm_hardware snd_vortex_playback_hw_spdif = {
  71. .info =
  72. (SNDRV_PCM_INFO_MMAP | /* SNDRV_PCM_INFO_RESUME | */
  73. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_INTERLEAVED |
  74. SNDRV_PCM_INFO_MMAP_VALID),
  75. .formats =
  76. SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U8 |
  77. SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE | SNDRV_PCM_FMTBIT_MU_LAW |
  78. SNDRV_PCM_FMTBIT_A_LAW,
  79. .rates =
  80. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
  81. .rate_min = 32000,
  82. .rate_max = 48000,
  83. .channels_min = 1,
  84. .channels_max = 2,
  85. .buffer_bytes_max = 0x10000,
  86. .period_bytes_min = 0x100,
  87. .period_bytes_max = 0x1000,
  88. .periods_min = 2,
  89. .periods_max = 64,
  90. };
  91. #ifndef CHIP_AU8810
  92. static struct snd_pcm_hardware snd_vortex_playback_hw_wt = {
  93. .info = (SNDRV_PCM_INFO_MMAP |
  94. SNDRV_PCM_INFO_INTERLEAVED |
  95. SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID),
  96. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  97. .rates = SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_CONTINUOUS, // SNDRV_PCM_RATE_48000,
  98. .rate_min = 8000,
  99. .rate_max = 48000,
  100. .channels_min = 1,
  101. .channels_max = 2,
  102. .buffer_bytes_max = 0x10000,
  103. .period_bytes_min = 0x0400,
  104. .period_bytes_max = 0x1000,
  105. .periods_min = 2,
  106. .periods_max = 64,
  107. };
  108. #endif
  109. #ifdef CHIP_AU8830
  110. static unsigned int au8830_channels[3] = {
  111. 1, 2, 4,
  112. };
  113. static struct snd_pcm_hw_constraint_list hw_constraints_au8830_channels = {
  114. .count = ARRAY_SIZE(au8830_channels),
  115. .list = au8830_channels,
  116. .mask = 0,
  117. };
  118. #endif
  119. /* open callback */
  120. static int snd_vortex_pcm_open(struct snd_pcm_substream *substream)
  121. {
  122. vortex_t *vortex = snd_pcm_substream_chip(substream);
  123. struct snd_pcm_runtime *runtime = substream->runtime;
  124. int err;
  125. /* Force equal size periods */
  126. if ((err =
  127. snd_pcm_hw_constraint_integer(runtime,
  128. SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  129. return err;
  130. /* Avoid PAGE_SIZE boundary to fall inside of a period. */
  131. if ((err =
  132. snd_pcm_hw_constraint_pow2(runtime, 0,
  133. SNDRV_PCM_HW_PARAM_PERIOD_BYTES)) < 0)
  134. return err;
  135. if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) {
  136. #ifndef CHIP_AU8820
  137. if (VORTEX_PCM_TYPE(substream->pcm) == VORTEX_PCM_A3D) {
  138. runtime->hw = snd_vortex_playback_hw_a3d;
  139. }
  140. #endif
  141. if (VORTEX_PCM_TYPE(substream->pcm) == VORTEX_PCM_SPDIF) {
  142. runtime->hw = snd_vortex_playback_hw_spdif;
  143. switch (vortex->spdif_sr) {
  144. case 32000:
  145. runtime->hw.rates = SNDRV_PCM_RATE_32000;
  146. break;
  147. case 44100:
  148. runtime->hw.rates = SNDRV_PCM_RATE_44100;
  149. break;
  150. case 48000:
  151. runtime->hw.rates = SNDRV_PCM_RATE_48000;
  152. break;
  153. }
  154. }
  155. if (VORTEX_PCM_TYPE(substream->pcm) == VORTEX_PCM_ADB
  156. || VORTEX_PCM_TYPE(substream->pcm) == VORTEX_PCM_I2S)
  157. runtime->hw = snd_vortex_playback_hw_adb;
  158. #ifdef CHIP_AU8830
  159. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
  160. VORTEX_PCM_TYPE(substream->pcm) == VORTEX_PCM_ADB) {
  161. runtime->hw.channels_max = 4;
  162. snd_pcm_hw_constraint_list(runtime, 0,
  163. SNDRV_PCM_HW_PARAM_CHANNELS,
  164. &hw_constraints_au8830_channels);
  165. }
  166. #endif
  167. substream->runtime->private_data = NULL;
  168. }
  169. #ifndef CHIP_AU8810
  170. else {
  171. runtime->hw = snd_vortex_playback_hw_wt;
  172. substream->runtime->private_data = NULL;
  173. }
  174. #endif
  175. return 0;
  176. }
  177. /* close callback */
  178. static int snd_vortex_pcm_close(struct snd_pcm_substream *substream)
  179. {
  180. //vortex_t *chip = snd_pcm_substream_chip(substream);
  181. stream_t *stream = (stream_t *) substream->runtime->private_data;
  182. // the hardware-specific codes will be here
  183. if (stream != NULL) {
  184. stream->substream = NULL;
  185. stream->nr_ch = 0;
  186. }
  187. substream->runtime->private_data = NULL;
  188. return 0;
  189. }
  190. /* hw_params callback */
  191. static int
  192. snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
  193. struct snd_pcm_hw_params *hw_params)
  194. {
  195. vortex_t *chip = snd_pcm_substream_chip(substream);
  196. stream_t *stream = (stream_t *) (substream->runtime->private_data);
  197. int err;
  198. // Alloc buffer memory.
  199. err =
  200. snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  201. if (err < 0) {
  202. printk(KERN_ERR "Vortex: pcm page alloc failed!\n");
  203. return err;
  204. }
  205. /*
  206. printk(KERN_INFO "Vortex: periods %d, period_bytes %d, channels = %d\n", params_periods(hw_params),
  207. params_period_bytes(hw_params), params_channels(hw_params));
  208. */
  209. spin_lock_irq(&chip->lock);
  210. // Make audio routes and config buffer DMA.
  211. if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) {
  212. int dma, type = VORTEX_PCM_TYPE(substream->pcm);
  213. /* Dealloc any routes. */
  214. if (stream != NULL)
  215. vortex_adb_allocroute(chip, stream->dma,
  216. stream->nr_ch, stream->dir,
  217. stream->type);
  218. /* Alloc routes. */
  219. dma =
  220. vortex_adb_allocroute(chip, -1,
  221. params_channels(hw_params),
  222. substream->stream, type);
  223. if (dma < 0) {
  224. spin_unlock_irq(&chip->lock);
  225. return dma;
  226. }
  227. stream = substream->runtime->private_data = &chip->dma_adb[dma];
  228. stream->substream = substream;
  229. /* Setup Buffers. */
  230. vortex_adbdma_setbuffers(chip, dma,
  231. params_period_bytes(hw_params),
  232. params_periods(hw_params));
  233. }
  234. #ifndef CHIP_AU8810
  235. else {
  236. /* if (stream != NULL)
  237. vortex_wt_allocroute(chip, substream->number, 0); */
  238. vortex_wt_allocroute(chip, substream->number,
  239. params_channels(hw_params));
  240. stream = substream->runtime->private_data =
  241. &chip->dma_wt[substream->number];
  242. stream->dma = substream->number;
  243. stream->substream = substream;
  244. vortex_wtdma_setbuffers(chip, substream->number,
  245. params_period_bytes(hw_params),
  246. params_periods(hw_params));
  247. }
  248. #endif
  249. spin_unlock_irq(&chip->lock);
  250. return 0;
  251. }
  252. /* hw_free callback */
  253. static int snd_vortex_pcm_hw_free(struct snd_pcm_substream *substream)
  254. {
  255. vortex_t *chip = snd_pcm_substream_chip(substream);
  256. stream_t *stream = (stream_t *) (substream->runtime->private_data);
  257. spin_lock_irq(&chip->lock);
  258. // Delete audio routes.
  259. if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) {
  260. if (stream != NULL)
  261. vortex_adb_allocroute(chip, stream->dma,
  262. stream->nr_ch, stream->dir,
  263. stream->type);
  264. }
  265. #ifndef CHIP_AU8810
  266. else {
  267. if (stream != NULL)
  268. vortex_wt_allocroute(chip, stream->dma, 0);
  269. }
  270. #endif
  271. substream->runtime->private_data = NULL;
  272. spin_unlock_irq(&chip->lock);
  273. return snd_pcm_lib_free_pages(substream);
  274. }
  275. /* prepare callback */
  276. static int snd_vortex_pcm_prepare(struct snd_pcm_substream *substream)
  277. {
  278. vortex_t *chip = snd_pcm_substream_chip(substream);
  279. struct snd_pcm_runtime *runtime = substream->runtime;
  280. stream_t *stream = (stream_t *) substream->runtime->private_data;
  281. int dma = stream->dma, fmt, dir;
  282. // set up the hardware with the current configuration.
  283. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  284. dir = 1;
  285. else
  286. dir = 0;
  287. fmt = vortex_alsafmt_aspfmt(runtime->format);
  288. spin_lock_irq(&chip->lock);
  289. if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) {
  290. vortex_adbdma_setmode(chip, dma, 1, dir, fmt, 0 /*? */ ,
  291. 0);
  292. vortex_adbdma_setstartbuffer(chip, dma, 0);
  293. if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_SPDIF)
  294. vortex_adb_setsrc(chip, dma, runtime->rate, dir);
  295. }
  296. #ifndef CHIP_AU8810
  297. else {
  298. vortex_wtdma_setmode(chip, dma, 1, fmt, 0, 0);
  299. // FIXME: Set rate (i guess using vortex_wt_writereg() somehow).
  300. vortex_wtdma_setstartbuffer(chip, dma, 0);
  301. }
  302. #endif
  303. spin_unlock_irq(&chip->lock);
  304. return 0;
  305. }
  306. /* trigger callback */
  307. static int snd_vortex_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  308. {
  309. vortex_t *chip = snd_pcm_substream_chip(substream);
  310. stream_t *stream = (stream_t *) substream->runtime->private_data;
  311. int dma = stream->dma;
  312. spin_lock(&chip->lock);
  313. switch (cmd) {
  314. case SNDRV_PCM_TRIGGER_START:
  315. // do something to start the PCM engine
  316. //printk(KERN_INFO "vortex: start %d\n", dma);
  317. stream->fifo_enabled = 1;
  318. if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT) {
  319. vortex_adbdma_resetup(chip, dma);
  320. vortex_adbdma_startfifo(chip, dma);
  321. }
  322. #ifndef CHIP_AU8810
  323. else {
  324. printk(KERN_INFO "vortex: wt start %d\n", dma);
  325. vortex_wtdma_startfifo(chip, dma);
  326. }
  327. #endif
  328. break;
  329. case SNDRV_PCM_TRIGGER_STOP:
  330. // do something to stop the PCM engine
  331. //printk(KERN_INFO "vortex: stop %d\n", dma);
  332. stream->fifo_enabled = 0;
  333. if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT)
  334. vortex_adbdma_pausefifo(chip, dma);
  335. //vortex_adbdma_stopfifo(chip, dma);
  336. #ifndef CHIP_AU8810
  337. else {
  338. printk(KERN_INFO "vortex: wt stop %d\n", dma);
  339. vortex_wtdma_stopfifo(chip, dma);
  340. }
  341. #endif
  342. break;
  343. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  344. //printk(KERN_INFO "vortex: pause %d\n", dma);
  345. if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT)
  346. vortex_adbdma_pausefifo(chip, dma);
  347. #ifndef CHIP_AU8810
  348. else
  349. vortex_wtdma_pausefifo(chip, dma);
  350. #endif
  351. break;
  352. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  353. //printk(KERN_INFO "vortex: resume %d\n", dma);
  354. if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT)
  355. vortex_adbdma_resumefifo(chip, dma);
  356. #ifndef CHIP_AU8810
  357. else
  358. vortex_wtdma_resumefifo(chip, dma);
  359. #endif
  360. break;
  361. default:
  362. spin_unlock(&chip->lock);
  363. return -EINVAL;
  364. }
  365. spin_unlock(&chip->lock);
  366. return 0;
  367. }
  368. /* pointer callback */
  369. static snd_pcm_uframes_t snd_vortex_pcm_pointer(struct snd_pcm_substream *substream)
  370. {
  371. vortex_t *chip = snd_pcm_substream_chip(substream);
  372. stream_t *stream = (stream_t *) substream->runtime->private_data;
  373. int dma = stream->dma;
  374. snd_pcm_uframes_t current_ptr = 0;
  375. spin_lock(&chip->lock);
  376. if (VORTEX_PCM_TYPE(substream->pcm) != VORTEX_PCM_WT)
  377. current_ptr = vortex_adbdma_getlinearpos(chip, dma);
  378. #ifndef CHIP_AU8810
  379. else
  380. current_ptr = vortex_wtdma_getlinearpos(chip, dma);
  381. #endif
  382. //printk(KERN_INFO "vortex: pointer = 0x%x\n", current_ptr);
  383. spin_unlock(&chip->lock);
  384. return (bytes_to_frames(substream->runtime, current_ptr));
  385. }
  386. /* operators */
  387. static struct snd_pcm_ops snd_vortex_playback_ops = {
  388. .open = snd_vortex_pcm_open,
  389. .close = snd_vortex_pcm_close,
  390. .ioctl = snd_pcm_lib_ioctl,
  391. .hw_params = snd_vortex_pcm_hw_params,
  392. .hw_free = snd_vortex_pcm_hw_free,
  393. .prepare = snd_vortex_pcm_prepare,
  394. .trigger = snd_vortex_pcm_trigger,
  395. .pointer = snd_vortex_pcm_pointer,
  396. .page = snd_pcm_sgbuf_ops_page,
  397. };
  398. /*
  399. * definitions of capture are omitted here...
  400. */
  401. static char *vortex_pcm_prettyname[VORTEX_PCM_LAST] = {
  402. CARD_NAME " ADB",
  403. CARD_NAME " SPDIF",
  404. CARD_NAME " A3D",
  405. CARD_NAME " WT",
  406. CARD_NAME " I2S",
  407. };
  408. static char *vortex_pcm_name[VORTEX_PCM_LAST] = {
  409. "adb",
  410. "spdif",
  411. "a3d",
  412. "wt",
  413. "i2s",
  414. };
  415. /* SPDIF kcontrol */
  416. static int snd_vortex_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  417. {
  418. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  419. uinfo->count = 1;
  420. return 0;
  421. }
  422. static int snd_vortex_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  423. {
  424. ucontrol->value.iec958.status[0] = 0xff;
  425. ucontrol->value.iec958.status[1] = 0xff;
  426. ucontrol->value.iec958.status[2] = 0xff;
  427. ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
  428. return 0;
  429. }
  430. static int snd_vortex_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  431. {
  432. vortex_t *vortex = snd_kcontrol_chip(kcontrol);
  433. ucontrol->value.iec958.status[0] = 0x00;
  434. ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL|IEC958_AES1_CON_DIGDIGCONV_ID;
  435. ucontrol->value.iec958.status[2] = 0x00;
  436. switch (vortex->spdif_sr) {
  437. case 32000: ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_32000; break;
  438. case 44100: ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_44100; break;
  439. case 48000: ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_48000; break;
  440. }
  441. return 0;
  442. }
  443. static int snd_vortex_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  444. {
  445. vortex_t *vortex = snd_kcontrol_chip(kcontrol);
  446. int spdif_sr = 48000;
  447. switch (ucontrol->value.iec958.status[3] & IEC958_AES3_CON_FS) {
  448. case IEC958_AES3_CON_FS_32000: spdif_sr = 32000; break;
  449. case IEC958_AES3_CON_FS_44100: spdif_sr = 44100; break;
  450. case IEC958_AES3_CON_FS_48000: spdif_sr = 48000; break;
  451. }
  452. if (spdif_sr == vortex->spdif_sr)
  453. return 0;
  454. vortex->spdif_sr = spdif_sr;
  455. vortex_spdif_init(vortex, vortex->spdif_sr, 1);
  456. return 1;
  457. }
  458. /* spdif controls */
  459. static struct snd_kcontrol_new snd_vortex_mixer_spdif[] __devinitdata = {
  460. {
  461. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  462. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  463. .info = snd_vortex_spdif_info,
  464. .get = snd_vortex_spdif_get,
  465. .put = snd_vortex_spdif_put,
  466. },
  467. {
  468. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  469. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  470. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
  471. .info = snd_vortex_spdif_info,
  472. .get = snd_vortex_spdif_mask_get
  473. },
  474. };
  475. /* create a pcm device */
  476. static int __devinit snd_vortex_new_pcm(vortex_t *chip, int idx, int nr)
  477. {
  478. struct snd_pcm *pcm;
  479. struct snd_kcontrol *kctl;
  480. int i;
  481. int err, nr_capt;
  482. if (!chip || idx < 0 || idx >= VORTEX_PCM_LAST)
  483. return -ENODEV;
  484. /* idx indicates which kind of PCM device. ADB, SPDIF, I2S and A3D share the
  485. * same dma engine. WT uses it own separate dma engine whcih cant capture. */
  486. if (idx == VORTEX_PCM_ADB)
  487. nr_capt = nr;
  488. else
  489. nr_capt = 0;
  490. err = snd_pcm_new(chip->card, vortex_pcm_prettyname[idx], idx, nr,
  491. nr_capt, &pcm);
  492. if (err < 0)
  493. return err;
  494. snprintf(pcm->name, sizeof(pcm->name),
  495. "%s %s", CARD_NAME_SHORT, vortex_pcm_name[idx]);
  496. chip->pcm[idx] = pcm;
  497. // This is an evil hack, but it saves a lot of duplicated code.
  498. VORTEX_PCM_TYPE(pcm) = idx;
  499. pcm->private_data = chip;
  500. /* set operators */
  501. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  502. &snd_vortex_playback_ops);
  503. if (idx == VORTEX_PCM_ADB)
  504. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
  505. &snd_vortex_playback_ops);
  506. /* pre-allocation of Scatter-Gather buffers */
  507. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
  508. snd_dma_pci_data(chip->pci_dev),
  509. 0x10000, 0x10000);
  510. if (VORTEX_PCM_TYPE(pcm) == VORTEX_PCM_SPDIF) {
  511. for (i = 0; i < ARRAY_SIZE(snd_vortex_mixer_spdif); i++) {
  512. kctl = snd_ctl_new1(&snd_vortex_mixer_spdif[i], chip);
  513. if (!kctl)
  514. return -ENOMEM;
  515. if ((err = snd_ctl_add(chip->card, kctl)) < 0)
  516. return err;
  517. }
  518. }
  519. return 0;
  520. }