cpia_usb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * cpia_usb CPiA USB driver
  3. *
  4. * Supports CPiA based parallel port Video Camera's.
  5. *
  6. * Copyright (C) 1999 Jochen Scharrlach <Jochen.Scharrlach@schwaben.de>
  7. * Copyright (C) 1999, 2000 Johannes Erdfelt <johannes@erdfelt.com>
  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. /* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */
  24. /* #define _CPIA_DEBUG_ 1 */
  25. #include <linux/module.h>
  26. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <linux/wait.h>
  29. #include <linux/list.h>
  30. #include <linux/slab.h>
  31. #include <linux/vmalloc.h>
  32. #include <linux/usb.h>
  33. #include "cpia.h"
  34. #define USB_REQ_CPIA_GRAB_FRAME 0xC1
  35. #define USB_REQ_CPIA_UPLOAD_FRAME 0xC2
  36. #define WAIT_FOR_NEXT_FRAME 0
  37. #define FORCE_FRAME_UPLOAD 1
  38. #define FRAMES_PER_DESC 10
  39. #define FRAME_SIZE_PER_DESC 960 /* Shouldn't be hardcoded */
  40. #define CPIA_NUMSBUF 2
  41. #define STREAM_BUF_SIZE (PAGE_SIZE * 4)
  42. #define SCRATCH_BUF_SIZE (STREAM_BUF_SIZE * 2)
  43. struct cpia_sbuf {
  44. char *data;
  45. struct urb *urb;
  46. };
  47. #define FRAMEBUF_LEN (CPIA_MAX_FRAME_SIZE+100)
  48. enum framebuf_status {
  49. FRAME_EMPTY,
  50. FRAME_READING,
  51. FRAME_READY,
  52. FRAME_ERROR,
  53. };
  54. struct framebuf {
  55. int length;
  56. enum framebuf_status status;
  57. u8 data[FRAMEBUF_LEN];
  58. struct framebuf *next;
  59. };
  60. struct usb_cpia {
  61. /* Device structure */
  62. struct usb_device *dev;
  63. unsigned char iface;
  64. wait_queue_head_t wq_stream;
  65. int cursbuf; /* Current receiving sbuf */
  66. struct cpia_sbuf sbuf[CPIA_NUMSBUF]; /* Double buffering */
  67. int streaming;
  68. int open;
  69. int present;
  70. struct framebuf *buffers[3];
  71. struct framebuf *curbuff, *workbuff;
  72. };
  73. static int cpia_usb_open(void *privdata);
  74. static int cpia_usb_registerCallback(void *privdata, void (*cb) (void *cbdata),
  75. void *cbdata);
  76. static int cpia_usb_transferCmd(void *privdata, u8 *command, u8 *data);
  77. static int cpia_usb_streamStart(void *privdata);
  78. static int cpia_usb_streamStop(void *privdata);
  79. static int cpia_usb_streamRead(void *privdata, u8 *frame, int noblock);
  80. static int cpia_usb_close(void *privdata);
  81. #define ABOUT "USB driver for Vision CPiA based cameras"
  82. static struct cpia_camera_ops cpia_usb_ops = {
  83. cpia_usb_open,
  84. cpia_usb_registerCallback,
  85. cpia_usb_transferCmd,
  86. cpia_usb_streamStart,
  87. cpia_usb_streamStop,
  88. cpia_usb_streamRead,
  89. cpia_usb_close,
  90. 0,
  91. THIS_MODULE
  92. };
  93. static LIST_HEAD(cam_list);
  94. static spinlock_t cam_list_lock_usb;
  95. static void cpia_usb_complete(struct urb *urb, struct pt_regs *regs)
  96. {
  97. int i;
  98. char *cdata;
  99. struct usb_cpia *ucpia;
  100. if (!urb || !urb->context)
  101. return;
  102. ucpia = (struct usb_cpia *) urb->context;
  103. if (!ucpia->dev || !ucpia->streaming || !ucpia->present || !ucpia->open)
  104. return;
  105. if (ucpia->workbuff->status == FRAME_EMPTY) {
  106. ucpia->workbuff->status = FRAME_READING;
  107. ucpia->workbuff->length = 0;
  108. }
  109. for (i = 0; i < urb->number_of_packets; i++) {
  110. int n = urb->iso_frame_desc[i].actual_length;
  111. int st = urb->iso_frame_desc[i].status;
  112. cdata = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
  113. if (st)
  114. printk(KERN_DEBUG "cpia data error: [%d] len=%d, status=%X\n", i, n, st);
  115. if (FRAMEBUF_LEN < ucpia->workbuff->length + n) {
  116. printk(KERN_DEBUG "cpia: scratch buf overflow!scr_len: %d, n: %d\n", ucpia->workbuff->length, n);
  117. return;
  118. }
  119. if (n) {
  120. if ((ucpia->workbuff->length > 0) ||
  121. (0x19 == cdata[0] && 0x68 == cdata[1])) {
  122. memcpy(ucpia->workbuff->data + ucpia->workbuff->length, cdata, n);
  123. ucpia->workbuff->length += n;
  124. } else
  125. DBG("Ignoring packet!\n");
  126. } else {
  127. if (ucpia->workbuff->length > 4 &&
  128. 0xff == ucpia->workbuff->data[ucpia->workbuff->length-1] &&
  129. 0xff == ucpia->workbuff->data[ucpia->workbuff->length-2] &&
  130. 0xff == ucpia->workbuff->data[ucpia->workbuff->length-3] &&
  131. 0xff == ucpia->workbuff->data[ucpia->workbuff->length-4]) {
  132. ucpia->workbuff->status = FRAME_READY;
  133. ucpia->curbuff = ucpia->workbuff;
  134. ucpia->workbuff = ucpia->workbuff->next;
  135. ucpia->workbuff->status = FRAME_EMPTY;
  136. ucpia->workbuff->length = 0;
  137. if (waitqueue_active(&ucpia->wq_stream))
  138. wake_up_interruptible(&ucpia->wq_stream);
  139. }
  140. }
  141. }
  142. /* resubmit */
  143. urb->dev = ucpia->dev;
  144. if ((i = usb_submit_urb(urb, GFP_ATOMIC)) != 0)
  145. printk(KERN_ERR "%s: usb_submit_urb ret %d\n", __FUNCTION__, i);
  146. }
  147. static int cpia_usb_open(void *privdata)
  148. {
  149. struct usb_cpia *ucpia = (struct usb_cpia *) privdata;
  150. struct urb *urb;
  151. int ret, retval = 0, fx, err;
  152. if (!ucpia)
  153. return -EINVAL;
  154. ucpia->sbuf[0].data = kmalloc(FRAMES_PER_DESC * FRAME_SIZE_PER_DESC, GFP_KERNEL);
  155. if (!ucpia->sbuf[0].data)
  156. return -EINVAL;
  157. ucpia->sbuf[1].data = kmalloc(FRAMES_PER_DESC * FRAME_SIZE_PER_DESC, GFP_KERNEL);
  158. if (!ucpia->sbuf[1].data) {
  159. retval = -EINVAL;
  160. goto error_0;
  161. }
  162. ret = usb_set_interface(ucpia->dev, ucpia->iface, 3);
  163. if (ret < 0) {
  164. printk(KERN_ERR "cpia_usb_open: usb_set_interface error (ret = %d)\n", ret);
  165. retval = -EBUSY;
  166. goto error_1;
  167. }
  168. ucpia->buffers[0]->status = FRAME_EMPTY;
  169. ucpia->buffers[0]->length = 0;
  170. ucpia->buffers[1]->status = FRAME_EMPTY;
  171. ucpia->buffers[1]->length = 0;
  172. ucpia->buffers[2]->status = FRAME_EMPTY;
  173. ucpia->buffers[2]->length = 0;
  174. ucpia->curbuff = ucpia->buffers[0];
  175. ucpia->workbuff = ucpia->buffers[1];
  176. /* We double buffer the Iso lists, and also know the polling
  177. * interval is every frame (1 == (1 << (bInterval -1))).
  178. */
  179. urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
  180. if (!urb) {
  181. printk(KERN_ERR "cpia_init_isoc: usb_alloc_urb 0\n");
  182. retval = -ENOMEM;
  183. goto error_1;
  184. }
  185. ucpia->sbuf[0].urb = urb;
  186. urb->dev = ucpia->dev;
  187. urb->context = ucpia;
  188. urb->pipe = usb_rcvisocpipe(ucpia->dev, 1);
  189. urb->transfer_flags = URB_ISO_ASAP;
  190. urb->transfer_buffer = ucpia->sbuf[0].data;
  191. urb->complete = cpia_usb_complete;
  192. urb->number_of_packets = FRAMES_PER_DESC;
  193. urb->interval = 1;
  194. urb->transfer_buffer_length = FRAME_SIZE_PER_DESC * FRAMES_PER_DESC;
  195. for (fx = 0; fx < FRAMES_PER_DESC; fx++) {
  196. urb->iso_frame_desc[fx].offset = FRAME_SIZE_PER_DESC * fx;
  197. urb->iso_frame_desc[fx].length = FRAME_SIZE_PER_DESC;
  198. }
  199. urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
  200. if (!urb) {
  201. printk(KERN_ERR "cpia_init_isoc: usb_alloc_urb 1\n");
  202. retval = -ENOMEM;
  203. goto error_urb0;
  204. }
  205. ucpia->sbuf[1].urb = urb;
  206. urb->dev = ucpia->dev;
  207. urb->context = ucpia;
  208. urb->pipe = usb_rcvisocpipe(ucpia->dev, 1);
  209. urb->transfer_flags = URB_ISO_ASAP;
  210. urb->transfer_buffer = ucpia->sbuf[1].data;
  211. urb->complete = cpia_usb_complete;
  212. urb->number_of_packets = FRAMES_PER_DESC;
  213. urb->interval = 1;
  214. urb->transfer_buffer_length = FRAME_SIZE_PER_DESC * FRAMES_PER_DESC;
  215. for (fx = 0; fx < FRAMES_PER_DESC; fx++) {
  216. urb->iso_frame_desc[fx].offset = FRAME_SIZE_PER_DESC * fx;
  217. urb->iso_frame_desc[fx].length = FRAME_SIZE_PER_DESC;
  218. }
  219. /* queue the ISO urbs, and resubmit in the completion handler */
  220. err = usb_submit_urb(ucpia->sbuf[0].urb, GFP_KERNEL);
  221. if (err) {
  222. printk(KERN_ERR "cpia_init_isoc: usb_submit_urb 0 ret %d\n",
  223. err);
  224. goto error_urb1;
  225. }
  226. err = usb_submit_urb(ucpia->sbuf[1].urb, GFP_KERNEL);
  227. if (err) {
  228. printk(KERN_ERR "cpia_init_isoc: usb_submit_urb 1 ret %d\n",
  229. err);
  230. goto error_urb1;
  231. }
  232. ucpia->streaming = 1;
  233. ucpia->open = 1;
  234. return 0;
  235. error_urb1: /* free urb 1 */
  236. usb_free_urb(ucpia->sbuf[1].urb);
  237. ucpia->sbuf[1].urb = NULL;
  238. error_urb0: /* free urb 0 */
  239. usb_free_urb(ucpia->sbuf[0].urb);
  240. ucpia->sbuf[0].urb = NULL;
  241. error_1:
  242. kfree (ucpia->sbuf[1].data);
  243. ucpia->sbuf[1].data = NULL;
  244. error_0:
  245. kfree (ucpia->sbuf[0].data);
  246. ucpia->sbuf[0].data = NULL;
  247. return retval;
  248. }
  249. //
  250. // convenience functions
  251. //
  252. /****************************************************************************
  253. *
  254. * WritePacket
  255. *
  256. ***************************************************************************/
  257. static int WritePacket(struct usb_device *udev, const u8 *packet, u8 *buf, size_t size)
  258. {
  259. if (!packet)
  260. return -EINVAL;
  261. return usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
  262. packet[1] + (packet[0] << 8),
  263. USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  264. packet[2] + (packet[3] << 8),
  265. packet[4] + (packet[5] << 8), buf, size, 1000);
  266. }
  267. /****************************************************************************
  268. *
  269. * ReadPacket
  270. *
  271. ***************************************************************************/
  272. static int ReadPacket(struct usb_device *udev, u8 *packet, u8 *buf, size_t size)
  273. {
  274. if (!packet || size <= 0)
  275. return -EINVAL;
  276. return usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  277. packet[1] + (packet[0] << 8),
  278. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  279. packet[2] + (packet[3] << 8),
  280. packet[4] + (packet[5] << 8), buf, size, 1000);
  281. }
  282. static int cpia_usb_transferCmd(void *privdata, u8 *command, u8 *data)
  283. {
  284. int err = 0;
  285. int databytes;
  286. struct usb_cpia *ucpia = (struct usb_cpia *)privdata;
  287. struct usb_device *udev = ucpia->dev;
  288. if (!udev) {
  289. DBG("Internal driver error: udev is NULL\n");
  290. return -EINVAL;
  291. }
  292. if (!command) {
  293. DBG("Internal driver error: command is NULL\n");
  294. return -EINVAL;
  295. }
  296. databytes = (((int)command[7])<<8) | command[6];
  297. if (command[0] == DATA_IN) {
  298. u8 buffer[8];
  299. if (!data) {
  300. DBG("Internal driver error: data is NULL\n");
  301. return -EINVAL;
  302. }
  303. err = ReadPacket(udev, command, buffer, 8);
  304. if (err < 0)
  305. return err;
  306. memcpy(data, buffer, databytes);
  307. } else if(command[0] == DATA_OUT)
  308. WritePacket(udev, command, data, databytes);
  309. else {
  310. DBG("Unexpected first byte of command: %x\n", command[0]);
  311. err = -EINVAL;
  312. }
  313. return 0;
  314. }
  315. static int cpia_usb_registerCallback(void *privdata, void (*cb) (void *cbdata),
  316. void *cbdata)
  317. {
  318. return -ENODEV;
  319. }
  320. static int cpia_usb_streamStart(void *privdata)
  321. {
  322. return -ENODEV;
  323. }
  324. static int cpia_usb_streamStop(void *privdata)
  325. {
  326. return -ENODEV;
  327. }
  328. static int cpia_usb_streamRead(void *privdata, u8 *frame, int noblock)
  329. {
  330. struct usb_cpia *ucpia = (struct usb_cpia *) privdata;
  331. struct framebuf *mybuff;
  332. if (!ucpia || !ucpia->present)
  333. return -1;
  334. if (ucpia->curbuff->status != FRAME_READY)
  335. interruptible_sleep_on(&ucpia->wq_stream);
  336. else
  337. DBG("Frame already waiting!\n");
  338. mybuff = ucpia->curbuff;
  339. if (!mybuff)
  340. return -1;
  341. if (mybuff->status != FRAME_READY || mybuff->length < 4) {
  342. DBG("Something went wrong!\n");
  343. return -1;
  344. }
  345. memcpy(frame, mybuff->data, mybuff->length);
  346. mybuff->status = FRAME_EMPTY;
  347. /* DBG("read done, %d bytes, Header: %x/%x, Footer: %x%x%x%x\n", */
  348. /* mybuff->length, frame[0], frame[1], */
  349. /* frame[mybuff->length-4], frame[mybuff->length-3], */
  350. /* frame[mybuff->length-2], frame[mybuff->length-1]); */
  351. return mybuff->length;
  352. }
  353. static void cpia_usb_free_resources(struct usb_cpia *ucpia, int try)
  354. {
  355. if (!ucpia->streaming)
  356. return;
  357. ucpia->streaming = 0;
  358. /* Set packet size to 0 */
  359. if (try) {
  360. int ret;
  361. ret = usb_set_interface(ucpia->dev, ucpia->iface, 0);
  362. if (ret < 0) {
  363. printk(KERN_ERR "usb_set_interface error (ret = %d)\n", ret);
  364. return;
  365. }
  366. }
  367. /* Unschedule all of the iso td's */
  368. if (ucpia->sbuf[1].urb) {
  369. usb_kill_urb(ucpia->sbuf[1].urb);
  370. usb_free_urb(ucpia->sbuf[1].urb);
  371. ucpia->sbuf[1].urb = NULL;
  372. }
  373. if (ucpia->sbuf[1].data) {
  374. kfree(ucpia->sbuf[1].data);
  375. ucpia->sbuf[1].data = NULL;
  376. }
  377. if (ucpia->sbuf[0].urb) {
  378. usb_kill_urb(ucpia->sbuf[0].urb);
  379. usb_free_urb(ucpia->sbuf[0].urb);
  380. ucpia->sbuf[0].urb = NULL;
  381. }
  382. if (ucpia->sbuf[0].data) {
  383. kfree(ucpia->sbuf[0].data);
  384. ucpia->sbuf[0].data = NULL;
  385. }
  386. }
  387. static int cpia_usb_close(void *privdata)
  388. {
  389. struct usb_cpia *ucpia = (struct usb_cpia *) privdata;
  390. if(!ucpia)
  391. return -ENODEV;
  392. ucpia->open = 0;
  393. /* ucpia->present = 0 protects against trying to reset the
  394. * alt setting if camera is physically disconnected while open */
  395. cpia_usb_free_resources(ucpia, ucpia->present);
  396. return 0;
  397. }
  398. int cpia_usb_init(void)
  399. {
  400. /* return -ENODEV; */
  401. return 0;
  402. }
  403. /* Probing and initializing */
  404. static int cpia_probe(struct usb_interface *intf,
  405. const struct usb_device_id *id)
  406. {
  407. struct usb_device *udev = interface_to_usbdev(intf);
  408. struct usb_host_interface *interface;
  409. struct usb_cpia *ucpia;
  410. struct cam_data *cam;
  411. int ret;
  412. /* A multi-config CPiA camera? */
  413. if (udev->descriptor.bNumConfigurations != 1)
  414. return -ENODEV;
  415. interface = intf->cur_altsetting;
  416. printk(KERN_INFO "USB CPiA camera found\n");
  417. ucpia = kmalloc(sizeof(*ucpia), GFP_KERNEL);
  418. if (!ucpia) {
  419. printk(KERN_ERR "couldn't kmalloc cpia struct\n");
  420. return -ENOMEM;
  421. }
  422. memset(ucpia, 0, sizeof(*ucpia));
  423. ucpia->dev = udev;
  424. ucpia->iface = interface->desc.bInterfaceNumber;
  425. init_waitqueue_head(&ucpia->wq_stream);
  426. ucpia->buffers[0] = vmalloc(sizeof(*ucpia->buffers[0]));
  427. if (!ucpia->buffers[0]) {
  428. printk(KERN_ERR "couldn't vmalloc frame buffer 0\n");
  429. goto fail_alloc_0;
  430. }
  431. ucpia->buffers[1] = vmalloc(sizeof(*ucpia->buffers[1]));
  432. if (!ucpia->buffers[1]) {
  433. printk(KERN_ERR "couldn't vmalloc frame buffer 1\n");
  434. goto fail_alloc_1;
  435. }
  436. ucpia->buffers[2] = vmalloc(sizeof(*ucpia->buffers[2]));
  437. if (!ucpia->buffers[2]) {
  438. printk(KERN_ERR "couldn't vmalloc frame buffer 2\n");
  439. goto fail_alloc_2;
  440. }
  441. ucpia->buffers[0]->next = ucpia->buffers[1];
  442. ucpia->buffers[1]->next = ucpia->buffers[2];
  443. ucpia->buffers[2]->next = ucpia->buffers[0];
  444. ret = usb_set_interface(udev, ucpia->iface, 0);
  445. if (ret < 0) {
  446. printk(KERN_ERR "cpia_probe: usb_set_interface error (ret = %d)\n", ret);
  447. /* goto fail_all; */
  448. }
  449. /* Before register_camera, important */
  450. ucpia->present = 1;
  451. cam = cpia_register_camera(&cpia_usb_ops, ucpia);
  452. if (!cam) {
  453. LOG("failed to cpia_register_camera\n");
  454. goto fail_all;
  455. }
  456. spin_lock( &cam_list_lock_usb );
  457. list_add( &cam->cam_data_list, &cam_list );
  458. spin_unlock( &cam_list_lock_usb );
  459. usb_set_intfdata(intf, cam);
  460. return 0;
  461. fail_all:
  462. vfree(ucpia->buffers[2]);
  463. ucpia->buffers[2] = NULL;
  464. fail_alloc_2:
  465. vfree(ucpia->buffers[1]);
  466. ucpia->buffers[1] = NULL;
  467. fail_alloc_1:
  468. vfree(ucpia->buffers[0]);
  469. ucpia->buffers[0] = NULL;
  470. fail_alloc_0:
  471. kfree(ucpia);
  472. return -EIO;
  473. }
  474. static void cpia_disconnect(struct usb_interface *intf);
  475. static struct usb_device_id cpia_id_table [] = {
  476. { USB_DEVICE(0x0553, 0x0002) },
  477. { USB_DEVICE(0x0813, 0x0001) },
  478. { } /* Terminating entry */
  479. };
  480. MODULE_DEVICE_TABLE (usb, cpia_id_table);
  481. MODULE_LICENSE("GPL");
  482. static struct usb_driver cpia_driver = {
  483. .owner = THIS_MODULE,
  484. .name = "cpia",
  485. .probe = cpia_probe,
  486. .disconnect = cpia_disconnect,
  487. .id_table = cpia_id_table,
  488. };
  489. static void cpia_disconnect(struct usb_interface *intf)
  490. {
  491. struct cam_data *cam = usb_get_intfdata(intf);
  492. struct usb_cpia *ucpia;
  493. struct usb_device *udev;
  494. usb_set_intfdata(intf, NULL);
  495. if (!cam)
  496. return;
  497. ucpia = (struct usb_cpia *) cam->lowlevel_data;
  498. spin_lock( &cam_list_lock_usb );
  499. list_del(&cam->cam_data_list);
  500. spin_unlock( &cam_list_lock_usb );
  501. ucpia->present = 0;
  502. cpia_unregister_camera(cam);
  503. if(ucpia->open)
  504. cpia_usb_close(cam->lowlevel_data);
  505. ucpia->curbuff->status = FRAME_ERROR;
  506. if (waitqueue_active(&ucpia->wq_stream))
  507. wake_up_interruptible(&ucpia->wq_stream);
  508. udev = interface_to_usbdev(intf);
  509. ucpia->curbuff = ucpia->workbuff = NULL;
  510. if (ucpia->buffers[2]) {
  511. vfree(ucpia->buffers[2]);
  512. ucpia->buffers[2] = NULL;
  513. }
  514. if (ucpia->buffers[1]) {
  515. vfree(ucpia->buffers[1]);
  516. ucpia->buffers[1] = NULL;
  517. }
  518. if (ucpia->buffers[0]) {
  519. vfree(ucpia->buffers[0]);
  520. ucpia->buffers[0] = NULL;
  521. }
  522. cam->lowlevel_data = NULL;
  523. kfree(ucpia);
  524. }
  525. static int __init usb_cpia_init(void)
  526. {
  527. printk(KERN_INFO "%s v%d.%d.%d\n",ABOUT,
  528. CPIA_USB_MAJ_VER,CPIA_USB_MIN_VER,CPIA_USB_PATCH_VER);
  529. spin_lock_init(&cam_list_lock_usb);
  530. return usb_register(&cpia_driver);
  531. }
  532. static void __exit usb_cpia_cleanup(void)
  533. {
  534. usb_deregister(&cpia_driver);
  535. }
  536. module_init (usb_cpia_init);
  537. module_exit (usb_cpia_cleanup);