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.
20 CIP_NONBLOCKING = 0x00,
25 * enum cip_sfc - a stream's sample rate
37 #define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \
41 struct fw_iso_context;
42 struct snd_pcm_substream;
44 struct amdtp_out_stream {
46 enum cip_out_flags flags;
47 struct fw_iso_context *context;
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);
58 unsigned int syt_interval;
59 unsigned int transfer_delay;
60 unsigned int source_node_id_field;
61 struct iso_packets_buffer buffer;
63 struct snd_pcm_substream *pcm;
64 struct tasklet_struct period_tasklet;
67 unsigned int data_block_counter;
69 unsigned int data_block_state;
71 unsigned int last_syt_offset;
72 unsigned int syt_offset_state;
74 unsigned int pcm_buffer_pointer;
75 unsigned int pcm_period_pointer;
79 int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
80 enum cip_out_flags flags);
81 void amdtp_out_stream_destroy(struct amdtp_out_stream *s);
83 void amdtp_out_stream_set_rate(struct amdtp_out_stream *s, unsigned int rate);
84 unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s);
86 int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed);
87 void amdtp_out_stream_update(struct amdtp_out_stream *s);
88 void amdtp_out_stream_stop(struct amdtp_out_stream *s);
90 void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
91 snd_pcm_format_t format);
92 void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
93 unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
94 void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
96 static inline bool amdtp_out_stream_running(struct amdtp_out_stream *s)
98 return !IS_ERR(s->context);
102 * amdtp_out_stream_set_pcm - configure format of PCM samples
103 * @s: the AMDTP output stream to be configured
104 * @pcm_channels: the number of PCM samples in each data block, to be encoded
105 * as AM824 multi-bit linear audio
107 * This function must not be called while the stream is running.
109 static inline void amdtp_out_stream_set_pcm(struct amdtp_out_stream *s,
110 unsigned int pcm_channels)
112 s->pcm_channels = pcm_channels;
116 * amdtp_out_stream_set_midi - configure format of MIDI data
117 * @s: the AMDTP output stream to be configured
118 * @midi_ports: the number of MIDI ports (i.e., MPX-MIDI Data Channels)
120 * This function must not be called while the stream is running.
122 static inline void amdtp_out_stream_set_midi(struct amdtp_out_stream *s,
123 unsigned int midi_ports)
125 s->midi_ports = midi_ports;
129 * amdtp_out_streaming_error - check for streaming error
130 * @s: the AMDTP output stream
132 * If this function returns true, the stream's packet queue has stopped due to
133 * an asynchronous error.
135 static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
137 return s->packet_index < 0;
141 * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device
142 * @s: the AMDTP output stream
143 * @pcm: the PCM device to be started, or %NULL to stop the current device
145 * Call this function on a running isochronous stream to enable the actual
146 * transmission of PCM data. This function should be called from the PCM
147 * device's .trigger callback.
149 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
150 struct snd_pcm_substream *pcm)
152 ACCESS_ONCE(s->pcm) = pcm;
155 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)