amdtp.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
  2. #define SOUND_FIREWIRE_AMDTP_H_INCLUDED
  3. #include <linux/interrupt.h>
  4. #include <linux/mutex.h>
  5. #include <linux/spinlock.h>
  6. #include "packets-buffer.h"
  7. /**
  8. * enum cip_out_flags - describes details of the streaming protocol
  9. * @CIP_NONBLOCKING: In non-blocking mode, each packet contains
  10. * sample_rate/8000 samples, with rounding up or down to adjust
  11. * for clock skew and left-over fractional samples. This should
  12. * be used if supported by the device.
  13. */
  14. enum cip_out_flags {
  15. CIP_NONBLOCKING = 0,
  16. };
  17. /**
  18. * enum cip_sfc - a stream's sample rate
  19. */
  20. enum cip_sfc {
  21. CIP_SFC_32000 = 0,
  22. CIP_SFC_44100 = 1,
  23. CIP_SFC_48000 = 2,
  24. CIP_SFC_88200 = 3,
  25. CIP_SFC_96000 = 4,
  26. CIP_SFC_176400 = 5,
  27. CIP_SFC_192000 = 6,
  28. };
  29. #define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \
  30. SNDRV_PCM_FMTBIT_S32)
  31. struct fw_unit;
  32. struct fw_iso_context;
  33. struct snd_pcm_substream;
  34. struct amdtp_out_stream {
  35. struct fw_unit *unit;
  36. enum cip_out_flags flags;
  37. struct fw_iso_context *context;
  38. struct mutex mutex;
  39. enum cip_sfc sfc;
  40. unsigned int data_block_quadlets;
  41. unsigned int pcm_channels;
  42. unsigned int midi_ports;
  43. void (*transfer_samples)(struct amdtp_out_stream *s,
  44. struct snd_pcm_substream *pcm,
  45. __be32 *buffer, unsigned int frames);
  46. unsigned int syt_interval;
  47. unsigned int source_node_id_field;
  48. struct iso_packets_buffer buffer;
  49. struct snd_pcm_substream *pcm;
  50. struct tasklet_struct period_tasklet;
  51. int packet_index;
  52. unsigned int data_block_counter;
  53. unsigned int data_block_state;
  54. unsigned int last_syt_offset;
  55. unsigned int syt_offset_state;
  56. unsigned int pcm_buffer_pointer;
  57. unsigned int pcm_period_pointer;
  58. };
  59. int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
  60. enum cip_out_flags flags);
  61. void amdtp_out_stream_destroy(struct amdtp_out_stream *s);
  62. void amdtp_out_stream_set_rate(struct amdtp_out_stream *s, unsigned int rate);
  63. unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s);
  64. int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed);
  65. void amdtp_out_stream_update(struct amdtp_out_stream *s);
  66. void amdtp_out_stream_stop(struct amdtp_out_stream *s);
  67. void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
  68. snd_pcm_format_t format);
  69. void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
  70. void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
  71. /**
  72. * amdtp_out_stream_set_pcm - configure format of PCM samples
  73. * @s: the AMDTP output stream to be configured
  74. * @pcm_channels: the number of PCM samples in each data block, to be encoded
  75. * as AM824 multi-bit linear audio
  76. *
  77. * This function must not be called while the stream is running.
  78. */
  79. static inline void amdtp_out_stream_set_pcm(struct amdtp_out_stream *s,
  80. unsigned int pcm_channels)
  81. {
  82. s->pcm_channels = pcm_channels;
  83. }
  84. /**
  85. * amdtp_out_stream_set_midi - configure format of MIDI data
  86. * @s: the AMDTP output stream to be configured
  87. * @midi_ports: the number of MIDI ports (i.e., MPX-MIDI Data Channels)
  88. *
  89. * This function must not be called while the stream is running.
  90. */
  91. static inline void amdtp_out_stream_set_midi(struct amdtp_out_stream *s,
  92. unsigned int midi_ports)
  93. {
  94. s->midi_ports = midi_ports;
  95. }
  96. /**
  97. * amdtp_out_streaming_error - check for streaming error
  98. * @s: the AMDTP output stream
  99. *
  100. * If this function returns true, the stream's packet queue has stopped due to
  101. * an asynchronous error.
  102. */
  103. static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
  104. {
  105. return s->packet_index < 0;
  106. }
  107. /**
  108. * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device
  109. * @s: the AMDTP output stream
  110. * @pcm: the PCM device to be started, or %NULL to stop the current device
  111. *
  112. * Call this function on a running isochronous stream to enable the actual
  113. * transmission of PCM data. This function should be called from the PCM
  114. * device's .trigger callback.
  115. */
  116. static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
  117. struct snd_pcm_substream *pcm)
  118. {
  119. ACCESS_ONCE(s->pcm) = pcm;
  120. }
  121. /**
  122. * amdtp_out_stream_pcm_pointer - get the PCM buffer position
  123. * @s: the AMDTP output stream that transports the PCM data
  124. *
  125. * Returns the current buffer position, in frames.
  126. */
  127. static inline unsigned long
  128. amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s)
  129. {
  130. return ACCESS_ONCE(s->pcm_buffer_pointer);
  131. }
  132. static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
  133. {
  134. return sfc & 1;
  135. }
  136. #endif