1#ifndef SOUND_FIREWIRE_AMDTP_H_INCLUDED
2#define SOUND_FIREWIRE_AMDTP_H_INCLUDED
3
4#include <linux/interrupt.h>
5#include <linux/mutex.h>
6#include "packets-buffer.h"
7
8
9
10
11
12
13
14
15enum cip_out_flags {
16 CIP_NONBLOCKING = 0,
17};
18
19
20
21
22enum cip_sfc {
23 CIP_SFC_32000 = 0,
24 CIP_SFC_44100 = 1,
25 CIP_SFC_48000 = 2,
26 CIP_SFC_88200 = 3,
27 CIP_SFC_96000 = 4,
28 CIP_SFC_176400 = 5,
29 CIP_SFC_192000 = 6,
30};
31
32#define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \
33 SNDRV_PCM_FMTBIT_S32)
34
35struct fw_unit;
36struct fw_iso_context;
37struct snd_pcm_substream;
38
39struct amdtp_out_stream {
40 struct fw_unit *unit;
41 enum cip_out_flags flags;
42 struct fw_iso_context *context;
43 struct mutex mutex;
44
45 enum cip_sfc sfc;
46 unsigned int data_block_quadlets;
47 unsigned int pcm_channels;
48 unsigned int midi_ports;
49 void (*transfer_samples)(struct amdtp_out_stream *s,
50 struct snd_pcm_substream *pcm,
51 __be32 *buffer, unsigned int frames);
52
53 unsigned int syt_interval;
54 unsigned int source_node_id_field;
55 struct iso_packets_buffer buffer;
56
57 struct snd_pcm_substream *pcm;
58 struct tasklet_struct period_tasklet;
59
60 int packet_index;
61 unsigned int data_block_counter;
62
63 unsigned int data_block_state;
64
65 unsigned int last_syt_offset;
66 unsigned int syt_offset_state;
67
68 unsigned int pcm_buffer_pointer;
69 unsigned int pcm_period_pointer;
70 bool pointer_flush;
71};
72
73int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
74 enum cip_out_flags flags);
75void amdtp_out_stream_destroy(struct amdtp_out_stream *s);
76
77void amdtp_out_stream_set_rate(struct amdtp_out_stream *s, unsigned int rate);
78unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s);
79
80int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed);
81void amdtp_out_stream_update(struct amdtp_out_stream *s);
82void amdtp_out_stream_stop(struct amdtp_out_stream *s);
83
84void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
85 snd_pcm_format_t format);
86void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
87unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
88void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
89
90
91
92
93
94
95
96
97
98static inline void amdtp_out_stream_set_pcm(struct amdtp_out_stream *s,
99 unsigned int pcm_channels)
100{
101 s->pcm_channels = pcm_channels;
102}
103
104
105
106
107
108
109
110
111static inline void amdtp_out_stream_set_midi(struct amdtp_out_stream *s,
112 unsigned int midi_ports)
113{
114 s->midi_ports = midi_ports;
115}
116
117
118
119
120
121
122
123
124static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
125{
126 return s->packet_index < 0;
127}
128
129
130
131
132
133
134
135
136
137
138static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
139 struct snd_pcm_substream *pcm)
140{
141 ACCESS_ONCE(s->pcm) = pcm;
142}
143
144static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
145{
146 return sfc & 1;
147}
148
149#endif
150