ALSA: hda - Select FW_LOADER from CONFIG_SND_HDA_CODEC_CA0132_DSP
[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
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.
a7304e3b
CL
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.
31ef9134
CL
22 */
23enum cip_out_flags {
e84d15f6
CL
24 CIP_NONBLOCKING = 0x00,
25 CIP_BLOCKING = 0x01,
a7304e3b 26 CIP_HI_DUALWIRE = 0x02,
31ef9134
CL
27};
28
29/**
30 * enum cip_sfc - a stream's sample rate
31 */
32enum 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,
a7304e3b 40 CIP_SFC_COUNT
31ef9134
CL
41};
42
43#define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \
44 SNDRV_PCM_FMTBIT_S32)
45
46struct fw_unit;
47struct fw_iso_context;
48struct snd_pcm_substream;
49
50struct 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;
a7304e3b 57 bool dual_wire;
31ef9134
CL
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;
e84d15f6 66 unsigned int transfer_delay;
31ef9134
CL
67 unsigned int source_node_id_field;
68 struct iso_packets_buffer buffer;
69
70 struct snd_pcm_substream *pcm;
76fb8789 71 struct tasklet_struct period_tasklet;
31ef9134 72
ec00f5e4 73 int packet_index;
31ef9134
CL
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;
92b862c7 83 bool pointer_flush;
31ef9134
CL
84};
85
86int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
87 enum cip_out_flags flags);
88void amdtp_out_stream_destroy(struct amdtp_out_stream *s);
89
a7304e3b
CL
90void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s,
91 unsigned int rate,
92 unsigned int pcm_channels,
93 unsigned int midi_ports);
31ef9134
CL
94unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s);
95
96int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed);
97void amdtp_out_stream_update(struct amdtp_out_stream *s);
98void amdtp_out_stream_stop(struct amdtp_out_stream *s);
99
100void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,
101 snd_pcm_format_t format);
76fb8789 102void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);
e9148ddd 103unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);
31ef9134
CL
104void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);
105
c5280e99 106extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];
a7304e3b 107
20b65dd0
CL
108static inline bool amdtp_out_stream_running(struct amdtp_out_stream *s)
109{
110 return !IS_ERR(s->context);
111}
112
ec00f5e4
CL
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 */
120static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
121{
122 return s->packet_index < 0;
123}
124
31ef9134
CL
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 */
134static 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
31ef9134
CL
140static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
141{
142 return sfc & 1;
143}
144
145#endif
This page took 0.116421 seconds and 5 git commands to generate.