blob: 42d3e6fc2c61d7a05d79fc420761f87e407f4583 [file] [log] [blame]
Markus Grabner705ecec2009-02-27 19:43:04 -08001/*
Chris Rorvickc078a4a2015-01-20 02:20:50 -06002 * Line 6 Linux USB driver
Markus Grabner705ecec2009-02-27 19:43:04 -08003 *
Markus Grabner1027f4762010-08-12 01:35:30 +02004 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
Markus Grabner705ecec2009-02-27 19:43:04 -08005 *
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
Markus Grabner705ecec2009-02-27 19:43:04 -080019#include <sound/pcm.h>
20
21#include "driver.h"
22#include "usbdefs.h"
23
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -080024/* number of URBs */
Markus Grabner1027f4762010-08-12 01:35:30 +020025#define LINE6_ISO_BUFFERS 2
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -080026
Markus Grabner1027f4762010-08-12 01:35:30 +020027/*
28 number of USB frames per URB
Chris Rorvickc6fffce2015-01-20 02:20:49 -060029 The Line 6 Windows driver always transmits two frames per packet, but
Markus Grabner1027f4762010-08-12 01:35:30 +020030 the Linux driver performs significantly better (i.e., lower latency)
31 with only one frame per packet.
32*/
33#define LINE6_ISO_PACKETS 1
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -080034
35/* in a "full speed" device (such as the PODxt Pro) this means 1ms */
36#define LINE6_ISO_INTERVAL 1
37
Markus Grabner1027f4762010-08-12 01:35:30 +020038#define LINE6_IMPULSE_DEFAULT_PERIOD 100
Markus Grabner1027f4762010-08-12 01:35:30 +020039
Markus Grabner705ecec2009-02-27 19:43:04 -080040/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -060041 Get substream from Line 6 PCM data structure
Markus Grabner705ecec2009-02-27 19:43:04 -080042*/
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -070043#define get_substream(line6pcm, stream) \
44 (line6pcm->pcm->streams[stream].substream)
Markus Grabner705ecec2009-02-27 19:43:04 -080045
Markus Grabner1027f4762010-08-12 01:35:30 +020046/*
Markus Grabner0ca54882012-01-20 00:09:09 +010047 PCM mode bits.
48
Chris Rorvickc6fffce2015-01-20 02:20:49 -060049 There are several features of the Line 6 USB driver which require PCM
Markus Grabner0ca54882012-01-20 00:09:09 +010050 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
Takashi Iwai63e20df2015-01-27 15:24:09 +010057 subsystems with respect to PCM usage.
Markus Grabner0ca54882012-01-20 00:09:09 +010058
Takashi Iwai63e20df2015-01-27 15:24:09 +010059 We define two bit flags, "opened" and "running", for each playback
60 or capture stream. Both can contain the bit flag corresponding to
61 LINE6_STREAM_* type,
62 LINE6_STREAM_PCM = ALSA PCM playback or capture
63 LINE6_STREAM_MONITOR = software monitoring
64 IMPULSE = optional impulse response measurement
65 The opened flag indicates whether the buffer is allocated while
66 the running flag indicates whether the stream is running.
67
68 For monitor or impulse operations, the driver needs to call
69 snd_line6_duplex_acquire() or snd_line6_duplex_release() with the
70 appropriate LINE6_STREAM_* flag.
Markus Grabner1027f4762010-08-12 01:35:30 +020071*/
Takashi Iwai63e20df2015-01-27 15:24:09 +010072
73/* stream types */
Markus Grabner705ecec2009-02-27 19:43:04 -080074enum {
Takashi Iwai63e20df2015-01-27 15:24:09 +010075 LINE6_STREAM_PCM,
76 LINE6_STREAM_MONITOR,
77 LINE6_STREAM_IMPULSE,
78};
Markus Grabner1027f4762010-08-12 01:35:30 +020079
Takashi Iwai63e20df2015-01-27 15:24:09 +010080/* misc bit flags for PCM operation */
81enum {
82 LINE6_FLAG_PAUSE_PLAYBACK,
83 LINE6_FLAG_PREPARED,
Markus Grabner705ecec2009-02-27 19:43:04 -080084};
85
86struct line6_pcm_properties {
87 struct snd_pcm_hardware snd_line6_playback_hw, snd_line6_capture_hw;
88 struct snd_pcm_hw_constraint_ratdens snd_line6_rates;
89 int bytes_per_frame;
90};
91
Takashi Iwaiad0119a2015-01-23 16:10:57 +010092struct line6_pcm_stream {
93 /* allocated URBs */
94 struct urb *urbs[LINE6_ISO_BUFFERS];
95
96 /* Temporary buffer;
97 * Since the packet size is not known in advance, this buffer is
98 * large enough to store maximum size packets.
99 */
100 unsigned char *buffer;
101
102 /* Free frame position in the buffer. */
103 snd_pcm_uframes_t pos;
104
105 /* Count processed bytes;
106 * This is modulo period size (to determine when a period is finished).
107 */
108 unsigned bytes;
109
110 /* Counter to create desired sample rate */
111 unsigned count;
112
113 /* period size in bytes */
114 unsigned period;
115
116 /* Processed frame position in the buffer;
117 * The contents of the ring buffer have been consumed by the USB
118 * subsystem (i.e., sent to the USB device) up to this position.
119 */
120 snd_pcm_uframes_t pos_done;
121
122 /* Bit mask of active URBs */
123 unsigned long active_urbs;
124
125 /* Bit mask of URBs currently being unlinked */
126 unsigned long unlink_urbs;
127
128 /* Spin lock to protect updates of the buffer positions (not contents)
129 */
130 spinlock_t lock;
131
Takashi Iwai63e20df2015-01-27 15:24:09 +0100132 /* Bit flags for operational stream types */
133 unsigned long opened;
134
135 /* Bit flags for running stream types */
136 unsigned long running;
137
Takashi Iwaiad0119a2015-01-23 16:10:57 +0100138 int last_frame;
139};
140
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -0800141struct snd_line6_pcm {
Markus Grabner705ecec2009-02-27 19:43:04 -0800142 /**
Chris Rorvickc6fffce2015-01-20 02:20:49 -0600143 Pointer back to the Line 6 driver data structure.
Markus Grabner705ecec2009-02-27 19:43:04 -0800144 */
145 struct usb_line6 *line6;
146
147 /**
148 Properties.
149 */
150 struct line6_pcm_properties *properties;
151
152 /**
153 ALSA pcm stream
154 */
155 struct snd_pcm *pcm;
156
Takashi Iwai63e20df2015-01-27 15:24:09 +0100157 /* protection to state changes of in/out streams */
158 struct mutex state_mutex;
159
Takashi Iwaiad0119a2015-01-23 16:10:57 +0100160 /* Capture and playback streams */
161 struct line6_pcm_stream in;
162 struct line6_pcm_stream out;
Markus Grabner705ecec2009-02-27 19:43:04 -0800163
164 /**
Markus Grabner1027f4762010-08-12 01:35:30 +0200165 Previously captured frame (for software monitoring).
166 */
167 unsigned char *prev_fbuf;
168
169 /**
170 Size of previously captured frame (for software monitoring).
171 */
172 int prev_fsize;
173
174 /**
Markus Grabner705ecec2009-02-27 19:43:04 -0800175 Maximum size of USB packet.
176 */
177 int max_packet_size;
178
179 /**
Markus Grabner705ecec2009-02-27 19:43:04 -0800180 PCM playback volume (left and right).
181 */
Markus Grabner1027f4762010-08-12 01:35:30 +0200182 int volume_playback[2];
183
184 /**
185 PCM monitor volume.
186 */
187 int volume_monitor;
188
Markus Grabner1027f4762010-08-12 01:35:30 +0200189 /**
190 Volume of impulse response test signal (if zero, test is disabled).
191 */
192 int impulse_volume;
193
194 /**
195 Period of impulse response test signal.
196 */
197 int impulse_period;
198
199 /**
200 Counter for impulse response test signal.
201 */
202 int impulse_count;
Markus Grabner705ecec2009-02-27 19:43:04 -0800203
204 /**
Takashi Iwai63e20df2015-01-27 15:24:09 +0100205 Several status bits (see LINE6_FLAG_*).
Markus Grabner705ecec2009-02-27 19:43:04 -0800206 */
207 unsigned long flags;
208};
209
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -0800210extern int line6_init_pcm(struct usb_line6 *line6,
211 struct line6_pcm_properties *properties);
Markus Grabner705ecec2009-02-27 19:43:04 -0800212extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd);
213extern int snd_line6_prepare(struct snd_pcm_substream *substream);
Takashi Iwai63e20df2015-01-27 15:24:09 +0100214extern int snd_line6_hw_params(struct snd_pcm_substream *substream,
215 struct snd_pcm_hw_params *hw_params);
216extern int snd_line6_hw_free(struct snd_pcm_substream *substream);
Takashi Iwai2954f912015-01-27 15:41:27 +0100217extern snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream);
Markus Grabner1027f4762010-08-12 01:35:30 +0200218extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm);
Takashi Iwai63e20df2015-01-27 15:24:09 +0100219extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type);
220extern void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type);
Markus Grabner1027f4762010-08-12 01:35:30 +0200221
Markus Grabner705ecec2009-02-27 19:43:04 -0800222#endif