amdtp.h 4.2 KB

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