Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1 | /* |
Chris Rorvick | c078a4a | 2015-01-20 02:20:50 -0600 | [diff] [blame] | 2 | * Line 6 Linux USB driver |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 3 | * |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 4 | * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 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 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 19 | #include <sound/pcm.h> |
| 20 | |
| 21 | #include "driver.h" |
| 22 | #include "usbdefs.h" |
| 23 | |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 24 | /* number of URBs */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 25 | #define LINE6_ISO_BUFFERS 2 |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 26 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 27 | /* |
| 28 | number of USB frames per URB |
Chris Rorvick | c6fffce | 2015-01-20 02:20:49 -0600 | [diff] [blame] | 29 | The Line 6 Windows driver always transmits two frames per packet, but |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 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 |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 34 | |
| 35 | /* in a "full speed" device (such as the PODxt Pro) this means 1ms */ |
| 36 | #define LINE6_ISO_INTERVAL 1 |
| 37 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 38 | #define LINE6_IMPULSE_DEFAULT_PERIOD 100 |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 39 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 40 | /* |
Chris Rorvick | c6fffce | 2015-01-20 02:20:49 -0600 | [diff] [blame] | 41 | Get substream from Line 6 PCM data structure |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 42 | */ |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 43 | #define get_substream(line6pcm, stream) \ |
| 44 | (line6pcm->pcm->streams[stream].substream) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 45 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 46 | /* |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 47 | PCM mode bits. |
| 48 | |
Chris Rorvick | c6fffce | 2015-01-20 02:20:49 -0600 | [diff] [blame] | 49 | There are several features of the Line 6 USB driver which require PCM |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 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 |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 57 | subsystems with respect to PCM usage. |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 58 | |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 59 | 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 Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 71 | */ |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 72 | |
| 73 | /* stream types */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 74 | enum { |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 75 | LINE6_STREAM_PCM, |
| 76 | LINE6_STREAM_MONITOR, |
| 77 | LINE6_STREAM_IMPULSE, |
| 78 | }; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 79 | |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 80 | /* misc bit flags for PCM operation */ |
| 81 | enum { |
| 82 | LINE6_FLAG_PAUSE_PLAYBACK, |
| 83 | LINE6_FLAG_PREPARED, |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | struct 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 Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 92 | struct 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 Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 132 | /* Bit flags for operational stream types */ |
| 133 | unsigned long opened; |
| 134 | |
| 135 | /* Bit flags for running stream types */ |
| 136 | unsigned long running; |
| 137 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 138 | int last_frame; |
| 139 | }; |
| 140 | |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 141 | struct snd_line6_pcm { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 142 | /** |
Chris Rorvick | c6fffce | 2015-01-20 02:20:49 -0600 | [diff] [blame] | 143 | Pointer back to the Line 6 driver data structure. |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 144 | */ |
| 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 Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 157 | /* protection to state changes of in/out streams */ |
| 158 | struct mutex state_mutex; |
| 159 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 160 | /* Capture and playback streams */ |
| 161 | struct line6_pcm_stream in; |
| 162 | struct line6_pcm_stream out; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 163 | |
| 164 | /** |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 165 | 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 Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 175 | Maximum size of USB packet. |
| 176 | */ |
| 177 | int max_packet_size; |
| 178 | |
| 179 | /** |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 180 | PCM playback volume (left and right). |
| 181 | */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 182 | int volume_playback[2]; |
| 183 | |
| 184 | /** |
| 185 | PCM monitor volume. |
| 186 | */ |
| 187 | int volume_monitor; |
| 188 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 189 | /** |
| 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 Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 203 | |
| 204 | /** |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 205 | Several status bits (see LINE6_FLAG_*). |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 206 | */ |
| 207 | unsigned long flags; |
| 208 | }; |
| 209 | |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 210 | extern int line6_init_pcm(struct usb_line6 *line6, |
| 211 | struct line6_pcm_properties *properties); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 212 | extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd); |
| 213 | extern int snd_line6_prepare(struct snd_pcm_substream *substream); |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 214 | extern int snd_line6_hw_params(struct snd_pcm_substream *substream, |
| 215 | struct snd_pcm_hw_params *hw_params); |
| 216 | extern int snd_line6_hw_free(struct snd_pcm_substream *substream); |
Takashi Iwai | 2954f91 | 2015-01-27 15:41:27 +0100 | [diff] [blame] | 217 | extern snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 218 | extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm); |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 219 | extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type); |
| 220 | extern void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 221 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 222 | #endif |