aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb/caiaq/audio.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/usb/caiaq/audio.c')
-rw-r--r--sound/usb/caiaq/audio.c459
1 files changed, 238 insertions, 221 deletions
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index fde9a7a29cb6..67330af21b0e 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -16,6 +16,7 @@
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/ 17*/
18 18
19#include <linux/device.h>
19#include <linux/spinlock.h> 20#include <linux/spinlock.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21#include <linux/init.h> 22#include <linux/init.h>
@@ -39,8 +40,8 @@
39#define ENDPOINT_CAPTURE 2 40#define ENDPOINT_CAPTURE 2
40#define ENDPOINT_PLAYBACK 6 41#define ENDPOINT_PLAYBACK 6
41 42
42#define MAKE_CHECKBYTE(dev,stream,i) \ 43#define MAKE_CHECKBYTE(cdev,stream,i) \
43 (stream << 1) | (~(i / (dev->n_streams * BYTES_PER_SAMPLE_USB)) & 1) 44 (stream << 1) | (~(i / (cdev->n_streams * BYTES_PER_SAMPLE_USB)) & 1)
44 45
45static struct snd_pcm_hardware snd_usb_caiaq_pcm_hardware = { 46static struct snd_pcm_hardware snd_usb_caiaq_pcm_hardware = {
46 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 47 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
@@ -60,32 +61,32 @@ static struct snd_pcm_hardware snd_usb_caiaq_pcm_hardware = {
60}; 61};
61 62
62static void 63static void
63activate_substream(struct snd_usb_caiaqdev *dev, 64activate_substream(struct snd_usb_caiaqdev *cdev,
64 struct snd_pcm_substream *sub) 65 struct snd_pcm_substream *sub)
65{ 66{
66 spin_lock(&dev->spinlock); 67 spin_lock(&cdev->spinlock);
67 68
68 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 69 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
69 dev->sub_playback[sub->number] = sub; 70 cdev->sub_playback[sub->number] = sub;
70 else 71 else
71 dev->sub_capture[sub->number] = sub; 72 cdev->sub_capture[sub->number] = sub;
72 73
73 spin_unlock(&dev->spinlock); 74 spin_unlock(&cdev->spinlock);
74} 75}
75 76
76static void 77static void
77deactivate_substream(struct snd_usb_caiaqdev *dev, 78deactivate_substream(struct snd_usb_caiaqdev *cdev,
78 struct snd_pcm_substream *sub) 79 struct snd_pcm_substream *sub)
79{ 80{
80 unsigned long flags; 81 unsigned long flags;
81 spin_lock_irqsave(&dev->spinlock, flags); 82 spin_lock_irqsave(&cdev->spinlock, flags);
82 83
83 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 84 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
84 dev->sub_playback[sub->number] = NULL; 85 cdev->sub_playback[sub->number] = NULL;
85 else 86 else
86 dev->sub_capture[sub->number] = NULL; 87 cdev->sub_capture[sub->number] = NULL;
87 88
88 spin_unlock_irqrestore(&dev->spinlock, flags); 89 spin_unlock_irqrestore(&cdev->spinlock, flags);
89} 90}
90 91
91static int 92static int
@@ -98,28 +99,30 @@ all_substreams_zero(struct snd_pcm_substream **subs)
98 return 1; 99 return 1;
99} 100}
100 101
101static int stream_start(struct snd_usb_caiaqdev *dev) 102static int stream_start(struct snd_usb_caiaqdev *cdev)
102{ 103{
103 int i, ret; 104 int i, ret;
105 struct device *dev = caiaqdev_to_dev(cdev);
104 106
105 debug("%s(%p)\n", __func__, dev); 107 dev_dbg(dev, "%s(%p)\n", __func__, cdev);
106 108
107 if (dev->streaming) 109 if (cdev->streaming)
108 return -EINVAL; 110 return -EINVAL;
109 111
110 memset(dev->sub_playback, 0, sizeof(dev->sub_playback)); 112 memset(cdev->sub_playback, 0, sizeof(cdev->sub_playback));
111 memset(dev->sub_capture, 0, sizeof(dev->sub_capture)); 113 memset(cdev->sub_capture, 0, sizeof(cdev->sub_capture));
112 dev->input_panic = 0; 114 cdev->input_panic = 0;
113 dev->output_panic = 0; 115 cdev->output_panic = 0;
114 dev->first_packet = 4; 116 cdev->first_packet = 4;
115 dev->streaming = 1; 117 cdev->streaming = 1;
116 dev->warned = 0; 118 cdev->warned = 0;
117 119
118 for (i = 0; i < N_URBS; i++) { 120 for (i = 0; i < N_URBS; i++) {
119 ret = usb_submit_urb(dev->data_urbs_in[i], GFP_ATOMIC); 121 ret = usb_submit_urb(cdev->data_urbs_in[i], GFP_ATOMIC);
120 if (ret) { 122 if (ret) {
121 log("unable to trigger read #%d! (ret %d)\n", i, ret); 123 dev_err(dev, "unable to trigger read #%d! (ret %d)\n",
122 dev->streaming = 0; 124 i, ret);
125 cdev->streaming = 0;
123 return -EPIPE; 126 return -EPIPE;
124 } 127 }
125 } 128 }
@@ -127,46 +130,51 @@ static int stream_start(struct snd_usb_caiaqdev *dev)
127 return 0; 130 return 0;
128} 131}
129 132
130static void stream_stop(struct snd_usb_caiaqdev *dev) 133static void stream_stop(struct snd_usb_caiaqdev *cdev)
131{ 134{
132 int i; 135 int i;
136 struct device *dev = caiaqdev_to_dev(cdev);
133 137
134 debug("%s(%p)\n", __func__, dev); 138 dev_dbg(dev, "%s(%p)\n", __func__, cdev);
135 if (!dev->streaming) 139 if (!cdev->streaming)
136 return; 140 return;
137 141
138 dev->streaming = 0; 142 cdev->streaming = 0;
139 143
140 for (i = 0; i < N_URBS; i++) { 144 for (i = 0; i < N_URBS; i++) {
141 usb_kill_urb(dev->data_urbs_in[i]); 145 usb_kill_urb(cdev->data_urbs_in[i]);
142 146
143 if (test_bit(i, &dev->outurb_active_mask)) 147 if (test_bit(i, &cdev->outurb_active_mask))
144 usb_kill_urb(dev->data_urbs_out[i]); 148 usb_kill_urb(cdev->data_urbs_out[i]);
145 } 149 }
146 150
147 dev->outurb_active_mask = 0; 151 cdev->outurb_active_mask = 0;
148} 152}
149 153
150static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream) 154static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream)
151{ 155{
152 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 156 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
153 debug("%s(%p)\n", __func__, substream); 157 struct device *dev = caiaqdev_to_dev(cdev);
154 substream->runtime->hw = dev->pcm_info; 158
159 dev_dbg(dev, "%s(%p)\n", __func__, substream);
160 substream->runtime->hw = cdev->pcm_info;
155 snd_pcm_limit_hw_rates(substream->runtime); 161 snd_pcm_limit_hw_rates(substream->runtime);
162
156 return 0; 163 return 0;
157} 164}
158 165
159static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream) 166static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
160{ 167{
161 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 168 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
169 struct device *dev = caiaqdev_to_dev(cdev);
162 170
163 debug("%s(%p)\n", __func__, substream); 171 dev_dbg(dev, "%s(%p)\n", __func__, substream);
164 if (all_substreams_zero(dev->sub_playback) && 172 if (all_substreams_zero(cdev->sub_playback) &&
165 all_substreams_zero(dev->sub_capture)) { 173 all_substreams_zero(cdev->sub_capture)) {
166 /* when the last client has stopped streaming, 174 /* when the last client has stopped streaming,
167 * all sample rates are allowed again */ 175 * all sample rates are allowed again */
168 stream_stop(dev); 176 stream_stop(cdev);
169 dev->pcm_info.rates = dev->samplerates; 177 cdev->pcm_info.rates = cdev->samplerates;
170 } 178 }
171 179
172 return 0; 180 return 0;
@@ -175,15 +183,13 @@ static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
175static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub, 183static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub,
176 struct snd_pcm_hw_params *hw_params) 184 struct snd_pcm_hw_params *hw_params)
177{ 185{
178 debug("%s(%p)\n", __func__, sub);
179 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params)); 186 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params));
180} 187}
181 188
182static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub) 189static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub)
183{ 190{
184 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); 191 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub);
185 debug("%s(%p)\n", __func__, sub); 192 deactivate_substream(cdev, sub);
186 deactivate_substream(dev, sub);
187 return snd_pcm_lib_free_pages(sub); 193 return snd_pcm_lib_free_pages(sub);
188} 194}
189 195
@@ -199,15 +205,16 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
199{ 205{
200 int bytes_per_sample, bpp, ret, i; 206 int bytes_per_sample, bpp, ret, i;
201 int index = substream->number; 207 int index = substream->number;
202 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 208 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
203 struct snd_pcm_runtime *runtime = substream->runtime; 209 struct snd_pcm_runtime *runtime = substream->runtime;
210 struct device *dev = caiaqdev_to_dev(cdev);
204 211
205 debug("%s(%p)\n", __func__, substream); 212 dev_dbg(dev, "%s(%p)\n", __func__, substream);
206 213
207 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 214 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
208 int out_pos; 215 int out_pos;
209 216
210 switch (dev->spec.data_alignment) { 217 switch (cdev->spec.data_alignment) {
211 case 0: 218 case 0:
212 case 2: 219 case 2:
213 out_pos = BYTES_PER_SAMPLE + 1; 220 out_pos = BYTES_PER_SAMPLE + 1;
@@ -218,12 +225,12 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
218 break; 225 break;
219 } 226 }
220 227
221 dev->period_out_count[index] = out_pos; 228 cdev->period_out_count[index] = out_pos;
222 dev->audio_out_buf_pos[index] = out_pos; 229 cdev->audio_out_buf_pos[index] = out_pos;
223 } else { 230 } else {
224 int in_pos; 231 int in_pos;
225 232
226 switch (dev->spec.data_alignment) { 233 switch (cdev->spec.data_alignment) {
227 case 0: 234 case 0:
228 in_pos = BYTES_PER_SAMPLE + 2; 235 in_pos = BYTES_PER_SAMPLE + 2;
229 break; 236 break;
@@ -236,44 +243,44 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
236 break; 243 break;
237 } 244 }
238 245
239 dev->period_in_count[index] = in_pos; 246 cdev->period_in_count[index] = in_pos;
240 dev->audio_in_buf_pos[index] = in_pos; 247 cdev->audio_in_buf_pos[index] = in_pos;
241 } 248 }
242 249
243 if (dev->streaming) 250 if (cdev->streaming)
244 return 0; 251 return 0;
245 252
246 /* the first client that opens a stream defines the sample rate 253 /* the first client that opens a stream defines the sample rate
247 * setting for all subsequent calls, until the last client closed. */ 254 * setting for all subsequent calls, until the last client closed. */
248 for (i=0; i < ARRAY_SIZE(rates); i++) 255 for (i=0; i < ARRAY_SIZE(rates); i++)
249 if (runtime->rate == rates[i]) 256 if (runtime->rate == rates[i])
250 dev->pcm_info.rates = 1 << i; 257 cdev->pcm_info.rates = 1 << i;
251 258
252 snd_pcm_limit_hw_rates(runtime); 259 snd_pcm_limit_hw_rates(runtime);
253 260
254 bytes_per_sample = BYTES_PER_SAMPLE; 261 bytes_per_sample = BYTES_PER_SAMPLE;
255 if (dev->spec.data_alignment >= 2) 262 if (cdev->spec.data_alignment >= 2)
256 bytes_per_sample++; 263 bytes_per_sample++;
257 264
258 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE) 265 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
259 * bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams; 266 * bytes_per_sample * CHANNELS_PER_STREAM * cdev->n_streams;
260 267
261 if (bpp > MAX_ENDPOINT_SIZE) 268 if (bpp > MAX_ENDPOINT_SIZE)
262 bpp = MAX_ENDPOINT_SIZE; 269 bpp = MAX_ENDPOINT_SIZE;
263 270
264 ret = snd_usb_caiaq_set_audio_params(dev, runtime->rate, 271 ret = snd_usb_caiaq_set_audio_params(cdev, runtime->rate,
265 runtime->sample_bits, bpp); 272 runtime->sample_bits, bpp);
266 if (ret) 273 if (ret)
267 return ret; 274 return ret;
268 275
269 ret = stream_start(dev); 276 ret = stream_start(cdev);
270 if (ret) 277 if (ret)
271 return ret; 278 return ret;
272 279
273 dev->output_running = 0; 280 cdev->output_running = 0;
274 wait_event_timeout(dev->prepare_wait_queue, dev->output_running, HZ); 281 wait_event_timeout(cdev->prepare_wait_queue, cdev->output_running, HZ);
275 if (!dev->output_running) { 282 if (!cdev->output_running) {
276 stream_stop(dev); 283 stream_stop(cdev);
277 return -EPIPE; 284 return -EPIPE;
278 } 285 }
279 286
@@ -282,18 +289,19 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
282 289
283static int snd_usb_caiaq_pcm_trigger(struct snd_pcm_substream *sub, int cmd) 290static int snd_usb_caiaq_pcm_trigger(struct snd_pcm_substream *sub, int cmd)
284{ 291{
285 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); 292 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub);
293 struct device *dev = caiaqdev_to_dev(cdev);
286 294
287 debug("%s(%p) cmd %d\n", __func__, sub, cmd); 295 dev_dbg(dev, "%s(%p) cmd %d\n", __func__, sub, cmd);
288 296
289 switch (cmd) { 297 switch (cmd) {
290 case SNDRV_PCM_TRIGGER_START: 298 case SNDRV_PCM_TRIGGER_START:
291 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 299 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
292 activate_substream(dev, sub); 300 activate_substream(cdev, sub);
293 break; 301 break;
294 case SNDRV_PCM_TRIGGER_STOP: 302 case SNDRV_PCM_TRIGGER_STOP:
295 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 303 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
296 deactivate_substream(dev, sub); 304 deactivate_substream(cdev, sub);
297 break; 305 break;
298 default: 306 default:
299 return -EINVAL; 307 return -EINVAL;
@@ -306,25 +314,25 @@ static snd_pcm_uframes_t
306snd_usb_caiaq_pcm_pointer(struct snd_pcm_substream *sub) 314snd_usb_caiaq_pcm_pointer(struct snd_pcm_substream *sub)
307{ 315{
308 int index = sub->number; 316 int index = sub->number;
309 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); 317 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub);
310 snd_pcm_uframes_t ptr; 318 snd_pcm_uframes_t ptr;
311 319
312 spin_lock(&dev->spinlock); 320 spin_lock(&cdev->spinlock);
313 321
314 if (dev->input_panic || dev->output_panic) { 322 if (cdev->input_panic || cdev->output_panic) {
315 ptr = SNDRV_PCM_POS_XRUN; 323 ptr = SNDRV_PCM_POS_XRUN;
316 goto unlock; 324 goto unlock;
317 } 325 }
318 326
319 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 327 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
320 ptr = bytes_to_frames(sub->runtime, 328 ptr = bytes_to_frames(sub->runtime,
321 dev->audio_out_buf_pos[index]); 329 cdev->audio_out_buf_pos[index]);
322 else 330 else
323 ptr = bytes_to_frames(sub->runtime, 331 ptr = bytes_to_frames(sub->runtime,
324 dev->audio_in_buf_pos[index]); 332 cdev->audio_in_buf_pos[index]);
325 333
326unlock: 334unlock:
327 spin_unlock(&dev->spinlock); 335 spin_unlock(&cdev->spinlock);
328 return ptr; 336 return ptr;
329} 337}
330 338
@@ -340,21 +348,21 @@ static struct snd_pcm_ops snd_usb_caiaq_ops = {
340 .pointer = snd_usb_caiaq_pcm_pointer 348 .pointer = snd_usb_caiaq_pcm_pointer
341}; 349};
342 350
343static void check_for_elapsed_periods(struct snd_usb_caiaqdev *dev, 351static void check_for_elapsed_periods(struct snd_usb_caiaqdev *cdev,
344 struct snd_pcm_substream **subs) 352 struct snd_pcm_substream **subs)
345{ 353{
346 int stream, pb, *cnt; 354 int stream, pb, *cnt;
347 struct snd_pcm_substream *sub; 355 struct snd_pcm_substream *sub;
348 356
349 for (stream = 0; stream < dev->n_streams; stream++) { 357 for (stream = 0; stream < cdev->n_streams; stream++) {
350 sub = subs[stream]; 358 sub = subs[stream];
351 if (!sub) 359 if (!sub)
352 continue; 360 continue;
353 361
354 pb = snd_pcm_lib_period_bytes(sub); 362 pb = snd_pcm_lib_period_bytes(sub);
355 cnt = (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) ? 363 cnt = (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
356 &dev->period_out_count[stream] : 364 &cdev->period_out_count[stream] :
357 &dev->period_in_count[stream]; 365 &cdev->period_in_count[stream];
358 366
359 if (*cnt >= pb) { 367 if (*cnt >= pb) {
360 snd_pcm_period_elapsed(sub); 368 snd_pcm_period_elapsed(sub);
@@ -363,7 +371,7 @@ static void check_for_elapsed_periods(struct snd_usb_caiaqdev *dev,
363 } 371 }
364} 372}
365 373
366static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev, 374static void read_in_urb_mode0(struct snd_usb_caiaqdev *cdev,
367 const struct urb *urb, 375 const struct urb *urb,
368 const struct usb_iso_packet_descriptor *iso) 376 const struct usb_iso_packet_descriptor *iso)
369{ 377{
@@ -371,27 +379,27 @@ static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev,
371 struct snd_pcm_substream *sub; 379 struct snd_pcm_substream *sub;
372 int stream, i; 380 int stream, i;
373 381
374 if (all_substreams_zero(dev->sub_capture)) 382 if (all_substreams_zero(cdev->sub_capture))
375 return; 383 return;
376 384
377 for (i = 0; i < iso->actual_length;) { 385 for (i = 0; i < iso->actual_length;) {
378 for (stream = 0; stream < dev->n_streams; stream++, i++) { 386 for (stream = 0; stream < cdev->n_streams; stream++, i++) {
379 sub = dev->sub_capture[stream]; 387 sub = cdev->sub_capture[stream];
380 if (sub) { 388 if (sub) {
381 struct snd_pcm_runtime *rt = sub->runtime; 389 struct snd_pcm_runtime *rt = sub->runtime;
382 char *audio_buf = rt->dma_area; 390 char *audio_buf = rt->dma_area;
383 int sz = frames_to_bytes(rt, rt->buffer_size); 391 int sz = frames_to_bytes(rt, rt->buffer_size);
384 audio_buf[dev->audio_in_buf_pos[stream]++] 392 audio_buf[cdev->audio_in_buf_pos[stream]++]
385 = usb_buf[i]; 393 = usb_buf[i];
386 dev->period_in_count[stream]++; 394 cdev->period_in_count[stream]++;
387 if (dev->audio_in_buf_pos[stream] == sz) 395 if (cdev->audio_in_buf_pos[stream] == sz)
388 dev->audio_in_buf_pos[stream] = 0; 396 cdev->audio_in_buf_pos[stream] = 0;
389 } 397 }
390 } 398 }
391 } 399 }
392} 400}
393 401
394static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev, 402static void read_in_urb_mode2(struct snd_usb_caiaqdev *cdev,
395 const struct urb *urb, 403 const struct urb *urb,
396 const struct usb_iso_packet_descriptor *iso) 404 const struct usb_iso_packet_descriptor *iso)
397{ 405{
@@ -401,48 +409,49 @@ static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
401 int stream, i; 409 int stream, i;
402 410
403 for (i = 0; i < iso->actual_length;) { 411 for (i = 0; i < iso->actual_length;) {
404 if (i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 0) { 412 if (i % (cdev->n_streams * BYTES_PER_SAMPLE_USB) == 0) {
405 for (stream = 0; 413 for (stream = 0;
406 stream < dev->n_streams; 414 stream < cdev->n_streams;
407 stream++, i++) { 415 stream++, i++) {
408 if (dev->first_packet) 416 if (cdev->first_packet)
409 continue; 417 continue;
410 418
411 check_byte = MAKE_CHECKBYTE(dev, stream, i); 419 check_byte = MAKE_CHECKBYTE(cdev, stream, i);
412 420
413 if ((usb_buf[i] & 0x3f) != check_byte) 421 if ((usb_buf[i] & 0x3f) != check_byte)
414 dev->input_panic = 1; 422 cdev->input_panic = 1;
415 423
416 if (usb_buf[i] & 0x80) 424 if (usb_buf[i] & 0x80)
417 dev->output_panic = 1; 425 cdev->output_panic = 1;
418 } 426 }
419 } 427 }
420 dev->first_packet = 0; 428 cdev->first_packet = 0;
421 429
422 for (stream = 0; stream < dev->n_streams; stream++, i++) { 430 for (stream = 0; stream < cdev->n_streams; stream++, i++) {
423 sub = dev->sub_capture[stream]; 431 sub = cdev->sub_capture[stream];
424 if (dev->input_panic) 432 if (cdev->input_panic)
425 usb_buf[i] = 0; 433 usb_buf[i] = 0;
426 434
427 if (sub) { 435 if (sub) {
428 struct snd_pcm_runtime *rt = sub->runtime; 436 struct snd_pcm_runtime *rt = sub->runtime;
429 char *audio_buf = rt->dma_area; 437 char *audio_buf = rt->dma_area;
430 int sz = frames_to_bytes(rt, rt->buffer_size); 438 int sz = frames_to_bytes(rt, rt->buffer_size);
431 audio_buf[dev->audio_in_buf_pos[stream]++] = 439 audio_buf[cdev->audio_in_buf_pos[stream]++] =
432 usb_buf[i]; 440 usb_buf[i];
433 dev->period_in_count[stream]++; 441 cdev->period_in_count[stream]++;
434 if (dev->audio_in_buf_pos[stream] == sz) 442 if (cdev->audio_in_buf_pos[stream] == sz)
435 dev->audio_in_buf_pos[stream] = 0; 443 cdev->audio_in_buf_pos[stream] = 0;
436 } 444 }
437 } 445 }
438 } 446 }
439} 447}
440 448
441static void read_in_urb_mode3(struct snd_usb_caiaqdev *dev, 449static void read_in_urb_mode3(struct snd_usb_caiaqdev *cdev,
442 const struct urb *urb, 450 const struct urb *urb,
443 const struct usb_iso_packet_descriptor *iso) 451 const struct usb_iso_packet_descriptor *iso)
444{ 452{
445 unsigned char *usb_buf = urb->transfer_buffer + iso->offset; 453 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
454 struct device *dev = caiaqdev_to_dev(cdev);
446 int stream, i; 455 int stream, i;
447 456
448 /* paranoia check */ 457 /* paranoia check */
@@ -450,12 +459,12 @@ static void read_in_urb_mode3(struct snd_usb_caiaqdev *dev,
450 return; 459 return;
451 460
452 for (i = 0; i < iso->actual_length;) { 461 for (i = 0; i < iso->actual_length;) {
453 for (stream = 0; stream < dev->n_streams; stream++) { 462 for (stream = 0; stream < cdev->n_streams; stream++) {
454 struct snd_pcm_substream *sub = dev->sub_capture[stream]; 463 struct snd_pcm_substream *sub = cdev->sub_capture[stream];
455 char *audio_buf = NULL; 464 char *audio_buf = NULL;
456 int c, n, sz = 0; 465 int c, n, sz = 0;
457 466
458 if (sub && !dev->input_panic) { 467 if (sub && !cdev->input_panic) {
459 struct snd_pcm_runtime *rt = sub->runtime; 468 struct snd_pcm_runtime *rt = sub->runtime;
460 audio_buf = rt->dma_area; 469 audio_buf = rt->dma_area;
461 sz = frames_to_bytes(rt, rt->buffer_size); 470 sz = frames_to_bytes(rt, rt->buffer_size);
@@ -465,23 +474,23 @@ static void read_in_urb_mode3(struct snd_usb_caiaqdev *dev,
465 /* 3 audio data bytes, followed by 1 check byte */ 474 /* 3 audio data bytes, followed by 1 check byte */
466 if (audio_buf) { 475 if (audio_buf) {
467 for (n = 0; n < BYTES_PER_SAMPLE; n++) { 476 for (n = 0; n < BYTES_PER_SAMPLE; n++) {
468 audio_buf[dev->audio_in_buf_pos[stream]++] = usb_buf[i+n]; 477 audio_buf[cdev->audio_in_buf_pos[stream]++] = usb_buf[i+n];
469 478
470 if (dev->audio_in_buf_pos[stream] == sz) 479 if (cdev->audio_in_buf_pos[stream] == sz)
471 dev->audio_in_buf_pos[stream] = 0; 480 cdev->audio_in_buf_pos[stream] = 0;
472 } 481 }
473 482
474 dev->period_in_count[stream] += BYTES_PER_SAMPLE; 483 cdev->period_in_count[stream] += BYTES_PER_SAMPLE;
475 } 484 }
476 485
477 i += BYTES_PER_SAMPLE; 486 i += BYTES_PER_SAMPLE;
478 487
479 if (usb_buf[i] != ((stream << 1) | c) && 488 if (usb_buf[i] != ((stream << 1) | c) &&
480 !dev->first_packet) { 489 !cdev->first_packet) {
481 if (!dev->input_panic) 490 if (!cdev->input_panic)
482 printk(" EXPECTED: %02x got %02x, c %d, stream %d, i %d\n", 491 dev_warn(dev, " EXPECTED: %02x got %02x, c %d, stream %d, i %d\n",
483 ((stream << 1) | c), usb_buf[i], c, stream, i); 492 ((stream << 1) | c), usb_buf[i], c, stream, i);
484 dev->input_panic = 1; 493 cdev->input_panic = 1;
485 } 494 }
486 495
487 i++; 496 i++;
@@ -489,41 +498,43 @@ static void read_in_urb_mode3(struct snd_usb_caiaqdev *dev,
489 } 498 }
490 } 499 }
491 500
492 if (dev->first_packet > 0) 501 if (cdev->first_packet > 0)
493 dev->first_packet--; 502 cdev->first_packet--;
494} 503}
495 504
496static void read_in_urb(struct snd_usb_caiaqdev *dev, 505static void read_in_urb(struct snd_usb_caiaqdev *cdev,
497 const struct urb *urb, 506 const struct urb *urb,
498 const struct usb_iso_packet_descriptor *iso) 507 const struct usb_iso_packet_descriptor *iso)
499{ 508{
500 if (!dev->streaming) 509 struct device *dev = caiaqdev_to_dev(cdev);
510
511 if (!cdev->streaming)
501 return; 512 return;
502 513
503 if (iso->actual_length < dev->bpp) 514 if (iso->actual_length < cdev->bpp)
504 return; 515 return;
505 516
506 switch (dev->spec.data_alignment) { 517 switch (cdev->spec.data_alignment) {
507 case 0: 518 case 0:
508 read_in_urb_mode0(dev, urb, iso); 519 read_in_urb_mode0(cdev, urb, iso);
509 break; 520 break;
510 case 2: 521 case 2:
511 read_in_urb_mode2(dev, urb, iso); 522 read_in_urb_mode2(cdev, urb, iso);
512 break; 523 break;
513 case 3: 524 case 3:
514 read_in_urb_mode3(dev, urb, iso); 525 read_in_urb_mode3(cdev, urb, iso);
515 break; 526 break;
516 } 527 }
517 528
518 if ((dev->input_panic || dev->output_panic) && !dev->warned) { 529 if ((cdev->input_panic || cdev->output_panic) && !cdev->warned) {
519 debug("streaming error detected %s %s\n", 530 dev_warn(dev, "streaming error detected %s %s\n",
520 dev->input_panic ? "(input)" : "", 531 cdev->input_panic ? "(input)" : "",
521 dev->output_panic ? "(output)" : ""); 532 cdev->output_panic ? "(output)" : "");
522 dev->warned = 1; 533 cdev->warned = 1;
523 } 534 }
524} 535}
525 536
526static void fill_out_urb_mode_0(struct snd_usb_caiaqdev *dev, 537static void fill_out_urb_mode_0(struct snd_usb_caiaqdev *cdev,
527 struct urb *urb, 538 struct urb *urb,
528 const struct usb_iso_packet_descriptor *iso) 539 const struct usb_iso_packet_descriptor *iso)
529{ 540{
@@ -532,32 +543,32 @@ static void fill_out_urb_mode_0(struct snd_usb_caiaqdev *dev,
532 int stream, i; 543 int stream, i;
533 544
534 for (i = 0; i < iso->length;) { 545 for (i = 0; i < iso->length;) {
535 for (stream = 0; stream < dev->n_streams; stream++, i++) { 546 for (stream = 0; stream < cdev->n_streams; stream++, i++) {
536 sub = dev->sub_playback[stream]; 547 sub = cdev->sub_playback[stream];
537 if (sub) { 548 if (sub) {
538 struct snd_pcm_runtime *rt = sub->runtime; 549 struct snd_pcm_runtime *rt = sub->runtime;
539 char *audio_buf = rt->dma_area; 550 char *audio_buf = rt->dma_area;
540 int sz = frames_to_bytes(rt, rt->buffer_size); 551 int sz = frames_to_bytes(rt, rt->buffer_size);
541 usb_buf[i] = 552 usb_buf[i] =
542 audio_buf[dev->audio_out_buf_pos[stream]]; 553 audio_buf[cdev->audio_out_buf_pos[stream]];
543 dev->period_out_count[stream]++; 554 cdev->period_out_count[stream]++;
544 dev->audio_out_buf_pos[stream]++; 555 cdev->audio_out_buf_pos[stream]++;
545 if (dev->audio_out_buf_pos[stream] == sz) 556 if (cdev->audio_out_buf_pos[stream] == sz)
546 dev->audio_out_buf_pos[stream] = 0; 557 cdev->audio_out_buf_pos[stream] = 0;
547 } else 558 } else
548 usb_buf[i] = 0; 559 usb_buf[i] = 0;
549 } 560 }
550 561
551 /* fill in the check bytes */ 562 /* fill in the check bytes */
552 if (dev->spec.data_alignment == 2 && 563 if (cdev->spec.data_alignment == 2 &&
553 i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 564 i % (cdev->n_streams * BYTES_PER_SAMPLE_USB) ==
554 (dev->n_streams * CHANNELS_PER_STREAM)) 565 (cdev->n_streams * CHANNELS_PER_STREAM))
555 for (stream = 0; stream < dev->n_streams; stream++, i++) 566 for (stream = 0; stream < cdev->n_streams; stream++, i++)
556 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i); 567 usb_buf[i] = MAKE_CHECKBYTE(cdev, stream, i);
557 } 568 }
558} 569}
559 570
560static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *dev, 571static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *cdev,
561 struct urb *urb, 572 struct urb *urb,
562 const struct usb_iso_packet_descriptor *iso) 573 const struct usb_iso_packet_descriptor *iso)
563{ 574{
@@ -565,8 +576,8 @@ static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *dev,
565 int stream, i; 576 int stream, i;
566 577
567 for (i = 0; i < iso->length;) { 578 for (i = 0; i < iso->length;) {
568 for (stream = 0; stream < dev->n_streams; stream++) { 579 for (stream = 0; stream < cdev->n_streams; stream++) {
569 struct snd_pcm_substream *sub = dev->sub_playback[stream]; 580 struct snd_pcm_substream *sub = cdev->sub_playback[stream];
570 char *audio_buf = NULL; 581 char *audio_buf = NULL;
571 int c, n, sz = 0; 582 int c, n, sz = 0;
572 583
@@ -579,17 +590,17 @@ static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *dev,
579 for (c = 0; c < CHANNELS_PER_STREAM; c++) { 590 for (c = 0; c < CHANNELS_PER_STREAM; c++) {
580 for (n = 0; n < BYTES_PER_SAMPLE; n++) { 591 for (n = 0; n < BYTES_PER_SAMPLE; n++) {
581 if (audio_buf) { 592 if (audio_buf) {
582 usb_buf[i+n] = audio_buf[dev->audio_out_buf_pos[stream]++]; 593 usb_buf[i+n] = audio_buf[cdev->audio_out_buf_pos[stream]++];
583 594
584 if (dev->audio_out_buf_pos[stream] == sz) 595 if (cdev->audio_out_buf_pos[stream] == sz)
585 dev->audio_out_buf_pos[stream] = 0; 596 cdev->audio_out_buf_pos[stream] = 0;
586 } else { 597 } else {
587 usb_buf[i+n] = 0; 598 usb_buf[i+n] = 0;
588 } 599 }
589 } 600 }
590 601
591 if (audio_buf) 602 if (audio_buf)
592 dev->period_out_count[stream] += BYTES_PER_SAMPLE; 603 cdev->period_out_count[stream] += BYTES_PER_SAMPLE;
593 604
594 i += BYTES_PER_SAMPLE; 605 i += BYTES_PER_SAMPLE;
595 606
@@ -600,17 +611,17 @@ static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *dev,
600 } 611 }
601} 612}
602 613
603static inline void fill_out_urb(struct snd_usb_caiaqdev *dev, 614static inline void fill_out_urb(struct snd_usb_caiaqdev *cdev,
604 struct urb *urb, 615 struct urb *urb,
605 const struct usb_iso_packet_descriptor *iso) 616 const struct usb_iso_packet_descriptor *iso)
606{ 617{
607 switch (dev->spec.data_alignment) { 618 switch (cdev->spec.data_alignment) {
608 case 0: 619 case 0:
609 case 2: 620 case 2:
610 fill_out_urb_mode_0(dev, urb, iso); 621 fill_out_urb_mode_0(cdev, urb, iso);
611 break; 622 break;
612 case 3: 623 case 3:
613 fill_out_urb_mode_3(dev, urb, iso); 624 fill_out_urb_mode_3(cdev, urb, iso);
614 break; 625 break;
615 } 626 }
616} 627}
@@ -618,7 +629,8 @@ static inline void fill_out_urb(struct snd_usb_caiaqdev *dev,
618static void read_completed(struct urb *urb) 629static void read_completed(struct urb *urb)
619{ 630{
620 struct snd_usb_caiaq_cb_info *info = urb->context; 631 struct snd_usb_caiaq_cb_info *info = urb->context;
621 struct snd_usb_caiaqdev *dev; 632 struct snd_usb_caiaqdev *cdev;
633 struct device *dev;
622 struct urb *out = NULL; 634 struct urb *out = NULL;
623 int i, frame, len, send_it = 0, outframe = 0; 635 int i, frame, len, send_it = 0, outframe = 0;
624 size_t offset = 0; 636 size_t offset = 0;
@@ -626,20 +638,21 @@ static void read_completed(struct urb *urb)
626 if (urb->status || !info) 638 if (urb->status || !info)
627 return; 639 return;
628 640
629 dev = info->dev; 641 cdev = info->cdev;
642 dev = caiaqdev_to_dev(cdev);
630 643
631 if (!dev->streaming) 644 if (!cdev->streaming)
632 return; 645 return;
633 646
634 /* find an unused output urb that is unused */ 647 /* find an unused output urb that is unused */
635 for (i = 0; i < N_URBS; i++) 648 for (i = 0; i < N_URBS; i++)
636 if (test_and_set_bit(i, &dev->outurb_active_mask) == 0) { 649 if (test_and_set_bit(i, &cdev->outurb_active_mask) == 0) {
637 out = dev->data_urbs_out[i]; 650 out = cdev->data_urbs_out[i];
638 break; 651 break;
639 } 652 }
640 653
641 if (!out) { 654 if (!out) {
642 log("Unable to find an output urb to use\n"); 655 dev_err(dev, "Unable to find an output urb to use\n");
643 goto requeue; 656 goto requeue;
644 } 657 }
645 658
@@ -656,12 +669,12 @@ static void read_completed(struct urb *urb)
656 offset += len; 669 offset += len;
657 670
658 if (len > 0) { 671 if (len > 0) {
659 spin_lock(&dev->spinlock); 672 spin_lock(&cdev->spinlock);
660 fill_out_urb(dev, out, &out->iso_frame_desc[outframe]); 673 fill_out_urb(cdev, out, &out->iso_frame_desc[outframe]);
661 read_in_urb(dev, urb, &urb->iso_frame_desc[frame]); 674 read_in_urb(cdev, urb, &urb->iso_frame_desc[frame]);
662 spin_unlock(&dev->spinlock); 675 spin_unlock(&cdev->spinlock);
663 check_for_elapsed_periods(dev, dev->sub_playback); 676 check_for_elapsed_periods(cdev, cdev->sub_playback);
664 check_for_elapsed_periods(dev, dev->sub_capture); 677 check_for_elapsed_periods(cdev, cdev->sub_capture);
665 send_it = 1; 678 send_it = 1;
666 } 679 }
667 680
@@ -674,7 +687,7 @@ static void read_completed(struct urb *urb)
674 usb_submit_urb(out, GFP_ATOMIC); 687 usb_submit_urb(out, GFP_ATOMIC);
675 } else { 688 } else {
676 struct snd_usb_caiaq_cb_info *oinfo = out->context; 689 struct snd_usb_caiaq_cb_info *oinfo = out->context;
677 clear_bit(oinfo->index, &dev->outurb_active_mask); 690 clear_bit(oinfo->index, &cdev->outurb_active_mask);
678 } 691 }
679 692
680requeue: 693requeue:
@@ -693,21 +706,22 @@ requeue:
693static void write_completed(struct urb *urb) 706static void write_completed(struct urb *urb)
694{ 707{
695 struct snd_usb_caiaq_cb_info *info = urb->context; 708 struct snd_usb_caiaq_cb_info *info = urb->context;
696 struct snd_usb_caiaqdev *dev = info->dev; 709 struct snd_usb_caiaqdev *cdev = info->cdev;
697 710
698 if (!dev->output_running) { 711 if (!cdev->output_running) {
699 dev->output_running = 1; 712 cdev->output_running = 1;
700 wake_up(&dev->prepare_wait_queue); 713 wake_up(&cdev->prepare_wait_queue);
701 } 714 }
702 715
703 clear_bit(info->index, &dev->outurb_active_mask); 716 clear_bit(info->index, &cdev->outurb_active_mask);
704} 717}
705 718
706static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret) 719static struct urb **alloc_urbs(struct snd_usb_caiaqdev *cdev, int dir, int *ret)
707{ 720{
708 int i, frame; 721 int i, frame;
709 struct urb **urbs; 722 struct urb **urbs;
710 struct usb_device *usb_dev = dev->chip.dev; 723 struct usb_device *usb_dev = cdev->chip.dev;
724 struct device *dev = caiaqdev_to_dev(cdev);
711 unsigned int pipe; 725 unsigned int pipe;
712 726
713 pipe = (dir == SNDRV_PCM_STREAM_PLAYBACK) ? 727 pipe = (dir == SNDRV_PCM_STREAM_PLAYBACK) ?
@@ -716,7 +730,7 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
716 730
717 urbs = kmalloc(N_URBS * sizeof(*urbs), GFP_KERNEL); 731 urbs = kmalloc(N_URBS * sizeof(*urbs), GFP_KERNEL);
718 if (!urbs) { 732 if (!urbs) {
719 log("unable to kmalloc() urbs, OOM!?\n"); 733 dev_err(dev, "unable to kmalloc() urbs, OOM!?\n");
720 *ret = -ENOMEM; 734 *ret = -ENOMEM;
721 return NULL; 735 return NULL;
722 } 736 }
@@ -724,7 +738,7 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
724 for (i = 0; i < N_URBS; i++) { 738 for (i = 0; i < N_URBS; i++) {
725 urbs[i] = usb_alloc_urb(FRAMES_PER_URB, GFP_KERNEL); 739 urbs[i] = usb_alloc_urb(FRAMES_PER_URB, GFP_KERNEL);
726 if (!urbs[i]) { 740 if (!urbs[i]) {
727 log("unable to usb_alloc_urb(), OOM!?\n"); 741 dev_err(dev, "unable to usb_alloc_urb(), OOM!?\n");
728 *ret = -ENOMEM; 742 *ret = -ENOMEM;
729 return urbs; 743 return urbs;
730 } 744 }
@@ -732,7 +746,7 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
732 urbs[i]->transfer_buffer = 746 urbs[i]->transfer_buffer =
733 kmalloc(FRAMES_PER_URB * BYTES_PER_FRAME, GFP_KERNEL); 747 kmalloc(FRAMES_PER_URB * BYTES_PER_FRAME, GFP_KERNEL);
734 if (!urbs[i]->transfer_buffer) { 748 if (!urbs[i]->transfer_buffer) {
735 log("unable to kmalloc() transfer buffer, OOM!?\n"); 749 dev_err(dev, "unable to kmalloc() transfer buffer, OOM!?\n");
736 *ret = -ENOMEM; 750 *ret = -ENOMEM;
737 return urbs; 751 return urbs;
738 } 752 }
@@ -749,7 +763,7 @@ static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
749 urbs[i]->pipe = pipe; 763 urbs[i]->pipe = pipe;
750 urbs[i]->transfer_buffer_length = FRAMES_PER_URB 764 urbs[i]->transfer_buffer_length = FRAMES_PER_URB
751 * BYTES_PER_FRAME; 765 * BYTES_PER_FRAME;
752 urbs[i]->context = &dev->data_cb_info[i]; 766 urbs[i]->context = &cdev->data_cb_info[i];
753 urbs[i]->interval = 1; 767 urbs[i]->interval = 1;
754 urbs[i]->transfer_flags = URB_ISO_ASAP; 768 urbs[i]->transfer_flags = URB_ISO_ASAP;
755 urbs[i]->number_of_packets = FRAMES_PER_URB; 769 urbs[i]->number_of_packets = FRAMES_PER_URB;
@@ -780,110 +794,113 @@ static void free_urbs(struct urb **urbs)
780 kfree(urbs); 794 kfree(urbs);
781} 795}
782 796
783int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev) 797int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *cdev)
784{ 798{
785 int i, ret; 799 int i, ret;
800 struct device *dev = caiaqdev_to_dev(cdev);
786 801
787 dev->n_audio_in = max(dev->spec.num_analog_audio_in, 802 cdev->n_audio_in = max(cdev->spec.num_analog_audio_in,
788 dev->spec.num_digital_audio_in) / 803 cdev->spec.num_digital_audio_in) /
789 CHANNELS_PER_STREAM; 804 CHANNELS_PER_STREAM;
790 dev->n_audio_out = max(dev->spec.num_analog_audio_out, 805 cdev->n_audio_out = max(cdev->spec.num_analog_audio_out,
791 dev->spec.num_digital_audio_out) / 806 cdev->spec.num_digital_audio_out) /
792 CHANNELS_PER_STREAM; 807 CHANNELS_PER_STREAM;
793 dev->n_streams = max(dev->n_audio_in, dev->n_audio_out); 808 cdev->n_streams = max(cdev->n_audio_in, cdev->n_audio_out);
794 809
795 debug("dev->n_audio_in = %d\n", dev->n_audio_in); 810 dev_dbg(dev, "cdev->n_audio_in = %d\n", cdev->n_audio_in);
796 debug("dev->n_audio_out = %d\n", dev->n_audio_out); 811 dev_dbg(dev, "cdev->n_audio_out = %d\n", cdev->n_audio_out);
797 debug("dev->n_streams = %d\n", dev->n_streams); 812 dev_dbg(dev, "cdev->n_streams = %d\n", cdev->n_streams);
798 813
799 if (dev->n_streams > MAX_STREAMS) { 814 if (cdev->n_streams > MAX_STREAMS) {
800 log("unable to initialize device, too many streams.\n"); 815 dev_err(dev, "unable to initialize device, too many streams.\n");
801 return -EINVAL; 816 return -EINVAL;
802 } 817 }
803 818
804 ret = snd_pcm_new(dev->chip.card, dev->product_name, 0, 819 ret = snd_pcm_new(cdev->chip.card, cdev->product_name, 0,
805 dev->n_audio_out, dev->n_audio_in, &dev->pcm); 820 cdev->n_audio_out, cdev->n_audio_in, &cdev->pcm);
806 821
807 if (ret < 0) { 822 if (ret < 0) {
808 log("snd_pcm_new() returned %d\n", ret); 823 dev_err(dev, "snd_pcm_new() returned %d\n", ret);
809 return ret; 824 return ret;
810 } 825 }
811 826
812 dev->pcm->private_data = dev; 827 cdev->pcm->private_data = cdev;
813 strlcpy(dev->pcm->name, dev->product_name, sizeof(dev->pcm->name)); 828 strlcpy(cdev->pcm->name, cdev->product_name, sizeof(cdev->pcm->name));
814 829
815 memset(dev->sub_playback, 0, sizeof(dev->sub_playback)); 830 memset(cdev->sub_playback, 0, sizeof(cdev->sub_playback));
816 memset(dev->sub_capture, 0, sizeof(dev->sub_capture)); 831 memset(cdev->sub_capture, 0, sizeof(cdev->sub_capture));
817 832
818 memcpy(&dev->pcm_info, &snd_usb_caiaq_pcm_hardware, 833 memcpy(&cdev->pcm_info, &snd_usb_caiaq_pcm_hardware,
819 sizeof(snd_usb_caiaq_pcm_hardware)); 834 sizeof(snd_usb_caiaq_pcm_hardware));
820 835
821 /* setup samplerates */ 836 /* setup samplerates */
822 dev->samplerates = dev->pcm_info.rates; 837 cdev->samplerates = cdev->pcm_info.rates;
823 switch (dev->chip.usb_id) { 838 switch (cdev->chip.usb_id) {
824 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): 839 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
825 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): 840 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
826 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_SESSIONIO): 841 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_SESSIONIO):
827 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_GUITARRIGMOBILE): 842 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_GUITARRIGMOBILE):
828 dev->samplerates |= SNDRV_PCM_RATE_192000; 843 cdev->samplerates |= SNDRV_PCM_RATE_192000;
829 /* fall thru */ 844 /* fall thru */
830 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO2DJ): 845 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO2DJ):
831 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ): 846 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
832 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ): 847 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
833 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORAUDIO2): 848 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORAUDIO2):
834 dev->samplerates |= SNDRV_PCM_RATE_88200; 849 cdev->samplerates |= SNDRV_PCM_RATE_88200;
835 break; 850 break;
836 } 851 }
837 852
838 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_PLAYBACK, 853 snd_pcm_set_ops(cdev->pcm, SNDRV_PCM_STREAM_PLAYBACK,
839 &snd_usb_caiaq_ops); 854 &snd_usb_caiaq_ops);
840 snd_pcm_set_ops(dev->pcm, SNDRV_PCM_STREAM_CAPTURE, 855 snd_pcm_set_ops(cdev->pcm, SNDRV_PCM_STREAM_CAPTURE,
841 &snd_usb_caiaq_ops); 856 &snd_usb_caiaq_ops);
842 857
843 snd_pcm_lib_preallocate_pages_for_all(dev->pcm, 858 snd_pcm_lib_preallocate_pages_for_all(cdev->pcm,
844 SNDRV_DMA_TYPE_CONTINUOUS, 859 SNDRV_DMA_TYPE_CONTINUOUS,
845 snd_dma_continuous_data(GFP_KERNEL), 860 snd_dma_continuous_data(GFP_KERNEL),
846 MAX_BUFFER_SIZE, MAX_BUFFER_SIZE); 861 MAX_BUFFER_SIZE, MAX_BUFFER_SIZE);
847 862
848 dev->data_cb_info = 863 cdev->data_cb_info =
849 kmalloc(sizeof(struct snd_usb_caiaq_cb_info) * N_URBS, 864 kmalloc(sizeof(struct snd_usb_caiaq_cb_info) * N_URBS,
850 GFP_KERNEL); 865 GFP_KERNEL);
851 866
852 if (!dev->data_cb_info) 867 if (!cdev->data_cb_info)
853 return -ENOMEM; 868 return -ENOMEM;
854 869
855 dev->outurb_active_mask = 0; 870 cdev->outurb_active_mask = 0;
856 BUILD_BUG_ON(N_URBS > (sizeof(dev->outurb_active_mask) * 8)); 871 BUILD_BUG_ON(N_URBS > (sizeof(cdev->outurb_active_mask) * 8));
857 872
858 for (i = 0; i < N_URBS; i++) { 873 for (i = 0; i < N_URBS; i++) {
859 dev->data_cb_info[i].dev = dev; 874 cdev->data_cb_info[i].cdev = cdev;
860 dev->data_cb_info[i].index = i; 875 cdev->data_cb_info[i].index = i;
861 } 876 }
862 877
863 dev->data_urbs_in = alloc_urbs(dev, SNDRV_PCM_STREAM_CAPTURE, &ret); 878 cdev->data_urbs_in = alloc_urbs(cdev, SNDRV_PCM_STREAM_CAPTURE, &ret);
864 if (ret < 0) { 879 if (ret < 0) {
865 kfree(dev->data_cb_info); 880 kfree(cdev->data_cb_info);
866 free_urbs(dev->data_urbs_in); 881 free_urbs(cdev->data_urbs_in);
867 return ret; 882 return ret;
868 } 883 }
869 884
870 dev->data_urbs_out = alloc_urbs(dev, SNDRV_PCM_STREAM_PLAYBACK, &ret); 885 cdev->data_urbs_out = alloc_urbs(cdev, SNDRV_PCM_STREAM_PLAYBACK, &ret);
871 if (ret < 0) { 886 if (ret < 0) {
872 kfree(dev->data_cb_info); 887 kfree(cdev->data_cb_info);
873 free_urbs(dev->data_urbs_in); 888 free_urbs(cdev->data_urbs_in);
874 free_urbs(dev->data_urbs_out); 889 free_urbs(cdev->data_urbs_out);
875 return ret; 890 return ret;
876 } 891 }
877 892
878 return 0; 893 return 0;
879} 894}
880 895
881void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *dev) 896void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *cdev)
882{ 897{
883 debug("%s(%p)\n", __func__, dev); 898 struct device *dev = caiaqdev_to_dev(cdev);
884 stream_stop(dev); 899
885 free_urbs(dev->data_urbs_in); 900 dev_dbg(dev, "%s(%p)\n", __func__, cdev);
886 free_urbs(dev->data_urbs_out); 901 stream_stop(cdev);
887 kfree(dev->data_cb_info); 902 free_urbs(cdev->data_urbs_in);
903 free_urbs(cdev->data_urbs_out);
904 kfree(cdev->data_cb_info);
888} 905}
889 906