blob: fd4ce30302799458accc878e2752d94c2ac98725 [file] [log] [blame]
Clemens Ladisch31ef9132011-03-15 07:53:21 +01001#ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
2#define SOUND_FIREWIRE_AMDTP_H_INCLUDED
3
Clemens Ladisch76fb8782012-05-13 22:03:09 +02004#include <linux/interrupt.h>
Clemens Ladisch31ef9132011-03-15 07:53:21 +01005#include <linux/mutex.h>
Clemens Ladisch31ef9132011-03-15 07:53:21 +01006#include "packets-buffer.h"
7
8/**
9 * enum cip_out_flags - describes details of the streaming protocol
10 * @CIP_NONBLOCKING: In non-blocking mode, each packet contains
11 * sample_rate/8000 samples, with rounding up or down to adjust
12 * for clock skew and left-over fractional samples. This should
13 * be used if supported by the device.
Clemens Ladische84d15f2011-09-04 22:12:48 +020014 * @CIP_BLOCKING: In blocking mode, each packet contains either zero or
15 * SYT_INTERVAL samples, with these two types alternating so that
16 * the overall sample rate comes out right.
Clemens Ladisch31ef9132011-03-15 07:53:21 +010017 */
18enum cip_out_flags {
Clemens Ladische84d15f2011-09-04 22:12:48 +020019 CIP_NONBLOCKING = 0x00,
20 CIP_BLOCKING = 0x01,
Clemens Ladisch31ef9132011-03-15 07:53:21 +010021};
22
23/**
24 * enum cip_sfc - a stream's sample rate
25 */
26enum cip_sfc {
27 CIP_SFC_32000 = 0,
28 CIP_SFC_44100 = 1,
29 CIP_SFC_48000 = 2,
30 CIP_SFC_88200 = 3,
31 CIP_SFC_96000 = 4,
32 CIP_SFC_176400 = 5,
33 CIP_SFC_192000 = 6,
34};
35
36#define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \
37 SNDRV_PCM_FMTBIT_S32)
38
39struct fw_unit;
40struct fw_iso_context;
41struct snd_pcm_substream;
42
43struct amdtp_out_stream {
44 struct fw_unit *unit;
45 enum cip_out_flags flags;
46 struct fw_iso_context *context;
47 struct mutex mutex;
48
49 enum cip_sfc sfc;
50 unsigned int data_block_quadlets;
51 unsigned int pcm_channels;
52 unsigned int midi_ports;
53 void (*transfer_samples)(struct amdtp_out_stream *s,
54 struct snd_pcm_substream *pcm,
55 __be32 *buffer, unsigned int frames);
56
57 unsigned int syt_interval;
Clemens Ladische84d15f2011-09-04 22:12:48 +020058 unsigned int transfer_delay;
Clemens Ladisch31ef9132011-03-15 07:53:21 +010059 unsigned int source_node_id_field;
60 struct iso_packets_buffer buffer;
61
62 struct snd_pcm_substream *pcm;
Clemens Ladisch76fb8782012-05-13 22:03:09 +020063 struct tasklet_struct period_tasklet;
Clemens Ladisch31ef9132011-03-15 07:53:21 +010064
Clemens Ladischec00f5e2011-03-15 07:57:24 +010065 int packet_index;
Clemens Ladisch31ef9132011-03-15 07:53:21 +010066 unsigned int data_block_counter;
67
68 unsigned int data_block_state;
69
70 unsigned int last_syt_offset;
71 unsigned int syt_offset_state;
72
73 unsigned int pcm_buffer_pointer;
74 unsigned int pcm_period_pointer;
Clemens Ladisch92b862c2012-05-13 19:07:22 +020075 bool pointer_flush;
Clemens Ladisch31ef9132011-03-15 07:53:21 +010076};
77
78int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
79 enum cip_out_flags flags);
80void amdtp_out_stream_destroy(struct amdtp_out_stream *s);
81
82void amdtp_out_stream_set_rate(struct amdtp_out_stream *s, unsigned int rate);
83unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s);
84
85int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed);
86void amdtp_out_stream_update(struct amdtp_out_stream *s);
87void amdtp_out_stream_stop(struct amdtp_out_stream *s);
88
89void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
90 snd_pcm_format_t format);
Clemens Ladisch76fb8782012-05-13 22:03:09 +020091void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
Clemens Ladische9148dd2012-05-13 18:49:14 +020092unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
Clemens Ladisch31ef9132011-03-15 07:53:21 +010093void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
94
95/**
96 * amdtp_out_stream_set_pcm - configure format of PCM samples
97 * @s: the AMDTP output stream to be configured
98 * @pcm_channels: the number of PCM samples in each data block, to be encoded
99 * as AM824 multi-bit linear audio
100 *
101 * This function must not be called while the stream is running.
102 */
103static inline void amdtp_out_stream_set_pcm(struct amdtp_out_stream *s,
104 unsigned int pcm_channels)
105{
106 s->pcm_channels = pcm_channels;
107}
108
109/**
110 * amdtp_out_stream_set_midi - configure format of MIDI data
111 * @s: the AMDTP output stream to be configured
112 * @midi_ports: the number of MIDI ports (i.e., MPX-MIDI Data Channels)
113 *
114 * This function must not be called while the stream is running.
115 */
116static inline void amdtp_out_stream_set_midi(struct amdtp_out_stream *s,
117 unsigned int midi_ports)
118{
119 s->midi_ports = midi_ports;
120}
121
122/**
Clemens Ladischec00f5e2011-03-15 07:57:24 +0100123 * amdtp_out_streaming_error - check for streaming error
124 * @s: the AMDTP output stream
125 *
126 * If this function returns true, the stream's packet queue has stopped due to
127 * an asynchronous error.
128 */
129static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
130{
131 return s->packet_index < 0;
132}
133
134/**
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100135 * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device
136 * @s: the AMDTP output stream
137 * @pcm: the PCM device to be started, or %NULL to stop the current device
138 *
139 * Call this function on a running isochronous stream to enable the actual
140 * transmission of PCM data. This function should be called from the PCM
141 * device's .trigger callback.
142 */
143static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
144 struct snd_pcm_substream *pcm)
145{
146 ACCESS_ONCE(s->pcm) = pcm;
147}
148
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100149static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
150{
151 return sfc & 1;
152}
153
154#endif