amdtp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. * Audio and Music Data Transmission Protocol (IEC 61883-6) streams
  3. * with Common Isochronous Packet (IEC 61883-1) headers
  4. *
  5. * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
  6. * Licensed under the terms of the GNU General Public License, version 2.
  7. */
  8. #include <linux/device.h>
  9. #include <linux/err.h>
  10. #include <linux/firewire.h>
  11. #include <linux/module.h>
  12. #include <linux/slab.h>
  13. #include <sound/pcm.h>
  14. #include "amdtp.h"
  15. #define TICKS_PER_CYCLE 3072
  16. #define CYCLES_PER_SECOND 8000
  17. #define TICKS_PER_SECOND (TICKS_PER_CYCLE * CYCLES_PER_SECOND)
  18. #define TRANSFER_DELAY_TICKS 0x2e00 /* 479.17 µs */
  19. #define TAG_CIP 1
  20. #define CIP_EOH (1u << 31)
  21. #define CIP_FMT_AM (0x10 << 24)
  22. #define AMDTP_FDF_AM824 (0 << 19)
  23. #define AMDTP_FDF_SFC_SHIFT 16
  24. /* TODO: make these configurable */
  25. #define INTERRUPT_INTERVAL 16
  26. #define QUEUE_LENGTH 48
  27. static void pcm_period_tasklet(unsigned long data);
  28. /**
  29. * amdtp_out_stream_init - initialize an AMDTP output stream structure
  30. * @s: the AMDTP output stream to initialize
  31. * @unit: the target of the stream
  32. * @flags: the packet transmission method to use
  33. */
  34. int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
  35. enum cip_out_flags flags)
  36. {
  37. if (flags != CIP_NONBLOCKING)
  38. return -EINVAL;
  39. s->unit = fw_unit_get(unit);
  40. s->flags = flags;
  41. s->context = ERR_PTR(-1);
  42. mutex_init(&s->mutex);
  43. tasklet_init(&s->period_tasklet, pcm_period_tasklet, (unsigned long)s);
  44. s->packet_index = 0;
  45. return 0;
  46. }
  47. EXPORT_SYMBOL(amdtp_out_stream_init);
  48. /**
  49. * amdtp_out_stream_destroy - free stream resources
  50. * @s: the AMDTP output stream to destroy
  51. */
  52. void amdtp_out_stream_destroy(struct amdtp_out_stream *s)
  53. {
  54. WARN_ON(!IS_ERR(s->context));
  55. mutex_destroy(&s->mutex);
  56. fw_unit_put(s->unit);
  57. }
  58. EXPORT_SYMBOL(amdtp_out_stream_destroy);
  59. /**
  60. * amdtp_out_stream_set_rate - set the sample rate
  61. * @s: the AMDTP output stream to configure
  62. * @rate: the sample rate
  63. *
  64. * The sample rate must be set before the stream is started, and must not be
  65. * changed while the stream is running.
  66. */
  67. void amdtp_out_stream_set_rate(struct amdtp_out_stream *s, unsigned int rate)
  68. {
  69. static const struct {
  70. unsigned int rate;
  71. unsigned int syt_interval;
  72. } rate_info[] = {
  73. [CIP_SFC_32000] = { 32000, 8, },
  74. [CIP_SFC_44100] = { 44100, 8, },
  75. [CIP_SFC_48000] = { 48000, 8, },
  76. [CIP_SFC_88200] = { 88200, 16, },
  77. [CIP_SFC_96000] = { 96000, 16, },
  78. [CIP_SFC_176400] = { 176400, 32, },
  79. [CIP_SFC_192000] = { 192000, 32, },
  80. };
  81. unsigned int sfc;
  82. if (WARN_ON(!IS_ERR(s->context)))
  83. return;
  84. for (sfc = 0; sfc < ARRAY_SIZE(rate_info); ++sfc)
  85. if (rate_info[sfc].rate == rate) {
  86. s->sfc = sfc;
  87. s->syt_interval = rate_info[sfc].syt_interval;
  88. return;
  89. }
  90. WARN_ON(1);
  91. }
  92. EXPORT_SYMBOL(amdtp_out_stream_set_rate);
  93. /**
  94. * amdtp_out_stream_get_max_payload - get the stream's packet size
  95. * @s: the AMDTP output stream
  96. *
  97. * This function must not be called before the stream has been configured
  98. * with amdtp_out_stream_set_hw_params(), amdtp_out_stream_set_pcm(), and
  99. * amdtp_out_stream_set_midi().
  100. */
  101. unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s)
  102. {
  103. static const unsigned int max_data_blocks[] = {
  104. [CIP_SFC_32000] = 4,
  105. [CIP_SFC_44100] = 6,
  106. [CIP_SFC_48000] = 6,
  107. [CIP_SFC_88200] = 12,
  108. [CIP_SFC_96000] = 12,
  109. [CIP_SFC_176400] = 23,
  110. [CIP_SFC_192000] = 24,
  111. };
  112. s->data_block_quadlets = s->pcm_channels;
  113. s->data_block_quadlets += DIV_ROUND_UP(s->midi_ports, 8);
  114. return 8 + max_data_blocks[s->sfc] * 4 * s->data_block_quadlets;
  115. }
  116. EXPORT_SYMBOL(amdtp_out_stream_get_max_payload);
  117. static void amdtp_write_s16(struct amdtp_out_stream *s,
  118. struct snd_pcm_substream *pcm,
  119. __be32 *buffer, unsigned int frames);
  120. static void amdtp_write_s32(struct amdtp_out_stream *s,
  121. struct snd_pcm_substream *pcm,
  122. __be32 *buffer, unsigned int frames);
  123. /**
  124. * amdtp_out_stream_set_pcm_format - set the PCM format
  125. * @s: the AMDTP output stream to configure
  126. * @format: the format of the ALSA PCM device
  127. *
  128. * The sample format must be set before the stream is started, and must not be
  129. * changed while the stream is running.
  130. */
  131. void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
  132. snd_pcm_format_t format)
  133. {
  134. if (WARN_ON(!IS_ERR(s->context)))
  135. return;
  136. switch (format) {
  137. default:
  138. WARN_ON(1);
  139. /* fall through */
  140. case SNDRV_PCM_FORMAT_S16:
  141. s->transfer_samples = amdtp_write_s16;
  142. break;
  143. case SNDRV_PCM_FORMAT_S32:
  144. s->transfer_samples = amdtp_write_s32;
  145. break;
  146. }
  147. }
  148. EXPORT_SYMBOL(amdtp_out_stream_set_pcm_format);
  149. /**
  150. * amdtp_out_stream_pcm_prepare - prepare PCM device for running
  151. * @s: the AMDTP output stream
  152. *
  153. * This function should be called from the PCM device's .prepare callback.
  154. */
  155. void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
  156. {
  157. tasklet_kill(&s->period_tasklet);
  158. s->pcm_buffer_pointer = 0;
  159. s->pcm_period_pointer = 0;
  160. s->pointer_flush = true;
  161. }
  162. EXPORT_SYMBOL(amdtp_out_stream_pcm_prepare);
  163. static unsigned int calculate_data_blocks(struct amdtp_out_stream *s)
  164. {
  165. unsigned int phase, data_blocks;
  166. if (!cip_sfc_is_base_44100(s->sfc)) {
  167. /* Sample_rate / 8000 is an integer, and precomputed. */
  168. data_blocks = s->data_block_state;
  169. } else {
  170. phase = s->data_block_state;
  171. /*
  172. * This calculates the number of data blocks per packet so that
  173. * 1) the overall rate is correct and exactly synchronized to
  174. * the bus clock, and
  175. * 2) packets with a rounded-up number of blocks occur as early
  176. * as possible in the sequence (to prevent underruns of the
  177. * device's buffer).
  178. */
  179. if (s->sfc == CIP_SFC_44100)
  180. /* 6 6 5 6 5 6 5 ... */
  181. data_blocks = 5 + ((phase & 1) ^
  182. (phase == 0 || phase >= 40));
  183. else
  184. /* 12 11 11 11 11 ... or 23 22 22 22 22 ... */
  185. data_blocks = 11 * (s->sfc >> 1) + (phase == 0);
  186. if (++phase >= (80 >> (s->sfc >> 1)))
  187. phase = 0;
  188. s->data_block_state = phase;
  189. }
  190. return data_blocks;
  191. }
  192. static unsigned int calculate_syt(struct amdtp_out_stream *s,
  193. unsigned int cycle)
  194. {
  195. unsigned int syt_offset, phase, index, syt;
  196. if (s->last_syt_offset < TICKS_PER_CYCLE) {
  197. if (!cip_sfc_is_base_44100(s->sfc))
  198. syt_offset = s->last_syt_offset + s->syt_offset_state;
  199. else {
  200. /*
  201. * The time, in ticks, of the n'th SYT_INTERVAL sample is:
  202. * n * SYT_INTERVAL * 24576000 / sample_rate
  203. * Modulo TICKS_PER_CYCLE, the difference between successive
  204. * elements is about 1386.23. Rounding the results of this
  205. * formula to the SYT precision results in a sequence of
  206. * differences that begins with:
  207. * 1386 1386 1387 1386 1386 1386 1387 1386 1386 1386 1387 ...
  208. * This code generates _exactly_ the same sequence.
  209. */
  210. phase = s->syt_offset_state;
  211. index = phase % 13;
  212. syt_offset = s->last_syt_offset;
  213. syt_offset += 1386 + ((index && !(index & 3)) ||
  214. phase == 146);
  215. if (++phase >= 147)
  216. phase = 0;
  217. s->syt_offset_state = phase;
  218. }
  219. } else
  220. syt_offset = s->last_syt_offset - TICKS_PER_CYCLE;
  221. s->last_syt_offset = syt_offset;
  222. if (syt_offset < TICKS_PER_CYCLE) {
  223. syt_offset += TRANSFER_DELAY_TICKS - TICKS_PER_CYCLE;
  224. syt = (cycle + syt_offset / TICKS_PER_CYCLE) << 12;
  225. syt += syt_offset % TICKS_PER_CYCLE;
  226. return syt & 0xffff;
  227. } else {
  228. return 0xffff; /* no info */
  229. }
  230. }
  231. static void amdtp_write_s32(struct amdtp_out_stream *s,
  232. struct snd_pcm_substream *pcm,
  233. __be32 *buffer, unsigned int frames)
  234. {
  235. struct snd_pcm_runtime *runtime = pcm->runtime;
  236. unsigned int channels, remaining_frames, frame_step, i, c;
  237. const u32 *src;
  238. channels = s->pcm_channels;
  239. src = (void *)runtime->dma_area +
  240. s->pcm_buffer_pointer * (runtime->frame_bits / 8);
  241. remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
  242. frame_step = s->data_block_quadlets - channels;
  243. for (i = 0; i < frames; ++i) {
  244. for (c = 0; c < channels; ++c) {
  245. *buffer = cpu_to_be32((*src >> 8) | 0x40000000);
  246. src++;
  247. buffer++;
  248. }
  249. buffer += frame_step;
  250. if (--remaining_frames == 0)
  251. src = (void *)runtime->dma_area;
  252. }
  253. }
  254. static void amdtp_write_s16(struct amdtp_out_stream *s,
  255. struct snd_pcm_substream *pcm,
  256. __be32 *buffer, unsigned int frames)
  257. {
  258. struct snd_pcm_runtime *runtime = pcm->runtime;
  259. unsigned int channels, remaining_frames, frame_step, i, c;
  260. const u16 *src;
  261. channels = s->pcm_channels;
  262. src = (void *)runtime->dma_area +
  263. s->pcm_buffer_pointer * (runtime->frame_bits / 8);
  264. remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
  265. frame_step = s->data_block_quadlets - channels;
  266. for (i = 0; i < frames; ++i) {
  267. for (c = 0; c < channels; ++c) {
  268. *buffer = cpu_to_be32((*src << 8) | 0x40000000);
  269. src++;
  270. buffer++;
  271. }
  272. buffer += frame_step;
  273. if (--remaining_frames == 0)
  274. src = (void *)runtime->dma_area;
  275. }
  276. }
  277. static void amdtp_fill_pcm_silence(struct amdtp_out_stream *s,
  278. __be32 *buffer, unsigned int frames)
  279. {
  280. unsigned int i, c;
  281. for (i = 0; i < frames; ++i) {
  282. for (c = 0; c < s->pcm_channels; ++c)
  283. buffer[c] = cpu_to_be32(0x40000000);
  284. buffer += s->data_block_quadlets;
  285. }
  286. }
  287. static void amdtp_fill_midi(struct amdtp_out_stream *s,
  288. __be32 *buffer, unsigned int frames)
  289. {
  290. unsigned int i;
  291. for (i = 0; i < frames; ++i)
  292. buffer[s->pcm_channels + i * s->data_block_quadlets] =
  293. cpu_to_be32(0x80000000);
  294. }
  295. static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
  296. {
  297. __be32 *buffer;
  298. unsigned int index, data_blocks, syt, ptr;
  299. struct snd_pcm_substream *pcm;
  300. struct fw_iso_packet packet;
  301. int err;
  302. if (s->packet_index < 0)
  303. return;
  304. index = s->packet_index;
  305. data_blocks = calculate_data_blocks(s);
  306. syt = calculate_syt(s, cycle);
  307. buffer = s->buffer.packets[index].buffer;
  308. buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) |
  309. (s->data_block_quadlets << 16) |
  310. s->data_block_counter);
  311. buffer[1] = cpu_to_be32(CIP_EOH | CIP_FMT_AM | AMDTP_FDF_AM824 |
  312. (s->sfc << AMDTP_FDF_SFC_SHIFT) | syt);
  313. buffer += 2;
  314. pcm = ACCESS_ONCE(s->pcm);
  315. if (pcm)
  316. s->transfer_samples(s, pcm, buffer, data_blocks);
  317. else
  318. amdtp_fill_pcm_silence(s, buffer, data_blocks);
  319. if (s->midi_ports)
  320. amdtp_fill_midi(s, buffer, data_blocks);
  321. s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff;
  322. packet.payload_length = 8 + data_blocks * 4 * s->data_block_quadlets;
  323. packet.interrupt = IS_ALIGNED(index + 1, INTERRUPT_INTERVAL);
  324. packet.skip = 0;
  325. packet.tag = TAG_CIP;
  326. packet.sy = 0;
  327. packet.header_length = 0;
  328. err = fw_iso_context_queue(s->context, &packet, &s->buffer.iso_buffer,
  329. s->buffer.packets[index].offset);
  330. if (err < 0) {
  331. dev_err(&s->unit->device, "queueing error: %d\n", err);
  332. s->packet_index = -1;
  333. amdtp_out_stream_pcm_abort(s);
  334. return;
  335. }
  336. if (++index >= QUEUE_LENGTH)
  337. index = 0;
  338. s->packet_index = index;
  339. if (pcm) {
  340. ptr = s->pcm_buffer_pointer + data_blocks;
  341. if (ptr >= pcm->runtime->buffer_size)
  342. ptr -= pcm->runtime->buffer_size;
  343. ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
  344. s->pcm_period_pointer += data_blocks;
  345. if (s->pcm_period_pointer >= pcm->runtime->period_size) {
  346. s->pcm_period_pointer -= pcm->runtime->period_size;
  347. s->pointer_flush = false;
  348. tasklet_hi_schedule(&s->period_tasklet);
  349. }
  350. }
  351. }
  352. static void pcm_period_tasklet(unsigned long data)
  353. {
  354. struct amdtp_out_stream *s = (void *)data;
  355. struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm);
  356. if (pcm)
  357. snd_pcm_period_elapsed(pcm);
  358. }
  359. static void out_packet_callback(struct fw_iso_context *context, u32 cycle,
  360. size_t header_length, void *header, void *data)
  361. {
  362. struct amdtp_out_stream *s = data;
  363. unsigned int i, packets = header_length / 4;
  364. /*
  365. * Compute the cycle of the last queued packet.
  366. * (We need only the four lowest bits for the SYT, so we can ignore
  367. * that bits 0-11 must wrap around at 3072.)
  368. */
  369. cycle += QUEUE_LENGTH - packets;
  370. for (i = 0; i < packets; ++i)
  371. queue_out_packet(s, ++cycle);
  372. fw_iso_context_queue_flush(s->context);
  373. }
  374. static int queue_initial_skip_packets(struct amdtp_out_stream *s)
  375. {
  376. struct fw_iso_packet skip_packet = {
  377. .skip = 1,
  378. };
  379. unsigned int i;
  380. int err;
  381. for (i = 0; i < QUEUE_LENGTH; ++i) {
  382. skip_packet.interrupt = IS_ALIGNED(s->packet_index + 1,
  383. INTERRUPT_INTERVAL);
  384. err = fw_iso_context_queue(s->context, &skip_packet, NULL, 0);
  385. if (err < 0)
  386. return err;
  387. if (++s->packet_index >= QUEUE_LENGTH)
  388. s->packet_index = 0;
  389. }
  390. return 0;
  391. }
  392. /**
  393. * amdtp_out_stream_start - start sending packets
  394. * @s: the AMDTP output stream to start
  395. * @channel: the isochronous channel on the bus
  396. * @speed: firewire speed code
  397. *
  398. * The stream cannot be started until it has been configured with
  399. * amdtp_out_stream_set_hw_params(), amdtp_out_stream_set_pcm(), and
  400. * amdtp_out_stream_set_midi(); and it must be started before any
  401. * PCM or MIDI device can be started.
  402. */
  403. int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
  404. {
  405. static const struct {
  406. unsigned int data_block;
  407. unsigned int syt_offset;
  408. } initial_state[] = {
  409. [CIP_SFC_32000] = { 4, 3072 },
  410. [CIP_SFC_48000] = { 6, 1024 },
  411. [CIP_SFC_96000] = { 12, 1024 },
  412. [CIP_SFC_192000] = { 24, 1024 },
  413. [CIP_SFC_44100] = { 0, 67 },
  414. [CIP_SFC_88200] = { 0, 67 },
  415. [CIP_SFC_176400] = { 0, 67 },
  416. };
  417. int err;
  418. mutex_lock(&s->mutex);
  419. if (WARN_ON(!IS_ERR(s->context) ||
  420. (!s->pcm_channels && !s->midi_ports))) {
  421. err = -EBADFD;
  422. goto err_unlock;
  423. }
  424. s->data_block_state = initial_state[s->sfc].data_block;
  425. s->syt_offset_state = initial_state[s->sfc].syt_offset;
  426. s->last_syt_offset = TICKS_PER_CYCLE;
  427. err = iso_packets_buffer_init(&s->buffer, s->unit, QUEUE_LENGTH,
  428. amdtp_out_stream_get_max_payload(s),
  429. DMA_TO_DEVICE);
  430. if (err < 0)
  431. goto err_unlock;
  432. s->context = fw_iso_context_create(fw_parent_device(s->unit)->card,
  433. FW_ISO_CONTEXT_TRANSMIT,
  434. channel, speed, 0,
  435. out_packet_callback, s);
  436. if (IS_ERR(s->context)) {
  437. err = PTR_ERR(s->context);
  438. if (err == -EBUSY)
  439. dev_err(&s->unit->device,
  440. "no free output stream on this controller\n");
  441. goto err_buffer;
  442. }
  443. amdtp_out_stream_update(s);
  444. s->packet_index = 0;
  445. s->data_block_counter = 0;
  446. err = queue_initial_skip_packets(s);
  447. if (err < 0)
  448. goto err_context;
  449. err = fw_iso_context_start(s->context, -1, 0, 0);
  450. if (err < 0)
  451. goto err_context;
  452. mutex_unlock(&s->mutex);
  453. return 0;
  454. err_context:
  455. fw_iso_context_destroy(s->context);
  456. s->context = ERR_PTR(-1);
  457. err_buffer:
  458. iso_packets_buffer_destroy(&s->buffer, s->unit);
  459. err_unlock:
  460. mutex_unlock(&s->mutex);
  461. return err;
  462. }
  463. EXPORT_SYMBOL(amdtp_out_stream_start);
  464. /**
  465. * amdtp_out_stream_pcm_pointer - get the PCM buffer position
  466. * @s: the AMDTP output stream that transports the PCM data
  467. *
  468. * Returns the current buffer position, in frames.
  469. */
  470. unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s)
  471. {
  472. /* this optimization is allowed to be racy */
  473. if (s->pointer_flush)
  474. fw_iso_context_flush_completions(s->context);
  475. else
  476. s->pointer_flush = true;
  477. return ACCESS_ONCE(s->pcm_buffer_pointer);
  478. }
  479. EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
  480. /**
  481. * amdtp_out_stream_update - update the stream after a bus reset
  482. * @s: the AMDTP output stream
  483. */
  484. void amdtp_out_stream_update(struct amdtp_out_stream *s)
  485. {
  486. ACCESS_ONCE(s->source_node_id_field) =
  487. (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
  488. }
  489. EXPORT_SYMBOL(amdtp_out_stream_update);
  490. /**
  491. * amdtp_out_stream_stop - stop sending packets
  492. * @s: the AMDTP output stream to stop
  493. *
  494. * All PCM and MIDI devices of the stream must be stopped before the stream
  495. * itself can be stopped.
  496. */
  497. void amdtp_out_stream_stop(struct amdtp_out_stream *s)
  498. {
  499. mutex_lock(&s->mutex);
  500. if (IS_ERR(s->context)) {
  501. mutex_unlock(&s->mutex);
  502. return;
  503. }
  504. tasklet_kill(&s->period_tasklet);
  505. fw_iso_context_stop(s->context);
  506. fw_iso_context_destroy(s->context);
  507. s->context = ERR_PTR(-1);
  508. iso_packets_buffer_destroy(&s->buffer, s->unit);
  509. mutex_unlock(&s->mutex);
  510. }
  511. EXPORT_SYMBOL(amdtp_out_stream_stop);
  512. /**
  513. * amdtp_out_stream_pcm_abort - abort the running PCM device
  514. * @s: the AMDTP stream about to be stopped
  515. *
  516. * If the isochronous stream needs to be stopped asynchronously, call this
  517. * function first to stop the PCM device.
  518. */
  519. void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s)
  520. {
  521. struct snd_pcm_substream *pcm;
  522. pcm = ACCESS_ONCE(s->pcm);
  523. if (pcm) {
  524. snd_pcm_stream_lock_irq(pcm);
  525. if (snd_pcm_running(pcm))
  526. snd_pcm_stop(pcm, SNDRV_PCM_STATE_XRUN);
  527. snd_pcm_stream_unlock_irq(pcm);
  528. }
  529. }
  530. EXPORT_SYMBOL(amdtp_out_stream_pcm_abort);