amdtp.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
  2. #define SOUND_FIREWIRE_AMDTP_H_INCLUDED
  3. #include <linux/err.h>
  4. #include <linux/interrupt.h>
  5. #include <linux/mutex.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. * @CIP_BLOCKING: In blocking mode, each packet contains either zero or
  14. * SYT_INTERVAL samples, with these two types alternating so that
  15. * the overall sample rate comes out right.
  16. * @CIP_HI_DUALWIRE: At rates above 96 kHz, pretend that the stream runs
  17. * at half the actual sample rate with twice the number of channels;
  18. * two samples of a channel are stored consecutively in the packet.
  19. * Requires blocking mode and SYT_INTERVAL-aligned PCM buffer size.
  20. */
  21. enum cip_out_flags {
  22. CIP_NONBLOCKING = 0x00,
  23. CIP_BLOCKING = 0x01,
  24. CIP_HI_DUALWIRE = 0x02,
  25. };
  26. /**
  27. * enum cip_sfc - a stream's sample rate
  28. */
  29. enum cip_sfc {
  30. CIP_SFC_32000 = 0,
  31. CIP_SFC_44100 = 1,
  32. CIP_SFC_48000 = 2,
  33. CIP_SFC_88200 = 3,
  34. CIP_SFC_96000 = 4,
  35. CIP_SFC_176400 = 5,
  36. CIP_SFC_192000 = 6,
  37. CIP_SFC_COUNT
  38. };
  39. #define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \
  40. SNDRV_PCM_FMTBIT_S32)
  41. struct fw_unit;
  42. struct fw_iso_context;
  43. struct snd_pcm_substream;
  44. struct amdtp_out_stream {
  45. struct fw_unit *unit;
  46. enum cip_out_flags flags;
  47. struct fw_iso_context *context;
  48. struct mutex mutex;
  49. enum cip_sfc sfc;
  50. bool dual_wire;
  51. unsigned int data_block_quadlets;
  52. unsigned int pcm_channels;
  53. unsigned int midi_ports;
  54. void (*transfer_samples)(struct amdtp_out_stream *s,
  55. struct snd_pcm_substream *pcm,
  56. __be32 *buffer, unsigned int frames);
  57. unsigned int syt_interval;
  58. unsigned int transfer_delay;
  59. unsigned int source_node_id_field;
  60. struct iso_packets_buffer buffer;
  61. struct snd_pcm_substream *pcm;
  62. struct tasklet_struct period_tasklet;
  63. int packet_index;
  64. unsigned int data_block_counter;
  65. unsigned int data_block_state;
  66. unsigned int last_syt_offset;
  67. unsigned int syt_offset_state;
  68. unsigned int pcm_buffer_pointer;
  69. unsigned int pcm_period_pointer;
  70. bool pointer_flush;
  71. };
  72. int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
  73. enum cip_out_flags flags);
  74. void amdtp_out_stream_destroy(struct amdtp_out_stream *s);
  75. void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s,
  76. unsigned int rate,
  77. unsigned int pcm_channels,
  78. unsigned int midi_ports);
  79. unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s);
  80. int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed);
  81. void amdtp_out_stream_update(struct amdtp_out_stream *s);
  82. void amdtp_out_stream_stop(struct amdtp_out_stream *s);
  83. void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
  84. snd_pcm_format_t format);
  85. void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
  86. unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
  87. void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
  88. extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
  89. static inline bool amdtp_out_stream_running(struct amdtp_out_stream *s)
  90. {
  91. return !IS_ERR(s->context);
  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_trigger - start/stop playback from a PCM device
  106. * @s: the AMDTP output stream
  107. * @pcm: the PCM device to be started, or %NULL to stop the current device
  108. *
  109. * Call this function on a running isochronous stream to enable the actual
  110. * transmission of PCM data. This function should be called from the PCM
  111. * device's .trigger callback.
  112. */
  113. static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
  114. struct snd_pcm_substream *pcm)
  115. {
  116. ACCESS_ONCE(s->pcm) = pcm;
  117. }
  118. static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
  119. {
  120. return sfc & 1;
  121. }
  122. #endif