em28xx-core.c 16 KB

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