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 <sound/asound.h>
8 #include "packets-buffer.h"
11 * enum cip_flags - describes details of the streaming protocol
12 * @CIP_NONBLOCKING: In non-blocking mode, each packet contains
13 * sample_rate/8000 samples, with rounding up or down to adjust
14 * for clock skew and left-over fractional samples. This should
15 * be used if supported by the device.
16 * @CIP_BLOCKING: In blocking mode, each packet contains either zero or
17 * SYT_INTERVAL samples, with these two types alternating so that
18 * the overall sample rate comes out right.
19 * @CIP_HI_DUALWIRE: At rates above 96 kHz, pretend that the stream runs
20 * at half the actual sample rate with twice the number of channels;
21 * two samples of a channel are stored consecutively in the packet.
22 * Requires blocking mode and SYT_INTERVAL-aligned PCM buffer size.
25 CIP_NONBLOCKING = 0x00,
27 CIP_HI_DUALWIRE = 0x02,
31 * enum cip_sfc - a stream's sample rate
44 #define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \
48 struct fw_iso_context;
49 struct snd_pcm_substream;
51 enum amdtp_stream_direction {
59 enum amdtp_stream_direction direction;
60 struct fw_iso_context *context;
65 unsigned int data_block_quadlets;
66 unsigned int pcm_channels;
67 unsigned int midi_ports;
68 void (*transfer_samples)(struct amdtp_stream *s,
69 struct snd_pcm_substream *pcm,
70 __be32 *buffer, unsigned int frames);
72 unsigned int syt_interval;
73 unsigned int transfer_delay;
74 unsigned int source_node_id_field;
75 struct iso_packets_buffer buffer;
77 struct snd_pcm_substream *pcm;
78 struct tasklet_struct period_tasklet;
81 unsigned int data_block_counter;
83 unsigned int data_block_state;
85 unsigned int last_syt_offset;
86 unsigned int syt_offset_state;
88 unsigned int pcm_buffer_pointer;
89 unsigned int pcm_period_pointer;
93 int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
94 enum amdtp_stream_direction dir,
95 enum cip_flags flags);
96 void amdtp_stream_destroy(struct amdtp_stream *s);
98 void amdtp_stream_set_parameters(struct amdtp_stream *s,
100 unsigned int pcm_channels,
101 unsigned int midi_ports);
102 unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s);
104 int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed);
105 void amdtp_stream_update(struct amdtp_stream *s);
106 void amdtp_stream_stop(struct amdtp_stream *s);
108 void amdtp_stream_set_pcm_format(struct amdtp_stream *s,
109 snd_pcm_format_t format);
110 void amdtp_stream_pcm_prepare(struct amdtp_stream *s);
111 unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s);
112 void amdtp_stream_pcm_abort(struct amdtp_stream *s);
114 extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
117 * amdtp_stream_running - check stream is running or not
118 * @s: the AMDTP stream
120 * If this function returns true, the stream is running.
122 static inline bool amdtp_stream_running(struct amdtp_stream *s)
124 return !IS_ERR(s->context);
128 * amdtp_streaming_error - check for streaming error
129 * @s: the AMDTP stream
131 * If this function returns true, the stream's packet queue has stopped due to
132 * an asynchronous error.
134 static inline bool amdtp_streaming_error(struct amdtp_stream *s)
136 return s->packet_index < 0;
140 * amdtp_stream_pcm_trigger - start/stop playback from a PCM device
141 * @s: the AMDTP stream
142 * @pcm: the PCM device to be started, or %NULL to stop the current device
144 * Call this function on a running isochronous stream to enable the actual
145 * transmission of PCM data. This function should be called from the PCM
146 * device's .trigger callback.
148 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
149 struct snd_pcm_substream *pcm)
151 ACCESS_ONCE(s->pcm) = pcm;
154 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)