amdtp.c 16 KB

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