blob: e6ca631e3f799e02c4e14c36ad6fbc78ed093fff [file] [log] [blame]
Markus Grabner705ecec2009-02-27 19:43:04 -08001/*
Markus Grabnere1a164d2010-08-23 01:08:25 +02002 * Line6 Linux USB driver - 0.9.1beta
Markus Grabner705ecec2009-02-27 19:43:04 -08003 *
Markus Grabner1027f4762010-08-12 01:35:30 +02004 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
Markus Grabner705ecec2009-02-27 19:43:04 -08005 *
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
Stefan Hajnoczi140e28b2011-11-23 08:20:45 +000012#include <linux/slab.h>
Markus Grabner705ecec2009-02-27 19:43:04 -080013#include <sound/core.h>
14#include <sound/pcm.h>
15#include <sound/pcm_params.h>
16
17#include "audio.h"
Markus Grabner1027f4762010-08-12 01:35:30 +020018#include "capture.h"
19#include "driver.h"
Markus Grabner705ecec2009-02-27 19:43:04 -080020#include "pcm.h"
21#include "pod.h"
Markus Grabner1027f4762010-08-12 01:35:30 +020022
Markus Grabner705ecec2009-02-27 19:43:04 -080023/*
24 Find a free URB and submit it.
25*/
Markus Grabner1027f4762010-08-12 01:35:30 +020026static int submit_audio_in_urb(struct snd_line6_pcm *line6pcm)
Markus Grabner705ecec2009-02-27 19:43:04 -080027{
Markus Grabner1027f4762010-08-12 01:35:30 +020028 int index;
Markus Grabner705ecec2009-02-27 19:43:04 -080029 unsigned long flags;
Markus Grabner705ecec2009-02-27 19:43:04 -080030 int i, urb_size;
Markus Grabnere1a164d2010-08-23 01:08:25 +020031 int ret;
Markus Grabner705ecec2009-02-27 19:43:04 -080032 struct urb *urb_in;
33
34 spin_lock_irqsave(&line6pcm->lock_audio_in, flags);
Shawn Bohrere0645d62009-11-15 22:17:52 -060035 index =
36 find_first_zero_bit(&line6pcm->active_urb_in, LINE6_ISO_BUFFERS);
Markus Grabner705ecec2009-02-27 19:43:04 -080037
Markus Grabner1027f4762010-08-12 01:35:30 +020038 if (index < 0 || index >= LINE6_ISO_BUFFERS) {
Markus Grabner705ecec2009-02-27 19:43:04 -080039 spin_unlock_irqrestore(&line6pcm->lock_audio_in, flags);
Markus Grabner1027f4762010-08-12 01:35:30 +020040 dev_err(line6pcm->line6->ifcdev, "no free URB found\n");
Markus Grabner705ecec2009-02-27 19:43:04 -080041 return -EINVAL;
42 }
43
44 urb_in = line6pcm->urb_audio_in[index];
45 urb_size = 0;
46
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -080047 for (i = 0; i < LINE6_ISO_PACKETS; ++i) {
Shawn Bohrere0645d62009-11-15 22:17:52 -060048 struct usb_iso_packet_descriptor *fin =
49 &urb_in->iso_frame_desc[i];
Markus Grabner705ecec2009-02-27 19:43:04 -080050 fin->offset = urb_size;
51 fin->length = line6pcm->max_packet_size;
52 urb_size += line6pcm->max_packet_size;
53 }
54
Shawn Bohrere0645d62009-11-15 22:17:52 -060055 urb_in->transfer_buffer =
56 line6pcm->buffer_in +
57 index * LINE6_ISO_PACKETS * line6pcm->max_packet_size;
Markus Grabner705ecec2009-02-27 19:43:04 -080058 urb_in->transfer_buffer_length = urb_size;
Markus Grabner1027f4762010-08-12 01:35:30 +020059 urb_in->context = line6pcm;
Markus Grabner705ecec2009-02-27 19:43:04 -080060
Markus Grabnere1a164d2010-08-23 01:08:25 +020061 ret = usb_submit_urb(urb_in, GFP_ATOMIC);
62
63 if (ret == 0)
Markus Grabner705ecec2009-02-27 19:43:04 -080064 set_bit(index, &line6pcm->active_urb_in);
65 else
Markus Grabner1027f4762010-08-12 01:35:30 +020066 dev_err(line6pcm->line6->ifcdev,
Markus Grabnere1a164d2010-08-23 01:08:25 +020067 "URB in #%d submission failed (%d)\n", index, ret);
Markus Grabner705ecec2009-02-27 19:43:04 -080068
69 spin_unlock_irqrestore(&line6pcm->lock_audio_in, flags);
70 return 0;
71}
72
73/*
74 Submit all currently available capture URBs.
75*/
Markus Grabner1027f4762010-08-12 01:35:30 +020076int line6_submit_audio_in_all_urbs(struct snd_line6_pcm *line6pcm)
Markus Grabner705ecec2009-02-27 19:43:04 -080077{
78 int ret, i;
79
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -080080 for (i = 0; i < LINE6_ISO_BUFFERS; ++i) {
Markus Grabner1027f4762010-08-12 01:35:30 +020081 ret = submit_audio_in_urb(line6pcm);
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -080082 if (ret < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -080083 return ret;
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -080084 }
Markus Grabner705ecec2009-02-27 19:43:04 -080085
86 return 0;
87}
88
89/*
90 Unlink all currently active capture URBs.
91*/
Markus Grabner1027f4762010-08-12 01:35:30 +020092void line6_unlink_audio_in_urbs(struct snd_line6_pcm *line6pcm)
Markus Grabner705ecec2009-02-27 19:43:04 -080093{
94 unsigned int i;
95
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -080096 for (i = LINE6_ISO_BUFFERS; i--;) {
97 if (test_bit(i, &line6pcm->active_urb_in)) {
98 if (!test_and_set_bit(i, &line6pcm->unlink_urb_in)) {
Markus Grabner705ecec2009-02-27 19:43:04 -080099 struct urb *u = line6pcm->urb_audio_in[i];
Jerry Snitselaarf3c52612014-04-24 00:31:48 -0700100
Markus Grabner705ecec2009-02-27 19:43:04 -0800101 usb_unlink_urb(u);
102 }
103 }
104 }
105}
106
107/*
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800108 Wait until unlinking of all currently active capture URBs has been
109 finished.
Markus Grabner705ecec2009-02-27 19:43:04 -0800110*/
Markus Grabner0ca54882012-01-20 00:09:09 +0100111void line6_wait_clear_audio_in_urbs(struct snd_line6_pcm *line6pcm)
Markus Grabner705ecec2009-02-27 19:43:04 -0800112{
113 int timeout = HZ;
114 unsigned int i;
115 int alive;
116
117 do {
118 alive = 0;
119 for (i = LINE6_ISO_BUFFERS; i--;) {
120 if (test_bit(i, &line6pcm->active_urb_in))
121 alive++;
122 }
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800123 if (!alive)
Markus Grabner705ecec2009-02-27 19:43:04 -0800124 break;
125 set_current_state(TASK_UNINTERRUPTIBLE);
126 schedule_timeout(1);
127 } while (--timeout > 0);
128 if (alive)
129 snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive);
Markus Grabner705ecec2009-02-27 19:43:04 -0800130}
131
132/*
133 Unlink all currently active capture URBs, and wait for finishing.
134*/
Markus Grabner1027f4762010-08-12 01:35:30 +0200135void line6_unlink_wait_clear_audio_in_urbs(struct snd_line6_pcm *line6pcm)
Markus Grabner705ecec2009-02-27 19:43:04 -0800136{
Markus Grabner1027f4762010-08-12 01:35:30 +0200137 line6_unlink_audio_in_urbs(line6pcm);
Markus Grabner0ca54882012-01-20 00:09:09 +0100138 line6_wait_clear_audio_in_urbs(line6pcm);
Markus Grabner705ecec2009-02-27 19:43:04 -0800139}
140
141/*
Markus Grabner1027f4762010-08-12 01:35:30 +0200142 Copy data into ALSA capture buffer.
143*/
144void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, int fsize)
145{
146 struct snd_pcm_substream *substream =
147 get_substream(line6pcm, SNDRV_PCM_STREAM_CAPTURE);
148 struct snd_pcm_runtime *runtime = substream->runtime;
149 const int bytes_per_frame = line6pcm->properties->bytes_per_frame;
150 int frames = fsize / bytes_per_frame;
151
Peter Huewe597a1e72010-12-07 23:38:02 +0100152 if (runtime == NULL)
Markus Grabnerc7fcf252010-09-17 23:33:25 +0200153 return;
154
Markus Grabner1027f4762010-08-12 01:35:30 +0200155 if (line6pcm->pos_in_done + frames > runtime->buffer_size) {
156 /*
Markus Grabnere1a164d2010-08-23 01:08:25 +0200157 The transferred area goes over buffer boundary,
158 copy two separate chunks.
159 */
Markus Grabner1027f4762010-08-12 01:35:30 +0200160 int len;
Mikhail Boikob5f87cf2014-03-18 23:59:46 +0200161
Markus Grabner1027f4762010-08-12 01:35:30 +0200162 len = runtime->buffer_size - line6pcm->pos_in_done;
163
164 if (len > 0) {
165 memcpy(runtime->dma_area +
166 line6pcm->pos_in_done * bytes_per_frame, fbuf,
167 len * bytes_per_frame);
168 memcpy(runtime->dma_area, fbuf + len * bytes_per_frame,
169 (frames - len) * bytes_per_frame);
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -0700170 } else {
171 /* this is somewhat paranoid */
172 dev_err(line6pcm->line6->ifcdev,
173 "driver bug: len = %d\n", len);
174 }
Markus Grabner1027f4762010-08-12 01:35:30 +0200175 } else {
176 /* copy single chunk */
177 memcpy(runtime->dma_area +
178 line6pcm->pos_in_done * bytes_per_frame, fbuf, fsize);
179 }
180
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -0700181 line6pcm->pos_in_done += frames;
182 if (line6pcm->pos_in_done >= runtime->buffer_size)
Markus Grabner1027f4762010-08-12 01:35:30 +0200183 line6pcm->pos_in_done -= runtime->buffer_size;
184}
185
186void line6_capture_check_period(struct snd_line6_pcm *line6pcm, int length)
187{
188 struct snd_pcm_substream *substream =
189 get_substream(line6pcm, SNDRV_PCM_STREAM_CAPTURE);
190
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -0700191 line6pcm->bytes_in += length;
192 if (line6pcm->bytes_in >= line6pcm->period_in) {
Markus Grabner1027f4762010-08-12 01:35:30 +0200193 line6pcm->bytes_in %= line6pcm->period_in;
194 snd_pcm_period_elapsed(substream);
195 }
196}
197
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100198void line6_free_capture_buffer(struct snd_line6_pcm *line6pcm)
199{
200 kfree(line6pcm->buffer_in);
201 line6pcm->buffer_in = NULL;
202}
203
Markus Grabner1027f4762010-08-12 01:35:30 +0200204/*
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -0700205 * Callback for completed capture URB.
206 */
Greg Kroah-Hartman0c7ab152009-02-27 20:28:04 -0800207static void audio_in_callback(struct urb *urb)
Markus Grabner705ecec2009-02-27 19:43:04 -0800208{
209 int i, index, length = 0, shutdown = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800210 unsigned long flags;
211
Markus Grabner1027f4762010-08-12 01:35:30 +0200212 struct snd_line6_pcm *line6pcm = (struct snd_line6_pcm *)urb->context;
213
214 line6pcm->last_frame_in = urb->start_frame;
Markus Grabner705ecec2009-02-27 19:43:04 -0800215
216 /* find index of URB */
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800217 for (index = 0; index < LINE6_ISO_BUFFERS; ++index)
218 if (urb == line6pcm->urb_audio_in[index])
Markus Grabner705ecec2009-02-27 19:43:04 -0800219 break;
220
Markus Grabner705ecec2009-02-27 19:43:04 -0800221 spin_lock_irqsave(&line6pcm->lock_audio_in, flags);
222
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800223 for (i = 0; i < LINE6_ISO_PACKETS; ++i) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800224 char *fbuf;
225 int fsize;
226 struct usb_iso_packet_descriptor *fin = &urb->iso_frame_desc[i];
227
Markus Grabnere1a164d2010-08-23 01:08:25 +0200228 if (fin->status == -EXDEV) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800229 shutdown = 1;
230 break;
231 }
232
233 fbuf = urb->transfer_buffer + fin->offset;
234 fsize = fin->actual_length;
Markus Grabner1027f4762010-08-12 01:35:30 +0200235
236 if (fsize > line6pcm->max_packet_size) {
237 dev_err(line6pcm->line6->ifcdev,
238 "driver and/or device bug: packet too large (%d > %d)\n",
239 fsize, line6pcm->max_packet_size);
240 }
241
Markus Grabner705ecec2009-02-27 19:43:04 -0800242 length += fsize;
243
Markus Grabner1027f4762010-08-12 01:35:30 +0200244 /* the following assumes LINE6_ISO_PACKETS == 1: */
Markus Grabner1027f4762010-08-12 01:35:30 +0200245 line6pcm->prev_fbuf = fbuf;
Markus Grabner1027f4762010-08-12 01:35:30 +0200246 line6pcm->prev_fsize = fsize;
Markus Grabner705ecec2009-02-27 19:43:04 -0800247
Markus Grabner1027f4762010-08-12 01:35:30 +0200248#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
Markus Grabner0ca54882012-01-20 00:09:09 +0100249 if (!(line6pcm->flags & LINE6_BITS_PCM_IMPULSE))
Markus Grabner1027f4762010-08-12 01:35:30 +0200250#endif
Stefan Hajnoczia71cac22012-11-11 13:24:39 +0100251 if (test_bit(LINE6_INDEX_PCM_ALSA_CAPTURE_STREAM,
252 &line6pcm->flags) && (fsize > 0))
Markus Grabner1027f4762010-08-12 01:35:30 +0200253 line6_capture_copy(line6pcm, fbuf, fsize);
Markus Grabner705ecec2009-02-27 19:43:04 -0800254 }
255
256 clear_bit(index, &line6pcm->active_urb_in);
257
Markus Grabner1027f4762010-08-12 01:35:30 +0200258 if (test_and_clear_bit(index, &line6pcm->unlink_urb_in))
Markus Grabner705ecec2009-02-27 19:43:04 -0800259 shutdown = 1;
260
261 spin_unlock_irqrestore(&line6pcm->lock_audio_in, flags);
262
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800263 if (!shutdown) {
Markus Grabner1027f4762010-08-12 01:35:30 +0200264 submit_audio_in_urb(line6pcm);
Markus Grabner705ecec2009-02-27 19:43:04 -0800265
Markus Grabnere1a164d2010-08-23 01:08:25 +0200266#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
Markus Grabner0ca54882012-01-20 00:09:09 +0100267 if (!(line6pcm->flags & LINE6_BITS_PCM_IMPULSE))
Markus Grabnere1a164d2010-08-23 01:08:25 +0200268#endif
Stefan Hajnoczia71cac22012-11-11 13:24:39 +0100269 if (test_bit(LINE6_INDEX_PCM_ALSA_CAPTURE_STREAM,
270 &line6pcm->flags))
Markus Grabnere1a164d2010-08-23 01:08:25 +0200271 line6_capture_check_period(line6pcm, length);
Markus Grabner705ecec2009-02-27 19:43:04 -0800272 }
273}
274
275/* open capture callback */
276static int snd_line6_capture_open(struct snd_pcm_substream *substream)
277{
278 int err;
279 struct snd_pcm_runtime *runtime = substream->runtime;
280 struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
281
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800282 err = snd_pcm_hw_constraint_ratdens(runtime, 0,
283 SNDRV_PCM_HW_PARAM_RATE,
Markus Grabnere1a164d2010-08-23 01:08:25 +0200284 (&line6pcm->
285 properties->snd_line6_rates));
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800286 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800287 return err;
288
289 runtime->hw = line6pcm->properties->snd_line6_capture_hw;
290 return 0;
291}
292
293/* close capture callback */
294static int snd_line6_capture_close(struct snd_pcm_substream *substream)
295{
296 return 0;
297}
298
299/* hw_params capture callback */
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800300static int snd_line6_capture_hw_params(struct snd_pcm_substream *substream,
301 struct snd_pcm_hw_params *hw_params)
Markus Grabner705ecec2009-02-27 19:43:04 -0800302{
303 int ret;
304 struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
305
306 /* -- Florian Demski [FD] */
307 /* don't ask me why, but this fixes the bug on my machine */
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800308 if (line6pcm == NULL) {
309 if (substream->pcm == NULL)
Markus Grabner705ecec2009-02-27 19:43:04 -0800310 return -ENOMEM;
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800311 if (substream->pcm->private_data == NULL)
Markus Grabner705ecec2009-02-27 19:43:04 -0800312 return -ENOMEM;
313 substream->private_data = substream->pcm->private_data;
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800314 line6pcm = snd_pcm_substream_chip(substream);
Markus Grabner705ecec2009-02-27 19:43:04 -0800315 }
316 /* -- [FD] end */
317
Markus Grabner0ca54882012-01-20 00:09:09 +0100318 ret = line6_pcm_acquire(line6pcm, LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER);
Stefan Hajnoczi140e28b2011-11-23 08:20:45 +0000319
Markus Grabner0ca54882012-01-20 00:09:09 +0100320 if (ret < 0)
321 return ret;
Stefan Hajnoczi140e28b2011-11-23 08:20:45 +0000322
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800323 ret = snd_pcm_lib_malloc_pages(substream,
324 params_buffer_bytes(hw_params));
Markus Grabner0ca54882012-01-20 00:09:09 +0100325 if (ret < 0) {
326 line6_pcm_release(line6pcm, LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER);
Markus Grabner705ecec2009-02-27 19:43:04 -0800327 return ret;
Markus Grabner0ca54882012-01-20 00:09:09 +0100328 }
Markus Grabner705ecec2009-02-27 19:43:04 -0800329
330 line6pcm->period_in = params_period_bytes(hw_params);
Markus Grabner705ecec2009-02-27 19:43:04 -0800331 return 0;
332}
333
334/* hw_free capture callback */
335static int snd_line6_capture_hw_free(struct snd_pcm_substream *substream)
336{
Stefan Hajnoczi140e28b2011-11-23 08:20:45 +0000337 struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
Jerry Snitselaarf3c52612014-04-24 00:31:48 -0700338
Markus Grabner0ca54882012-01-20 00:09:09 +0100339 line6_pcm_release(line6pcm, LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER);
Markus Grabner705ecec2009-02-27 19:43:04 -0800340 return snd_pcm_lib_free_pages(substream);
341}
342
343/* trigger callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200344int snd_line6_capture_trigger(struct snd_line6_pcm *line6pcm, int cmd)
Markus Grabner705ecec2009-02-27 19:43:04 -0800345{
Markus Grabner705ecec2009-02-27 19:43:04 -0800346 int err;
Markus Grabner705ecec2009-02-27 19:43:04 -0800347
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800348 switch (cmd) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800349 case SNDRV_PCM_TRIGGER_START:
Markus Grabner1027f4762010-08-12 01:35:30 +0200350#ifdef CONFIG_PM
351 case SNDRV_PCM_TRIGGER_RESUME:
352#endif
Stefan Hajnoczia71cac22012-11-11 13:24:39 +0100353 err = line6_pcm_acquire(line6pcm,
354 LINE6_BIT_PCM_ALSA_CAPTURE_STREAM);
Markus Grabner705ecec2009-02-27 19:43:04 -0800355
Markus Grabner1027f4762010-08-12 01:35:30 +0200356 if (err < 0)
357 return err;
Markus Grabner705ecec2009-02-27 19:43:04 -0800358
359 break;
360
361 case SNDRV_PCM_TRIGGER_STOP:
Markus Grabner1027f4762010-08-12 01:35:30 +0200362#ifdef CONFIG_PM
363 case SNDRV_PCM_TRIGGER_SUSPEND:
364#endif
Stefan Hajnoczia71cac22012-11-11 13:24:39 +0100365 err = line6_pcm_release(line6pcm,
366 LINE6_BIT_PCM_ALSA_CAPTURE_STREAM);
Markus Grabner1027f4762010-08-12 01:35:30 +0200367
368 if (err < 0)
369 return err;
Markus Grabner705ecec2009-02-27 19:43:04 -0800370
371 break;
372
373 default:
374 return -EINVAL;
375 }
376
377 return 0;
378}
379
380/* capture pointer callback */
381static snd_pcm_uframes_t
382snd_line6_capture_pointer(struct snd_pcm_substream *substream)
383{
384 struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
Jerry Snitselaarf3c52612014-04-24 00:31:48 -0700385
Markus Grabner705ecec2009-02-27 19:43:04 -0800386 return line6pcm->pos_in_done;
387}
388
389/* capture operators */
390struct snd_pcm_ops snd_line6_capture_ops = {
Markus Grabnere1a164d2010-08-23 01:08:25 +0200391 .open = snd_line6_capture_open,
392 .close = snd_line6_capture_close,
393 .ioctl = snd_pcm_lib_ioctl,
394 .hw_params = snd_line6_capture_hw_params,
395 .hw_free = snd_line6_capture_hw_free,
396 .prepare = snd_line6_prepare,
397 .trigger = snd_line6_trigger,
398 .pointer = snd_line6_capture_pointer,
Markus Grabner705ecec2009-02-27 19:43:04 -0800399};
400
Markus Grabner1027f4762010-08-12 01:35:30 +0200401int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm)
Markus Grabner705ecec2009-02-27 19:43:04 -0800402{
403 int i;
404
405 /* create audio URBs and fill in constant values: */
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800406 for (i = 0; i < LINE6_ISO_BUFFERS; ++i) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800407 struct urb *urb;
408
409 /* URB for audio in: */
Shawn Bohrere0645d62009-11-15 22:17:52 -0600410 urb = line6pcm->urb_audio_in[i] =
411 usb_alloc_urb(LINE6_ISO_PACKETS, GFP_KERNEL);
Markus Grabner705ecec2009-02-27 19:43:04 -0800412
Greg Kroah-Hartman6efc5662009-02-27 22:39:22 -0800413 if (urb == NULL) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800414 dev_err(line6pcm->line6->ifcdev, "Out of memory\n");
415 return -ENOMEM;
416 }
417
418 urb->dev = line6pcm->line6->usbdev;
Shawn Bohrere0645d62009-11-15 22:17:52 -0600419 urb->pipe =
420 usb_rcvisocpipe(line6pcm->line6->usbdev,
Markus Grabnere1a164d2010-08-23 01:08:25 +0200421 line6pcm->ep_audio_read &
422 USB_ENDPOINT_NUMBER_MASK);
Markus Grabner705ecec2009-02-27 19:43:04 -0800423 urb->transfer_flags = URB_ISO_ASAP;
424 urb->start_frame = -1;
425 urb->number_of_packets = LINE6_ISO_PACKETS;
426 urb->interval = LINE6_ISO_INTERVAL;
427 urb->error_count = 0;
428 urb->complete = audio_in_callback;
429 }
430
431 return 0;
432}