amdtp.h 4.2 KB

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