1 /****************************************************************************
3 * Filename: cpia2_usb.c
5 * Copyright 2001, STMicrolectronics, Inc.
6 * Contact: steve.miller@st.com
9 * This is a USB driver for CPia2 based video cameras.
10 * The infrastructure of this driver is based on the cpia usb driver by
11 * Jochen Scharrlach and Johannes Erdfeldt.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * Stripped of 2.4 stuff ready for main kernel submit by
28 * Alan Cox <alan@redhat.com>
29 ****************************************************************************/
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/usb.h>
37 static int frame_sizes
[] = {
48 #define FRAMES_PER_DESC 10
49 #define FRAME_SIZE_PER_DESC frame_sizes[cam->cur_alt]
51 static void process_frame(struct camera_data
*cam
);
52 static void cpia2_usb_complete(struct urb
*urb
);
53 static int cpia2_usb_probe(struct usb_interface
*intf
,
54 const struct usb_device_id
*id
);
55 static void cpia2_usb_disconnect(struct usb_interface
*intf
);
57 static void free_sbufs(struct camera_data
*cam
);
58 static void add_APPn(struct camera_data
*cam
);
59 static void add_COM(struct camera_data
*cam
);
60 static int submit_urbs(struct camera_data
*cam
);
61 static int set_alternate(struct camera_data
*cam
, unsigned int alt
);
62 static int configure_transfer_mode(struct camera_data
*cam
, unsigned int alt
);
64 static struct usb_device_id cpia2_id_table
[] = {
65 {USB_DEVICE(0x0553, 0x0100)},
66 {USB_DEVICE(0x0553, 0x0140)},
67 {USB_DEVICE(0x0553, 0x0151)}, /* STV0676 */
68 {} /* Terminating entry */
70 MODULE_DEVICE_TABLE(usb
, cpia2_id_table
);
72 static struct usb_driver cpia2_driver
= {
74 .probe
= cpia2_usb_probe
,
75 .disconnect
= cpia2_usb_disconnect
,
76 .id_table
= cpia2_id_table
80 /******************************************************************************
84 *****************************************************************************/
85 static void process_frame(struct camera_data
*cam
)
87 static int frame_count
= 0;
89 unsigned char *inbuff
= cam
->workbuff
->data
;
91 DBG("Processing frame #%d, current:%d\n",
92 cam
->workbuff
->num
, cam
->curbuff
->num
);
94 if(cam
->workbuff
->length
> cam
->workbuff
->max_length
)
95 cam
->workbuff
->max_length
= cam
->workbuff
->length
;
97 if ((inbuff
[0] == 0xFF) && (inbuff
[1] == 0xD8)) {
100 cam
->workbuff
->status
= FRAME_ERROR
;
101 DBG("Start of frame not found\n");
106 * Now the output buffer should have a JPEG image in it.
108 if(!cam
->first_image_seen
) {
109 /* Always skip the first image after streaming
110 * starts. It is almost certainly corrupt. */
111 cam
->first_image_seen
= 1;
112 cam
->workbuff
->status
= FRAME_EMPTY
;
115 if (cam
->workbuff
->length
> 3) {
117 cam
->workbuff
->length
< cam
->workbuff
->max_length
) {
118 /* No junk in the buffers */
119 memset(cam
->workbuff
->data
+cam
->workbuff
->length
,
120 0, cam
->workbuff
->max_length
-
121 cam
->workbuff
->length
);
123 cam
->workbuff
->max_length
= cam
->workbuff
->length
;
124 cam
->workbuff
->status
= FRAME_READY
;
126 if(!cam
->mmapped
&& cam
->num_frames
> 2) {
127 /* During normal reading, the most recent
128 * frame will be read. If the current frame
129 * hasn't started reading yet, it will never
130 * be read, so mark it empty. If the buffer is
131 * mmapped, or we have few buffers, we need to
132 * wait for the user to free the buffer.
134 * NOTE: This is not entirely foolproof with 3
135 * buffers, but it would take an EXTREMELY
136 * overloaded system to cause problems (possible
137 * image data corruption). Basically, it would
138 * need to take more time to execute cpia2_read
139 * than it would for the camera to send
140 * cam->num_frames-2 frames before problems
143 cam
->curbuff
->status
= FRAME_EMPTY
;
145 cam
->curbuff
= cam
->workbuff
;
146 cam
->workbuff
= cam
->workbuff
->next
;
147 DBG("Changed buffers, work:%d, current:%d\n",
148 cam
->workbuff
->num
, cam
->curbuff
->num
);
151 DBG("Not enough data for an image.\n");
154 cam
->workbuff
->status
= FRAME_ERROR
;
158 /******************************************************************************
162 * Adds a user specified APPn record
163 *****************************************************************************/
164 static void add_APPn(struct camera_data
*cam
)
166 if(cam
->APP_len
> 0) {
167 cam
->workbuff
->data
[cam
->workbuff
->length
++] = 0xFF;
168 cam
->workbuff
->data
[cam
->workbuff
->length
++] = 0xE0+cam
->APPn
;
169 cam
->workbuff
->data
[cam
->workbuff
->length
++] = 0;
170 cam
->workbuff
->data
[cam
->workbuff
->length
++] = cam
->APP_len
+2;
171 memcpy(cam
->workbuff
->data
+cam
->workbuff
->length
,
172 cam
->APP_data
, cam
->APP_len
);
173 cam
->workbuff
->length
+= cam
->APP_len
;
177 /******************************************************************************
181 * Adds a user specified COM record
182 *****************************************************************************/
183 static void add_COM(struct camera_data
*cam
)
185 if(cam
->COM_len
> 0) {
186 cam
->workbuff
->data
[cam
->workbuff
->length
++] = 0xFF;
187 cam
->workbuff
->data
[cam
->workbuff
->length
++] = 0xFE;
188 cam
->workbuff
->data
[cam
->workbuff
->length
++] = 0;
189 cam
->workbuff
->data
[cam
->workbuff
->length
++] = cam
->COM_len
+2;
190 memcpy(cam
->workbuff
->data
+cam
->workbuff
->length
,
191 cam
->COM_data
, cam
->COM_len
);
192 cam
->workbuff
->length
+= cam
->COM_len
;
196 /******************************************************************************
200 * callback when incoming packet is received
201 *****************************************************************************/
202 static void cpia2_usb_complete(struct urb
*urb
)
205 unsigned char *cdata
;
206 static int frame_ready
= false;
207 struct camera_data
*cam
= (struct camera_data
*) urb
->context
;
209 if (urb
->status
!=0) {
210 if (!(urb
->status
== -ENOENT
||
211 urb
->status
== -ECONNRESET
||
212 urb
->status
== -ESHUTDOWN
))
214 DBG("urb->status = %d!\n", urb
->status
);
216 DBG("Stopping streaming\n");
220 if (!cam
->streaming
|| !cam
->present
|| cam
->open_count
== 0) {
221 LOG("Will now stop the streaming: streaming = %d, "
222 "present=%d, open_count=%d\n",
223 cam
->streaming
, cam
->present
, cam
->open_count
);
230 //DBG("Collating %d packets\n", urb->number_of_packets);
231 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
232 u16 checksum
, iso_checksum
;
234 int n
= urb
->iso_frame_desc
[i
].actual_length
;
235 int st
= urb
->iso_frame_desc
[i
].status
;
237 if(cam
->workbuff
->status
== FRAME_READY
) {
238 struct framebuf
*ptr
;
239 /* Try to find an available buffer */
240 DBG("workbuff full, searching\n");
241 for (ptr
= cam
->workbuff
->next
;
242 ptr
!= cam
->workbuff
;
245 if (ptr
->status
== FRAME_EMPTY
) {
246 ptr
->status
= FRAME_READING
;
251 if (ptr
== cam
->workbuff
)
252 break; /* No READING or EMPTY buffers left */
257 if (cam
->workbuff
->status
== FRAME_EMPTY
||
258 cam
->workbuff
->status
== FRAME_ERROR
) {
259 cam
->workbuff
->status
= FRAME_READING
;
260 cam
->workbuff
->length
= 0;
263 //DBG(" Packet %d length = %d, status = %d\n", i, n, st);
264 cdata
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
;
267 LOG("cpia2 data error: [%d] len=%d, status = %d\n",
270 cam
->workbuff
->status
= FRAME_ERROR
;
279 checksum
+= cdata
[j
];
280 iso_checksum
= cdata
[j
] + cdata
[j
+1]*256;
281 if(checksum
!= iso_checksum
) {
282 LOG("checksum mismatch: [%d] len=%d, calculated = %x, checksum = %x\n",
283 i
, n
, (int)checksum
, (int)iso_checksum
);
285 cam
->workbuff
->status
= FRAME_ERROR
;
291 if(cam
->workbuff
->status
!= FRAME_READING
) {
292 if((0xFF == cdata
[0] && 0xD8 == cdata
[1]) ||
293 (0xD8 == cdata
[0] && 0xFF == cdata
[1] &&
295 /* frame is skipped, but increment total
296 * frame count anyway */
299 DBG("workbuff not reading, status=%d\n",
300 cam
->workbuff
->status
);
304 if (cam
->frame_size
< cam
->workbuff
->length
+ n
) {
305 ERR("buffer overflow! length: %d, n: %d\n",
306 cam
->workbuff
->length
, n
);
307 cam
->workbuff
->status
= FRAME_ERROR
;
308 if(cam
->workbuff
->length
> cam
->workbuff
->max_length
)
309 cam
->workbuff
->max_length
=
310 cam
->workbuff
->length
;
314 if (cam
->workbuff
->length
== 0) {
316 if ((0xD8 == cdata
[0]) && (0xFF == cdata
[1])) {
318 } else if((0xFF == cdata
[0]) && (0xD8 == cdata
[1])
319 && (0xFF == cdata
[2])) {
322 DBG("Ignoring packet, not beginning!\n");
325 DBG("Start of frame pattern found\n");
326 do_gettimeofday(&cam
->workbuff
->timestamp
);
327 cam
->workbuff
->seq
= cam
->frame_count
++;
328 cam
->workbuff
->data
[0] = 0xFF;
329 cam
->workbuff
->data
[1] = 0xD8;
330 cam
->workbuff
->length
= 2;
333 memcpy(cam
->workbuff
->data
+cam
->workbuff
->length
,
334 cdata
+data_offset
, n
-data_offset
);
335 cam
->workbuff
->length
+= n
-data_offset
;
336 } else if (cam
->workbuff
->length
> 0) {
337 memcpy(cam
->workbuff
->data
+ cam
->workbuff
->length
,
339 cam
->workbuff
->length
+= n
;
342 if ((cam
->workbuff
->length
>= 3) &&
343 (cam
->workbuff
->data
[cam
->workbuff
->length
- 3] == 0xFF) &&
344 (cam
->workbuff
->data
[cam
->workbuff
->length
- 2] == 0xD9) &&
345 (cam
->workbuff
->data
[cam
->workbuff
->length
- 1] == 0xFF)) {
347 cam
->workbuff
->data
[cam
->workbuff
->length
- 1] = 0;
348 cam
->workbuff
->length
-= 1;
349 } else if ((cam
->workbuff
->length
>= 2) &&
350 (cam
->workbuff
->data
[cam
->workbuff
->length
- 2] == 0xFF) &&
351 (cam
->workbuff
->data
[cam
->workbuff
->length
- 1] == 0xD9)) {
356 DBG("Workbuff image size = %d\n",cam
->workbuff
->length
);
361 if (waitqueue_active(&cam
->wq_stream
))
362 wake_up_interruptible(&cam
->wq_stream
);
369 if ((i
= usb_submit_urb(urb
, GFP_ATOMIC
)) != 0)
370 ERR("%s: usb_submit_urb ret %d!\n", __func__
, i
);
374 /******************************************************************************
376 * configure_transfer_mode
378 *****************************************************************************/
379 static int configure_transfer_mode(struct camera_data
*cam
, unsigned int alt
)
381 static unsigned char iso_regs
[8][4] = {
382 {0x00, 0x00, 0x00, 0x00},
383 {0x00, 0x00, 0x00, 0x00},
384 {0xB9, 0x00, 0x00, 0x7E},
385 {0xB9, 0x00, 0x01, 0x7E},
386 {0xB9, 0x00, 0x02, 0x7E},
387 {0xB9, 0x00, 0x02, 0xFE},
388 {0xB9, 0x00, 0x03, 0x7E},
389 {0xB9, 0x00, 0x03, 0xFD}
391 struct cpia2_command cmd
;
398 * Write the isoc registers according to the alternate selected
400 cmd
.direction
= TRANSFER_WRITE
;
401 cmd
.buffer
.block_data
[0] = iso_regs
[alt
][0];
402 cmd
.buffer
.block_data
[1] = iso_regs
[alt
][1];
403 cmd
.buffer
.block_data
[2] = iso_regs
[alt
][2];
404 cmd
.buffer
.block_data
[3] = iso_regs
[alt
][3];
405 cmd
.req_mode
= CAMERAACCESS_TYPE_BLOCK
| CAMERAACCESS_VC
;
406 cmd
.start
= CPIA2_VC_USB_ISOLIM
;
408 cpia2_send_command(cam
, &cmd
);
411 * Enable relevant streams before starting polling.
412 * First read USB Stream Config Register.
414 cmd
.direction
= TRANSFER_READ
;
415 cmd
.req_mode
= CAMERAACCESS_TYPE_BLOCK
| CAMERAACCESS_VC
;
416 cmd
.start
= CPIA2_VC_USB_STRM
;
418 cpia2_send_command(cam
, &cmd
);
419 reg
= cmd
.buffer
.block_data
[0];
421 /* Clear iso, bulk, and int */
422 reg
&= ~(CPIA2_VC_USB_STRM_BLK_ENABLE
|
423 CPIA2_VC_USB_STRM_ISO_ENABLE
|
424 CPIA2_VC_USB_STRM_INT_ENABLE
);
426 if (alt
== USBIF_BULK
) {
427 DBG("Enabling bulk xfer\n");
428 reg
|= CPIA2_VC_USB_STRM_BLK_ENABLE
; /* Enable Bulk */
429 cam
->xfer_mode
= XFER_BULK
;
430 } else if (alt
>= USBIF_ISO_1
) {
431 DBG("Enabling ISOC xfer\n");
432 reg
|= CPIA2_VC_USB_STRM_ISO_ENABLE
;
433 cam
->xfer_mode
= XFER_ISOC
;
436 cmd
.buffer
.block_data
[0] = reg
;
437 cmd
.direction
= TRANSFER_WRITE
;
438 cmd
.start
= CPIA2_VC_USB_STRM
;
440 cmd
.req_mode
= CAMERAACCESS_TYPE_BLOCK
| CAMERAACCESS_VC
;
441 cpia2_send_command(cam
, &cmd
);
446 /******************************************************************************
448 * cpia2_usb_change_streaming_alternate
450 *****************************************************************************/
451 int cpia2_usb_change_streaming_alternate(struct camera_data
*cam
,
456 if(alt
< USBIF_ISO_1
|| alt
> USBIF_ISO_6
)
459 if(alt
== cam
->params
.camera_state
.stream_mode
)
462 cpia2_usb_stream_pause(cam
);
464 configure_transfer_mode(cam
, alt
);
466 cam
->params
.camera_state
.stream_mode
= alt
;
468 /* Reset the camera to prevent image quality degradation */
469 cpia2_reset_camera(cam
);
471 cpia2_usb_stream_resume(cam
);
476 /******************************************************************************
480 *****************************************************************************/
481 int set_alternate(struct camera_data
*cam
, unsigned int alt
)
485 if(alt
== cam
->cur_alt
)
488 if (cam
->cur_alt
!= USBIF_CMDONLY
) {
489 DBG("Changing from alt %d to %d\n", cam
->cur_alt
, USBIF_CMDONLY
);
490 ret
= usb_set_interface(cam
->dev
, cam
->iface
, USBIF_CMDONLY
);
494 if (alt
!= USBIF_CMDONLY
) {
495 DBG("Changing from alt %d to %d\n", USBIF_CMDONLY
, alt
);
496 ret
= usb_set_interface(cam
->dev
, cam
->iface
, alt
);
501 cam
->old_alt
= cam
->cur_alt
;
507 /******************************************************************************
511 * Free all cam->sbuf[]. All non-NULL .data and .urb members that are non-NULL
512 * are assumed to be allocated. Non-NULL .urb members are also assumed to be
513 * submitted (and must therefore be killed before they are freed).
514 *****************************************************************************/
515 static void free_sbufs(struct camera_data
*cam
)
519 for (i
= 0; i
< NUM_SBUF
; i
++) {
520 if(cam
->sbuf
[i
].urb
) {
521 usb_kill_urb(cam
->sbuf
[i
].urb
);
522 usb_free_urb(cam
->sbuf
[i
].urb
);
523 cam
->sbuf
[i
].urb
= NULL
;
525 if(cam
->sbuf
[i
].data
) {
526 kfree(cam
->sbuf
[i
].data
);
527 cam
->sbuf
[i
].data
= NULL
;
533 * Convenience functions
535 /****************************************************************************
539 ***************************************************************************/
540 static int write_packet(struct usb_device
*udev
,
541 u8 request
, u8
* registers
, u16 start
, size_t size
)
543 if (!registers
|| size
<= 0)
546 return usb_control_msg(udev
,
547 usb_sndctrlpipe(udev
, 0),
549 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
552 registers
, /* buffer */
557 /****************************************************************************
561 ***************************************************************************/
562 static int read_packet(struct usb_device
*udev
,
563 u8 request
, u8
* registers
, u16 start
, size_t size
)
565 if (!registers
|| size
<= 0)
568 return usb_control_msg(udev
,
569 usb_rcvctrlpipe(udev
, 0),
571 USB_DIR_IN
|USB_TYPE_VENDOR
|USB_RECIP_DEVICE
,
574 registers
, /* buffer */
579 /******************************************************************************
581 * cpia2_usb_transfer_cmd
583 *****************************************************************************/
584 int cpia2_usb_transfer_cmd(struct camera_data
*cam
,
586 u8 request
, u8 start
, u8 count
, u8 direction
)
589 struct usb_device
*udev
= cam
->dev
;
592 ERR("%s: Internal driver error: udev is NULL\n", __func__
);
597 ERR("%s: Internal driver error: register array is NULL\n", __func__
);
601 if (direction
== TRANSFER_READ
) {
602 err
= read_packet(udev
, request
, (u8
*)registers
, start
, count
);
605 } else if (direction
== TRANSFER_WRITE
) {
606 err
=write_packet(udev
, request
, (u8
*)registers
, start
, count
);
608 LOG("Control message failed, err val = %d\n", err
);
609 LOG("Message: request = 0x%0X, start = 0x%0X\n",
611 LOG("Message: count = %d, register[0] = 0x%0X\n",
612 count
, ((unsigned char *) registers
)[0]);
616 LOG("Unexpected first byte of direction: %d\n",
622 LOG("Unexpected error: %d\n", err
);
627 /******************************************************************************
631 *****************************************************************************/
632 static int submit_urbs(struct camera_data
*cam
)
637 for(i
=0; i
<NUM_SBUF
; ++i
) {
638 if (cam
->sbuf
[i
].data
)
641 kmalloc(FRAMES_PER_DESC
* FRAME_SIZE_PER_DESC
, GFP_KERNEL
);
642 if (!cam
->sbuf
[i
].data
) {
644 kfree(cam
->sbuf
[i
].data
);
645 cam
->sbuf
[i
].data
= NULL
;
651 /* We double buffer the Isoc lists, and also know the polling
652 * interval is every frame (1 == (1 << (bInterval -1))).
654 for(i
=0; i
<NUM_SBUF
; ++i
) {
655 if(cam
->sbuf
[i
].urb
) {
658 urb
= usb_alloc_urb(FRAMES_PER_DESC
, GFP_KERNEL
);
663 cam
->sbuf
[i
].urb
= urb
;
666 urb
->pipe
= usb_rcvisocpipe(cam
->dev
, 1 /*ISOC endpoint*/);
667 urb
->transfer_flags
= URB_ISO_ASAP
;
668 urb
->transfer_buffer
= cam
->sbuf
[i
].data
;
669 urb
->complete
= cpia2_usb_complete
;
670 urb
->number_of_packets
= FRAMES_PER_DESC
;
672 urb
->transfer_buffer_length
=
673 FRAME_SIZE_PER_DESC
* FRAMES_PER_DESC
;
675 for (fx
= 0; fx
< FRAMES_PER_DESC
; fx
++) {
676 urb
->iso_frame_desc
[fx
].offset
=
677 FRAME_SIZE_PER_DESC
* fx
;
678 urb
->iso_frame_desc
[fx
].length
= FRAME_SIZE_PER_DESC
;
683 /* Queue the ISO urbs, and resubmit in the completion handler */
684 for(i
=0; i
<NUM_SBUF
; ++i
) {
685 err
= usb_submit_urb(cam
->sbuf
[i
].urb
, GFP_KERNEL
);
687 ERR("usb_submit_urb[%d]() = %d\n", i
, err
);
695 /******************************************************************************
697 * cpia2_usb_stream_start
699 *****************************************************************************/
700 int cpia2_usb_stream_start(struct camera_data
*cam
, unsigned int alternate
)
710 DBG("Flushing buffers\n");
711 for(i
=0; i
<cam
->num_frames
; ++i
) {
712 cam
->buffers
[i
].status
= FRAME_EMPTY
;
713 cam
->buffers
[i
].length
= 0;
715 cam
->curbuff
= &cam
->buffers
[0];
716 cam
->workbuff
= cam
->curbuff
->next
;
720 old_alt
= cam
->params
.camera_state
.stream_mode
;
721 cam
->params
.camera_state
.stream_mode
= 0;
722 ret
= cpia2_usb_change_streaming_alternate(cam
, alternate
);
725 ERR("cpia2_usb_change_streaming_alternate() = %d!\n", ret
);
726 cam
->params
.camera_state
.stream_mode
= old_alt
;
727 ret2
= set_alternate(cam
, USBIF_CMDONLY
);
729 ERR("cpia2_usb_change_streaming_alternate(%d) =%d has already "
730 "failed. Then tried to call "
731 "set_alternate(USBIF_CMDONLY) = %d.\n",
732 alternate
, ret
, ret2
);
735 cam
->frame_count
= 0;
737 ret
= cpia2_usb_stream_resume(cam
);
742 /******************************************************************************
744 * cpia2_usb_stream_pause
746 *****************************************************************************/
747 int cpia2_usb_stream_pause(struct camera_data
*cam
)
751 ret
= set_alternate(cam
, USBIF_CMDONLY
);
757 /******************************************************************************
759 * cpia2_usb_stream_resume
761 *****************************************************************************/
762 int cpia2_usb_stream_resume(struct camera_data
*cam
)
766 cam
->first_image_seen
= 0;
767 ret
= set_alternate(cam
, cam
->params
.camera_state
.stream_mode
);
769 ret
= submit_urbs(cam
);
775 /******************************************************************************
777 * cpia2_usb_stream_stop
779 *****************************************************************************/
780 int cpia2_usb_stream_stop(struct camera_data
*cam
)
783 ret
= cpia2_usb_stream_pause(cam
);
785 configure_transfer_mode(cam
, 0);
789 /******************************************************************************
793 * Probe and initialize.
794 *****************************************************************************/
795 static int cpia2_usb_probe(struct usb_interface
*intf
,
796 const struct usb_device_id
*id
)
798 struct usb_device
*udev
= interface_to_usbdev(intf
);
799 struct usb_interface_descriptor
*interface
;
800 struct camera_data
*cam
;
803 /* A multi-config CPiA2 camera? */
804 if (udev
->descriptor
.bNumConfigurations
!= 1)
806 interface
= &intf
->cur_altsetting
->desc
;
808 /* If we get to this point, we found a CPiA2 camera */
809 LOG("CPiA2 USB camera found\n");
811 if((cam
= cpia2_init_camera_struct()) == NULL
)
815 cam
->iface
= interface
->bInterfaceNumber
;
817 ret
= set_alternate(cam
, USBIF_CMDONLY
);
819 ERR("%s: usb_set_interface error (ret = %d)\n", __func__
, ret
);
824 if ((ret
= cpia2_register_camera(cam
)) < 0) {
825 ERR("%s: Failed to register cpia2 camera (ret = %d)\n", __func__
, ret
);
831 if((ret
= cpia2_init_camera(cam
)) < 0) {
832 ERR("%s: failed to initialize cpia2 camera (ret = %d)\n", __func__
, ret
);
833 cpia2_unregister_camera(cam
);
837 LOG(" CPiA Version: %d.%02d (%d.%d)\n",
838 cam
->params
.version
.firmware_revision_hi
,
839 cam
->params
.version
.firmware_revision_lo
,
840 cam
->params
.version
.asic_id
,
841 cam
->params
.version
.asic_rev
);
842 LOG(" CPiA PnP-ID: %04x:%04x:%04x\n",
843 cam
->params
.pnp_id
.vendor
,
844 cam
->params
.pnp_id
.product
,
845 cam
->params
.pnp_id
.device_revision
);
846 LOG(" SensorID: %d.(version %d)\n",
847 cam
->params
.version
.sensor_flags
,
848 cam
->params
.version
.sensor_rev
);
850 usb_set_intfdata(intf
, cam
);
855 /******************************************************************************
859 *****************************************************************************/
860 static void cpia2_usb_disconnect(struct usb_interface
*intf
)
862 struct camera_data
*cam
= usb_get_intfdata(intf
);
863 usb_set_intfdata(intf
, NULL
);
866 DBG("Stopping stream\n");
867 cpia2_usb_stream_stop(cam
);
869 DBG("Unregistering camera\n");
870 cpia2_unregister_camera(cam
);
873 DBG("Wakeup waiting processes\n");
874 cam
->curbuff
->status
= FRAME_READY
;
875 cam
->curbuff
->length
= 0;
876 if (waitqueue_active(&cam
->wq_stream
))
877 wake_up_interruptible(&cam
->wq_stream
);
880 DBG("Releasing interface\n");
881 usb_driver_release_interface(&cpia2_driver
, intf
);
883 if (cam
->open_count
== 0) {
884 DBG("Freeing camera structure\n");
888 LOG("CPiA2 camera disconnected.\n");
892 /******************************************************************************
896 *****************************************************************************/
897 int cpia2_usb_init(void)
899 return usb_register(&cpia2_driver
);
902 /******************************************************************************
906 *****************************************************************************/
907 void cpia2_usb_cleanup(void)
909 schedule_timeout(2 * HZ
);
910 usb_deregister(&cpia2_driver
);