amdtp.h 4.6 KB

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