blob: bb0c9cbf2a785c5ae7e937ed78f2475563918364 [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"
Markus Grabner705ecec2009-02-27 19:43:04 -080022
Markus Grabner1027f4762010-08-12 01:35:30 +020023/*
24 number of USB frames per URB
Chris Rorvickc6fffce2015-01-20 02:20:49 -060025 The Line 6 Windows driver always transmits two frames per packet, but
Markus Grabner1027f4762010-08-12 01:35:30 +020026 the Linux driver performs significantly better (i.e., lower latency)
27 with only one frame per packet.
28*/
29#define LINE6_ISO_PACKETS 1
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -080030
Andrej Krutak79faa2b2016-09-18 20:59:22 +020031/* in a "full speed" device (such as the PODxt Pro) this means 1ms,
32 * for "high speed" it's 1/8ms
33 */
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -080034#define LINE6_ISO_INTERVAL 1
35
Markus Grabner1027f4762010-08-12 01:35:30 +020036#define LINE6_IMPULSE_DEFAULT_PERIOD 100
Markus Grabner1027f4762010-08-12 01:35:30 +020037
Markus Grabner705ecec2009-02-27 19:43:04 -080038/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -060039 Get substream from Line 6 PCM data structure
Markus Grabner705ecec2009-02-27 19:43:04 -080040*/
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -070041#define get_substream(line6pcm, stream) \
42 (line6pcm->pcm->streams[stream].substream)
Markus Grabner705ecec2009-02-27 19:43:04 -080043
Markus Grabner1027f4762010-08-12 01:35:30 +020044/*
Markus Grabner0ca54882012-01-20 00:09:09 +010045 PCM mode bits.
46
Chris Rorvickc6fffce2015-01-20 02:20:49 -060047 There are several features of the Line 6 USB driver which require PCM
Markus Grabner0ca54882012-01-20 00:09:09 +010048 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
Takashi Iwai63e20df2015-01-27 15:24:09 +010055 subsystems with respect to PCM usage.
Markus Grabner0ca54882012-01-20 00:09:09 +010056
Takashi Iwai63e20df2015-01-27 15:24:09 +010057 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
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010067 line6_pcm_acquire() or line6_pcm_release() with the appropriate
68 LINE6_STREAM_* flag.
Markus Grabner1027f4762010-08-12 01:35:30 +020069*/
Takashi Iwai63e20df2015-01-27 15:24:09 +010070
71/* stream types */
Markus Grabner705ecec2009-02-27 19:43:04 -080072enum {
Takashi Iwai63e20df2015-01-27 15:24:09 +010073 LINE6_STREAM_PCM,
74 LINE6_STREAM_MONITOR,
75 LINE6_STREAM_IMPULSE,
Andrej Krutakf56742c2016-09-18 20:59:25 +020076 LINE6_STREAM_CAPTURE_HELPER,
Takashi Iwai63e20df2015-01-27 15:24:09 +010077};
Markus Grabner1027f4762010-08-12 01:35:30 +020078
Takashi Iwai63e20df2015-01-27 15:24:09 +010079/* misc bit flags for PCM operation */
80enum {
81 LINE6_FLAG_PAUSE_PLAYBACK,
82 LINE6_FLAG_PREPARED,
Markus Grabner705ecec2009-02-27 19:43:04 -080083};
84
85struct line6_pcm_properties {
Takashi Iwai1263f612015-01-28 15:08:59 +010086 struct snd_pcm_hardware playback_hw, capture_hw;
87 struct snd_pcm_hw_constraint_ratdens rates;
Andrej Krutak97d78ac2016-09-18 20:59:24 +020088 int bytes_per_channel;
Markus Grabner705ecec2009-02-27 19:43:04 -080089};
90
Takashi Iwaiad0119a2015-01-23 16:10:57 +010091struct line6_pcm_stream {
92 /* allocated URBs */
Andrej Krutakb2233d92016-09-18 20:59:21 +020093 struct urb **urbs;
Takashi Iwaiad0119a2015-01-23 16:10:57 +010094
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;
100
101 /* Free frame position in the buffer. */
102 snd_pcm_uframes_t pos;
103
104 /* Count processed bytes;
105 * This is modulo period size (to determine when a period is finished).
106 */
107 unsigned bytes;
108
109 /* Counter to create desired sample rate */
110 unsigned count;
111
112 /* period size in bytes */
113 unsigned period;
114
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;
120
121 /* Bit mask of active URBs */
122 unsigned long active_urbs;
123
124 /* Bit mask of URBs currently being unlinked */
125 unsigned long unlink_urbs;
126
127 /* Spin lock to protect updates of the buffer positions (not contents)
128 */
129 spinlock_t lock;
130
Takashi Iwai63e20df2015-01-27 15:24:09 +0100131 /* Bit flags for operational stream types */
132 unsigned long opened;
133
134 /* Bit flags for running stream types */
135 unsigned long running;
136
Takashi Iwaiad0119a2015-01-23 16:10:57 +0100137 int last_frame;
138};
139
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -0800140struct snd_line6_pcm {
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100141 /* Pointer back to the Line 6 driver data structure */
Markus Grabner705ecec2009-02-27 19:43:04 -0800142 struct usb_line6 *line6;
143
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100144 /* Properties. */
Markus Grabner705ecec2009-02-27 19:43:04 -0800145 struct line6_pcm_properties *properties;
146
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100147 /* ALSA pcm stream */
Markus Grabner705ecec2009-02-27 19:43:04 -0800148 struct snd_pcm *pcm;
149
Takashi Iwai63e20df2015-01-27 15:24:09 +0100150 /* protection to state changes of in/out streams */
151 struct mutex state_mutex;
152
Takashi Iwaiad0119a2015-01-23 16:10:57 +0100153 /* Capture and playback streams */
154 struct line6_pcm_stream in;
155 struct line6_pcm_stream out;
Markus Grabner705ecec2009-02-27 19:43:04 -0800156
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100157 /* Previously captured frame (for software monitoring) */
Markus Grabner1027f4762010-08-12 01:35:30 +0200158 unsigned char *prev_fbuf;
159
Andrej Krutak7a0f55a2016-09-18 20:59:23 +0200160 /* Size of previously captured frame (for software monitoring/sync) */
Markus Grabner1027f4762010-08-12 01:35:30 +0200161 int prev_fsize;
162
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100163 /* Maximum size of USB packet */
Andrej Krutak7a0f55a2016-09-18 20:59:23 +0200164 int max_packet_size_in;
165 int max_packet_size_out;
Markus Grabner705ecec2009-02-27 19:43:04 -0800166
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100167 /* PCM playback volume (left and right) */
Markus Grabner1027f4762010-08-12 01:35:30 +0200168 int volume_playback[2];
169
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100170 /* PCM monitor volume */
Markus Grabner1027f4762010-08-12 01:35:30 +0200171 int volume_monitor;
172
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100173 /* Volume of impulse response test signal (if zero, test is disabled) */
Markus Grabner1027f4762010-08-12 01:35:30 +0200174 int impulse_volume;
175
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100176 /* Period of impulse response test signal */
Markus Grabner1027f4762010-08-12 01:35:30 +0200177 int impulse_period;
178
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100179 /* Counter for impulse response test signal */
Markus Grabner1027f4762010-08-12 01:35:30 +0200180 int impulse_count;
Markus Grabner705ecec2009-02-27 19:43:04 -0800181
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100182 /* Several status bits (see LINE6_FLAG_*) */
Markus Grabner705ecec2009-02-27 19:43:04 -0800183 unsigned long flags;
184};
185
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -0800186extern int line6_init_pcm(struct usb_line6 *line6,
187 struct line6_pcm_properties *properties);
Markus Grabner705ecec2009-02-27 19:43:04 -0800188extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd);
189extern int snd_line6_prepare(struct snd_pcm_substream *substream);
Takashi Iwai63e20df2015-01-27 15:24:09 +0100190extern 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);
Takashi Iwai2954f912015-01-27 15:41:27 +0100193extern snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream);
Markus Grabner1027f4762010-08-12 01:35:30 +0200194extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm);
Andrej Krutakf56742c2016-09-18 20:59:25 +0200195extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type,
196 bool start);
Takashi Iwai63e20df2015-01-27 15:24:09 +0100197extern void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type);
Markus Grabner1027f4762010-08-12 01:35:30 +0200198
Markus Grabner705ecec2009-02-27 19:43:04 -0800199#endif