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" |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 22 | |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 23 | /* number of URBs */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 24 | #define LINE6_ISO_BUFFERS 2 |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 25 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 26 | /* |
| 27 | number of USB frames per URB |
Chris Rorvick | c6fffce | 2015-01-20 02:20:49 -0600 | [diff] [blame] | 28 | The Line 6 Windows driver always transmits two frames per packet, but |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 29 | the Linux driver performs significantly better (i.e., lower latency) |
| 30 | with only one frame per packet. |
| 31 | */ |
| 32 | #define LINE6_ISO_PACKETS 1 |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 33 | |
| 34 | /* in a "full speed" device (such as the PODxt Pro) this means 1ms */ |
| 35 | #define LINE6_ISO_INTERVAL 1 |
| 36 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 37 | #define LINE6_IMPULSE_DEFAULT_PERIOD 100 |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 38 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 39 | /* |
Chris Rorvick | c6fffce | 2015-01-20 02:20:49 -0600 | [diff] [blame] | 40 | Get substream from Line 6 PCM data structure |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 41 | */ |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 42 | #define get_substream(line6pcm, stream) \ |
| 43 | (line6pcm->pcm->streams[stream].substream) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 44 | |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 45 | /* |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 46 | PCM mode bits. |
| 47 | |
Chris Rorvick | c6fffce | 2015-01-20 02:20:49 -0600 | [diff] [blame] | 48 | 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] | 49 | data to be exchanged with the device: |
| 50 | *) PCM playback and capture via ALSA |
| 51 | *) software monitoring (for devices without hardware monitoring) |
| 52 | *) optional impulse response measurement |
| 53 | However, from the device's point of view, there is just a single |
| 54 | capture and playback stream, which must be shared between these |
| 55 | subsystems. It is therefore necessary to maintain the state of the |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 56 | subsystems with respect to PCM usage. |
Markus Grabner | 0ca5488 | 2012-01-20 00:09:09 +0100 | [diff] [blame] | 57 | |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 58 | We define two bit flags, "opened" and "running", for each playback |
| 59 | or capture stream. Both can contain the bit flag corresponding to |
| 60 | LINE6_STREAM_* type, |
| 61 | LINE6_STREAM_PCM = ALSA PCM playback or capture |
| 62 | LINE6_STREAM_MONITOR = software monitoring |
| 63 | IMPULSE = optional impulse response measurement |
| 64 | The opened flag indicates whether the buffer is allocated while |
| 65 | the running flag indicates whether the stream is running. |
| 66 | |
| 67 | For monitor or impulse operations, the driver needs to call |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 68 | line6_pcm_acquire() or line6_pcm_release() with the appropriate |
| 69 | LINE6_STREAM_* flag. |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 70 | */ |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 71 | |
| 72 | /* stream types */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 73 | enum { |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 74 | LINE6_STREAM_PCM, |
| 75 | LINE6_STREAM_MONITOR, |
| 76 | LINE6_STREAM_IMPULSE, |
| 77 | }; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 78 | |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 79 | /* misc bit flags for PCM operation */ |
| 80 | enum { |
| 81 | LINE6_FLAG_PAUSE_PLAYBACK, |
| 82 | LINE6_FLAG_PREPARED, |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | struct line6_pcm_properties { |
Takashi Iwai | 1263f61 | 2015-01-28 15:08:59 +0100 | [diff] [blame] | 86 | struct snd_pcm_hardware playback_hw, capture_hw; |
| 87 | struct snd_pcm_hw_constraint_ratdens rates; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 88 | int bytes_per_frame; |
| 89 | }; |
| 90 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 91 | struct line6_pcm_stream { |
| 92 | /* allocated URBs */ |
| 93 | struct urb *urbs[LINE6_ISO_BUFFERS]; |
| 94 | |
| 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 Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 131 | /* Bit flags for operational stream types */ |
| 132 | unsigned long opened; |
| 133 | |
| 134 | /* Bit flags for running stream types */ |
| 135 | unsigned long running; |
| 136 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 137 | int last_frame; |
| 138 | }; |
| 139 | |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 140 | struct snd_line6_pcm { |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 141 | /* Pointer back to the Line 6 driver data structure */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 142 | struct usb_line6 *line6; |
| 143 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 144 | /* Properties. */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 145 | struct line6_pcm_properties *properties; |
| 146 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 147 | /* ALSA pcm stream */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 148 | struct snd_pcm *pcm; |
| 149 | |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 150 | /* protection to state changes of in/out streams */ |
| 151 | struct mutex state_mutex; |
| 152 | |
Takashi Iwai | ad0119a | 2015-01-23 16:10:57 +0100 | [diff] [blame] | 153 | /* Capture and playback streams */ |
| 154 | struct line6_pcm_stream in; |
| 155 | struct line6_pcm_stream out; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 156 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 157 | /* Previously captured frame (for software monitoring) */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 158 | unsigned char *prev_fbuf; |
| 159 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 160 | /* Size of previously captured frame (for software monitoring) */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 161 | int prev_fsize; |
| 162 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 163 | /* Maximum size of USB packet */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 164 | int max_packet_size; |
| 165 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 166 | /* PCM playback volume (left and right) */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 167 | int volume_playback[2]; |
| 168 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 169 | /* PCM monitor volume */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 170 | int volume_monitor; |
| 171 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 172 | /* Volume of impulse response test signal (if zero, test is disabled) */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 173 | int impulse_volume; |
| 174 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 175 | /* Period of impulse response test signal */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 176 | int impulse_period; |
| 177 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 178 | /* Counter for impulse response test signal */ |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 179 | int impulse_count; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 180 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 181 | /* Several status bits (see LINE6_FLAG_*) */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 182 | unsigned long flags; |
| 183 | }; |
| 184 | |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 185 | extern int line6_init_pcm(struct usb_line6 *line6, |
| 186 | struct line6_pcm_properties *properties); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 187 | extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd); |
| 188 | extern int snd_line6_prepare(struct snd_pcm_substream *substream); |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 189 | extern int snd_line6_hw_params(struct snd_pcm_substream *substream, |
| 190 | struct snd_pcm_hw_params *hw_params); |
| 191 | extern int snd_line6_hw_free(struct snd_pcm_substream *substream); |
Takashi Iwai | 2954f91 | 2015-01-27 15:41:27 +0100 | [diff] [blame] | 192 | 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] | 193 | extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm); |
Takashi Iwai | 63e20df | 2015-01-27 15:24:09 +0100 | [diff] [blame] | 194 | extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type); |
| 195 | extern void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 196 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 197 | #endif |