au88x0_pcm.c 16 KB

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