vx_pcm.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Driver for Digigram VX soundcards
  4. *
  5. * PCM part
  6. *
  7. * Copyright (c) 2002,2003 by Takashi Iwai <tiwai@suse.de>
  8. *
  9. * STRATEGY
  10. * for playback, we send series of "chunks", which size is equal with the
  11. * IBL size, typically 126 samples. at each end of chunk, the end-of-buffer
  12. * interrupt is notified, and the interrupt handler will feed the next chunk.
  13. *
  14. * the current position is calculated from the sample count RMH.
  15. * pipe->transferred is the counter of data which has been already transferred.
  16. * if this counter reaches to the period size, snd_pcm_period_elapsed() will
  17. * be issued.
  18. *
  19. * for capture, the situation is much easier.
  20. * to get a low latency response, we'll check the capture streams at each
  21. * interrupt (capture stream has no EOB notification). if the pending
  22. * data is accumulated to the period size, snd_pcm_period_elapsed() is
  23. * called and the pointer is updated.
  24. *
  25. * the current point of read buffer is kept in pipe->hw_ptr. note that
  26. * this is in bytes.
  27. *
  28. * TODO
  29. * - linked trigger for full-duplex mode.
  30. * - scheduled action on the stream.
  31. */
  32. #include <linux/slab.h>
  33. #include <linux/delay.h>
  34. #include <sound/core.h>
  35. #include <sound/asoundef.h>
  36. #include <sound/pcm.h>
  37. #include <sound/vx_core.h>
  38. #include "vx_cmd.h"
  39. /*
  40. * read three pending pcm bytes via inb()
  41. */
  42. static void vx_pcm_read_per_bytes(struct vx_core *chip, struct snd_pcm_runtime *runtime,
  43. struct vx_pipe *pipe)
  44. {
  45. int offset = pipe->hw_ptr;
  46. unsigned char *buf = (unsigned char *)(runtime->dma_area + offset);
  47. *buf++ = vx_inb(chip, RXH);
  48. if (++offset >= pipe->buffer_bytes) {
  49. offset = 0;
  50. buf = (unsigned char *)runtime->dma_area;
  51. }
  52. *buf++ = vx_inb(chip, RXM);
  53. if (++offset >= pipe->buffer_bytes) {
  54. offset = 0;
  55. buf = (unsigned char *)runtime->dma_area;
  56. }
  57. *buf++ = vx_inb(chip, RXL);
  58. if (++offset >= pipe->buffer_bytes) {
  59. offset = 0;
  60. }
  61. pipe->hw_ptr = offset;
  62. }
  63. /*
  64. * vx_set_pcx_time - convert from the PC time to the RMH status time.
  65. * @pc_time: the pointer for the PC-time to set
  66. * @dsp_time: the pointer for RMH status time array
  67. */
  68. static void vx_set_pcx_time(struct vx_core *chip, pcx_time_t *pc_time,
  69. unsigned int *dsp_time)
  70. {
  71. dsp_time[0] = (unsigned int)((*pc_time) >> 24) & PCX_TIME_HI_MASK;
  72. dsp_time[1] = (unsigned int)(*pc_time) & MASK_DSP_WORD;
  73. }
  74. /*
  75. * vx_set_differed_time - set the differed time if specified
  76. * @rmh: the rmh record to modify
  77. * @pipe: the pipe to be checked
  78. *
  79. * if the pipe is programmed with the differed time, set the DSP time
  80. * on the rmh and changes its command length.
  81. *
  82. * returns the increase of the command length.
  83. */
  84. static int vx_set_differed_time(struct vx_core *chip, struct vx_rmh *rmh,
  85. struct vx_pipe *pipe)
  86. {
  87. /* Update The length added to the RMH command by the timestamp */
  88. if (! (pipe->differed_type & DC_DIFFERED_DELAY))
  89. return 0;
  90. /* Set the T bit */
  91. rmh->Cmd[0] |= DSP_DIFFERED_COMMAND_MASK;
  92. /* Time stamp is the 1st following parameter */
  93. vx_set_pcx_time(chip, &pipe->pcx_time, &rmh->Cmd[1]);
  94. /* Add the flags to a notified differed command */
  95. if (pipe->differed_type & DC_NOTIFY_DELAY)
  96. rmh->Cmd[1] |= NOTIFY_MASK_TIME_HIGH ;
  97. /* Add the flags to a multiple differed command */
  98. if (pipe->differed_type & DC_MULTIPLE_DELAY)
  99. rmh->Cmd[1] |= MULTIPLE_MASK_TIME_HIGH;
  100. /* Add the flags to a stream-time differed command */
  101. if (pipe->differed_type & DC_STREAM_TIME_DELAY)
  102. rmh->Cmd[1] |= STREAM_MASK_TIME_HIGH;
  103. rmh->LgCmd += 2;
  104. return 2;
  105. }
  106. /*
  107. * vx_set_stream_format - send the stream format command
  108. * @pipe: the affected pipe
  109. * @data: format bitmask
  110. */
  111. static int vx_set_stream_format(struct vx_core *chip, struct vx_pipe *pipe,
  112. unsigned int data)
  113. {
  114. struct vx_rmh rmh;
  115. vx_init_rmh(&rmh, pipe->is_capture ?
  116. CMD_FORMAT_STREAM_IN : CMD_FORMAT_STREAM_OUT);
  117. rmh.Cmd[0] |= pipe->number << FIELD_SIZE;
  118. /* Command might be longer since we may have to add a timestamp */
  119. vx_set_differed_time(chip, &rmh, pipe);
  120. rmh.Cmd[rmh.LgCmd] = (data & 0xFFFFFF00) >> 8;
  121. rmh.Cmd[rmh.LgCmd + 1] = (data & 0xFF) << 16 /*| (datal & 0xFFFF00) >> 8*/;
  122. rmh.LgCmd += 2;
  123. return vx_send_msg(chip, &rmh);
  124. }
  125. /*
  126. * vx_set_format - set the format of a pipe
  127. * @pipe: the affected pipe
  128. * @runtime: pcm runtime instance to be referred
  129. *
  130. * returns 0 if successful, or a negative error code.
  131. */
  132. static int vx_set_format(struct vx_core *chip, struct vx_pipe *pipe,
  133. struct snd_pcm_runtime *runtime)
  134. {
  135. unsigned int header = HEADER_FMT_BASE;
  136. if (runtime->channels == 1)
  137. header |= HEADER_FMT_MONO;
  138. if (snd_pcm_format_little_endian(runtime->format))
  139. header |= HEADER_FMT_INTEL;
  140. if (runtime->rate < 32000 && runtime->rate > 11025)
  141. header |= HEADER_FMT_UPTO32;
  142. else if (runtime->rate <= 11025)
  143. header |= HEADER_FMT_UPTO11;
  144. switch (snd_pcm_format_physical_width(runtime->format)) {
  145. // case 8: break;
  146. case 16: header |= HEADER_FMT_16BITS; break;
  147. case 24: header |= HEADER_FMT_24BITS; break;
  148. default :
  149. snd_BUG();
  150. return -EINVAL;
  151. }
  152. return vx_set_stream_format(chip, pipe, header);
  153. }
  154. /*
  155. * set / query the IBL size
  156. */
  157. static int vx_set_ibl(struct vx_core *chip, struct vx_ibl_info *info)
  158. {
  159. int err;
  160. struct vx_rmh rmh;
  161. vx_init_rmh(&rmh, CMD_IBL);
  162. rmh.Cmd[0] |= info->size & 0x03ffff;
  163. err = vx_send_msg(chip, &rmh);
  164. if (err < 0)
  165. return err;
  166. info->size = rmh.Stat[0];
  167. info->max_size = rmh.Stat[1];
  168. info->min_size = rmh.Stat[2];
  169. info->granularity = rmh.Stat[3];
  170. dev_dbg(chip->card->dev,
  171. "%s: size = %d, max = %d, min = %d, gran = %d\n",
  172. __func__, info->size, info->max_size, info->min_size,
  173. info->granularity);
  174. return 0;
  175. }
  176. /*
  177. * vx_get_pipe_state - get the state of a pipe
  178. * @pipe: the pipe to be checked
  179. * @state: the pointer for the returned state
  180. *
  181. * checks the state of a given pipe, and stores the state (1 = running,
  182. * 0 = paused) on the given pointer.
  183. *
  184. * called from trigger callback only
  185. */
  186. static int vx_get_pipe_state(struct vx_core *chip, struct vx_pipe *pipe, int *state)
  187. {
  188. int err;
  189. struct vx_rmh rmh;
  190. vx_init_rmh(&rmh, CMD_PIPE_STATE);
  191. vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0);
  192. err = vx_send_msg(chip, &rmh);
  193. if (! err)
  194. *state = (rmh.Stat[0] & (1 << pipe->number)) ? 1 : 0;
  195. return err;
  196. }
  197. /*
  198. * vx_query_hbuffer_size - query available h-buffer size in bytes
  199. * @pipe: the pipe to be checked
  200. *
  201. * return the available size on h-buffer in bytes,
  202. * or a negative error code.
  203. *
  204. * NOTE: calling this function always switches to the stream mode.
  205. * you'll need to disconnect the host to get back to the
  206. * normal mode.
  207. */
  208. static int vx_query_hbuffer_size(struct vx_core *chip, struct vx_pipe *pipe)
  209. {
  210. int result;
  211. struct vx_rmh rmh;
  212. vx_init_rmh(&rmh, CMD_SIZE_HBUFFER);
  213. vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0);
  214. if (pipe->is_capture)
  215. rmh.Cmd[0] |= 0x00000001;
  216. result = vx_send_msg(chip, &rmh);
  217. if (! result)
  218. result = rmh.Stat[0] & 0xffff;
  219. return result;
  220. }
  221. /*
  222. * vx_pipe_can_start - query whether a pipe is ready for start
  223. * @pipe: the pipe to be checked
  224. *
  225. * return 1 if ready, 0 if not ready, and negative value on error.
  226. *
  227. * called from trigger callback only
  228. */
  229. static int vx_pipe_can_start(struct vx_core *chip, struct vx_pipe *pipe)
  230. {
  231. int err;
  232. struct vx_rmh rmh;
  233. vx_init_rmh(&rmh, CMD_CAN_START_PIPE);
  234. vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0);
  235. rmh.Cmd[0] |= 1;
  236. err = vx_send_msg(chip, &rmh);
  237. if (! err) {
  238. if (rmh.Stat[0])
  239. err = 1;
  240. }
  241. return err;
  242. }
  243. /*
  244. * vx_conf_pipe - tell the pipe to stand by and wait for IRQA.
  245. * @pipe: the pipe to be configured
  246. */
  247. static int vx_conf_pipe(struct vx_core *chip, struct vx_pipe *pipe)
  248. {
  249. struct vx_rmh rmh;
  250. vx_init_rmh(&rmh, CMD_CONF_PIPE);
  251. if (pipe->is_capture)
  252. rmh.Cmd[0] |= COMMAND_RECORD_MASK;
  253. rmh.Cmd[1] = 1 << pipe->number;
  254. return vx_send_msg(chip, &rmh);
  255. }
  256. /*
  257. * vx_send_irqa - trigger IRQA
  258. */
  259. static int vx_send_irqa(struct vx_core *chip)
  260. {
  261. struct vx_rmh rmh;
  262. vx_init_rmh(&rmh, CMD_SEND_IRQA);
  263. return vx_send_msg(chip, &rmh);
  264. }
  265. #define MAX_WAIT_FOR_DSP 250
  266. /*
  267. * vx boards do not support inter-card sync, besides
  268. * only 126 samples require to be prepared before a pipe can start
  269. */
  270. #define CAN_START_DELAY 2 /* wait 2ms only before asking if the pipe is ready*/
  271. #define WAIT_STATE_DELAY 2 /* wait 2ms after irqA was requested and check if the pipe state toggled*/
  272. /*
  273. * vx_toggle_pipe - start / pause a pipe
  274. * @pipe: the pipe to be triggered
  275. * @state: start = 1, pause = 0
  276. *
  277. * called from trigger callback only
  278. *
  279. */
  280. static int vx_toggle_pipe(struct vx_core *chip, struct vx_pipe *pipe, int state)
  281. {
  282. int err, i, cur_state;
  283. /* Check the pipe is not already in the requested state */
  284. if (vx_get_pipe_state(chip, pipe, &cur_state) < 0)
  285. return -EBADFD;
  286. if (state == cur_state)
  287. return 0;
  288. /* If a start is requested, ask the DSP to get prepared
  289. * and wait for a positive acknowledge (when there are
  290. * enough sound buffer for this pipe)
  291. */
  292. if (state) {
  293. for (i = 0 ; i < MAX_WAIT_FOR_DSP; i++) {
  294. err = vx_pipe_can_start(chip, pipe);
  295. if (err > 0)
  296. break;
  297. /* Wait for a few, before asking again
  298. * to avoid flooding the DSP with our requests
  299. */
  300. mdelay(1);
  301. }
  302. }
  303. err = vx_conf_pipe(chip, pipe);
  304. if (err < 0)
  305. return err;
  306. err = vx_send_irqa(chip);
  307. if (err < 0)
  308. return err;
  309. /* If it completes successfully, wait for the pipes
  310. * reaching the expected state before returning
  311. * Check one pipe only (since they are synchronous)
  312. */
  313. for (i = 0; i < MAX_WAIT_FOR_DSP; i++) {
  314. err = vx_get_pipe_state(chip, pipe, &cur_state);
  315. if (err < 0 || cur_state == state)
  316. break;
  317. err = -EIO;
  318. mdelay(1);
  319. }
  320. return err < 0 ? -EIO : 0;
  321. }
  322. /*
  323. * vx_stop_pipe - stop a pipe
  324. * @pipe: the pipe to be stopped
  325. *
  326. * called from trigger callback only
  327. */
  328. static int vx_stop_pipe(struct vx_core *chip, struct vx_pipe *pipe)
  329. {
  330. struct vx_rmh rmh;
  331. vx_init_rmh(&rmh, CMD_STOP_PIPE);
  332. vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0);
  333. return vx_send_msg(chip, &rmh);
  334. }
  335. /*
  336. * vx_alloc_pipe - allocate a pipe and initialize the pipe instance
  337. * @capture: 0 = playback, 1 = capture operation
  338. * @audioid: the audio id to be assigned
  339. * @num_audio: number of audio channels
  340. * @pipep: the returned pipe instance
  341. *
  342. * return 0 on success, or a negative error code.
  343. */
  344. static int vx_alloc_pipe(struct vx_core *chip, int capture,
  345. int audioid, int num_audio,
  346. struct vx_pipe **pipep)
  347. {
  348. int err;
  349. struct vx_pipe *pipe;
  350. struct vx_rmh rmh;
  351. int data_mode;
  352. *pipep = NULL;
  353. vx_init_rmh(&rmh, CMD_RES_PIPE);
  354. vx_set_pipe_cmd_params(&rmh, capture, audioid, num_audio);
  355. #if 0 // NYI
  356. if (underrun_skip_sound)
  357. rmh.Cmd[0] |= BIT_SKIP_SOUND;
  358. #endif // NYI
  359. data_mode = (chip->uer_bits & IEC958_AES0_NONAUDIO) != 0;
  360. if (! capture && data_mode)
  361. rmh.Cmd[0] |= BIT_DATA_MODE;
  362. err = vx_send_msg(chip, &rmh);
  363. if (err < 0)
  364. return err;
  365. /* initialize the pipe record */
  366. pipe = kzalloc(sizeof(*pipe), GFP_KERNEL);
  367. if (! pipe) {
  368. /* release the pipe */
  369. vx_init_rmh(&rmh, CMD_FREE_PIPE);
  370. vx_set_pipe_cmd_params(&rmh, capture, audioid, 0);
  371. vx_send_msg(chip, &rmh);
  372. return -ENOMEM;
  373. }
  374. /* the pipe index should be identical with the audio index */
  375. pipe->number = audioid;
  376. pipe->is_capture = capture;
  377. pipe->channels = num_audio;
  378. pipe->differed_type = 0;
  379. pipe->pcx_time = 0;
  380. pipe->data_mode = data_mode;
  381. *pipep = pipe;
  382. return 0;
  383. }
  384. /*
  385. * vx_free_pipe - release a pipe
  386. * @pipe: pipe to be released
  387. */
  388. static int vx_free_pipe(struct vx_core *chip, struct vx_pipe *pipe)
  389. {
  390. struct vx_rmh rmh;
  391. vx_init_rmh(&rmh, CMD_FREE_PIPE);
  392. vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0);
  393. vx_send_msg(chip, &rmh);
  394. kfree(pipe);
  395. return 0;
  396. }
  397. /*
  398. * vx_start_stream - start the stream
  399. *
  400. * called from trigger callback only
  401. */
  402. static int vx_start_stream(struct vx_core *chip, struct vx_pipe *pipe)
  403. {
  404. struct vx_rmh rmh;
  405. vx_init_rmh(&rmh, CMD_START_ONE_STREAM);
  406. vx_set_stream_cmd_params(&rmh, pipe->is_capture, pipe->number);
  407. vx_set_differed_time(chip, &rmh, pipe);
  408. return vx_send_msg(chip, &rmh);
  409. }
  410. /*
  411. * vx_stop_stream - stop the stream
  412. *
  413. * called from trigger callback only
  414. */
  415. static int vx_stop_stream(struct vx_core *chip, struct vx_pipe *pipe)
  416. {
  417. struct vx_rmh rmh;
  418. vx_init_rmh(&rmh, CMD_STOP_STREAM);
  419. vx_set_stream_cmd_params(&rmh, pipe->is_capture, pipe->number);
  420. return vx_send_msg(chip, &rmh);
  421. }
  422. /*
  423. * playback hw information
  424. */
  425. static const struct snd_pcm_hardware vx_pcm_playback_hw = {
  426. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  427. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID /*|*/
  428. /*SNDRV_PCM_INFO_RESUME*/),
  429. .formats = (/*SNDRV_PCM_FMTBIT_U8 |*/
  430. SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE),
  431. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  432. .rate_min = 5000,
  433. .rate_max = 48000,
  434. .channels_min = 1,
  435. .channels_max = 2,
  436. .buffer_bytes_max = (128*1024),
  437. .period_bytes_min = 126,
  438. .period_bytes_max = (128*1024),
  439. .periods_min = 2,
  440. .periods_max = VX_MAX_PERIODS,
  441. .fifo_size = 126,
  442. };
  443. /*
  444. * vx_pcm_playback_open - open callback for playback
  445. */
  446. static int vx_pcm_playback_open(struct snd_pcm_substream *subs)
  447. {
  448. struct snd_pcm_runtime *runtime = subs->runtime;
  449. struct vx_core *chip = snd_pcm_substream_chip(subs);
  450. struct vx_pipe *pipe = NULL;
  451. unsigned int audio;
  452. int err;
  453. if (chip->chip_status & VX_STAT_IS_STALE)
  454. return -EBUSY;
  455. audio = subs->pcm->device * 2;
  456. if (snd_BUG_ON(audio >= chip->audio_outs))
  457. return -EINVAL;
  458. /* playback pipe may have been already allocated for monitoring */
  459. pipe = chip->playback_pipes[audio];
  460. if (! pipe) {
  461. /* not allocated yet */
  462. err = vx_alloc_pipe(chip, 0, audio, 2, &pipe); /* stereo playback */
  463. if (err < 0)
  464. return err;
  465. }
  466. /* open for playback */
  467. pipe->references++;
  468. pipe->substream = subs;
  469. chip->playback_pipes[audio] = pipe;
  470. runtime->hw = vx_pcm_playback_hw;
  471. runtime->hw.period_bytes_min = chip->ibl.size;
  472. runtime->private_data = pipe;
  473. /* align to 4 bytes (otherwise will be problematic when 24bit is used) */
  474. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 4);
  475. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 4);
  476. return 0;
  477. }
  478. /*
  479. * vx_pcm_playback_close - close callback for playback
  480. */
  481. static int vx_pcm_playback_close(struct snd_pcm_substream *subs)
  482. {
  483. struct vx_core *chip = snd_pcm_substream_chip(subs);
  484. struct vx_pipe *pipe;
  485. if (! subs->runtime->private_data)
  486. return -EINVAL;
  487. pipe = subs->runtime->private_data;
  488. if (--pipe->references == 0) {
  489. chip->playback_pipes[pipe->number] = NULL;
  490. vx_free_pipe(chip, pipe);
  491. }
  492. return 0;
  493. }
  494. /*
  495. * vx_notify_end_of_buffer - send "end-of-buffer" notifier at the given pipe
  496. * @pipe: the pipe to notify
  497. *
  498. * NB: call with a certain lock.
  499. */
  500. static int vx_notify_end_of_buffer(struct vx_core *chip, struct vx_pipe *pipe)
  501. {
  502. int err;
  503. struct vx_rmh rmh; /* use a temporary rmh here */
  504. /* Toggle Dsp Host Interface into Message mode */
  505. vx_send_rih_nolock(chip, IRQ_PAUSE_START_CONNECT);
  506. vx_init_rmh(&rmh, CMD_NOTIFY_END_OF_BUFFER);
  507. vx_set_stream_cmd_params(&rmh, 0, pipe->number);
  508. err = vx_send_msg_nolock(chip, &rmh);
  509. if (err < 0)
  510. return err;
  511. /* Toggle Dsp Host Interface back to sound transfer mode */
  512. vx_send_rih_nolock(chip, IRQ_PAUSE_START_CONNECT);
  513. return 0;
  514. }
  515. /*
  516. * vx_pcm_playback_transfer_chunk - transfer a single chunk
  517. * @subs: substream
  518. * @pipe: the pipe to transfer
  519. * @size: chunk size in bytes
  520. *
  521. * transfer a single buffer chunk. EOB notificaton is added after that.
  522. * called from the interrupt handler, too.
  523. *
  524. * return 0 if ok.
  525. */
  526. static int vx_pcm_playback_transfer_chunk(struct vx_core *chip,
  527. struct snd_pcm_runtime *runtime,
  528. struct vx_pipe *pipe, int size)
  529. {
  530. int space, err = 0;
  531. space = vx_query_hbuffer_size(chip, pipe);
  532. if (space < 0) {
  533. /* disconnect the host, SIZE_HBUF command always switches to the stream mode */
  534. vx_send_rih(chip, IRQ_CONNECT_STREAM_NEXT);
  535. dev_dbg(chip->card->dev, "error hbuffer\n");
  536. return space;
  537. }
  538. if (space < size) {
  539. vx_send_rih(chip, IRQ_CONNECT_STREAM_NEXT);
  540. dev_dbg(chip->card->dev, "no enough hbuffer space %d\n", space);
  541. return -EIO; /* XRUN */
  542. }
  543. /* we don't need irqsave here, because this function
  544. * is called from either trigger callback or irq handler
  545. */
  546. mutex_lock(&chip->lock);
  547. vx_pseudo_dma_write(chip, runtime, pipe, size);
  548. err = vx_notify_end_of_buffer(chip, pipe);
  549. /* disconnect the host, SIZE_HBUF command always switches to the stream mode */
  550. vx_send_rih_nolock(chip, IRQ_CONNECT_STREAM_NEXT);
  551. mutex_unlock(&chip->lock);
  552. return err;
  553. }
  554. /*
  555. * update the position of the given pipe.
  556. * pipe->position is updated and wrapped within the buffer size.
  557. * pipe->transferred is updated, too, but the size is not wrapped,
  558. * so that the caller can check the total transferred size later
  559. * (to call snd_pcm_period_elapsed).
  560. */
  561. static int vx_update_pipe_position(struct vx_core *chip,
  562. struct snd_pcm_runtime *runtime,
  563. struct vx_pipe *pipe)
  564. {
  565. struct vx_rmh rmh;
  566. int err, update;
  567. u64 count;
  568. vx_init_rmh(&rmh, CMD_STREAM_SAMPLE_COUNT);
  569. vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0);
  570. err = vx_send_msg(chip, &rmh);
  571. if (err < 0)
  572. return err;
  573. count = ((u64)(rmh.Stat[0] & 0xfffff) << 24) | (u64)rmh.Stat[1];
  574. update = (int)(count - pipe->cur_count);
  575. pipe->cur_count = count;
  576. pipe->position += update;
  577. if (pipe->position >= (int)runtime->buffer_size)
  578. pipe->position %= runtime->buffer_size;
  579. pipe->transferred += update;
  580. return 0;
  581. }
  582. /*
  583. * transfer the pending playback buffer data to DSP
  584. * called from interrupt handler
  585. */
  586. static void vx_pcm_playback_transfer(struct vx_core *chip,
  587. struct snd_pcm_substream *subs,
  588. struct vx_pipe *pipe, int nchunks)
  589. {
  590. int i, err;
  591. struct snd_pcm_runtime *runtime = subs->runtime;
  592. if (! pipe->prepared || (chip->chip_status & VX_STAT_IS_STALE))
  593. return;
  594. for (i = 0; i < nchunks; i++) {
  595. err = vx_pcm_playback_transfer_chunk(chip, runtime, pipe,
  596. chip->ibl.size);
  597. if (err < 0)
  598. return;
  599. }
  600. }
  601. /*
  602. * update the playback position and call snd_pcm_period_elapsed() if necessary
  603. * called from interrupt handler
  604. */
  605. static void vx_pcm_playback_update(struct vx_core *chip,
  606. struct snd_pcm_substream *subs,
  607. struct vx_pipe *pipe)
  608. {
  609. int err;
  610. struct snd_pcm_runtime *runtime = subs->runtime;
  611. if (pipe->running && ! (chip->chip_status & VX_STAT_IS_STALE)) {
  612. err = vx_update_pipe_position(chip, runtime, pipe);
  613. if (err < 0)
  614. return;
  615. if (pipe->transferred >= (int)runtime->period_size) {
  616. pipe->transferred %= runtime->period_size;
  617. snd_pcm_period_elapsed(subs);
  618. }
  619. }
  620. }
  621. /*
  622. * vx_pcm_playback_trigger - trigger callback for playback
  623. */
  624. static int vx_pcm_trigger(struct snd_pcm_substream *subs, int cmd)
  625. {
  626. struct vx_core *chip = snd_pcm_substream_chip(subs);
  627. struct vx_pipe *pipe = subs->runtime->private_data;
  628. int err;
  629. if (chip->chip_status & VX_STAT_IS_STALE)
  630. return -EBUSY;
  631. switch (cmd) {
  632. case SNDRV_PCM_TRIGGER_START:
  633. case SNDRV_PCM_TRIGGER_RESUME:
  634. if (! pipe->is_capture)
  635. vx_pcm_playback_transfer(chip, subs, pipe, 2);
  636. err = vx_start_stream(chip, pipe);
  637. if (err < 0) {
  638. pr_debug("vx: cannot start stream\n");
  639. return err;
  640. }
  641. err = vx_toggle_pipe(chip, pipe, 1);
  642. if (err < 0) {
  643. pr_debug("vx: cannot start pipe\n");
  644. vx_stop_stream(chip, pipe);
  645. return err;
  646. }
  647. chip->pcm_running++;
  648. pipe->running = 1;
  649. break;
  650. case SNDRV_PCM_TRIGGER_STOP:
  651. case SNDRV_PCM_TRIGGER_SUSPEND:
  652. vx_toggle_pipe(chip, pipe, 0);
  653. vx_stop_pipe(chip, pipe);
  654. vx_stop_stream(chip, pipe);
  655. chip->pcm_running--;
  656. pipe->running = 0;
  657. break;
  658. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  659. err = vx_toggle_pipe(chip, pipe, 0);
  660. if (err < 0)
  661. return err;
  662. break;
  663. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  664. err = vx_toggle_pipe(chip, pipe, 1);
  665. if (err < 0)
  666. return err;
  667. break;
  668. default:
  669. return -EINVAL;
  670. }
  671. return 0;
  672. }
  673. /*
  674. * vx_pcm_playback_pointer - pointer callback for playback
  675. */
  676. static snd_pcm_uframes_t vx_pcm_playback_pointer(struct snd_pcm_substream *subs)
  677. {
  678. struct snd_pcm_runtime *runtime = subs->runtime;
  679. struct vx_pipe *pipe = runtime->private_data;
  680. return pipe->position;
  681. }
  682. /*
  683. * vx_pcm_prepare - prepare callback for playback and capture
  684. */
  685. static int vx_pcm_prepare(struct snd_pcm_substream *subs)
  686. {
  687. struct vx_core *chip = snd_pcm_substream_chip(subs);
  688. struct snd_pcm_runtime *runtime = subs->runtime;
  689. struct vx_pipe *pipe = runtime->private_data;
  690. int err, data_mode;
  691. // int max_size, nchunks;
  692. if (chip->chip_status & VX_STAT_IS_STALE)
  693. return -EBUSY;
  694. data_mode = (chip->uer_bits & IEC958_AES0_NONAUDIO) != 0;
  695. if (data_mode != pipe->data_mode && ! pipe->is_capture) {
  696. /* IEC958 status (raw-mode) was changed */
  697. /* we reopen the pipe */
  698. struct vx_rmh rmh;
  699. dev_dbg(chip->card->dev,
  700. "reopen the pipe with data_mode = %d\n", data_mode);
  701. vx_init_rmh(&rmh, CMD_FREE_PIPE);
  702. vx_set_pipe_cmd_params(&rmh, 0, pipe->number, 0);
  703. err = vx_send_msg(chip, &rmh);
  704. if (err < 0)
  705. return err;
  706. vx_init_rmh(&rmh, CMD_RES_PIPE);
  707. vx_set_pipe_cmd_params(&rmh, 0, pipe->number, pipe->channels);
  708. if (data_mode)
  709. rmh.Cmd[0] |= BIT_DATA_MODE;
  710. err = vx_send_msg(chip, &rmh);
  711. if (err < 0)
  712. return err;
  713. pipe->data_mode = data_mode;
  714. }
  715. if (chip->pcm_running && chip->freq != runtime->rate) {
  716. dev_err(chip->card->dev,
  717. "vx: cannot set different clock %d from the current %d\n",
  718. runtime->rate, chip->freq);
  719. return -EINVAL;
  720. }
  721. vx_set_clock(chip, runtime->rate);
  722. err = vx_set_format(chip, pipe, runtime);
  723. if (err < 0)
  724. return err;
  725. if (vx_is_pcmcia(chip)) {
  726. pipe->align = 2; /* 16bit word */
  727. } else {
  728. pipe->align = 4; /* 32bit word */
  729. }
  730. pipe->buffer_bytes = frames_to_bytes(runtime, runtime->buffer_size);
  731. pipe->period_bytes = frames_to_bytes(runtime, runtime->period_size);
  732. pipe->hw_ptr = 0;
  733. /* set the timestamp */
  734. vx_update_pipe_position(chip, runtime, pipe);
  735. /* clear again */
  736. pipe->transferred = 0;
  737. pipe->position = 0;
  738. pipe->prepared = 1;
  739. return 0;
  740. }
  741. /*
  742. * operators for PCM playback
  743. */
  744. static const struct snd_pcm_ops vx_pcm_playback_ops = {
  745. .open = vx_pcm_playback_open,
  746. .close = vx_pcm_playback_close,
  747. .prepare = vx_pcm_prepare,
  748. .trigger = vx_pcm_trigger,
  749. .pointer = vx_pcm_playback_pointer,
  750. };
  751. /*
  752. * playback hw information
  753. */
  754. static const struct snd_pcm_hardware vx_pcm_capture_hw = {
  755. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  756. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID /*|*/
  757. /*SNDRV_PCM_INFO_RESUME*/),
  758. .formats = (/*SNDRV_PCM_FMTBIT_U8 |*/
  759. SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE),
  760. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  761. .rate_min = 5000,
  762. .rate_max = 48000,
  763. .channels_min = 1,
  764. .channels_max = 2,
  765. .buffer_bytes_max = (128*1024),
  766. .period_bytes_min = 126,
  767. .period_bytes_max = (128*1024),
  768. .periods_min = 2,
  769. .periods_max = VX_MAX_PERIODS,
  770. .fifo_size = 126,
  771. };
  772. /*
  773. * vx_pcm_capture_open - open callback for capture
  774. */
  775. static int vx_pcm_capture_open(struct snd_pcm_substream *subs)
  776. {
  777. struct snd_pcm_runtime *runtime = subs->runtime;
  778. struct vx_core *chip = snd_pcm_substream_chip(subs);
  779. struct vx_pipe *pipe;
  780. struct vx_pipe *pipe_out_monitoring = NULL;
  781. unsigned int audio;
  782. int err;
  783. if (chip->chip_status & VX_STAT_IS_STALE)
  784. return -EBUSY;
  785. audio = subs->pcm->device * 2;
  786. if (snd_BUG_ON(audio >= chip->audio_ins))
  787. return -EINVAL;
  788. err = vx_alloc_pipe(chip, 1, audio, 2, &pipe);
  789. if (err < 0)
  790. return err;
  791. pipe->substream = subs;
  792. chip->capture_pipes[audio] = pipe;
  793. /* check if monitoring is needed */
  794. if (chip->audio_monitor_active[audio]) {
  795. pipe_out_monitoring = chip->playback_pipes[audio];
  796. if (! pipe_out_monitoring) {
  797. /* allocate a pipe */
  798. err = vx_alloc_pipe(chip, 0, audio, 2, &pipe_out_monitoring);
  799. if (err < 0)
  800. return err;
  801. chip->playback_pipes[audio] = pipe_out_monitoring;
  802. }
  803. pipe_out_monitoring->references++;
  804. /*
  805. if an output pipe is available, it's audios still may need to be
  806. unmuted. hence we'll have to call a mixer entry point.
  807. */
  808. vx_set_monitor_level(chip, audio, chip->audio_monitor[audio],
  809. chip->audio_monitor_active[audio]);
  810. /* assuming stereo */
  811. vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1],
  812. chip->audio_monitor_active[audio+1]);
  813. }
  814. pipe->monitoring_pipe = pipe_out_monitoring; /* default value NULL */
  815. runtime->hw = vx_pcm_capture_hw;
  816. runtime->hw.period_bytes_min = chip->ibl.size;
  817. runtime->private_data = pipe;
  818. /* align to 4 bytes (otherwise will be problematic when 24bit is used) */
  819. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 4);
  820. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 4);
  821. return 0;
  822. }
  823. /*
  824. * vx_pcm_capture_close - close callback for capture
  825. */
  826. static int vx_pcm_capture_close(struct snd_pcm_substream *subs)
  827. {
  828. struct vx_core *chip = snd_pcm_substream_chip(subs);
  829. struct vx_pipe *pipe;
  830. struct vx_pipe *pipe_out_monitoring;
  831. if (! subs->runtime->private_data)
  832. return -EINVAL;
  833. pipe = subs->runtime->private_data;
  834. chip->capture_pipes[pipe->number] = NULL;
  835. pipe_out_monitoring = pipe->monitoring_pipe;
  836. /*
  837. if an output pipe is attached to this input,
  838. check if it needs to be released.
  839. */
  840. if (pipe_out_monitoring) {
  841. if (--pipe_out_monitoring->references == 0) {
  842. vx_free_pipe(chip, pipe_out_monitoring);
  843. chip->playback_pipes[pipe->number] = NULL;
  844. pipe->monitoring_pipe = NULL;
  845. }
  846. }
  847. vx_free_pipe(chip, pipe);
  848. return 0;
  849. }
  850. #define DMA_READ_ALIGN 6 /* hardware alignment for read */
  851. /*
  852. * vx_pcm_capture_update - update the capture buffer
  853. */
  854. static void vx_pcm_capture_update(struct vx_core *chip, struct snd_pcm_substream *subs,
  855. struct vx_pipe *pipe)
  856. {
  857. int size, space, count;
  858. struct snd_pcm_runtime *runtime = subs->runtime;
  859. if (!pipe->running || (chip->chip_status & VX_STAT_IS_STALE))
  860. return;
  861. size = runtime->buffer_size - snd_pcm_capture_avail(runtime);
  862. if (! size)
  863. return;
  864. size = frames_to_bytes(runtime, size);
  865. space = vx_query_hbuffer_size(chip, pipe);
  866. if (space < 0)
  867. goto _error;
  868. if (size > space)
  869. size = space;
  870. size = (size / 3) * 3; /* align to 3 bytes */
  871. if (size < DMA_READ_ALIGN)
  872. goto _error;
  873. /* keep the last 6 bytes, they will be read after disconnection */
  874. count = size - DMA_READ_ALIGN;
  875. /* read bytes until the current pointer reaches to the aligned position
  876. * for word-transfer
  877. */
  878. while (count > 0) {
  879. if ((pipe->hw_ptr % pipe->align) == 0)
  880. break;
  881. if (vx_wait_for_rx_full(chip) < 0)
  882. goto _error;
  883. vx_pcm_read_per_bytes(chip, runtime, pipe);
  884. count -= 3;
  885. }
  886. if (count > 0) {
  887. /* ok, let's accelerate! */
  888. int align = pipe->align * 3;
  889. space = (count / align) * align;
  890. if (space > 0) {
  891. vx_pseudo_dma_read(chip, runtime, pipe, space);
  892. count -= space;
  893. }
  894. }
  895. /* read the rest of bytes */
  896. while (count > 0) {
  897. if (vx_wait_for_rx_full(chip) < 0)
  898. goto _error;
  899. vx_pcm_read_per_bytes(chip, runtime, pipe);
  900. count -= 3;
  901. }
  902. /* disconnect the host, SIZE_HBUF command always switches to the stream mode */
  903. vx_send_rih(chip, IRQ_CONNECT_STREAM_NEXT);
  904. /* read the last pending 6 bytes */
  905. count = DMA_READ_ALIGN;
  906. while (count > 0) {
  907. vx_pcm_read_per_bytes(chip, runtime, pipe);
  908. count -= 3;
  909. }
  910. /* update the position */
  911. pipe->transferred += size;
  912. if (pipe->transferred >= pipe->period_bytes) {
  913. pipe->transferred %= pipe->period_bytes;
  914. snd_pcm_period_elapsed(subs);
  915. }
  916. return;
  917. _error:
  918. /* disconnect the host, SIZE_HBUF command always switches to the stream mode */
  919. vx_send_rih(chip, IRQ_CONNECT_STREAM_NEXT);
  920. return;
  921. }
  922. /*
  923. * vx_pcm_capture_pointer - pointer callback for capture
  924. */
  925. static snd_pcm_uframes_t vx_pcm_capture_pointer(struct snd_pcm_substream *subs)
  926. {
  927. struct snd_pcm_runtime *runtime = subs->runtime;
  928. struct vx_pipe *pipe = runtime->private_data;
  929. return bytes_to_frames(runtime, pipe->hw_ptr);
  930. }
  931. /*
  932. * operators for PCM capture
  933. */
  934. static const struct snd_pcm_ops vx_pcm_capture_ops = {
  935. .open = vx_pcm_capture_open,
  936. .close = vx_pcm_capture_close,
  937. .prepare = vx_pcm_prepare,
  938. .trigger = vx_pcm_trigger,
  939. .pointer = vx_pcm_capture_pointer,
  940. };
  941. /*
  942. * interrupt handler for pcm streams
  943. */
  944. void vx_pcm_update_intr(struct vx_core *chip, unsigned int events)
  945. {
  946. unsigned int i;
  947. struct vx_pipe *pipe;
  948. #define EVENT_MASK (END_OF_BUFFER_EVENTS_PENDING|ASYNC_EVENTS_PENDING)
  949. if (events & EVENT_MASK) {
  950. vx_init_rmh(&chip->irq_rmh, CMD_ASYNC);
  951. if (events & ASYNC_EVENTS_PENDING)
  952. chip->irq_rmh.Cmd[0] |= 0x00000001; /* SEL_ASYNC_EVENTS */
  953. if (events & END_OF_BUFFER_EVENTS_PENDING)
  954. chip->irq_rmh.Cmd[0] |= 0x00000002; /* SEL_END_OF_BUF_EVENTS */
  955. if (vx_send_msg(chip, &chip->irq_rmh) < 0) {
  956. dev_dbg(chip->card->dev, "msg send error!!\n");
  957. return;
  958. }
  959. i = 1;
  960. while (i < chip->irq_rmh.LgStat) {
  961. int p, buf, capture, eob;
  962. p = chip->irq_rmh.Stat[i] & MASK_FIRST_FIELD;
  963. capture = (chip->irq_rmh.Stat[i] & 0x400000) ? 1 : 0;
  964. eob = (chip->irq_rmh.Stat[i] & 0x800000) ? 1 : 0;
  965. i++;
  966. if (events & ASYNC_EVENTS_PENDING)
  967. i++;
  968. buf = 1; /* force to transfer */
  969. if (events & END_OF_BUFFER_EVENTS_PENDING) {
  970. if (eob)
  971. buf = chip->irq_rmh.Stat[i];
  972. i++;
  973. }
  974. if (capture)
  975. continue;
  976. if (snd_BUG_ON(p < 0 || p >= chip->audio_outs))
  977. continue;
  978. pipe = chip->playback_pipes[p];
  979. if (pipe && pipe->substream) {
  980. vx_pcm_playback_update(chip, pipe->substream, pipe);
  981. vx_pcm_playback_transfer(chip, pipe->substream, pipe, buf);
  982. }
  983. }
  984. }
  985. /* update the capture pcm pointers as frequently as possible */
  986. for (i = 0; i < chip->audio_ins; i++) {
  987. pipe = chip->capture_pipes[i];
  988. if (pipe && pipe->substream)
  989. vx_pcm_capture_update(chip, pipe->substream, pipe);
  990. }
  991. }
  992. /*
  993. * vx_init_audio_io - check the available audio i/o and allocate pipe arrays
  994. */
  995. static int vx_init_audio_io(struct vx_core *chip)
  996. {
  997. struct vx_rmh rmh;
  998. int preferred;
  999. vx_init_rmh(&rmh, CMD_SUPPORTED);
  1000. if (vx_send_msg(chip, &rmh) < 0) {
  1001. dev_err(chip->card->dev,
  1002. "vx: cannot get the supported audio data\n");
  1003. return -ENXIO;
  1004. }
  1005. chip->audio_outs = rmh.Stat[0] & MASK_FIRST_FIELD;
  1006. chip->audio_ins = (rmh.Stat[0] >> (FIELD_SIZE*2)) & MASK_FIRST_FIELD;
  1007. chip->audio_info = rmh.Stat[1];
  1008. /* allocate pipes */
  1009. chip->playback_pipes = kcalloc(chip->audio_outs, sizeof(struct vx_pipe *), GFP_KERNEL);
  1010. if (!chip->playback_pipes)
  1011. return -ENOMEM;
  1012. chip->capture_pipes = kcalloc(chip->audio_ins, sizeof(struct vx_pipe *), GFP_KERNEL);
  1013. if (!chip->capture_pipes) {
  1014. kfree(chip->playback_pipes);
  1015. return -ENOMEM;
  1016. }
  1017. preferred = chip->ibl.size;
  1018. chip->ibl.size = 0;
  1019. vx_set_ibl(chip, &chip->ibl); /* query the info */
  1020. if (preferred > 0) {
  1021. chip->ibl.size = roundup(preferred, chip->ibl.granularity);
  1022. if (chip->ibl.size > chip->ibl.max_size)
  1023. chip->ibl.size = chip->ibl.max_size;
  1024. } else
  1025. chip->ibl.size = chip->ibl.min_size; /* set to the minimum */
  1026. vx_set_ibl(chip, &chip->ibl);
  1027. return 0;
  1028. }
  1029. /*
  1030. * free callback for pcm
  1031. */
  1032. static void snd_vx_pcm_free(struct snd_pcm *pcm)
  1033. {
  1034. struct vx_core *chip = pcm->private_data;
  1035. chip->pcm[pcm->device] = NULL;
  1036. kfree(chip->playback_pipes);
  1037. chip->playback_pipes = NULL;
  1038. kfree(chip->capture_pipes);
  1039. chip->capture_pipes = NULL;
  1040. }
  1041. /*
  1042. * snd_vx_pcm_new - create and initialize a pcm
  1043. */
  1044. int snd_vx_pcm_new(struct vx_core *chip)
  1045. {
  1046. struct snd_pcm *pcm;
  1047. unsigned int i;
  1048. int err;
  1049. err = vx_init_audio_io(chip);
  1050. if (err < 0)
  1051. return err;
  1052. for (i = 0; i < chip->hw->num_codecs; i++) {
  1053. unsigned int outs, ins;
  1054. outs = chip->audio_outs > i * 2 ? 1 : 0;
  1055. ins = chip->audio_ins > i * 2 ? 1 : 0;
  1056. if (! outs && ! ins)
  1057. break;
  1058. err = snd_pcm_new(chip->card, "VX PCM", i,
  1059. outs, ins, &pcm);
  1060. if (err < 0)
  1061. return err;
  1062. if (outs)
  1063. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &vx_pcm_playback_ops);
  1064. if (ins)
  1065. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &vx_pcm_capture_ops);
  1066. snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC,
  1067. NULL, 0, 0);
  1068. pcm->private_data = chip;
  1069. pcm->private_free = snd_vx_pcm_free;
  1070. pcm->info_flags = 0;
  1071. pcm->nonatomic = true;
  1072. strcpy(pcm->name, chip->card->shortname);
  1073. chip->pcm[i] = pcm;
  1074. }
  1075. return 0;
  1076. }