ALSA: dice: clear device lock when closing hwdep device
[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
76fb8789 4#include <linux/interrupt.h>
31ef9134 5#include <linux/mutex.h>
31ef9134
CL
6#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.
e84d15f6
CL
14 * @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.
31ef9134
CL
17 */
18enum cip_out_flags {
e84d15f6
CL
19 CIP_NONBLOCKING = 0x00,
20 CIP_BLOCKING = 0x01,
31ef9134
CL
21};
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;
e84d15f6 58 unsigned int transfer_delay;
31ef9134
CL
59 unsigned int source_node_id_field;
60 struct iso_packets_buffer buffer;
61
62 struct snd_pcm_substream *pcm;
76fb8789 63 struct tasklet_struct period_tasklet;
31ef9134 64
ec00f5e4 65 int packet_index;
31ef9134
CL
66 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;
92b862c7 75 bool pointer_flush;
31ef9134
CL
76};
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);
76fb8789 91void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
e9148ddd 92unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
31ef9134
CL
93void 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
ec00f5e4
CL
122/**
123 * 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
31ef9134
CL
134/**
135 * 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
31ef9134
CL
149static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
150{
151 return sfc & 1;
152}
153
154#endif
This page took 0.11492 seconds and 5 git commands to generate.