]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/media/video/em28xx/em28xx-core.c
V4L/DVB (7607): CodingStyle fixes
[linux-2.6-omap-h63xx.git] / drivers / media / video / em28xx / em28xx-core.c
1 /*
2    em28xx-core.c - driver for Empia EM2800/EM2820/2840 USB video capture devices
3
4    Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
5                       Markus Rechberger <mrechberger@gmail.com>
6                       Mauro Carvalho Chehab <mchehab@infradead.org>
7                       Sascha Sommer <saschasommer@freenet.de>
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #include <linux/init.h>
25 #include <linux/list.h>
26 #include <linux/module.h>
27 #include <linux/usb.h>
28 #include <linux/vmalloc.h>
29
30 #include "em28xx.h"
31
32 /* #define ENABLE_DEBUG_ISOC_FRAMES */
33
34 static unsigned int core_debug;
35 module_param(core_debug,int,0644);
36 MODULE_PARM_DESC(core_debug,"enable debug messages [core]");
37
38 #define em28xx_coredbg(fmt, arg...) do {\
39         if (core_debug) \
40                 printk(KERN_INFO "%s %s :"fmt, \
41                          dev->name, __func__ , ##arg); } while (0)
42
43 static unsigned int reg_debug;
44 module_param(reg_debug,int,0644);
45 MODULE_PARM_DESC(reg_debug,"enable debug messages [URB reg]");
46
47 #define em28xx_regdbg(fmt, arg...) do {\
48         if (reg_debug) \
49                 printk(KERN_INFO "%s %s :"fmt, \
50                          dev->name, __func__ , ##arg); } while (0)
51
52 static int alt = EM28XX_PINOUT;
53 module_param(alt, int, 0644);
54 MODULE_PARM_DESC(alt, "alternate setting to use for video endpoint");
55
56 /* FIXME */
57 #define em28xx_isocdbg(fmt, arg...) do {\
58         if (core_debug) \
59                 printk(KERN_INFO "%s %s :"fmt, \
60                          dev->name, __func__ , ##arg); } while (0)
61
62 /*
63  * em28xx_read_reg_req()
64  * reads data from the usb device specifying bRequest
65  */
66 int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
67                                    char *buf, int len)
68 {
69         int ret, byte;
70
71         if (dev->state & DEV_DISCONNECTED)
72                 return(-ENODEV);
73
74         em28xx_regdbg("req=%02x, reg=%02x ", req, reg);
75
76         ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), req,
77                               USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
78                               0x0000, reg, buf, len, HZ);
79
80         if (reg_debug) {
81                 printk(ret < 0 ? " failed!\n" : "%02x values: ", ret);
82                 for (byte = 0; byte < len; byte++)
83                         printk(KERN_INFO " %02x", (unsigned char)buf[byte]);
84
85                 printk(KERN_INFO "\n");
86         }
87
88         return ret;
89 }
90
91 /*
92  * em28xx_read_reg_req()
93  * reads data from the usb device specifying bRequest
94  */
95 int em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg)
96 {
97         u8 val;
98         int ret;
99
100         if (dev->state & DEV_DISCONNECTED)
101                 return(-ENODEV);
102
103         em28xx_regdbg("req=%02x, reg=%02x:", req, reg);
104
105         ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), req,
106                               USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
107                               0x0000, reg, &val, 1, HZ);
108
109         if (reg_debug)
110                 printk(ret < 0 ? " failed!\n" :
111                                  "%02x\n", (unsigned char) val);
112
113         if (ret < 0)
114                 return ret;
115
116         return val;
117 }
118
119 int em28xx_read_reg(struct em28xx *dev, u16 reg)
120 {
121         return em28xx_read_reg_req(dev, USB_REQ_GET_STATUS, reg);
122 }
123
124 /*
125  * em28xx_write_regs_req()
126  * sends data to the usb device, specifying bRequest
127  */
128 int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
129                                  int len)
130 {
131         int ret;
132
133         /*usb_control_msg seems to expect a kmalloced buffer */
134         unsigned char *bufs;
135
136         if (dev->state & DEV_DISCONNECTED)
137                 return(-ENODEV);
138
139         bufs = kmalloc(len, GFP_KERNEL);
140
141         em28xx_regdbg("req=%02x reg=%02x:", req, reg);
142
143         if (reg_debug) {
144                 int i;
145                 for (i = 0; i < len; ++i)
146                         printk(KERN_INFO " %02x", (unsigned char)buf[i]);
147                 printk(KERN_INFO "\n");
148         }
149
150         if (!bufs)
151                 return -ENOMEM;
152         memcpy(bufs, buf, len);
153         ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), req,
154                               USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
155                               0x0000, reg, bufs, len, HZ);
156         msleep(5);              /* FIXME: magic number */
157         kfree(bufs);
158         return ret;
159 }
160
161 int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len)
162 {
163         return em28xx_write_regs_req(dev, USB_REQ_GET_STATUS, reg, buf, len);
164 }
165
166 /*
167  * em28xx_write_reg_bits()
168  * sets only some bits (specified by bitmask) of a register, by first reading
169  * the actual value
170  */
171 static int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
172                                  u8 bitmask)
173 {
174         int oldval;
175         u8 newval;
176
177         oldval = em28xx_read_reg(dev, reg);
178
179         if (oldval < 0)
180                 return oldval;
181
182         newval = (((u8) oldval) & ~bitmask) | (val & bitmask);
183         return em28xx_write_regs(dev, reg, &newval, 1);
184 }
185
186 /*
187  * em28xx_write_ac97()
188  * write a 16 bit value to the specified AC97 address (LSB first!)
189  */
190 static int em28xx_write_ac97(struct em28xx *dev, u8 reg, u8 *val)
191 {
192         int ret, i;
193         u8 addr = reg & 0x7f;
194
195         ret = em28xx_write_regs(dev, AC97LSB_REG, val, 2);
196         if (ret < 0)
197                 return ret;
198
199         ret = em28xx_write_regs(dev, AC97ADDR_REG, &addr, 1);
200         if (ret < 0)
201                 return ret;
202
203         /* Wait up to 50 ms for AC97 command to complete */
204         for (i = 0; i < 10; i++) {
205                 ret = em28xx_read_reg(dev, AC97BUSY_REG);
206                 if (ret < 0)
207                         return ret;
208
209                 if (!(ret & 0x01))
210                         return 0;
211                 msleep(5);
212         }
213         em28xx_warn("AC97 command still being executed: not handled properly!\n");
214         return 0;
215 }
216
217 static int em28xx_set_audio_source(struct em28xx *dev)
218 {
219         static char *enable  = "\x08\x08";
220         static char *disable = "\x08\x88";
221         char *video = enable, *line = disable;
222         int ret;
223         u8 input;
224
225         if (dev->is_em2800) {
226                 if (dev->ctl_ainput)
227                         input = EM2800_AUDIO_SRC_LINE;
228                 else
229                         input = EM2800_AUDIO_SRC_TUNER;
230
231                 ret = em28xx_write_regs(dev, EM2800_AUDIOSRC_REG, &input, 1);
232                 if (ret < 0)
233                         return ret;
234         }
235
236         if (dev->has_msp34xx)
237                 input = EM28XX_AUDIO_SRC_TUNER;
238         else {
239                 switch (dev->ctl_ainput) {
240                 case EM28XX_AMUX_VIDEO:
241                         input = EM28XX_AUDIO_SRC_TUNER;
242                         break;
243                 case EM28XX_AMUX_LINE_IN:
244                         input = EM28XX_AUDIO_SRC_LINE;
245                         break;
246                 case EM28XX_AMUX_AC97_VIDEO:
247                         input = EM28XX_AUDIO_SRC_LINE;
248                         break;
249                 case EM28XX_AMUX_AC97_LINE_IN:
250                         input = EM28XX_AUDIO_SRC_LINE;
251                         video = disable;
252                         line  = enable;
253                         break;
254                 }
255         }
256
257         ret = em28xx_write_reg_bits(dev, AUDIOSRC_REG, input, 0xc0);
258         if (ret < 0)
259                 return ret;
260         msleep(5);
261
262         /* Sets AC97 mixer registers
263            This is seems to be needed, even for non-ac97 configs
264          */
265         ret = em28xx_write_ac97(dev, VIDEO_AC97, video);
266         if (ret < 0)
267                 return ret;
268
269         ret = em28xx_write_ac97(dev, LINE_IN_AC97, line);
270
271         return ret;
272 }
273
274 int em28xx_audio_analog_set(struct em28xx *dev)
275 {
276         int ret;
277         char s[2] = { 0x00, 0x00 };
278         u8 xclk = 0x07;
279
280         s[0] |= 0x1f - dev->volume;
281         s[1] |= 0x1f - dev->volume;
282
283         /* Mute */
284         s[1] |= 0x80;
285         ret = em28xx_write_ac97(dev, MASTER_AC97, s);
286
287         if (ret < 0)
288                 return ret;
289
290         if (dev->has_12mhz_i2s)
291                 xclk |= 0x20;
292
293         if (!dev->mute)
294                 xclk |= 0x80;
295
296         ret = em28xx_write_reg_bits(dev, XCLK_REG, xclk, 0xa7);
297         if (ret < 0)
298                 return ret;
299         msleep(10);
300
301         /* Selects the proper audio input */
302         ret = em28xx_set_audio_source(dev);
303
304         /* Unmute device */
305         if (!dev->mute)
306                 s[1] &= ~0x80;
307         ret = em28xx_write_ac97(dev, MASTER_AC97, s);
308
309         return ret;
310 }
311 EXPORT_SYMBOL_GPL(em28xx_audio_analog_set);
312
313 int em28xx_colorlevels_set_default(struct em28xx *dev)
314 {
315         em28xx_write_regs(dev, YGAIN_REG, "\x10", 1);   /* contrast */
316         em28xx_write_regs(dev, YOFFSET_REG, "\x00", 1); /* brightness */
317         em28xx_write_regs(dev, UVGAIN_REG, "\x10", 1);  /* saturation */
318         em28xx_write_regs(dev, UOFFSET_REG, "\x00", 1);
319         em28xx_write_regs(dev, VOFFSET_REG, "\x00", 1);
320         em28xx_write_regs(dev, SHARPNESS_REG, "\x00", 1);
321
322         em28xx_write_regs(dev, GAMMA_REG, "\x20", 1);
323         em28xx_write_regs(dev, RGAIN_REG, "\x20", 1);
324         em28xx_write_regs(dev, GGAIN_REG, "\x20", 1);
325         em28xx_write_regs(dev, BGAIN_REG, "\x20", 1);
326         em28xx_write_regs(dev, ROFFSET_REG, "\x00", 1);
327         em28xx_write_regs(dev, GOFFSET_REG, "\x00", 1);
328         return em28xx_write_regs(dev, BOFFSET_REG, "\x00", 1);
329 }
330
331 int em28xx_capture_start(struct em28xx *dev, int start)
332 {
333         int rc;
334         /* FIXME: which is the best order? */
335         /* video registers are sampled by VREF */
336         rc = em28xx_write_reg_bits(dev, USBSUSP_REG,
337                                    start ? 0x10 : 0x00, 0x10);
338         if (rc < 0)
339                 return rc;
340
341         if (!start) {
342                 /* disable video capture */
343                 rc = em28xx_write_regs(dev, VINENABLE_REG, "\x27", 1);
344                 return rc;
345         }
346
347         /* enable video capture */
348         rc = em28xx_write_regs_req(dev, 0x00, 0x48, "\x00", 1);
349
350         if (dev->mode == EM28XX_ANALOG_MODE)
351                 rc = em28xx_write_regs(dev, VINENABLE_REG, "\x67", 1);
352         else
353                 rc = em28xx_write_regs(dev, VINENABLE_REG, "\x37", 1);
354
355         msleep(6);
356
357         return rc;
358 }
359
360 int em28xx_outfmt_set_yuv422(struct em28xx *dev)
361 {
362         em28xx_write_regs(dev, OUTFMT_REG, "\x34", 1);
363         em28xx_write_regs(dev, VINMODE_REG, "\x10", 1);
364         return em28xx_write_regs(dev, VINCTRL_REG, "\x11", 1);
365 }
366
367 static int em28xx_accumulator_set(struct em28xx *dev, u8 xmin, u8 xmax,
368                                   u8 ymin, u8 ymax)
369 {
370         em28xx_coredbg("em28xx Scale: (%d,%d)-(%d,%d)\n",
371                         xmin, ymin, xmax, ymax);
372
373         em28xx_write_regs(dev, XMIN_REG, &xmin, 1);
374         em28xx_write_regs(dev, XMAX_REG, &xmax, 1);
375         em28xx_write_regs(dev, YMIN_REG, &ymin, 1);
376         return em28xx_write_regs(dev, YMAX_REG, &ymax, 1);
377 }
378
379 static int em28xx_capture_area_set(struct em28xx *dev, u8 hstart, u8 vstart,
380                                    u16 width, u16 height)
381 {
382         u8 cwidth = width;
383         u8 cheight = height;
384         u8 overflow = (height >> 7 & 0x02) | (width >> 8 & 0x01);
385
386         em28xx_coredbg("em28xx Area Set: (%d,%d)\n",
387                         (width | (overflow & 2) << 7),
388                         (height | (overflow & 1) << 8));
389
390         em28xx_write_regs(dev, HSTART_REG, &hstart, 1);
391         em28xx_write_regs(dev, VSTART_REG, &vstart, 1);
392         em28xx_write_regs(dev, CWIDTH_REG, &cwidth, 1);
393         em28xx_write_regs(dev, CHEIGHT_REG, &cheight, 1);
394         return em28xx_write_regs(dev, OFLOW_REG, &overflow, 1);
395 }
396
397 static int em28xx_scaler_set(struct em28xx *dev, u16 h, u16 v)
398 {
399         u8 mode;
400         /* the em2800 scaler only supports scaling down to 50% */
401         if (dev->is_em2800)
402                 mode = (v ? 0x20 : 0x00) | (h ? 0x10 : 0x00);
403         else {
404                 u8 buf[2];
405                 buf[0] = h;
406                 buf[1] = h >> 8;
407                 em28xx_write_regs(dev, HSCALELOW_REG, (char *)buf, 2);
408                 buf[0] = v;
409                 buf[1] = v >> 8;
410                 em28xx_write_regs(dev, VSCALELOW_REG, (char *)buf, 2);
411                 /* it seems that both H and V scalers must be active
412                    to work correctly */
413                 mode = (h || v)? 0x30: 0x00;
414         }
415         return em28xx_write_reg_bits(dev, COMPR_REG, mode, 0x30);
416 }
417
418 /* FIXME: this only function read values from dev */
419 int em28xx_resolution_set(struct em28xx *dev)
420 {
421         int width, height;
422         width = norm_maxw(dev);
423         height = norm_maxh(dev) >> 1;
424
425         em28xx_outfmt_set_yuv422(dev);
426         em28xx_accumulator_set(dev, 1, (width - 4) >> 2, 1, (height - 4) >> 2);
427         em28xx_capture_area_set(dev, 0, 0, width >> 2, height >> 2);
428         return em28xx_scaler_set(dev, dev->hscale, dev->vscale);
429 }
430
431 int em28xx_set_alternate(struct em28xx *dev)
432 {
433         int errCode, prev_alt = dev->alt;
434         int i;
435         unsigned int min_pkt_size = dev->width * 2 + 4;
436
437         /* When image size is bigger than a certain value,
438            the frame size should be increased, otherwise, only
439            green screen will be received.
440          */
441         if (dev->width * 2 * dev->height > 720 * 240 * 2)
442                 min_pkt_size *= 2;
443
444         for (i = 0; i < dev->num_alt; i++) {
445                 /* stop when the selected alt setting offers enough bandwidth */
446                 if (dev->alt_max_pkt_size[i] >= min_pkt_size) {
447                         dev->alt = i;
448                         break;
449                 /* otherwise make sure that we end up with the maximum bandwidth
450                    because the min_pkt_size equation might be wrong...
451                 */
452                 } else if (dev->alt_max_pkt_size[i] >
453                            dev->alt_max_pkt_size[dev->alt])
454                         dev->alt = i;
455         }
456
457         if (dev->alt != prev_alt) {
458                 em28xx_coredbg("minimum isoc packet size: %u (alt=%d)\n",
459                                 min_pkt_size, dev->alt);
460                 dev->max_pkt_size = dev->alt_max_pkt_size[dev->alt];
461                 em28xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n",
462                                dev->alt, dev->max_pkt_size);
463                 errCode = usb_set_interface(dev->udev, 0, dev->alt);
464                 if (errCode < 0) {
465                         em28xx_errdev("cannot change alternate number to %d (error=%i)\n",
466                                         dev->alt, errCode);
467                         return errCode;
468                 }
469         }
470         return 0;
471 }
472
473 /* ------------------------------------------------------------------
474         URB control
475    ------------------------------------------------------------------*/
476
477 /*
478  * IRQ callback, called by URB callback
479  */
480 static void em28xx_irq_callback(struct urb *urb)
481 {
482         struct em28xx_dmaqueue  *dma_q = urb->context;
483         struct em28xx *dev = container_of(dma_q, struct em28xx, vidq);
484         int rc, i;
485
486         /* Copy data from URB */
487         spin_lock(&dev->slock);
488         rc = dev->isoc_ctl.isoc_copy(dev, urb);
489         spin_unlock(&dev->slock);
490
491         /* Reset urb buffers */
492         for (i = 0; i < urb->number_of_packets; i++) {
493                 urb->iso_frame_desc[i].status = 0;
494                 urb->iso_frame_desc[i].actual_length = 0;
495         }
496         urb->status = 0;
497
498         urb->status = usb_submit_urb(urb, GFP_ATOMIC);
499         if (urb->status) {
500                 em28xx_err("urb resubmit failed (error=%i)\n",
501                         urb->status);
502         }
503 }
504
505 /*
506  * Stop and Deallocate URBs
507  */
508 void em28xx_uninit_isoc(struct em28xx *dev)
509 {
510         struct urb *urb;
511         int i;
512
513         em28xx_isocdbg("em28xx: called em28xx_uninit_isoc\n");
514
515         dev->isoc_ctl.nfields = -1;
516         for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
517                 urb = dev->isoc_ctl.urb[i];
518                 if (urb) {
519                         usb_kill_urb(urb);
520                         usb_unlink_urb(urb);
521                         if (dev->isoc_ctl.transfer_buffer[i]) {
522                                 usb_buffer_free(dev->udev,
523                                         urb->transfer_buffer_length,
524                                         dev->isoc_ctl.transfer_buffer[i],
525                                         urb->transfer_dma);
526                         }
527                         usb_free_urb(urb);
528                         dev->isoc_ctl.urb[i] = NULL;
529                 }
530                 dev->isoc_ctl.transfer_buffer[i] = NULL;
531         }
532
533         kfree(dev->isoc_ctl.urb);
534         kfree(dev->isoc_ctl.transfer_buffer);
535
536         dev->isoc_ctl.urb = NULL;
537         dev->isoc_ctl.transfer_buffer = NULL;
538         dev->isoc_ctl.num_bufs = 0;
539
540         em28xx_capture_start(dev, 0);
541 }
542 EXPORT_SYMBOL_GPL(em28xx_uninit_isoc);
543
544 /*
545  * Allocate URBs and start IRQ
546  */
547 int em28xx_init_isoc(struct em28xx *dev, int max_packets,
548                      int num_bufs, int max_pkt_size,
549                      int (*isoc_copy) (struct em28xx *dev, struct urb *urb),
550                      int cap_type)
551 {
552         struct em28xx_dmaqueue *dma_q = &dev->vidq;
553         int i;
554         int sb_size, pipe;
555         struct urb *urb;
556         int j, k;
557         int rc;
558
559         em28xx_isocdbg("em28xx: called em28xx_prepare_isoc\n");
560
561         /* De-allocates all pending stuff */
562         em28xx_uninit_isoc(dev);
563
564         dev->isoc_ctl.isoc_copy = isoc_copy;
565         dev->isoc_ctl.num_bufs = num_bufs;
566
567         dev->isoc_ctl.urb = kzalloc(sizeof(void *)*num_bufs,  GFP_KERNEL);
568         if (!dev->isoc_ctl.urb) {
569                 em28xx_errdev("cannot alloc memory for usb buffers\n");
570                 return -ENOMEM;
571         }
572
573         dev->isoc_ctl.transfer_buffer = kzalloc(sizeof(void *)*num_bufs,
574                                               GFP_KERNEL);
575         if (!dev->isoc_ctl.urb) {
576                 em28xx_errdev("cannot allocate memory for usbtransfer\n");
577                 kfree(dev->isoc_ctl.urb);
578                 return -ENOMEM;
579         }
580
581         dev->isoc_ctl.max_pkt_size = max_pkt_size;
582         dev->isoc_ctl.buf = NULL;
583
584         sb_size = max_packets * dev->isoc_ctl.max_pkt_size;
585
586         /* allocate urbs and transfer buffers */
587         for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
588                 urb = usb_alloc_urb(max_packets, GFP_KERNEL);
589                 if (!urb) {
590                         em28xx_err("cannot alloc isoc_ctl.urb %i\n", i);
591                         em28xx_uninit_isoc(dev);
592                         return -ENOMEM;
593                 }
594                 dev->isoc_ctl.urb[i] = urb;
595
596                 dev->isoc_ctl.transfer_buffer[i] = usb_buffer_alloc(dev->udev,
597                         sb_size, GFP_KERNEL, &urb->transfer_dma);
598                 if (!dev->isoc_ctl.transfer_buffer[i]) {
599                         em28xx_err("unable to allocate %i bytes for transfer"
600                                         " buffer %i%s\n",
601                                         sb_size, i,
602                                         in_interrupt()?" while in int":"");
603                         em28xx_uninit_isoc(dev);
604                         return -ENOMEM;
605                 }
606                 memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size);
607
608                 /* FIXME: this is a hack - should be
609                         'desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK'
610                         should also be using 'desc.bInterval'
611                  */
612                 pipe = usb_rcvisocpipe(dev->udev,
613                         cap_type == EM28XX_ANALOG_CAPTURE ? 0x82 : 0x84);
614
615                 usb_fill_int_urb(urb, dev->udev, pipe,
616                                  dev->isoc_ctl.transfer_buffer[i], sb_size,
617                                  em28xx_irq_callback, dma_q, 1);
618
619                 urb->number_of_packets = max_packets;
620                 urb->transfer_flags = URB_ISO_ASAP;
621
622                 k = 0;
623                 for (j = 0; j < max_packets; j++) {
624                         urb->iso_frame_desc[j].offset = k;
625                         urb->iso_frame_desc[j].length =
626                                                 dev->isoc_ctl.max_pkt_size;
627                         k += dev->isoc_ctl.max_pkt_size;
628                 }
629         }
630
631         init_waitqueue_head(&dma_q->wq);
632
633         em28xx_capture_start(dev, cap_type);
634
635         /* submit urbs and enables IRQ */
636         for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
637                 rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
638                 if (rc) {
639                         em28xx_err("submit of urb %i failed (error=%i)\n", i,
640                                    rc);
641                         em28xx_uninit_isoc(dev);
642                         return rc;
643                 }
644         }
645
646         return 0;
647 }
648 EXPORT_SYMBOL_GPL(em28xx_init_isoc);