Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 1 | /* |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 2 | * Copyright (c) 2006-2008 Daniel Mack, Karsten Wiese |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | */ |
| 18 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 19 | #include <linux/spinlock.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame^] | 20 | #include <linux/slab.h> |
Daniel Mack | e431cf4 | 2009-03-28 21:19:49 +0100 | [diff] [blame] | 21 | #include <linux/init.h> |
| 22 | #include <linux/usb.h> |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 23 | #include <sound/core.h> |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 24 | #include <sound/pcm.h> |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 25 | |
Daniel Mack | 936e7d0 | 2009-04-01 19:05:39 +0200 | [diff] [blame] | 26 | #include "device.h" |
| 27 | #include "audio.h" |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 28 | |
| 29 | #define N_URBS 32 |
| 30 | #define CLOCK_DRIFT_TOLERANCE 5 |
| 31 | #define FRAMES_PER_URB 8 |
| 32 | #define BYTES_PER_FRAME 512 |
| 33 | #define CHANNELS_PER_STREAM 2 |
| 34 | #define BYTES_PER_SAMPLE 3 |
| 35 | #define BYTES_PER_SAMPLE_USB 4 |
| 36 | #define MAX_BUFFER_SIZE (128*1024) |
Daniel Mack | 6e9fc6b | 2008-04-14 15:40:31 +0200 | [diff] [blame] | 37 | #define MAX_ENDPOINT_SIZE 512 |
| 38 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 39 | #define ENDPOINT_CAPTURE 2 |
| 40 | #define ENDPOINT_PLAYBACK 6 |
| 41 | |
| 42 | #define MAKE_CHECKBYTE(dev,stream,i) \ |
| 43 | (stream << 1) | (~(i / (dev->n_streams * BYTES_PER_SAMPLE_USB)) & 1) |
| 44 | |
| 45 | static struct snd_pcm_hardware snd_usb_caiaq_pcm_hardware = { |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 46 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 47 | SNDRV_PCM_INFO_BLOCK_TRANSFER), |
| 48 | .formats = SNDRV_PCM_FMTBIT_S24_3BE, |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 49 | .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 50 | SNDRV_PCM_RATE_96000), |
| 51 | .rate_min = 44100, |
| 52 | .rate_max = 0, /* will overwrite later */ |
| 53 | .channels_min = CHANNELS_PER_STREAM, |
| 54 | .channels_max = CHANNELS_PER_STREAM, |
| 55 | .buffer_bytes_max = MAX_BUFFER_SIZE, |
Daniel Mack | 09189ac | 2008-01-24 18:46:42 +0100 | [diff] [blame] | 56 | .period_bytes_min = 128, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 57 | .period_bytes_max = MAX_BUFFER_SIZE, |
| 58 | .periods_min = 1, |
| 59 | .periods_max = 1024, |
| 60 | }; |
| 61 | |
| 62 | static void |
| 63 | activate_substream(struct snd_usb_caiaqdev *dev, |
| 64 | struct snd_pcm_substream *sub) |
| 65 | { |
Mark Hills | ac9dd9d | 2009-10-24 12:59:36 +0100 | [diff] [blame] | 66 | spin_lock(&dev->spinlock); |
| 67 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 68 | if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 69 | dev->sub_playback[sub->number] = sub; |
| 70 | else |
| 71 | dev->sub_capture[sub->number] = sub; |
Mark Hills | ac9dd9d | 2009-10-24 12:59:36 +0100 | [diff] [blame] | 72 | |
| 73 | spin_unlock(&dev->spinlock); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 74 | } |
| 75 | |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 76 | static void |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 77 | deactivate_substream(struct snd_usb_caiaqdev *dev, |
| 78 | struct snd_pcm_substream *sub) |
| 79 | { |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 80 | unsigned long flags; |
| 81 | spin_lock_irqsave(&dev->spinlock, flags); |
| 82 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 83 | if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 84 | dev->sub_playback[sub->number] = NULL; |
| 85 | else |
| 86 | dev->sub_capture[sub->number] = NULL; |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 87 | |
| 88 | spin_unlock_irqrestore(&dev->spinlock, flags); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static int |
| 92 | all_substreams_zero(struct snd_pcm_substream **subs) |
| 93 | { |
| 94 | int i; |
| 95 | for (i = 0; i < MAX_STREAMS; i++) |
| 96 | if (subs[i] != NULL) |
| 97 | return 0; |
| 98 | return 1; |
| 99 | } |
| 100 | |
| 101 | static int stream_start(struct snd_usb_caiaqdev *dev) |
| 102 | { |
| 103 | int i, ret; |
| 104 | |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 105 | debug("%s(%p)\n", __func__, dev); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 106 | |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 107 | if (dev->streaming) |
| 108 | return -EINVAL; |
| 109 | |
| 110 | memset(dev->sub_playback, 0, sizeof(dev->sub_playback)); |
| 111 | memset(dev->sub_capture, 0, sizeof(dev->sub_capture)); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 112 | dev->input_panic = 0; |
| 113 | dev->output_panic = 0; |
| 114 | dev->first_packet = 1; |
| 115 | dev->streaming = 1; |
Daniel Mack | 1313e70 | 2009-03-18 11:03:53 +0100 | [diff] [blame] | 116 | dev->warned = 0; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 117 | |
| 118 | for (i = 0; i < N_URBS; i++) { |
| 119 | ret = usb_submit_urb(dev->data_urbs_in[i], GFP_ATOMIC); |
| 120 | if (ret) { |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 121 | log("unable to trigger read #%d! (ret %d)\n", i, ret); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 122 | dev->streaming = 0; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 123 | return -EPIPE; |
| 124 | } |
| 125 | } |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 126 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static void stream_stop(struct snd_usb_caiaqdev *dev) |
| 131 | { |
| 132 | int i; |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 133 | |
| 134 | debug("%s(%p)\n", __func__, dev); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 135 | if (!dev->streaming) |
| 136 | return; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 137 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 138 | dev->streaming = 0; |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 139 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 140 | for (i = 0; i < N_URBS; i++) { |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 141 | usb_kill_urb(dev->data_urbs_in[i]); |
| 142 | usb_kill_urb(dev->data_urbs_out[i]); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
| 146 | static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream) |
| 147 | { |
| 148 | struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 149 | debug("%s(%p)\n", __func__, substream); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 150 | substream->runtime->hw = dev->pcm_info; |
| 151 | snd_pcm_limit_hw_rates(substream->runtime); |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream) |
| 156 | { |
| 157 | struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); |
| 158 | |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 159 | debug("%s(%p)\n", __func__, substream); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 160 | if (all_substreams_zero(dev->sub_playback) && |
| 161 | all_substreams_zero(dev->sub_capture)) { |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 162 | /* when the last client has stopped streaming, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 163 | * all sample rates are allowed again */ |
| 164 | stream_stop(dev); |
| 165 | dev->pcm_info.rates = dev->samplerates; |
| 166 | } |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 167 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub, |
| 172 | struct snd_pcm_hw_params *hw_params) |
| 173 | { |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 174 | debug("%s(%p)\n", __func__, sub); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 175 | return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params)); |
| 176 | } |
| 177 | |
| 178 | static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub) |
| 179 | { |
| 180 | struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 181 | debug("%s(%p)\n", __func__, sub); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 182 | deactivate_substream(dev, sub); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 183 | return snd_pcm_lib_free_pages(sub); |
| 184 | } |
| 185 | |
| 186 | /* this should probably go upstream */ |
| 187 | #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12 |
| 188 | #error "Change this table" |
| 189 | #endif |
| 190 | |
| 191 | static unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100, |
| 192 | 48000, 64000, 88200, 96000, 176400, 192000 }; |
| 193 | |
| 194 | static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream) |
| 195 | { |
| 196 | int bytes_per_sample, bpp, ret, i; |
| 197 | int index = substream->number; |
| 198 | struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); |
| 199 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 200 | |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 201 | debug("%s(%p)\n", __func__, substream); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 202 | |
Daniel Mack | a9b487f | 2009-04-27 12:18:05 +0200 | [diff] [blame] | 203 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 204 | dev->period_out_count[index] = BYTES_PER_SAMPLE + 1; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 205 | dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1; |
Daniel Mack | a9b487f | 2009-04-27 12:18:05 +0200 | [diff] [blame] | 206 | } else { |
Daniel Mack | 0a842c8 | 2009-06-17 17:45:11 +0200 | [diff] [blame] | 207 | int in_pos = (dev->spec.data_alignment == 2) ? 0 : 2; |
| 208 | dev->period_in_count[index] = BYTES_PER_SAMPLE + in_pos; |
| 209 | dev->audio_in_buf_pos[index] = BYTES_PER_SAMPLE + in_pos; |
Daniel Mack | a9b487f | 2009-04-27 12:18:05 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 212 | if (dev->streaming) |
| 213 | return 0; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 214 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 215 | /* the first client that opens a stream defines the sample rate |
| 216 | * setting for all subsequent calls, until the last client closed. */ |
| 217 | for (i=0; i < ARRAY_SIZE(rates); i++) |
| 218 | if (runtime->rate == rates[i]) |
| 219 | dev->pcm_info.rates = 1 << i; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 220 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 221 | snd_pcm_limit_hw_rates(runtime); |
| 222 | |
| 223 | bytes_per_sample = BYTES_PER_SAMPLE; |
| 224 | if (dev->spec.data_alignment == 2) |
| 225 | bytes_per_sample++; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 226 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 227 | bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE) |
| 228 | * bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams; |
Daniel Mack | 6e9fc6b | 2008-04-14 15:40:31 +0200 | [diff] [blame] | 229 | |
| 230 | if (bpp > MAX_ENDPOINT_SIZE) |
| 231 | bpp = MAX_ENDPOINT_SIZE; |
| 232 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 233 | ret = snd_usb_caiaq_set_audio_params(dev, runtime->rate, |
| 234 | runtime->sample_bits, bpp); |
| 235 | if (ret) |
| 236 | return ret; |
| 237 | |
| 238 | ret = stream_start(dev); |
| 239 | if (ret) |
| 240 | return ret; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 241 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 242 | dev->output_running = 0; |
| 243 | wait_event_timeout(dev->prepare_wait_queue, dev->output_running, HZ); |
| 244 | if (!dev->output_running) { |
| 245 | stream_stop(dev); |
| 246 | return -EPIPE; |
| 247 | } |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | static int snd_usb_caiaq_pcm_trigger(struct snd_pcm_substream *sub, int cmd) |
| 253 | { |
| 254 | struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); |
| 255 | |
| 256 | switch (cmd) { |
| 257 | case SNDRV_PCM_TRIGGER_START: |
| 258 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 259 | activate_substream(dev, sub); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 260 | break; |
| 261 | case SNDRV_PCM_TRIGGER_STOP: |
| 262 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 263 | deactivate_substream(dev, sub); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 264 | break; |
| 265 | default: |
| 266 | return -EINVAL; |
| 267 | } |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static snd_pcm_uframes_t |
| 273 | snd_usb_caiaq_pcm_pointer(struct snd_pcm_substream *sub) |
| 274 | { |
| 275 | int index = sub->number; |
| 276 | struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); |
Mark Hills | 3702b08 | 2009-10-24 12:59:35 +0100 | [diff] [blame] | 277 | snd_pcm_uframes_t ptr; |
| 278 | |
| 279 | spin_lock(&dev->spinlock); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 280 | |
| 281 | if (dev->input_panic || dev->output_panic) |
Mark Hills | 3702b08 | 2009-10-24 12:59:35 +0100 | [diff] [blame] | 282 | ptr = SNDRV_PCM_POS_XRUN; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 283 | |
| 284 | if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Mark Hills | 3702b08 | 2009-10-24 12:59:35 +0100 | [diff] [blame] | 285 | ptr = bytes_to_frames(sub->runtime, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 286 | dev->audio_out_buf_pos[index]); |
| 287 | else |
Mark Hills | 3702b08 | 2009-10-24 12:59:35 +0100 | [diff] [blame] | 288 | ptr = bytes_to_frames(sub->runtime, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 289 | dev->audio_in_buf_pos[index]); |
Mark Hills | 3702b08 | 2009-10-24 12:59:35 +0100 | [diff] [blame] | 290 | |
| 291 | spin_unlock(&dev->spinlock); |
| 292 | return ptr; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* operators for both playback and capture */ |
| 296 | static struct snd_pcm_ops snd_usb_caiaq_ops = { |
| 297 | .open = snd_usb_caiaq_substream_open, |
| 298 | .close = snd_usb_caiaq_substream_close, |
| 299 | .ioctl = snd_pcm_lib_ioctl, |
| 300 | .hw_params = snd_usb_caiaq_pcm_hw_params, |
| 301 | .hw_free = snd_usb_caiaq_pcm_hw_free, |
| 302 | .prepare = snd_usb_caiaq_pcm_prepare, |
| 303 | .trigger = snd_usb_caiaq_pcm_trigger, |
| 304 | .pointer = snd_usb_caiaq_pcm_pointer |
| 305 | }; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 306 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 307 | static void check_for_elapsed_periods(struct snd_usb_caiaqdev *dev, |
| 308 | struct snd_pcm_substream **subs) |
| 309 | { |
| 310 | int stream, pb, *cnt; |
| 311 | struct snd_pcm_substream *sub; |
| 312 | |
| 313 | for (stream = 0; stream < dev->n_streams; stream++) { |
| 314 | sub = subs[stream]; |
| 315 | if (!sub) |
| 316 | continue; |
| 317 | |
Daniel Mack | a9b487f | 2009-04-27 12:18:05 +0200 | [diff] [blame] | 318 | pb = snd_pcm_lib_period_bytes(sub); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 319 | cnt = (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) ? |
| 320 | &dev->period_out_count[stream] : |
| 321 | &dev->period_in_count[stream]; |
| 322 | |
| 323 | if (*cnt >= pb) { |
| 324 | snd_pcm_period_elapsed(sub); |
| 325 | *cnt %= pb; |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev, |
| 331 | const struct urb *urb, |
| 332 | const struct usb_iso_packet_descriptor *iso) |
| 333 | { |
| 334 | unsigned char *usb_buf = urb->transfer_buffer + iso->offset; |
| 335 | struct snd_pcm_substream *sub; |
| 336 | int stream, i; |
| 337 | |
| 338 | if (all_substreams_zero(dev->sub_capture)) |
| 339 | return; |
| 340 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 341 | for (i = 0; i < iso->actual_length;) { |
| 342 | for (stream = 0; stream < dev->n_streams; stream++, i++) { |
| 343 | sub = dev->sub_capture[stream]; |
| 344 | if (sub) { |
| 345 | struct snd_pcm_runtime *rt = sub->runtime; |
| 346 | char *audio_buf = rt->dma_area; |
| 347 | int sz = frames_to_bytes(rt, rt->buffer_size); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 348 | audio_buf[dev->audio_in_buf_pos[stream]++] |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 349 | = usb_buf[i]; |
| 350 | dev->period_in_count[stream]++; |
| 351 | if (dev->audio_in_buf_pos[stream] == sz) |
| 352 | dev->audio_in_buf_pos[stream] = 0; |
| 353 | } |
| 354 | } |
| 355 | } |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev, |
| 359 | const struct urb *urb, |
| 360 | const struct usb_iso_packet_descriptor *iso) |
| 361 | { |
| 362 | unsigned char *usb_buf = urb->transfer_buffer + iso->offset; |
| 363 | unsigned char check_byte; |
| 364 | struct snd_pcm_substream *sub; |
| 365 | int stream, i; |
| 366 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 367 | for (i = 0; i < iso->actual_length;) { |
| 368 | if (i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 0) { |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 369 | for (stream = 0; |
| 370 | stream < dev->n_streams; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 371 | stream++, i++) { |
| 372 | if (dev->first_packet) |
| 373 | continue; |
| 374 | |
| 375 | check_byte = MAKE_CHECKBYTE(dev, stream, i); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 376 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 377 | if ((usb_buf[i] & 0x3f) != check_byte) |
| 378 | dev->input_panic = 1; |
| 379 | |
| 380 | if (usb_buf[i] & 0x80) |
| 381 | dev->output_panic = 1; |
| 382 | } |
| 383 | } |
| 384 | dev->first_packet = 0; |
| 385 | |
| 386 | for (stream = 0; stream < dev->n_streams; stream++, i++) { |
| 387 | sub = dev->sub_capture[stream]; |
Daniel Mack | 9311c9b | 2009-03-18 11:03:54 +0100 | [diff] [blame] | 388 | if (dev->input_panic) |
| 389 | usb_buf[i] = 0; |
| 390 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 391 | if (sub) { |
| 392 | struct snd_pcm_runtime *rt = sub->runtime; |
| 393 | char *audio_buf = rt->dma_area; |
| 394 | int sz = frames_to_bytes(rt, rt->buffer_size); |
Karsten Wiese | a971c3d | 2007-03-29 17:02:45 +0200 | [diff] [blame] | 395 | audio_buf[dev->audio_in_buf_pos[stream]++] = |
| 396 | usb_buf[i]; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 397 | dev->period_in_count[stream]++; |
| 398 | if (dev->audio_in_buf_pos[stream] == sz) |
| 399 | dev->audio_in_buf_pos[stream] = 0; |
| 400 | } |
| 401 | } |
| 402 | } |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | static void read_in_urb(struct snd_usb_caiaqdev *dev, |
| 406 | const struct urb *urb, |
| 407 | const struct usb_iso_packet_descriptor *iso) |
| 408 | { |
| 409 | if (!dev->streaming) |
| 410 | return; |
| 411 | |
Daniel Mack | 9311c9b | 2009-03-18 11:03:54 +0100 | [diff] [blame] | 412 | if (iso->actual_length < dev->bpp) |
| 413 | return; |
| 414 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 415 | switch (dev->spec.data_alignment) { |
| 416 | case 0: |
| 417 | read_in_urb_mode0(dev, urb, iso); |
| 418 | break; |
| 419 | case 2: |
| 420 | read_in_urb_mode2(dev, urb, iso); |
| 421 | break; |
| 422 | } |
| 423 | |
Daniel Mack | 1313e70 | 2009-03-18 11:03:53 +0100 | [diff] [blame] | 424 | if ((dev->input_panic || dev->output_panic) && !dev->warned) { |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 425 | debug("streaming error detected %s %s\n", |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 426 | dev->input_panic ? "(input)" : "", |
| 427 | dev->output_panic ? "(output)" : ""); |
Daniel Mack | 1313e70 | 2009-03-18 11:03:53 +0100 | [diff] [blame] | 428 | dev->warned = 1; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 429 | } |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 430 | } |
| 431 | |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 432 | static void fill_out_urb(struct snd_usb_caiaqdev *dev, |
| 433 | struct urb *urb, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 434 | const struct usb_iso_packet_descriptor *iso) |
| 435 | { |
| 436 | unsigned char *usb_buf = urb->transfer_buffer + iso->offset; |
| 437 | struct snd_pcm_substream *sub; |
| 438 | int stream, i; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 439 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 440 | for (i = 0; i < iso->length;) { |
Karsten Wiese | a971c3d | 2007-03-29 17:02:45 +0200 | [diff] [blame] | 441 | for (stream = 0; stream < dev->n_streams; stream++, i++) { |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 442 | sub = dev->sub_playback[stream]; |
| 443 | if (sub) { |
| 444 | struct snd_pcm_runtime *rt = sub->runtime; |
| 445 | char *audio_buf = rt->dma_area; |
| 446 | int sz = frames_to_bytes(rt, rt->buffer_size); |
Karsten Wiese | a971c3d | 2007-03-29 17:02:45 +0200 | [diff] [blame] | 447 | usb_buf[i] = |
| 448 | audio_buf[dev->audio_out_buf_pos[stream]]; |
| 449 | dev->period_out_count[stream]++; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 450 | dev->audio_out_buf_pos[stream]++; |
| 451 | if (dev->audio_out_buf_pos[stream] == sz) |
| 452 | dev->audio_out_buf_pos[stream] = 0; |
| 453 | } else |
Karsten Wiese | a971c3d | 2007-03-29 17:02:45 +0200 | [diff] [blame] | 454 | usb_buf[i] = 0; |
| 455 | } |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 456 | |
| 457 | /* fill in the check bytes */ |
| 458 | if (dev->spec.data_alignment == 2 && |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 459 | i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 460 | (dev->n_streams * CHANNELS_PER_STREAM)) |
| 461 | for (stream = 0; stream < dev->n_streams; stream++, i++) |
| 462 | usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 463 | } |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static void read_completed(struct urb *urb) |
| 467 | { |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 468 | struct snd_usb_caiaq_cb_info *info = urb->context; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 469 | struct snd_usb_caiaqdev *dev; |
| 470 | struct urb *out; |
| 471 | int frame, len, send_it = 0, outframe = 0; |
| 472 | |
| 473 | if (urb->status || !info) |
| 474 | return; |
| 475 | |
| 476 | dev = info->dev; |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 477 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 478 | if (!dev->streaming) |
| 479 | return; |
| 480 | |
| 481 | out = dev->data_urbs_out[info->index]; |
| 482 | |
| 483 | /* read the recently received packet and send back one which has |
| 484 | * the same layout */ |
| 485 | for (frame = 0; frame < FRAMES_PER_URB; frame++) { |
| 486 | if (urb->iso_frame_desc[frame].status) |
| 487 | continue; |
| 488 | |
| 489 | len = urb->iso_frame_desc[outframe].actual_length; |
| 490 | out->iso_frame_desc[outframe].length = len; |
| 491 | out->iso_frame_desc[outframe].actual_length = 0; |
| 492 | out->iso_frame_desc[outframe].offset = BYTES_PER_FRAME * frame; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 493 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 494 | if (len > 0) { |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 495 | spin_lock(&dev->spinlock); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 496 | fill_out_urb(dev, out, &out->iso_frame_desc[outframe]); |
| 497 | read_in_urb(dev, urb, &urb->iso_frame_desc[frame]); |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 498 | spin_unlock(&dev->spinlock); |
| 499 | check_for_elapsed_periods(dev, dev->sub_playback); |
| 500 | check_for_elapsed_periods(dev, dev->sub_capture); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 501 | send_it = 1; |
| 502 | } |
| 503 | |
| 504 | outframe++; |
| 505 | } |
| 506 | |
| 507 | if (send_it) { |
| 508 | out->number_of_packets = FRAMES_PER_URB; |
| 509 | out->transfer_flags = URB_ISO_ASAP; |
| 510 | usb_submit_urb(out, GFP_ATOMIC); |
| 511 | } |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 512 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 513 | /* re-submit inbound urb */ |
| 514 | for (frame = 0; frame < FRAMES_PER_URB; frame++) { |
| 515 | urb->iso_frame_desc[frame].offset = BYTES_PER_FRAME * frame; |
| 516 | urb->iso_frame_desc[frame].length = BYTES_PER_FRAME; |
| 517 | urb->iso_frame_desc[frame].actual_length = 0; |
| 518 | } |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 519 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 520 | urb->number_of_packets = FRAMES_PER_URB; |
| 521 | urb->transfer_flags = URB_ISO_ASAP; |
| 522 | usb_submit_urb(urb, GFP_ATOMIC); |
| 523 | } |
| 524 | |
| 525 | static void write_completed(struct urb *urb) |
| 526 | { |
| 527 | struct snd_usb_caiaq_cb_info *info = urb->context; |
| 528 | struct snd_usb_caiaqdev *dev = info->dev; |
| 529 | |
| 530 | if (!dev->output_running) { |
| 531 | dev->output_running = 1; |
| 532 | wake_up(&dev->prepare_wait_queue); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret) |
| 537 | { |
| 538 | int i, frame; |
| 539 | struct urb **urbs; |
| 540 | struct usb_device *usb_dev = dev->chip.dev; |
| 541 | unsigned int pipe; |
| 542 | |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 543 | pipe = (dir == SNDRV_PCM_STREAM_PLAYBACK) ? |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 544 | usb_sndisocpipe(usb_dev, ENDPOINT_PLAYBACK) : |
| 545 | usb_rcvisocpipe(usb_dev, ENDPOINT_CAPTURE); |
| 546 | |
| 547 | urbs = kmalloc(N_URBS * sizeof(*urbs), GFP_KERNEL); |
| 548 | if (!urbs) { |
| 549 | log("unable to kmalloc() urbs, OOM!?\n"); |
| 550 | *ret = -ENOMEM; |
| 551 | return NULL; |
| 552 | } |
| 553 | |
| 554 | for (i = 0; i < N_URBS; i++) { |
| 555 | urbs[i] = usb_alloc_urb(FRAMES_PER_URB, GFP_KERNEL); |
| 556 | if (!urbs[i]) { |
| 557 | log("unable to usb_alloc_urb(), OOM!?\n"); |
| 558 | *ret = -ENOMEM; |
| 559 | return urbs; |
| 560 | } |
| 561 | |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 562 | urbs[i]->transfer_buffer = |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 563 | kmalloc(FRAMES_PER_URB * BYTES_PER_FRAME, GFP_KERNEL); |
| 564 | if (!urbs[i]->transfer_buffer) { |
| 565 | log("unable to kmalloc() transfer buffer, OOM!?\n"); |
| 566 | *ret = -ENOMEM; |
| 567 | return urbs; |
| 568 | } |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 569 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 570 | for (frame = 0; frame < FRAMES_PER_URB; frame++) { |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 571 | struct usb_iso_packet_descriptor *iso = |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 572 | &urbs[i]->iso_frame_desc[frame]; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 573 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 574 | iso->offset = BYTES_PER_FRAME * frame; |
| 575 | iso->length = BYTES_PER_FRAME; |
| 576 | } |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 577 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 578 | urbs[i]->dev = usb_dev; |
| 579 | urbs[i]->pipe = pipe; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 580 | urbs[i]->transfer_buffer_length = FRAMES_PER_URB |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 581 | * BYTES_PER_FRAME; |
| 582 | urbs[i]->context = &dev->data_cb_info[i]; |
| 583 | urbs[i]->interval = 1; |
| 584 | urbs[i]->transfer_flags = URB_ISO_ASAP; |
| 585 | urbs[i]->number_of_packets = FRAMES_PER_URB; |
| 586 | urbs[i]->complete = (dir == SNDRV_PCM_STREAM_CAPTURE) ? |
| 587 | read_completed : write_completed; |
| 588 | } |
| 589 | |
| 590 | *ret = 0; |
| 591 | return urbs; |
| 592 | } |
| 593 | |
| 594 | static void free_urbs(struct urb **urbs) |
| 595 | { |
| 596 | int i; |
| 597 | |
| 598 | if (!urbs) |
| 599 | return; |
| 600 | |
| 601 | for (i = 0; i < N_URBS; i++) { |
| 602 | if (!urbs[i]) |
| 603 | continue; |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 604 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 605 | usb_kill_urb(urbs[i]); |
| 606 | kfree(urbs[i]->transfer_buffer); |
| 607 | usb_free_urb(urbs[i]); |
| 608 | } |
| 609 | |
| 610 | kfree(urbs); |
| 611 | } |
| 612 | |
Randy Dunlap | 599c3e7 | 2008-01-16 14:56:04 +0100 | [diff] [blame] | 613 | int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 614 | { |
| 615 | int i, ret; |
| 616 | |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 617 | dev->n_audio_in = max(dev->spec.num_analog_audio_in, |
| 618 | dev->spec.num_digital_audio_in) / |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 619 | CHANNELS_PER_STREAM; |
| 620 | dev->n_audio_out = max(dev->spec.num_analog_audio_out, |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 621 | dev->spec.num_digital_audio_out) / |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 622 | CHANNELS_PER_STREAM; |
| 623 | dev->n_streams = max(dev->n_audio_in, dev->n_audio_out); |
| 624 | |
| 625 | debug("dev->n_audio_in = %d\n", dev->n_audio_in); |
| 626 | debug("dev->n_audio_out = %d\n", dev->n_audio_out); |
| 627 | debug("dev->n_streams = %d\n", dev->n_streams); |
| 628 | |
| 629 | if (dev->n_streams > MAX_STREAMS) { |
| 630 | log("unable to initialize device, too many streams.\n"); |
| 631 | return -EINVAL; |
| 632 | } |
| 633 | |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 634 | ret = snd_pcm_new(dev->chip.card, dev->product_name, 0, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 635 | dev->n_audio_out, dev->n_audio_in, &dev->pcm); |
| 636 | |
| 637 | if (ret < 0) { |
| 638 | log("snd_pcm_new() returned %d\n", ret); |
| 639 | return ret; |
| 640 | } |
| 641 | |
| 642 | dev->pcm->private_data = dev; |
| 643 | strcpy(dev->pcm->name, dev->product_name); |
| 644 | |
| 645 | memset(dev->sub_playback, 0, sizeof(dev->sub_playback)); |
| 646 | memset(dev->sub_capture, 0, sizeof(dev->sub_capture)); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 647 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 648 | memcpy(&dev->pcm_info, &snd_usb_caiaq_pcm_hardware, |
| 649 | sizeof(snd_usb_caiaq_pcm_hardware)); |
| 650 | |
| 651 | /* setup samplerates */ |
| 652 | dev->samplerates = dev->pcm_info.rates; |
| 653 | switch (dev->chip.usb_id) { |
| 654 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 655 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): |
Daniel Mack | f3e9d5d | 2008-05-08 15:42:15 +0200 | [diff] [blame] | 656 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_SESSIONIO): |
Daniel Mack | 2165592 | 2009-01-16 11:03:19 +0100 | [diff] [blame] | 657 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_GUITARRIGMOBILE): |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 658 | dev->samplerates |= SNDRV_PCM_RATE_192000; |
Daniel Mack | 2165592 | 2009-01-16 11:03:19 +0100 | [diff] [blame] | 659 | /* fall thru */ |
Daniel Mack | b30c494 | 2009-07-22 14:13:35 +0200 | [diff] [blame] | 660 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO2DJ): |
Daniel Mack | 2165592 | 2009-01-16 11:03:19 +0100 | [diff] [blame] | 661 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ): |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 662 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ): |
| 663 | dev->samplerates |= SNDRV_PCM_RATE_88200; |
| 664 | break; |
| 665 | } |
| 666 | |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 667 | snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 668 | &snd_usb_caiaq_ops); |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 669 | snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_CAPTURE, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 670 | &snd_usb_caiaq_ops); |
| 671 | |
| 672 | snd_pcm_lib_preallocate_pages_for_all(dev->pcm, |
| 673 | SNDRV_DMA_TYPE_CONTINUOUS, |
| 674 | snd_dma_continuous_data(GFP_KERNEL), |
| 675 | MAX_BUFFER_SIZE, MAX_BUFFER_SIZE); |
| 676 | |
| 677 | dev->data_cb_info = |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 678 | kmalloc(sizeof(struct snd_usb_caiaq_cb_info) * N_URBS, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 679 | GFP_KERNEL); |
| 680 | |
| 681 | if (!dev->data_cb_info) |
| 682 | return -ENOMEM; |
| 683 | |
| 684 | for (i = 0; i < N_URBS; i++) { |
| 685 | dev->data_cb_info[i].dev = dev; |
| 686 | dev->data_cb_info[i].index = i; |
| 687 | } |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 688 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 689 | dev->data_urbs_in = alloc_urbs(dev, SNDRV_PCM_STREAM_CAPTURE, &ret); |
| 690 | if (ret < 0) { |
| 691 | kfree(dev->data_cb_info); |
| 692 | free_urbs(dev->data_urbs_in); |
| 693 | return ret; |
| 694 | } |
Daniel Mack | 9318dce | 2009-06-01 21:36:23 +0200 | [diff] [blame] | 695 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 696 | dev->data_urbs_out = alloc_urbs(dev, SNDRV_PCM_STREAM_PLAYBACK, &ret); |
| 697 | if (ret < 0) { |
| 698 | kfree(dev->data_cb_info); |
| 699 | free_urbs(dev->data_urbs_in); |
| 700 | free_urbs(dev->data_urbs_out); |
| 701 | return ret; |
| 702 | } |
| 703 | |
| 704 | return 0; |
| 705 | } |
| 706 | |
| 707 | void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *dev) |
| 708 | { |
Daniel Mack | 8d04884 | 2008-04-14 15:39:14 +0200 | [diff] [blame] | 709 | debug("%s(%p)\n", __func__, dev); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 710 | stream_stop(dev); |
| 711 | free_urbs(dev->data_urbs_in); |
| 712 | free_urbs(dev->data_urbs_out); |
| 713 | kfree(dev->data_cb_info); |
| 714 | } |
| 715 | |