amdtp.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. */
  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. struct tasklet_struct period_tasklet;
  50. int packet_index;
  51. unsigned int data_block_counter;
  52. unsigned int data_block_state;
  53. unsigned int last_syt_offset;
  54. unsigned int syt_offset_state;
  55. unsigned int pcm_buffer_pointer;
  56. unsigned int pcm_period_pointer;
  57. bool pointer_flush;
  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. unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
  71. void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
  72. /**
  73. * amdtp_out_stream_set_pcm - configure format of PCM samples
  74. * @s: the AMDTP output stream to be configured
  75. * @pcm_channels: the number of PCM samples in each data block, to be encoded
  76. * as AM824 multi-bit linear audio
  77. *
  78. * This function must not be called while the stream is running.
  79. */
  80. static inline void amdtp_out_stream_set_pcm(struct amdtp_out_stream *s,
  81. unsigned int pcm_channels)
  82. {
  83. s->pcm_channels = pcm_channels;
  84. }
  85. /**
  86. * amdtp_out_stream_set_midi - configure format of MIDI data
  87. * @s: the AMDTP output stream to be configured
  88. * @midi_ports: the number of MIDI ports (i.e., MPX-MIDI Data Channels)
  89. *
  90. * This function must not be called while the stream is running.
  91. */
  92. static inline void amdtp_out_stream_set_midi(struct amdtp_out_stream *s,
  93. unsigned int midi_ports)
  94. {
  95. s->midi_ports = midi_ports;
  96. }
  97. /**
  98. * amdtp_out_streaming_error - check for streaming error
  99. * @s: the AMDTP output stream
  100. *
  101. * If this function returns true, the stream's packet queue has stopped due to
  102. * an asynchronous error.
  103. */
  104. static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
  105. {
  106. return s->packet_index < 0;
  107. }
  108. /**
  109. * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device
  110. * @s: the AMDTP output stream
  111. * @pcm: the PCM device to be started, or %NULL to stop the current device
  112. *
  113. * Call this function on a running isochronous stream to enable the actual
  114. * transmission of PCM data. This function should be called from the PCM
  115. * device's .trigger callback.
  116. */
  117. static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
  118. struct snd_pcm_substream *pcm)
  119. {
  120. ACCESS_ONCE(s->pcm) = pcm;
  121. }
  122. static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
  123. {
  124. return sfc & 1;
  125. }
  126. #endif