]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - sound/usb/line6/pcm.h
ALSA: line6: Remove superfluous NULL checks
[mirror_ubuntu-zesty-kernel.git] / sound / usb / line6 / pcm.h
CommitLineData
705ececd 1/*
e1a164d7 2 * Line6 Linux USB driver - 0.9.1beta
705ececd 3 *
1027f476 4 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
705ececd
MG
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 */
11
12/*
13 PCM interface to POD series devices.
14*/
15
16#ifndef PCM_H
17#define PCM_H
18
705ececd
MG
19#include <sound/pcm.h>
20
21#include "driver.h"
22#include "usbdefs.h"
23
a49e4838 24/* number of URBs */
1027f476 25#define LINE6_ISO_BUFFERS 2
a49e4838 26
1027f476
MG
27/*
28 number of USB frames per URB
29 The Line6 Windows driver always transmits two frames per packet, but
30 the Linux driver performs significantly better (i.e., lower latency)
31 with only one frame per packet.
32*/
33#define LINE6_ISO_PACKETS 1
a49e4838
GKH
34
35/* in a "full speed" device (such as the PODxt Pro) this means 1ms */
36#define LINE6_ISO_INTERVAL 1
37
1027f476 38#define LINE6_IMPULSE_DEFAULT_PERIOD 100
1027f476 39
705ececd 40/*
1027f476 41 Get substream from Line6 PCM data structure
705ececd 42*/
027360c5
GKH
43#define get_substream(line6pcm, stream) \
44 (line6pcm->pcm->streams[stream].substream)
705ececd 45
1027f476 46/*
0ca54888
MG
47 PCM mode bits.
48
49 There are several features of the Line6 USB driver which require PCM
50 data to be exchanged with the device:
51 *) PCM playback and capture via ALSA
52 *) software monitoring (for devices without hardware monitoring)
53 *) optional impulse response measurement
54 However, from the device's point of view, there is just a single
55 capture and playback stream, which must be shared between these
56 subsystems. It is therefore necessary to maintain the state of the
57 subsystems with respect to PCM usage. We define several constants of
58 the form LINE6_BIT_PCM_<subsystem>_<direction>_<resource> with the
59 following meanings:
60 *) <subsystem> is one of
61 -) ALSA: PCM playback and capture via ALSA
62 -) MONITOR: software monitoring
63 -) IMPULSE: optional impulse response measurement
64 *) <direction> is one of
65 -) PLAYBACK: audio output (from host to device)
66 -) CAPTURE: audio input (from device to host)
67 *) <resource> is one of
68 -) BUFFER: buffer required by PCM data stream
69 -) STREAM: actual PCM data stream
70
71 The subsystems call line6_pcm_acquire() to acquire the (shared)
72 resources needed for a particular operation (e.g., allocate the buffer
73 for ALSA playback or start the capture stream for software monitoring).
74 When a resource is no longer needed, it is released by calling
75 line6_pcm_release(). Buffer allocation and stream startup are handled
76 separately to allow the ALSA kernel driver to perform them at
77 appropriate places (since the callback which starts a PCM stream is not
78 allowed to sleep).
1027f476 79*/
705ececd 80enum {
0ca54888
MG
81 /* individual bit indices: */
82 LINE6_INDEX_PCM_ALSA_PLAYBACK_BUFFER,
83 LINE6_INDEX_PCM_ALSA_PLAYBACK_STREAM,
84 LINE6_INDEX_PCM_ALSA_CAPTURE_BUFFER,
85 LINE6_INDEX_PCM_ALSA_CAPTURE_STREAM,
86 LINE6_INDEX_PCM_MONITOR_PLAYBACK_BUFFER,
87 LINE6_INDEX_PCM_MONITOR_PLAYBACK_STREAM,
88 LINE6_INDEX_PCM_MONITOR_CAPTURE_BUFFER,
89 LINE6_INDEX_PCM_MONITOR_CAPTURE_STREAM,
0ca54888
MG
90 LINE6_INDEX_PCM_IMPULSE_PLAYBACK_BUFFER,
91 LINE6_INDEX_PCM_IMPULSE_PLAYBACK_STREAM,
92 LINE6_INDEX_PCM_IMPULSE_CAPTURE_BUFFER,
93 LINE6_INDEX_PCM_IMPULSE_CAPTURE_STREAM,
0ca54888
MG
94 LINE6_INDEX_PAUSE_PLAYBACK,
95 LINE6_INDEX_PREPARED,
96
5c3396f9
CR
97#define LINE6_BIT(x) LINE6_BIT_ ## x = 1 << LINE6_INDEX_ ## x
98
0ca54888
MG
99 /* individual bit masks: */
100 LINE6_BIT(PCM_ALSA_PLAYBACK_BUFFER),
101 LINE6_BIT(PCM_ALSA_PLAYBACK_STREAM),
102 LINE6_BIT(PCM_ALSA_CAPTURE_BUFFER),
103 LINE6_BIT(PCM_ALSA_CAPTURE_STREAM),
104 LINE6_BIT(PCM_MONITOR_PLAYBACK_BUFFER),
105 LINE6_BIT(PCM_MONITOR_PLAYBACK_STREAM),
106 LINE6_BIT(PCM_MONITOR_CAPTURE_BUFFER),
107 LINE6_BIT(PCM_MONITOR_CAPTURE_STREAM),
0ca54888
MG
108 LINE6_BIT(PCM_IMPULSE_PLAYBACK_BUFFER),
109 LINE6_BIT(PCM_IMPULSE_PLAYBACK_STREAM),
110 LINE6_BIT(PCM_IMPULSE_CAPTURE_BUFFER),
111 LINE6_BIT(PCM_IMPULSE_CAPTURE_STREAM),
0ca54888
MG
112 LINE6_BIT(PAUSE_PLAYBACK),
113 LINE6_BIT(PREPARED),
1027f476 114
0ca54888
MG
115 /* combined bit masks (by operation): */
116 LINE6_BITS_PCM_ALSA_BUFFER =
117 LINE6_BIT_PCM_ALSA_PLAYBACK_BUFFER |
118 LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER,
119
120 LINE6_BITS_PCM_ALSA_STREAM =
121 LINE6_BIT_PCM_ALSA_PLAYBACK_STREAM |
122 LINE6_BIT_PCM_ALSA_CAPTURE_STREAM,
123
124 LINE6_BITS_PCM_MONITOR =
125 LINE6_BIT_PCM_MONITOR_PLAYBACK_BUFFER |
126 LINE6_BIT_PCM_MONITOR_PLAYBACK_STREAM |
127 LINE6_BIT_PCM_MONITOR_CAPTURE_BUFFER |
128 LINE6_BIT_PCM_MONITOR_CAPTURE_STREAM,
129
0ca54888
MG
130 LINE6_BITS_PCM_IMPULSE =
131 LINE6_BIT_PCM_IMPULSE_PLAYBACK_BUFFER |
132 LINE6_BIT_PCM_IMPULSE_PLAYBACK_STREAM |
133 LINE6_BIT_PCM_IMPULSE_CAPTURE_BUFFER |
134 LINE6_BIT_PCM_IMPULSE_CAPTURE_STREAM,
0ca54888
MG
135
136 /* combined bit masks (by direction): */
137 LINE6_BITS_PLAYBACK_BUFFER =
0ca54888 138 LINE6_BIT_PCM_IMPULSE_PLAYBACK_BUFFER |
0ca54888 139 LINE6_BIT_PCM_ALSA_PLAYBACK_BUFFER |
690ea44e 140 LINE6_BIT_PCM_MONITOR_PLAYBACK_BUFFER,
0ca54888
MG
141
142 LINE6_BITS_PLAYBACK_STREAM =
0ca54888 143 LINE6_BIT_PCM_IMPULSE_PLAYBACK_STREAM |
0ca54888 144 LINE6_BIT_PCM_ALSA_PLAYBACK_STREAM |
690ea44e 145 LINE6_BIT_PCM_MONITOR_PLAYBACK_STREAM,
0ca54888
MG
146
147 LINE6_BITS_CAPTURE_BUFFER =
0ca54888 148 LINE6_BIT_PCM_IMPULSE_CAPTURE_BUFFER |
0ca54888 149 LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER |
690ea44e 150 LINE6_BIT_PCM_MONITOR_CAPTURE_BUFFER,
1027f476 151
0ca54888 152 LINE6_BITS_CAPTURE_STREAM =
0ca54888 153 LINE6_BIT_PCM_IMPULSE_CAPTURE_STREAM |
0ca54888
MG
154 LINE6_BIT_PCM_ALSA_CAPTURE_STREAM |
155 LINE6_BIT_PCM_MONITOR_CAPTURE_STREAM,
b957e0ce 156
0ca54888
MG
157 LINE6_BITS_STREAM =
158 LINE6_BITS_PLAYBACK_STREAM |
159 LINE6_BITS_CAPTURE_STREAM
705ececd
MG
160};
161
162struct line6_pcm_properties {
163 struct snd_pcm_hardware snd_line6_playback_hw, snd_line6_capture_hw;
164 struct snd_pcm_hw_constraint_ratdens snd_line6_rates;
165 int bytes_per_frame;
166};
167
a49e4838 168struct snd_line6_pcm {
705ececd
MG
169 /**
170 Pointer back to the Line6 driver data structure.
171 */
172 struct usb_line6 *line6;
173
174 /**
175 Properties.
176 */
177 struct line6_pcm_properties *properties;
178
179 /**
180 ALSA pcm stream
181 */
182 struct snd_pcm *pcm;
183
184 /**
185 URBs for audio playback.
186 */
187 struct urb *urb_audio_out[LINE6_ISO_BUFFERS];
188
189 /**
190 URBs for audio capture.
191 */
192 struct urb *urb_audio_in[LINE6_ISO_BUFFERS];
193
194 /**
1027f476
MG
195 Temporary buffer for playback.
196 Since the packet size is not known in advance, this buffer is
197 large enough to store maximum size packets.
705ececd 198 */
1027f476 199 unsigned char *buffer_out;
705ececd
MG
200
201 /**
202 Temporary buffer for capture.
a49e4838
GKH
203 Since the packet size is not known in advance, this buffer is
204 large enough to store maximum size packets.
705ececd
MG
205 */
206 unsigned char *buffer_in;
207
1027f476
MG
208 /**
209 Previously captured frame (for software monitoring).
210 */
211 unsigned char *prev_fbuf;
212
213 /**
214 Size of previously captured frame (for software monitoring).
215 */
216 int prev_fsize;
217
705ececd
MG
218 /**
219 Free frame position in the playback buffer.
220 */
221 snd_pcm_uframes_t pos_out;
222
223 /**
224 Count processed bytes for playback.
a49e4838
GKH
225 This is modulo period size (to determine when a period is
226 finished).
705ececd
MG
227 */
228 unsigned bytes_out;
229
230 /**
231 Counter to create desired playback sample rate.
232 */
233 unsigned count_out;
234
235 /**
236 Playback period size in bytes
237 */
238 unsigned period_out;
239
240 /**
241 Processed frame position in the playback buffer.
a49e4838
GKH
242 The contents of the output ring buffer have been consumed by
243 the USB subsystem (i.e., sent to the USB device) up to this
244 position.
705ececd
MG
245 */
246 snd_pcm_uframes_t pos_out_done;
247
248 /**
249 Count processed bytes for capture.
a49e4838
GKH
250 This is modulo period size (to determine when a period is
251 finished).
705ececd
MG
252 */
253 unsigned bytes_in;
254
255 /**
256 Counter to create desired capture sample rate.
257 */
258 unsigned count_in;
259
260 /**
261 Capture period size in bytes
262 */
263 unsigned period_in;
264
265 /**
266 Processed frame position in the capture buffer.
a49e4838
GKH
267 The contents of the output ring buffer have been consumed by
268 the USB subsystem (i.e., sent to the USB device) up to this
269 position.
705ececd
MG
270 */
271 snd_pcm_uframes_t pos_in_done;
272
273 /**
274 Bit mask of active playback URBs.
275 */
276 unsigned long active_urb_out;
277
278 /**
279 Maximum size of USB packet.
280 */
281 int max_packet_size;
282
705ececd
MG
283 /**
284 Bit mask of active capture URBs.
285 */
286 unsigned long active_urb_in;
287
288 /**
289 Bit mask of playback URBs currently being unlinked.
290 */
291 unsigned long unlink_urb_out;
292
293 /**
294 Bit mask of capture URBs currently being unlinked.
295 */
296 unsigned long unlink_urb_in;
297
298 /**
299 Spin lock to protect updates of the playback buffer positions (not
300 contents!)
301 */
302 spinlock_t lock_audio_out;
303
304 /**
305 Spin lock to protect updates of the capture buffer positions (not
306 contents!)
307 */
308 spinlock_t lock_audio_in;
309
310 /**
311 Spin lock to protect trigger.
312 */
313 spinlock_t lock_trigger;
314
315 /**
316 PCM playback volume (left and right).
317 */
1027f476
MG
318 int volume_playback[2];
319
320 /**
321 PCM monitor volume.
322 */
323 int volume_monitor;
324
1027f476
MG
325 /**
326 Volume of impulse response test signal (if zero, test is disabled).
327 */
328 int impulse_volume;
329
330 /**
331 Period of impulse response test signal.
332 */
333 int impulse_period;
334
335 /**
336 Counter for impulse response test signal.
337 */
338 int impulse_count;
705ececd
MG
339
340 /**
0ca54888 341 Several status bits (see LINE6_BIT_*).
705ececd
MG
342 */
343 unsigned long flags;
1027f476
MG
344
345 int last_frame_in, last_frame_out;
705ececd
MG
346};
347
a49e4838
GKH
348extern int line6_init_pcm(struct usb_line6 *line6,
349 struct line6_pcm_properties *properties);
705ececd
MG
350extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd);
351extern int snd_line6_prepare(struct snd_pcm_substream *substream);
1027f476 352extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm);
0ca54888
MG
353extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels);
354extern int line6_pcm_release(struct snd_line6_pcm *line6pcm, int channels);
1027f476 355
705ececd 356#endif