ALSA: firewire-lib: Split some codes into functions to reuse for both streams
[deliverable/linux.git] / sound / firewire / amdtp.h
CommitLineData
31ef9134
CL
1#ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
2#define SOUND_FIREWIRE_AMDTP_H_INCLUDED
3
20b65dd0 4#include <linux/err.h>
76fb8789 5#include <linux/interrupt.h>
31ef9134 6#include <linux/mutex.h>
777fb574 7#include <sound/asound.h>
31ef9134
CL
8#include "packets-buffer.h"
9
10/**
be4a2894 11 * enum cip_flags - describes details of the streaming protocol
31ef9134
CL
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.
e84d15f6
CL
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.
a7304e3b
CL
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.
31ef9134 23 */
be4a2894 24enum cip_flags {
e84d15f6
CL
25 CIP_NONBLOCKING = 0x00,
26 CIP_BLOCKING = 0x01,
a7304e3b 27 CIP_HI_DUALWIRE = 0x02,
31ef9134
CL
28};
29
30/**
31 * enum cip_sfc - a stream's sample rate
32 */
33enum cip_sfc {
34 CIP_SFC_32000 = 0,
35 CIP_SFC_44100 = 1,
36 CIP_SFC_48000 = 2,
37 CIP_SFC_88200 = 3,
38 CIP_SFC_96000 = 4,
39 CIP_SFC_176400 = 5,
40 CIP_SFC_192000 = 6,
a7304e3b 41 CIP_SFC_COUNT
31ef9134
CL
42};
43
44#define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \
45 SNDRV_PCM_FMTBIT_S32)
46
47struct fw_unit;
48struct fw_iso_context;
49struct snd_pcm_substream;
50
3ff7e8f0
TS
51enum amdtp_stream_direction {
52 AMDTP_OUT_STREAM = 0,
53 AMDTP_IN_STREAM
54};
55
be4a2894 56struct amdtp_stream {
31ef9134 57 struct fw_unit *unit;
be4a2894 58 enum cip_flags flags;
3ff7e8f0 59 enum amdtp_stream_direction direction;
31ef9134
CL
60 struct fw_iso_context *context;
61 struct mutex mutex;
62
63 enum cip_sfc sfc;
a7304e3b 64 bool dual_wire;
31ef9134
CL
65 unsigned int data_block_quadlets;
66 unsigned int pcm_channels;
67 unsigned int midi_ports;
be4a2894 68 void (*transfer_samples)(struct amdtp_stream *s,
31ef9134
CL
69 struct snd_pcm_substream *pcm,
70 __be32 *buffer, unsigned int frames);
71
72 unsigned int syt_interval;
e84d15f6 73 unsigned int transfer_delay;
31ef9134
CL
74 unsigned int source_node_id_field;
75 struct iso_packets_buffer buffer;
76
77 struct snd_pcm_substream *pcm;
76fb8789 78 struct tasklet_struct period_tasklet;
31ef9134 79
ec00f5e4 80 int packet_index;
31ef9134
CL
81 unsigned int data_block_counter;
82
83 unsigned int data_block_state;
84
85 unsigned int last_syt_offset;
86 unsigned int syt_offset_state;
87
88 unsigned int pcm_buffer_pointer;
89 unsigned int pcm_period_pointer;
92b862c7 90 bool pointer_flush;
31ef9134
CL
91};
92
be4a2894 93int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
3ff7e8f0 94 enum amdtp_stream_direction dir,
be4a2894
TS
95 enum cip_flags flags);
96void amdtp_stream_destroy(struct amdtp_stream *s);
31ef9134 97
be4a2894
TS
98void amdtp_stream_set_parameters(struct amdtp_stream *s,
99 unsigned int rate,
100 unsigned int pcm_channels,
101 unsigned int midi_ports);
102unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s);
31ef9134 103
be4a2894
TS
104int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed);
105void amdtp_stream_update(struct amdtp_stream *s);
106void amdtp_stream_stop(struct amdtp_stream *s);
31ef9134 107
be4a2894
TS
108void amdtp_stream_set_pcm_format(struct amdtp_stream *s,
109 snd_pcm_format_t format);
110void amdtp_stream_pcm_prepare(struct amdtp_stream *s);
111unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s);
112void amdtp_stream_pcm_abort(struct amdtp_stream *s);
31ef9134 113
c5280e99 114extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
a7304e3b 115
be4a2894
TS
116/**
117 * amdtp_stream_running - check stream is running or not
118 * @s: the AMDTP stream
119 *
120 * If this function returns true, the stream is running.
121 */
122static inline bool amdtp_stream_running(struct amdtp_stream *s)
20b65dd0
CL
123{
124 return !IS_ERR(s->context);
125}
126
ec00f5e4 127/**
be4a2894
TS
128 * amdtp_streaming_error - check for streaming error
129 * @s: the AMDTP stream
ec00f5e4
CL
130 *
131 * If this function returns true, the stream's packet queue has stopped due to
132 * an asynchronous error.
133 */
be4a2894 134static inline bool amdtp_streaming_error(struct amdtp_stream *s)
ec00f5e4
CL
135{
136 return s->packet_index < 0;
137}
138
31ef9134 139/**
be4a2894
TS
140 * amdtp_stream_pcm_trigger - start/stop playback from a PCM device
141 * @s: the AMDTP stream
31ef9134
CL
142 * @pcm: the PCM device to be started, or %NULL to stop the current device
143 *
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.
147 */
be4a2894
TS
148static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
149 struct snd_pcm_substream *pcm)
31ef9134
CL
150{
151 ACCESS_ONCE(s->pcm) = pcm;
152}
153
31ef9134
CL
154static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
155{
156 return sfc & 1;
157}
158
159#endif
This page took 0.199793 seconds and 5 git commands to generate.