]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - sound/firewire/amdtp.h
ALSA: dice: remove 10s period length limit
[karo-tx-linux.git] / sound / firewire / amdtp.h
1 #ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
2 #define SOUND_FIREWIRE_AMDTP_H_INCLUDED
3
4 #include <linux/err.h>
5 #include <linux/interrupt.h>
6 #include <linux/mutex.h>
7 #include "packets-buffer.h"
8
9 /**
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.
22  */
23 enum cip_out_flags {
24         CIP_NONBLOCKING = 0x00,
25         CIP_BLOCKING    = 0x01,
26         CIP_HI_DUALWIRE = 0x02,
27 };
28
29 /**
30  * enum cip_sfc - a stream's sample rate
31  */
32 enum cip_sfc {
33         CIP_SFC_32000  = 0,
34         CIP_SFC_44100  = 1,
35         CIP_SFC_48000  = 2,
36         CIP_SFC_88200  = 3,
37         CIP_SFC_96000  = 4,
38         CIP_SFC_176400 = 5,
39         CIP_SFC_192000 = 6,
40         CIP_SFC_COUNT
41 };
42
43 #define AMDTP_OUT_PCM_FORMAT_BITS       (SNDRV_PCM_FMTBIT_S16 | \
44                                          SNDRV_PCM_FMTBIT_S32)
45
46 struct fw_unit;
47 struct fw_iso_context;
48 struct snd_pcm_substream;
49
50 struct amdtp_out_stream {
51         struct fw_unit *unit;
52         enum cip_out_flags flags;
53         struct fw_iso_context *context;
54         struct mutex mutex;
55
56         enum cip_sfc sfc;
57         bool dual_wire;
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);
64
65         unsigned int syt_interval;
66         unsigned int transfer_delay;
67         unsigned int source_node_id_field;
68         struct iso_packets_buffer buffer;
69
70         struct snd_pcm_substream *pcm;
71         struct tasklet_struct period_tasklet;
72
73         int packet_index;
74         unsigned int data_block_counter;
75
76         unsigned int data_block_state;
77
78         unsigned int last_syt_offset;
79         unsigned int syt_offset_state;
80
81         unsigned int pcm_buffer_pointer;
82         unsigned int pcm_period_pointer;
83         bool pointer_flush;
84 };
85
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);
89
90 void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s,
91                                      unsigned int rate,
92                                      unsigned int pcm_channels,
93                                      unsigned int midi_ports);
94 unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s);
95
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);
99
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);
105
106 extern unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
107
108 static inline bool amdtp_out_stream_running(struct amdtp_out_stream *s)
109 {
110         return !IS_ERR(s->context);
111 }
112
113 /**
114  * amdtp_out_streaming_error - check for streaming error
115  * @s: the AMDTP output stream
116  *
117  * If this function returns true, the stream's packet queue has stopped due to
118  * an asynchronous error.
119  */
120 static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
121 {
122         return s->packet_index < 0;
123 }
124
125 /**
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
129  *
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.
133  */
134 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
135                                                 struct snd_pcm_substream *pcm)
136 {
137         ACCESS_ONCE(s->pcm) = pcm;
138 }
139
140 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
141 {
142         return sfc & 1;
143 }
144
145 #endif