ALSA: dice: fix device detection for other vendors
[linux-2.6-block.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>
31ef9134
CL
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.
e84d15f6
CL
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.
31ef9134
CL
18 */
19enum cip_out_flags {
e84d15f6
CL
20 CIP_NONBLOCKING = 0x00,
21 CIP_BLOCKING = 0x01,
31ef9134
CL
22};
23
24/**
25 * enum cip_sfc - a stream's sample rate
26 */
27enum cip_sfc {
28 CIP_SFC_32000 = 0,
29 CIP_SFC_44100 = 1,
30 CIP_SFC_48000 = 2,
31 CIP_SFC_88200 = 3,
32 CIP_SFC_96000 = 4,
33 CIP_SFC_176400 = 5,
34 CIP_SFC_192000 = 6,
35};
36
37#define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \
38 SNDRV_PCM_FMTBIT_S32)
39
40struct fw_unit;
41struct fw_iso_context;
42struct snd_pcm_substream;
43
44struct amdtp_out_stream {
45 struct fw_unit *unit;
46 enum cip_out_flags flags;
47 struct fw_iso_context *context;
48 struct mutex mutex;
49
50 enum cip_sfc sfc;
51 unsigned int data_block_quadlets;
52 unsigned int pcm_channels;
53 unsigned int midi_ports;
54 void (*transfer_samples)(struct amdtp_out_stream *s,
55 struct snd_pcm_substream *pcm,
56 __be32 *buffer, unsigned int frames);
57
58 unsigned int syt_interval;
e84d15f6 59 unsigned int transfer_delay;
31ef9134
CL
60 unsigned int source_node_id_field;
61 struct iso_packets_buffer buffer;
62
63 struct snd_pcm_substream *pcm;
76fb8789 64 struct tasklet_struct period_tasklet;
31ef9134 65
ec00f5e4 66 int packet_index;
31ef9134
CL
67 unsigned int data_block_counter;
68
69 unsigned int data_block_state;
70
71 unsigned int last_syt_offset;
72 unsigned int syt_offset_state;
73
74 unsigned int pcm_buffer_pointer;
75 unsigned int pcm_period_pointer;
92b862c7 76 bool pointer_flush;
31ef9134
CL
77};
78
79int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
80 enum cip_out_flags flags);
81void amdtp_out_stream_destroy(struct amdtp_out_stream *s);
82
83void amdtp_out_stream_set_rate(struct amdtp_out_stream *s, unsigned int rate);
84unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s);
85
86int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed);
87void amdtp_out_stream_update(struct amdtp_out_stream *s);
88void amdtp_out_stream_stop(struct amdtp_out_stream *s);
89
90void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
91 snd_pcm_format_t format);
76fb8789 92void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
e9148ddd 93unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
31ef9134
CL
94void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
95
20b65dd0
CL
96static inline bool amdtp_out_stream_running(struct amdtp_out_stream *s)
97{
98 return !IS_ERR(s->context);
99}
100
31ef9134
CL
101/**
102 * amdtp_out_stream_set_pcm - configure format of PCM samples
103 * @s: the AMDTP output stream to be configured
104 * @pcm_channels: the number of PCM samples in each data block, to be encoded
105 * as AM824 multi-bit linear audio
106 *
107 * This function must not be called while the stream is running.
108 */
109static inline void amdtp_out_stream_set_pcm(struct amdtp_out_stream *s,
110 unsigned int pcm_channels)
111{
112 s->pcm_channels = pcm_channels;
113}
114
115/**
116 * amdtp_out_stream_set_midi - configure format of MIDI data
117 * @s: the AMDTP output stream to be configured
118 * @midi_ports: the number of MIDI ports (i.e., MPX-MIDI Data Channels)
119 *
120 * This function must not be called while the stream is running.
121 */
122static inline void amdtp_out_stream_set_midi(struct amdtp_out_stream *s,
123 unsigned int midi_ports)
124{
125 s->midi_ports = midi_ports;
126}
127
ec00f5e4
CL
128/**
129 * amdtp_out_streaming_error - check for streaming error
130 * @s: the AMDTP output stream
131 *
132 * If this function returns true, the stream's packet queue has stopped due to
133 * an asynchronous error.
134 */
135static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
136{
137 return s->packet_index < 0;
138}
139
31ef9134
CL
140/**
141 * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device
142 * @s: the AMDTP output stream
143 * @pcm: the PCM device to be started, or %NULL to stop the current device
144 *
145 * Call this function on a running isochronous stream to enable the actual
146 * transmission of PCM data. This function should be called from the PCM
147 * device's .trigger callback.
148 */
149static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
150 struct snd_pcm_substream *pcm)
151{
152 ACCESS_ONCE(s->pcm) = pcm;
153}
154
31ef9134
CL
155static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
156{
157 return sfc & 1;
158}
159
160#endif