amdtp.h 4.4 KB

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