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_out_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 struct amdtp_out_stream
{
53 enum cip_out_flags flags
;
54 struct fw_iso_context
*context
;
59 unsigned int data_block_quadlets
;
60 unsigned int pcm_channels
;
61 unsigned int midi_ports
;
62 void (*transfer_samples
)(struct amdtp_out_stream
*s
,
63 struct snd_pcm_substream
*pcm
,
64 __be32
*buffer
, unsigned int frames
);
66 unsigned int syt_interval
;
67 unsigned int transfer_delay
;
68 unsigned int source_node_id_field
;
69 struct iso_packets_buffer buffer
;
71 struct snd_pcm_substream
*pcm
;
72 struct tasklet_struct period_tasklet
;
75 unsigned int data_block_counter
;
77 unsigned int data_block_state
;
79 unsigned int last_syt_offset
;
80 unsigned int syt_offset_state
;
82 unsigned int pcm_buffer_pointer
;
83 unsigned int pcm_period_pointer
;
87 int amdtp_out_stream_init(struct amdtp_out_stream
*s
, struct fw_unit
*unit
,
88 enum cip_out_flags flags
);
89 void amdtp_out_stream_destroy(struct amdtp_out_stream
*s
);
91 void amdtp_out_stream_set_parameters(struct amdtp_out_stream
*s
,
93 unsigned int pcm_channels
,
94 unsigned int midi_ports
);
95 unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream
*s
);
97 int amdtp_out_stream_start(struct amdtp_out_stream
*s
, int channel
, int speed
);
98 void amdtp_out_stream_update(struct amdtp_out_stream
*s
);
99 void amdtp_out_stream_stop(struct amdtp_out_stream
*s
);
101 void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream
*s
,
102 snd_pcm_format_t format
);
103 void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream
*s
);
104 unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream
*s
);
105 void amdtp_out_stream_pcm_abort(struct amdtp_out_stream
*s
);
107 extern const unsigned int amdtp_syt_intervals
[CIP_SFC_COUNT
];
109 static inline bool amdtp_out_stream_running(struct amdtp_out_stream
*s
)
111 return !IS_ERR(s
->context
);
115 * amdtp_out_streaming_error - check for streaming error
116 * @s: the AMDTP output stream
118 * If this function returns true, the stream's packet queue has stopped due to
119 * an asynchronous error.
121 static inline bool amdtp_out_streaming_error(struct amdtp_out_stream
*s
)
123 return s
->packet_index
< 0;
127 * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device
128 * @s: the AMDTP output stream
129 * @pcm: the PCM device to be started, or %NULL to stop the current device
131 * Call this function on a running isochronous stream to enable the actual
132 * transmission of PCM data. This function should be called from the PCM
133 * device's .trigger callback.
135 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream
*s
,
136 struct snd_pcm_substream
*pcm
)
138 ACCESS_ONCE(s
->pcm
) = pcm
;
141 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc
)