]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - sound/usb/line6/pcm.h
Merge branch 'fixes-for-v4.9-rc2' of http://git.agner.ch/git/linux-drm-fsl-dcu into...
[mirror_ubuntu-zesty-kernel.git] / sound / usb / line6 / pcm.h
CommitLineData
705ececd 1/*
c078a4aa 2 * Line 6 Linux USB driver
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"
705ececd 22
1027f476
MG
23/*
24 number of USB frames per URB
c6fffce9 25 The Line 6 Windows driver always transmits two frames per packet, but
1027f476
MG
26 the Linux driver performs significantly better (i.e., lower latency)
27 with only one frame per packet.
28*/
29#define LINE6_ISO_PACKETS 1
a49e4838 30
79faa2b0
AK
31/* in a "full speed" device (such as the PODxt Pro) this means 1ms,
32 * for "high speed" it's 1/8ms
33 */
a49e4838
GKH
34#define LINE6_ISO_INTERVAL 1
35
1027f476 36#define LINE6_IMPULSE_DEFAULT_PERIOD 100
1027f476 37
705ececd 38/*
c6fffce9 39 Get substream from Line 6 PCM data structure
705ececd 40*/
027360c5
GKH
41#define get_substream(line6pcm, stream) \
42 (line6pcm->pcm->streams[stream].substream)
705ececd 43
1027f476 44/*
0ca54888
MG
45 PCM mode bits.
46
c6fffce9 47 There are several features of the Line 6 USB driver which require PCM
0ca54888
MG
48 data to be exchanged with the device:
49 *) PCM playback and capture via ALSA
50 *) software monitoring (for devices without hardware monitoring)
51 *) optional impulse response measurement
52 However, from the device's point of view, there is just a single
53 capture and playback stream, which must be shared between these
54 subsystems. It is therefore necessary to maintain the state of the
63e20df1
TI
55 subsystems with respect to PCM usage.
56
57 We define two bit flags, "opened" and "running", for each playback
58 or capture stream. Both can contain the bit flag corresponding to
59 LINE6_STREAM_* type,
60 LINE6_STREAM_PCM = ALSA PCM playback or capture
61 LINE6_STREAM_MONITOR = software monitoring
62 IMPULSE = optional impulse response measurement
63 The opened flag indicates whether the buffer is allocated while
64 the running flag indicates whether the stream is running.
65
66 For monitor or impulse operations, the driver needs to call
cddbd4f1
TI
67 line6_pcm_acquire() or line6_pcm_release() with the appropriate
68 LINE6_STREAM_* flag.
1027f476 69*/
63e20df1
TI
70
71/* stream types */
72enum {
73 LINE6_STREAM_PCM,
74 LINE6_STREAM_MONITOR,
75 LINE6_STREAM_IMPULSE,
f56742cc 76 LINE6_STREAM_CAPTURE_HELPER,
63e20df1
TI
77};
78
79/* misc bit flags for PCM operation */
705ececd 80enum {
63e20df1
TI
81 LINE6_FLAG_PAUSE_PLAYBACK,
82 LINE6_FLAG_PREPARED,
705ececd
MG
83};
84
85struct line6_pcm_properties {
1263f611
TI
86 struct snd_pcm_hardware playback_hw, capture_hw;
87 struct snd_pcm_hw_constraint_ratdens rates;
97d78acf 88 int bytes_per_channel;
705ececd
MG
89};
90
ad0119ab
TI
91struct line6_pcm_stream {
92 /* allocated URBs */
b2233d97 93 struct urb **urbs;
705ececd 94
ad0119ab
TI
95 /* Temporary buffer;
96 * Since the packet size is not known in advance, this buffer is
97 * large enough to store maximum size packets.
98 */
99 unsigned char *buffer;
705ececd 100
ad0119ab
TI
101 /* Free frame position in the buffer. */
102 snd_pcm_uframes_t pos;
705ececd 103
ad0119ab
TI
104 /* Count processed bytes;
105 * This is modulo period size (to determine when a period is finished).
106 */
107 unsigned bytes;
705ececd 108
ad0119ab
TI
109 /* Counter to create desired sample rate */
110 unsigned count;
705ececd 111
ad0119ab
TI
112 /* period size in bytes */
113 unsigned period;
705ececd 114
ad0119ab
TI
115 /* Processed frame position in the buffer;
116 * The contents of the ring buffer have been consumed by the USB
117 * subsystem (i.e., sent to the USB device) up to this position.
118 */
119 snd_pcm_uframes_t pos_done;
705ececd 120
ad0119ab
TI
121 /* Bit mask of active URBs */
122 unsigned long active_urbs;
1027f476 123
ad0119ab
TI
124 /* Bit mask of URBs currently being unlinked */
125 unsigned long unlink_urbs;
705ececd 126
ad0119ab
TI
127 /* Spin lock to protect updates of the buffer positions (not contents)
128 */
129 spinlock_t lock;
705ececd 130
63e20df1
TI
131 /* Bit flags for operational stream types */
132 unsigned long opened;
133
134 /* Bit flags for running stream types */
135 unsigned long running;
136
ad0119ab
TI
137 int last_frame;
138};
705ececd 139
ad0119ab 140struct snd_line6_pcm {
cddbd4f1 141 /* Pointer back to the Line 6 driver data structure */
ad0119ab 142 struct usb_line6 *line6;
705ececd 143
cddbd4f1 144 /* Properties. */
ad0119ab 145 struct line6_pcm_properties *properties;
705ececd 146
cddbd4f1 147 /* ALSA pcm stream */
ad0119ab 148 struct snd_pcm *pcm;
705ececd 149
63e20df1
TI
150 /* protection to state changes of in/out streams */
151 struct mutex state_mutex;
152
ad0119ab
TI
153 /* Capture and playback streams */
154 struct line6_pcm_stream in;
155 struct line6_pcm_stream out;
705ececd 156
cddbd4f1 157 /* Previously captured frame (for software monitoring) */
ad0119ab 158 unsigned char *prev_fbuf;
705ececd 159
7a0f55ae 160 /* Size of previously captured frame (for software monitoring/sync) */
ad0119ab 161 int prev_fsize;
705ececd 162
cddbd4f1 163 /* Maximum size of USB packet */
7a0f55ae
AK
164 int max_packet_size_in;
165 int max_packet_size_out;
705ececd 166
cddbd4f1 167 /* PCM playback volume (left and right) */
1027f476
MG
168 int volume_playback[2];
169
cddbd4f1 170 /* PCM monitor volume */
1027f476
MG
171 int volume_monitor;
172
cddbd4f1 173 /* Volume of impulse response test signal (if zero, test is disabled) */
1027f476
MG
174 int impulse_volume;
175
cddbd4f1 176 /* Period of impulse response test signal */
1027f476
MG
177 int impulse_period;
178
cddbd4f1 179 /* Counter for impulse response test signal */
1027f476 180 int impulse_count;
705ececd 181
cddbd4f1 182 /* Several status bits (see LINE6_FLAG_*) */
705ececd
MG
183 unsigned long flags;
184};
185
a49e4838
GKH
186extern int line6_init_pcm(struct usb_line6 *line6,
187 struct line6_pcm_properties *properties);
705ececd
MG
188extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd);
189extern int snd_line6_prepare(struct snd_pcm_substream *substream);
63e20df1
TI
190extern int snd_line6_hw_params(struct snd_pcm_substream *substream,
191 struct snd_pcm_hw_params *hw_params);
192extern int snd_line6_hw_free(struct snd_pcm_substream *substream);
2954f914 193extern snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream);
1027f476 194extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm);
f56742cc
AK
195extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type,
196 bool start);
63e20df1 197extern void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type);
1027f476 198
705ececd 199#endif