1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 2 /* 3 * Line 6 Linux USB driver 3 * Line 6 Linux USB driver 4 * 4 * 5 * Copyright (C) 2004-2010 Markus Grabner (lin !! 5 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at) 6 */ 6 */ 7 7 8 /* 8 /* 9 PCM interface to POD series devices. 9 PCM interface to POD series devices. 10 */ 10 */ 11 11 12 #ifndef PCM_H 12 #ifndef PCM_H 13 #define PCM_H 13 #define PCM_H 14 14 15 #include <sound/pcm.h> 15 #include <sound/pcm.h> 16 16 17 #include "driver.h" 17 #include "driver.h" 18 18 19 /* 19 /* 20 number of USB frames per URB 20 number of USB frames per URB 21 The Line 6 Windows driver always trans 21 The Line 6 Windows driver always transmits two frames per packet, but 22 the Linux driver performs significantl 22 the Linux driver performs significantly better (i.e., lower latency) 23 with only one frame per packet. 23 with only one frame per packet. 24 */ 24 */ 25 #define LINE6_ISO_PACKETS 1 25 #define LINE6_ISO_PACKETS 1 26 26 27 /* in a "full speed" device (such as the PODxt 27 /* in a "full speed" device (such as the PODxt Pro) this means 1ms, 28 * for "high speed" it's 1/8ms 28 * for "high speed" it's 1/8ms 29 */ 29 */ 30 #define LINE6_ISO_INTERVAL 1 30 #define LINE6_ISO_INTERVAL 1 31 31 32 #define LINE6_IMPULSE_DEFAULT_PERIOD 100 32 #define LINE6_IMPULSE_DEFAULT_PERIOD 100 33 33 34 /* 34 /* 35 Get substream from Line 6 PCM data str 35 Get substream from Line 6 PCM data structure 36 */ 36 */ 37 #define get_substream(line6pcm, stream) \ 37 #define get_substream(line6pcm, stream) \ 38 (line6pcm->pcm->streams[stream 38 (line6pcm->pcm->streams[stream].substream) 39 39 40 /* 40 /* 41 PCM mode bits. 41 PCM mode bits. 42 42 43 There are several features of the Line 43 There are several features of the Line 6 USB driver which require PCM 44 data to be exchanged with the device: 44 data to be exchanged with the device: 45 *) PCM playback and capture via ALSA 45 *) PCM playback and capture via ALSA 46 *) software monitoring (for devices wi 46 *) software monitoring (for devices without hardware monitoring) 47 *) optional impulse response measureme 47 *) optional impulse response measurement 48 However, from the device's point of vi 48 However, from the device's point of view, there is just a single 49 capture and playback stream, which mus 49 capture and playback stream, which must be shared between these 50 subsystems. It is therefore necessary 50 subsystems. It is therefore necessary to maintain the state of the 51 subsystems with respect to PCM usage. 51 subsystems with respect to PCM usage. 52 52 53 We define two bit flags, "opened" and 53 We define two bit flags, "opened" and "running", for each playback 54 or capture stream. Both can contain t 54 or capture stream. Both can contain the bit flag corresponding to 55 LINE6_STREAM_* type, 55 LINE6_STREAM_* type, 56 LINE6_STREAM_PCM = ALSA PCM playback 56 LINE6_STREAM_PCM = ALSA PCM playback or capture 57 LINE6_STREAM_MONITOR = software moni 57 LINE6_STREAM_MONITOR = software monitoring 58 IMPULSE = optional impulse response 58 IMPULSE = optional impulse response measurement 59 The opened flag indicates whether the 59 The opened flag indicates whether the buffer is allocated while 60 the running flag indicates whether the 60 the running flag indicates whether the stream is running. 61 61 62 For monitor or impulse operations, the 62 For monitor or impulse operations, the driver needs to call 63 line6_pcm_acquire() or line6_pcm_relea 63 line6_pcm_acquire() or line6_pcm_release() with the appropriate 64 LINE6_STREAM_* flag. 64 LINE6_STREAM_* flag. 65 */ 65 */ 66 66 67 /* stream types */ 67 /* stream types */ 68 enum { 68 enum { 69 LINE6_STREAM_PCM, 69 LINE6_STREAM_PCM, 70 LINE6_STREAM_MONITOR, 70 LINE6_STREAM_MONITOR, 71 LINE6_STREAM_IMPULSE, 71 LINE6_STREAM_IMPULSE, 72 LINE6_STREAM_CAPTURE_HELPER, 72 LINE6_STREAM_CAPTURE_HELPER, 73 }; 73 }; 74 74 75 /* misc bit flags for PCM operation */ 75 /* misc bit flags for PCM operation */ 76 enum { 76 enum { 77 LINE6_FLAG_PAUSE_PLAYBACK, 77 LINE6_FLAG_PAUSE_PLAYBACK, 78 LINE6_FLAG_PREPARED, 78 LINE6_FLAG_PREPARED, 79 }; 79 }; 80 80 81 struct line6_pcm_properties { 81 struct line6_pcm_properties { 82 struct snd_pcm_hardware playback_hw, c 82 struct snd_pcm_hardware playback_hw, capture_hw; 83 struct snd_pcm_hw_constraint_ratdens r 83 struct snd_pcm_hw_constraint_ratdens rates; 84 int bytes_per_channel; 84 int bytes_per_channel; 85 }; 85 }; 86 86 87 struct line6_pcm_stream { 87 struct line6_pcm_stream { 88 /* allocated URBs */ 88 /* allocated URBs */ 89 struct urb **urbs; 89 struct urb **urbs; 90 90 91 /* Temporary buffer; 91 /* Temporary buffer; 92 * Since the packet size is not known 92 * Since the packet size is not known in advance, this buffer is 93 * large enough to store maximum size 93 * large enough to store maximum size packets. 94 */ 94 */ 95 unsigned char *buffer; 95 unsigned char *buffer; 96 96 97 /* Free frame position in the buffer. 97 /* Free frame position in the buffer. */ 98 snd_pcm_uframes_t pos; 98 snd_pcm_uframes_t pos; 99 99 100 /* Count processed bytes; 100 /* Count processed bytes; 101 * This is modulo period size (to dete 101 * This is modulo period size (to determine when a period is finished). 102 */ 102 */ 103 unsigned bytes; 103 unsigned bytes; 104 104 105 /* Counter to create desired sample ra 105 /* Counter to create desired sample rate */ 106 unsigned count; 106 unsigned count; 107 107 108 /* period size in bytes */ 108 /* period size in bytes */ 109 unsigned period; 109 unsigned period; 110 110 111 /* Processed frame position in the buf 111 /* Processed frame position in the buffer; 112 * The contents of the ring buffer hav 112 * The contents of the ring buffer have been consumed by the USB 113 * subsystem (i.e., sent to the USB de 113 * subsystem (i.e., sent to the USB device) up to this position. 114 */ 114 */ 115 snd_pcm_uframes_t pos_done; 115 snd_pcm_uframes_t pos_done; 116 116 117 /* Bit mask of active URBs */ 117 /* Bit mask of active URBs */ 118 unsigned long active_urbs; 118 unsigned long active_urbs; 119 119 120 /* Bit mask of URBs currently being un 120 /* Bit mask of URBs currently being unlinked */ 121 unsigned long unlink_urbs; 121 unsigned long unlink_urbs; 122 122 123 /* Spin lock to protect updates of the 123 /* Spin lock to protect updates of the buffer positions (not contents) 124 */ 124 */ 125 spinlock_t lock; 125 spinlock_t lock; 126 126 127 /* Bit flags for operational stream ty 127 /* Bit flags for operational stream types */ 128 unsigned long opened; 128 unsigned long opened; 129 129 130 /* Bit flags for running stream types 130 /* Bit flags for running stream types */ 131 unsigned long running; 131 unsigned long running; 132 132 133 int last_frame; 133 int last_frame; 134 }; 134 }; 135 135 136 struct snd_line6_pcm { 136 struct snd_line6_pcm { 137 /* Pointer back to the Line 6 driver d 137 /* Pointer back to the Line 6 driver data structure */ 138 struct usb_line6 *line6; 138 struct usb_line6 *line6; 139 139 140 /* Properties. */ 140 /* Properties. */ 141 struct line6_pcm_properties *propertie 141 struct line6_pcm_properties *properties; 142 142 143 /* ALSA pcm stream */ 143 /* ALSA pcm stream */ 144 struct snd_pcm *pcm; 144 struct snd_pcm *pcm; 145 145 146 /* protection to state changes of in/o 146 /* protection to state changes of in/out streams */ 147 struct mutex state_mutex; 147 struct mutex state_mutex; 148 148 149 /* Capture and playback streams */ 149 /* Capture and playback streams */ 150 struct line6_pcm_stream in; 150 struct line6_pcm_stream in; 151 struct line6_pcm_stream out; 151 struct line6_pcm_stream out; 152 152 153 /* Previously captured frame (for soft 153 /* Previously captured frame (for software monitoring) */ 154 unsigned char *prev_fbuf; 154 unsigned char *prev_fbuf; 155 155 156 /* Size of previously captured frame ( 156 /* Size of previously captured frame (for software monitoring/sync) */ 157 int prev_fsize; 157 int prev_fsize; 158 158 159 /* Maximum size of USB packet */ 159 /* Maximum size of USB packet */ 160 int max_packet_size_in; 160 int max_packet_size_in; 161 int max_packet_size_out; 161 int max_packet_size_out; 162 162 163 /* PCM playback volume (left and right 163 /* PCM playback volume (left and right) */ 164 int volume_playback[2]; 164 int volume_playback[2]; 165 165 166 /* PCM monitor volume */ 166 /* PCM monitor volume */ 167 int volume_monitor; 167 int volume_monitor; 168 168 169 /* Volume of impulse response test sig 169 /* Volume of impulse response test signal (if zero, test is disabled) */ 170 int impulse_volume; 170 int impulse_volume; 171 171 172 /* Period of impulse response test sig 172 /* Period of impulse response test signal */ 173 int impulse_period; 173 int impulse_period; 174 174 175 /* Counter for impulse response test s 175 /* Counter for impulse response test signal */ 176 int impulse_count; 176 int impulse_count; 177 177 178 /* Several status bits (see LINE6_FLAG 178 /* Several status bits (see LINE6_FLAG_*) */ 179 unsigned long flags; 179 unsigned long flags; 180 }; 180 }; 181 181 182 extern int line6_init_pcm(struct usb_line6 *li 182 extern int line6_init_pcm(struct usb_line6 *line6, 183 struct line6_pcm_pro 183 struct line6_pcm_properties *properties); 184 extern int snd_line6_trigger(struct snd_pcm_su 184 extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd); 185 extern int snd_line6_prepare(struct snd_pcm_su 185 extern int snd_line6_prepare(struct snd_pcm_substream *substream); 186 extern int snd_line6_hw_params(struct snd_pcm_ 186 extern int snd_line6_hw_params(struct snd_pcm_substream *substream, 187 struct snd_pcm_ 187 struct snd_pcm_hw_params *hw_params); 188 extern int snd_line6_hw_free(struct snd_pcm_su 188 extern int snd_line6_hw_free(struct snd_pcm_substream *substream); 189 extern snd_pcm_uframes_t snd_line6_pointer(str 189 extern snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream); 190 extern void line6_pcm_disconnect(struct snd_li 190 extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm); 191 extern int line6_pcm_acquire(struct snd_line6_ 191 extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type, 192 bool start); 192 bool start); 193 extern void line6_pcm_release(struct snd_line6 193 extern void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type); 194 194 195 #endif 195 #endif 196 196
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.