1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Line 6 Linux USB driver
5 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
9 PCM interface to POD series devices.
15 #include <sound/pcm.h>
20 number of USB frames per URB
21 The Line 6 Windows driver always transmits two frames per packet, but
22 the Linux driver performs significantly better (i.e., lower latency)
23 with only one frame per packet.
25 #define LINE6_ISO_PACKETS 1
27 /* in a "full speed" device (such as the PODxt Pro) this means 1ms,
28 * for "high speed" it's 1/8ms
30 #define LINE6_ISO_INTERVAL 1
32 #define LINE6_IMPULSE_DEFAULT_PERIOD 100
35 Get substream from Line 6 PCM data structure
37 #define get_substream(line6pcm, stream) \
38 (line6pcm->pcm->streams[stream].substream)
43 There are several features of the Line 6 USB driver which require PCM
44 data to be exchanged with the device:
45 *) PCM playback and capture via ALSA
46 *) software monitoring (for devices without hardware monitoring)
47 *) optional impulse response measurement
48 However, from the device's point of view, there is just a single
49 capture and playback stream, which must be shared between these
50 subsystems. It is therefore necessary to maintain the state of the
51 subsystems with respect to PCM usage.
53 We define two bit flags, "opened" and "running", for each playback
54 or capture stream. Both can contain the bit flag corresponding to
56 LINE6_STREAM_PCM = ALSA PCM playback or capture
57 LINE6_STREAM_MONITOR = software monitoring
58 IMPULSE = optional impulse response measurement
59 The opened flag indicates whether the buffer is allocated while
60 the running flag indicates whether the stream is running.
62 For monitor or impulse operations, the driver needs to call
63 line6_pcm_acquire() or line6_pcm_release() with the appropriate
72 LINE6_STREAM_CAPTURE_HELPER
,
75 /* misc bit flags for PCM operation */
77 LINE6_FLAG_PAUSE_PLAYBACK
,
81 struct line6_pcm_properties
{
82 struct snd_pcm_hardware playback_hw
, capture_hw
;
83 struct snd_pcm_hw_constraint_ratdens rates
;
84 int bytes_per_channel
;
87 struct line6_pcm_stream
{
92 * Since the packet size is not known in advance, this buffer is
93 * large enough to store maximum size packets.
95 unsigned char *buffer
;
97 /* Free frame position in the buffer. */
98 snd_pcm_uframes_t pos
;
100 /* Count processed bytes;
101 * This is modulo period size (to determine when a period is finished).
105 /* Counter to create desired sample rate */
108 /* period size in bytes */
111 /* Processed frame position in the buffer;
112 * The contents of the ring buffer have been consumed by the USB
113 * subsystem (i.e., sent to the USB device) up to this position.
115 snd_pcm_uframes_t pos_done
;
117 /* Bit mask of active URBs */
118 unsigned long active_urbs
;
120 /* Bit mask of URBs currently being unlinked */
121 unsigned long unlink_urbs
;
123 /* Spin lock to protect updates of the buffer positions (not contents)
127 /* Bit flags for operational stream types */
128 unsigned long opened
;
130 /* Bit flags for running stream types */
131 unsigned long running
;
136 struct snd_line6_pcm
{
137 /* Pointer back to the Line 6 driver data structure */
138 struct usb_line6
*line6
;
141 struct line6_pcm_properties
*properties
;
143 /* ALSA pcm stream */
146 /* protection to state changes of in/out streams */
147 struct mutex state_mutex
;
149 /* Capture and playback streams */
150 struct line6_pcm_stream in
;
151 struct line6_pcm_stream out
;
153 /* Previously captured frame (for software monitoring) */
154 unsigned char *prev_fbuf
;
156 /* Size of previously captured frame (for software monitoring/sync) */
159 /* Maximum size of USB packet */
160 int max_packet_size_in
;
161 int max_packet_size_out
;
163 /* PCM playback volume (left and right) */
164 int volume_playback
[2];
166 /* PCM monitor volume */
169 /* Volume of impulse response test signal (if zero, test is disabled) */
172 /* Period of impulse response test signal */
175 /* Counter for impulse response test signal */
178 /* Several status bits (see LINE6_FLAG_*) */
182 extern int line6_init_pcm(struct usb_line6
*line6
,
183 struct line6_pcm_properties
*properties
);
184 extern int snd_line6_trigger(struct snd_pcm_substream
*substream
, int cmd
);
185 extern int snd_line6_prepare(struct snd_pcm_substream
*substream
);
186 extern int snd_line6_hw_params(struct snd_pcm_substream
*substream
,
187 struct snd_pcm_hw_params
*hw_params
);
188 extern int snd_line6_hw_free(struct snd_pcm_substream
*substream
);
189 extern snd_pcm_uframes_t
snd_line6_pointer(struct snd_pcm_substream
*substream
);
190 extern void line6_pcm_disconnect(struct snd_line6_pcm
*line6pcm
);
191 extern int line6_pcm_acquire(struct snd_line6_pcm
*line6pcm
, int type
,
193 extern void line6_pcm_release(struct snd_line6_pcm
*line6pcm
, int type
);