1 #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
2 #define SOUND_FIREWIRE_AMDTP_H_INCLUDED
5 #include <linux/interrupt.h>
6 #include <linux/mutex.h>
7 #include "packets-buffer.h"
10 * enum cip_out_flags - describes details of the streaming protocol
11 * @CIP_NONBLOCKING: In non-blocking mode, each packet contains
12 * sample_rate/8000 samples, with rounding up or down to adjust
13 * for clock skew and left-over fractional samples. This should
14 * be used if supported by the device.
15 * @CIP_BLOCKING: In blocking mode, each packet contains either zero or
16 * SYT_INTERVAL samples, with these two types alternating so that
17 * the overall sample rate comes out right.
18 * @CIP_HI_DUALWIRE: At rates above 96 kHz, pretend that the stream runs
19 * at half the actual sample rate with twice the number of channels;
20 * two samples of a channel are stored consecutively in the packet.
21 * Requires blocking mode and SYT_INTERVAL-aligned PCM buffer size.
24 CIP_NONBLOCKING = 0x00,
26 CIP_HI_DUALWIRE = 0x02,
30 * enum cip_sfc - a stream's sample rate
43 #define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \
47 struct fw_iso_context;
48 struct snd_pcm_substream;
50 struct amdtp_out_stream {
52 enum cip_out_flags flags;
53 struct fw_iso_context *context;
58 unsigned int data_block_quadlets;
59 unsigned int pcm_channels;
60 unsigned int midi_ports;
61 void (*transfer_samples)(struct amdtp_out_stream *s,
62 struct snd_pcm_substream *pcm,
63 __be32 *buffer, unsigned int frames);
65 unsigned int syt_interval;
66 unsigned int transfer_delay;
67 unsigned int source_node_id_field;
68 struct iso_packets_buffer buffer;
70 struct snd_pcm_substream *pcm;
71 struct tasklet_struct period_tasklet;
74 unsigned int data_block_counter;
76 unsigned int data_block_state;
78 unsigned int last_syt_offset;
79 unsigned int syt_offset_state;
81 unsigned int pcm_buffer_pointer;
82 unsigned int pcm_period_pointer;
86 int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
87 enum cip_out_flags flags);
88 void amdtp_out_stream_destroy(struct amdtp_out_stream *s);
90 void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s,
92 unsigned int pcm_channels,
93 unsigned int midi_ports);
94 unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s);
96 int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed);
97 void amdtp_out_stream_update(struct amdtp_out_stream *s);
98 void amdtp_out_stream_stop(struct amdtp_out_stream *s);
100 void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
101 snd_pcm_format_t format);
102 void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
103 unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
104 void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
106 extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
108 static inline bool amdtp_out_stream_running(struct amdtp_out_stream *s)
110 return !IS_ERR(s->context);
114 * amdtp_out_streaming_error - check for streaming error
115 * @s: the AMDTP output stream
117 * If this function returns true, the stream's packet queue has stopped due to
118 * an asynchronous error.
120 static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
122 return s->packet_index < 0;
126 * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device
127 * @s: the AMDTP output stream
128 * @pcm: the PCM device to be started, or %NULL to stop the current device
130 * Call this function on a running isochronous stream to enable the actual
131 * transmission of PCM data. This function should be called from the PCM
132 * device's .trigger callback.
134 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
135 struct snd_pcm_substream *pcm)
137 ACCESS_ONCE(s->pcm) = pcm;
140 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)