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@lxorguk.ukuu.org.uk>
29 ****************************************************************************/
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/usb.h>
34 #include <linux/module.h>
38 static int frame_sizes
[] = {
49 #define FRAMES_PER_DESC 10
50 #define FRAME_SIZE_PER_DESC frame_sizes[cam->cur_alt]
52 static void process_frame(struct camera_data
*cam
);
53 static void cpia2_usb_complete(struct urb
*urb
);
54 static int cpia2_usb_probe(struct usb_interface
*intf
,
55 const struct usb_device_id
*id
);
56 static void cpia2_usb_disconnect(struct usb_interface
*intf
);
58 static void free_sbufs(struct camera_data
*cam
);
59 static void add_APPn(struct camera_data
*cam
);
60 static void add_COM(struct camera_data
*cam
);
61 static int submit_urbs(struct camera_data
*cam
);
62 static int set_alternate(struct camera_data
*cam
, unsigned int alt
);
63 static int configure_transfer_mode(struct camera_data
*cam
, unsigned int alt
);
65 static struct usb_device_id cpia2_id_table
[] = {
66 {USB_DEVICE(0x0553, 0x0100)},
67 {USB_DEVICE(0x0553, 0x0140)},
68 {USB_DEVICE(0x0553, 0x0151)}, /* STV0676 */
69 {} /* Terminating entry */
71 MODULE_DEVICE_TABLE(usb
, cpia2_id_table
);
73 static struct usb_driver cpia2_driver
= {
75 .probe
= cpia2_usb_probe
,
76 .disconnect
= cpia2_usb_disconnect
,
77 .id_table
= cpia2_id_table
81 /******************************************************************************
85 *****************************************************************************/
86 static void process_frame(struct camera_data
*cam
)
88 static int frame_count
;
90 unsigned char *inbuff
= cam
->workbuff
->data
;
92 DBG("Processing frame #%d, current:%d\n",
93 cam
->workbuff
->num
, cam
->curbuff
->num
);
95 if(cam
->workbuff
->length
> cam
->workbuff
->max_length
)
96 cam
->workbuff
->max_length
= cam
->workbuff
->length
;
98 if ((inbuff
[0] == 0xFF) && (inbuff
[1] == 0xD8)) {
101 cam
->workbuff
->status
= FRAME_ERROR
;
102 DBG("Start of frame not found\n");
107 * Now the output buffer should have a JPEG image in it.
109 if(!cam
->first_image_seen
) {
110 /* Always skip the first image after streaming
111 * starts. It is almost certainly corrupt. */
112 cam
->first_image_seen
= 1;
113 cam
->workbuff
->status
= FRAME_EMPTY
;
116 if (cam
->workbuff
->length
> 3) {
118 cam
->workbuff
->length
< cam
->workbuff
->max_length
) {
119 /* No junk in the buffers */
120 memset(cam
->workbuff
->data
+cam
->workbuff
->length
,
121 0, cam
->workbuff
->max_length
-
122 cam
->workbuff
->length
);
124 cam
->workbuff
->max_length
= cam
->workbuff
->length
;
125 cam
->workbuff
->status
= FRAME_READY
;
127 if(!cam
->mmapped
&& cam
->num_frames
> 2) {
128 /* During normal reading, the most recent
129 * frame will be read. If the current frame
130 * hasn't started reading yet, it will never
131 * be read, so mark it empty. If the buffer is
132 * mmapped, or we have few buffers, we need to
133 * wait for the user to free the buffer.
135 * NOTE: This is not entirely foolproof with 3
136 * buffers, but it would take an EXTREMELY
137 * overloaded system to cause problems (possible
138 * image data corruption). Basically, it would
139 * need to take more time to execute cpia2_read
140 * than it would for the camera to send
141 * cam->num_frames-2 frames before problems
144 cam
->curbuff
->status
= FRAME_EMPTY
;
146 cam
->curbuff
= cam
->workbuff
;
147 cam
->workbuff
= cam
->workbuff
->next
;
148 DBG("Changed buffers, work:%d, current:%d\n",
149 cam
->workbuff
->num
, cam
->curbuff
->num
);
152 DBG("Not enough data for an image.\n");
155 cam
->workbuff
->status
= FRAME_ERROR
;
159 /******************************************************************************
163 * Adds a user specified APPn record
164 *****************************************************************************/
165 static void add_APPn(struct camera_data
*cam
)
167 if(cam
->APP_len
> 0) {
168 cam
->workbuff
->data
[cam
->workbuff
->length
++] = 0xFF;
169 cam
->workbuff
->data
[cam
->workbuff
->length
++] = 0xE0+cam
->APPn
;
170 cam
->workbuff
->data
[cam
->workbuff
->length
++] = 0;
171 cam
->workbuff
->data
[cam
->workbuff
->length
++] = cam
->APP_len
+2;
172 memcpy(cam
->workbuff
->data
+cam
->workbuff
->length
,
173 cam
->APP_data
, cam
->APP_len
);
174 cam
->workbuff
->length
+= cam
->APP_len
;
178 /******************************************************************************
182 * Adds a user specified COM record
183 *****************************************************************************/
184 static void add_COM(struct camera_data
*cam
)
186 if(cam
->COM_len
> 0) {
187 cam
->workbuff
->data
[cam
->workbuff
->length
++] = 0xFF;
188 cam
->workbuff
->data
[cam
->workbuff
->length
++] = 0xFE;
189 cam
->workbuff
->data
[cam
->workbuff
->length
++] = 0;
190 cam
->workbuff
->data
[cam
->workbuff
->length
++] = cam
->COM_len
+2;
191 memcpy(cam
->workbuff
->data
+cam
->workbuff
->length
,
192 cam
->COM_data
, cam
->COM_len
);
193 cam
->workbuff
->length
+= cam
->COM_len
;
197 /******************************************************************************
201 * callback when incoming packet is received
202 *****************************************************************************/
203 static void cpia2_usb_complete(struct urb
*urb
)
206 unsigned char *cdata
;
207 static int frame_ready
= false;
208 struct camera_data
*cam
= (struct camera_data
*) urb
->context
;
210 if (urb
->status
!=0) {
211 if (!(urb
->status
== -ENOENT
||
212 urb
->status
== -ECONNRESET
||
213 urb
->status
== -ESHUTDOWN
))
215 DBG("urb->status = %d!\n", urb
->status
);
217 DBG("Stopping streaming\n");
221 if (!cam
->streaming
|| !cam
->present
|| cam
->open_count
== 0) {
222 LOG("Will now stop the streaming: streaming = %d, "
223 "present=%d, open_count=%d\n",
224 cam
->streaming
, cam
->present
, cam
->open_count
);
231 //DBG("Collating %d packets\n", urb->number_of_packets);
232 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
233 u16 checksum
, iso_checksum
;
235 int n
= urb
->iso_frame_desc
[i
].actual_length
;
236 int st
= urb
->iso_frame_desc
[i
].status
;
238 if(cam
->workbuff
->status
== FRAME_READY
) {
239 struct framebuf
*ptr
;
240 /* Try to find an available buffer */
241 DBG("workbuff full, searching\n");
242 for (ptr
= cam
->workbuff
->next
;
243 ptr
!= cam
->workbuff
;
246 if (ptr
->status
== FRAME_EMPTY
) {
247 ptr
->status
= FRAME_READING
;
252 if (ptr
== cam
->workbuff
)
253 break; /* No READING or EMPTY buffers left */
258 if (cam
->workbuff
->status
== FRAME_EMPTY
||
259 cam
->workbuff
->status
== FRAME_ERROR
) {
260 cam
->workbuff
->status
= FRAME_READING
;
261 cam
->workbuff
->length
= 0;
264 //DBG(" Packet %d length = %d, status = %d\n", i, n, st);
265 cdata
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
;
268 LOG("cpia2 data error: [%d] len=%d, status = %d\n",
271 cam
->workbuff
->status
= FRAME_ERROR
;
280 checksum
+= cdata
[j
];
281 iso_checksum
= cdata
[j
] + cdata
[j
+1]*256;
282 if(checksum
!= iso_checksum
) {
283 LOG("checksum mismatch: [%d] len=%d, calculated = %x, checksum = %x\n",
284 i
, n
, (int)checksum
, (int)iso_checksum
);
286 cam
->workbuff
->status
= FRAME_ERROR
;
292 if(cam
->workbuff
->status
!= FRAME_READING
) {
293 if((0xFF == cdata
[0] && 0xD8 == cdata
[1]) ||
294 (0xD8 == cdata
[0] && 0xFF == cdata
[1] &&
296 /* frame is skipped, but increment total
297 * frame count anyway */
300 DBG("workbuff not reading, status=%d\n",
301 cam
->workbuff
->status
);
305 if (cam
->frame_size
< cam
->workbuff
->length
+ n
) {
306 ERR("buffer overflow! length: %d, n: %d\n",
307 cam
->workbuff
->length
, n
);
308 cam
->workbuff
->status
= FRAME_ERROR
;
309 if(cam
->workbuff
->length
> cam
->workbuff
->max_length
)
310 cam
->workbuff
->max_length
=
311 cam
->workbuff
->length
;
315 if (cam
->workbuff
->length
== 0) {
317 if ((0xD8 == cdata
[0]) && (0xFF == cdata
[1])) {
319 } else if((0xFF == cdata
[0]) && (0xD8 == cdata
[1])
320 && (0xFF == cdata
[2])) {
323 DBG("Ignoring packet, not beginning!\n");
326 DBG("Start of frame pattern found\n");
327 do_gettimeofday(&cam
->workbuff
->timestamp
);
328 cam
->workbuff
->seq
= cam
->frame_count
++;
329 cam
->workbuff
->data
[0] = 0xFF;
330 cam
->workbuff
->data
[1] = 0xD8;
331 cam
->workbuff
->length
= 2;
334 memcpy(cam
->workbuff
->data
+cam
->workbuff
->length
,
335 cdata
+data_offset
, n
-data_offset
);
336 cam
->workbuff
->length
+= n
-data_offset
;
337 } else if (cam
->workbuff
->length
> 0) {
338 memcpy(cam
->workbuff
->data
+ cam
->workbuff
->length
,
340 cam
->workbuff
->length
+= n
;
343 if ((cam
->workbuff
->length
>= 3) &&
344 (cam
->workbuff
->data
[cam
->workbuff
->length
- 3] == 0xFF) &&
345 (cam
->workbuff
->data
[cam
->workbuff
->length
- 2] == 0xD9) &&
346 (cam
->workbuff
->data
[cam
->workbuff
->length
- 1] == 0xFF)) {
348 cam
->workbuff
->data
[cam
->workbuff
->length
- 1] = 0;
349 cam
->workbuff
->length
-= 1;
350 } else if ((cam
->workbuff
->length
>= 2) &&
351 (cam
->workbuff
->data
[cam
->workbuff
->length
- 2] == 0xFF) &&
352 (cam
->workbuff
->data
[cam
->workbuff
->length
- 1] == 0xD9)) {
357 DBG("Workbuff image size = %d\n",cam
->workbuff
->length
);
362 if (waitqueue_active(&cam
->wq_stream
))
363 wake_up_interruptible(&cam
->wq_stream
);
370 if ((i
= usb_submit_urb(urb
, GFP_ATOMIC
)) != 0)
371 ERR("%s: usb_submit_urb ret %d!\n", __func__
, i
);
375 /******************************************************************************
377 * configure_transfer_mode
379 *****************************************************************************/
380 static int configure_transfer_mode(struct camera_data
*cam
, unsigned int alt
)
382 static unsigned char iso_regs
[8][4] = {
383 {0x00, 0x00, 0x00, 0x00},
384 {0x00, 0x00, 0x00, 0x00},
385 {0xB9, 0x00, 0x00, 0x7E},
386 {0xB9, 0x00, 0x01, 0x7E},
387 {0xB9, 0x00, 0x02, 0x7E},
388 {0xB9, 0x00, 0x02, 0xFE},
389 {0xB9, 0x00, 0x03, 0x7E},
390 {0xB9, 0x00, 0x03, 0xFD}
392 struct cpia2_command cmd
;
399 * Write the isoc registers according to the alternate selected
401 cmd
.direction
= TRANSFER_WRITE
;
402 cmd
.buffer
.block_data
[0] = iso_regs
[alt
][0];
403 cmd
.buffer
.block_data
[1] = iso_regs
[alt
][1];
404 cmd
.buffer
.block_data
[2] = iso_regs
[alt
][2];
405 cmd
.buffer
.block_data
[3] = iso_regs
[alt
][3];
406 cmd
.req_mode
= CAMERAACCESS_TYPE_BLOCK
| CAMERAACCESS_VC
;
407 cmd
.start
= CPIA2_VC_USB_ISOLIM
;
409 cpia2_send_command(cam
, &cmd
);
412 * Enable relevant streams before starting polling.
413 * First read USB Stream Config Register.
415 cmd
.direction
= TRANSFER_READ
;
416 cmd
.req_mode
= CAMERAACCESS_TYPE_BLOCK
| CAMERAACCESS_VC
;
417 cmd
.start
= CPIA2_VC_USB_STRM
;
419 cpia2_send_command(cam
, &cmd
);
420 reg
= cmd
.buffer
.block_data
[0];
422 /* Clear iso, bulk, and int */
423 reg
&= ~(CPIA2_VC_USB_STRM_BLK_ENABLE
|
424 CPIA2_VC_USB_STRM_ISO_ENABLE
|
425 CPIA2_VC_USB_STRM_INT_ENABLE
);
427 if (alt
== USBIF_BULK
) {
428 DBG("Enabling bulk xfer\n");
429 reg
|= CPIA2_VC_USB_STRM_BLK_ENABLE
; /* Enable Bulk */
430 cam
->xfer_mode
= XFER_BULK
;
431 } else if (alt
>= USBIF_ISO_1
) {
432 DBG("Enabling ISOC xfer\n");
433 reg
|= CPIA2_VC_USB_STRM_ISO_ENABLE
;
434 cam
->xfer_mode
= XFER_ISOC
;
437 cmd
.buffer
.block_data
[0] = reg
;
438 cmd
.direction
= TRANSFER_WRITE
;
439 cmd
.start
= CPIA2_VC_USB_STRM
;
441 cmd
.req_mode
= CAMERAACCESS_TYPE_BLOCK
| CAMERAACCESS_VC
;
442 cpia2_send_command(cam
, &cmd
);
447 /******************************************************************************
449 * cpia2_usb_change_streaming_alternate
451 *****************************************************************************/
452 int cpia2_usb_change_streaming_alternate(struct camera_data
*cam
,
457 if(alt
< USBIF_ISO_1
|| alt
> USBIF_ISO_6
)
460 if(alt
== cam
->params
.camera_state
.stream_mode
)
463 cpia2_usb_stream_pause(cam
);
465 configure_transfer_mode(cam
, alt
);
467 cam
->params
.camera_state
.stream_mode
= alt
;
469 /* Reset the camera to prevent image quality degradation */
470 cpia2_reset_camera(cam
);
472 cpia2_usb_stream_resume(cam
);
477 /******************************************************************************
481 *****************************************************************************/
482 static int set_alternate(struct camera_data
*cam
, unsigned int alt
)
486 if(alt
== cam
->cur_alt
)
489 if (cam
->cur_alt
!= USBIF_CMDONLY
) {
490 DBG("Changing from alt %d to %d\n", cam
->cur_alt
, USBIF_CMDONLY
);
491 ret
= usb_set_interface(cam
->dev
, cam
->iface
, USBIF_CMDONLY
);
495 if (alt
!= USBIF_CMDONLY
) {
496 DBG("Changing from alt %d to %d\n", USBIF_CMDONLY
, alt
);
497 ret
= usb_set_interface(cam
->dev
, cam
->iface
, alt
);
502 cam
->old_alt
= cam
->cur_alt
;
508 /******************************************************************************
512 * Free all cam->sbuf[]. All non-NULL .data and .urb members that are non-NULL
513 * are assumed to be allocated. Non-NULL .urb members are also assumed to be
514 * submitted (and must therefore be killed before they are freed).
515 *****************************************************************************/
516 static void free_sbufs(struct camera_data
*cam
)
520 for (i
= 0; i
< NUM_SBUF
; i
++) {
521 if(cam
->sbuf
[i
].urb
) {
522 usb_kill_urb(cam
->sbuf
[i
].urb
);
523 usb_free_urb(cam
->sbuf
[i
].urb
);
524 cam
->sbuf
[i
].urb
= NULL
;
526 if(cam
->sbuf
[i
].data
) {
527 kfree(cam
->sbuf
[i
].data
);
528 cam
->sbuf
[i
].data
= NULL
;
534 * Convenience functions
536 /****************************************************************************
540 ***************************************************************************/
541 static int write_packet(struct usb_device
*udev
,
542 u8 request
, u8
* registers
, u16 start
, size_t size
)
544 if (!registers
|| size
<= 0)
547 return usb_control_msg(udev
,
548 usb_sndctrlpipe(udev
, 0),
550 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
553 registers
, /* buffer */
558 /****************************************************************************
562 ***************************************************************************/
563 static int read_packet(struct usb_device
*udev
,
564 u8 request
, u8
* registers
, u16 start
, size_t size
)
566 if (!registers
|| size
<= 0)
569 return usb_control_msg(udev
,
570 usb_rcvctrlpipe(udev
, 0),
572 USB_DIR_IN
|USB_TYPE_VENDOR
|USB_RECIP_DEVICE
,
575 registers
, /* buffer */
580 /******************************************************************************
582 * cpia2_usb_transfer_cmd
584 *****************************************************************************/
585 int cpia2_usb_transfer_cmd(struct camera_data
*cam
,
587 u8 request
, u8 start
, u8 count
, u8 direction
)
590 struct usb_device
*udev
= cam
->dev
;
593 ERR("%s: Internal driver error: udev is NULL\n", __func__
);
598 ERR("%s: Internal driver error: register array is NULL\n", __func__
);
602 if (direction
== TRANSFER_READ
) {
603 err
= read_packet(udev
, request
, (u8
*)registers
, start
, count
);
606 } else if (direction
== TRANSFER_WRITE
) {
607 err
=write_packet(udev
, request
, (u8
*)registers
, start
, count
);
609 LOG("Control message failed, err val = %d\n", err
);
610 LOG("Message: request = 0x%0X, start = 0x%0X\n",
612 LOG("Message: count = %d, register[0] = 0x%0X\n",
613 count
, ((unsigned char *) registers
)[0]);
617 LOG("Unexpected first byte of direction: %d\n",
623 LOG("Unexpected error: %d\n", err
);
628 /******************************************************************************
632 *****************************************************************************/
633 static int submit_urbs(struct camera_data
*cam
)
638 for(i
=0; i
<NUM_SBUF
; ++i
) {
639 if (cam
->sbuf
[i
].data
)
642 kmalloc(FRAMES_PER_DESC
* FRAME_SIZE_PER_DESC
, GFP_KERNEL
);
643 if (!cam
->sbuf
[i
].data
) {
645 kfree(cam
->sbuf
[i
].data
);
646 cam
->sbuf
[i
].data
= NULL
;
652 /* We double buffer the Isoc lists, and also know the polling
653 * interval is every frame (1 == (1 << (bInterval -1))).
655 for(i
=0; i
<NUM_SBUF
; ++i
) {
656 if(cam
->sbuf
[i
].urb
) {
659 urb
= usb_alloc_urb(FRAMES_PER_DESC
, GFP_KERNEL
);
661 ERR("%s: usb_alloc_urb error!\n", __func__
);
662 for (j
= 0; j
< i
; j
++)
663 usb_free_urb(cam
->sbuf
[j
].urb
);
667 cam
->sbuf
[i
].urb
= urb
;
670 urb
->pipe
= usb_rcvisocpipe(cam
->dev
, 1 /*ISOC endpoint*/);
671 urb
->transfer_flags
= URB_ISO_ASAP
;
672 urb
->transfer_buffer
= cam
->sbuf
[i
].data
;
673 urb
->complete
= cpia2_usb_complete
;
674 urb
->number_of_packets
= FRAMES_PER_DESC
;
676 urb
->transfer_buffer_length
=
677 FRAME_SIZE_PER_DESC
* FRAMES_PER_DESC
;
679 for (fx
= 0; fx
< FRAMES_PER_DESC
; fx
++) {
680 urb
->iso_frame_desc
[fx
].offset
=
681 FRAME_SIZE_PER_DESC
* fx
;
682 urb
->iso_frame_desc
[fx
].length
= FRAME_SIZE_PER_DESC
;
687 /* Queue the ISO urbs, and resubmit in the completion handler */
688 for(i
=0; i
<NUM_SBUF
; ++i
) {
689 err
= usb_submit_urb(cam
->sbuf
[i
].urb
, GFP_KERNEL
);
691 ERR("usb_submit_urb[%d]() = %d\n", i
, err
);
699 /******************************************************************************
701 * cpia2_usb_stream_start
703 *****************************************************************************/
704 int cpia2_usb_stream_start(struct camera_data
*cam
, unsigned int alternate
)
714 DBG("Flushing buffers\n");
715 for(i
=0; i
<cam
->num_frames
; ++i
) {
716 cam
->buffers
[i
].status
= FRAME_EMPTY
;
717 cam
->buffers
[i
].length
= 0;
719 cam
->curbuff
= &cam
->buffers
[0];
720 cam
->workbuff
= cam
->curbuff
->next
;
724 old_alt
= cam
->params
.camera_state
.stream_mode
;
725 cam
->params
.camera_state
.stream_mode
= 0;
726 ret
= cpia2_usb_change_streaming_alternate(cam
, alternate
);
729 ERR("cpia2_usb_change_streaming_alternate() = %d!\n", ret
);
730 cam
->params
.camera_state
.stream_mode
= old_alt
;
731 ret2
= set_alternate(cam
, USBIF_CMDONLY
);
733 ERR("cpia2_usb_change_streaming_alternate(%d) =%d has already "
734 "failed. Then tried to call "
735 "set_alternate(USBIF_CMDONLY) = %d.\n",
736 alternate
, ret
, ret2
);
739 cam
->frame_count
= 0;
741 ret
= cpia2_usb_stream_resume(cam
);
746 /******************************************************************************
748 * cpia2_usb_stream_pause
750 *****************************************************************************/
751 int cpia2_usb_stream_pause(struct camera_data
*cam
)
755 ret
= set_alternate(cam
, USBIF_CMDONLY
);
761 /******************************************************************************
763 * cpia2_usb_stream_resume
765 *****************************************************************************/
766 int cpia2_usb_stream_resume(struct camera_data
*cam
)
770 cam
->first_image_seen
= 0;
771 ret
= set_alternate(cam
, cam
->params
.camera_state
.stream_mode
);
773 ret
= submit_urbs(cam
);
779 /******************************************************************************
781 * cpia2_usb_stream_stop
783 *****************************************************************************/
784 int cpia2_usb_stream_stop(struct camera_data
*cam
)
787 ret
= cpia2_usb_stream_pause(cam
);
789 configure_transfer_mode(cam
, 0);
793 /******************************************************************************
797 * Probe and initialize.
798 *****************************************************************************/
799 static int cpia2_usb_probe(struct usb_interface
*intf
,
800 const struct usb_device_id
*id
)
802 struct usb_device
*udev
= interface_to_usbdev(intf
);
803 struct usb_interface_descriptor
*interface
;
804 struct camera_data
*cam
;
807 /* A multi-config CPiA2 camera? */
808 if (udev
->descriptor
.bNumConfigurations
!= 1)
810 interface
= &intf
->cur_altsetting
->desc
;
812 /* If we get to this point, we found a CPiA2 camera */
813 LOG("CPiA2 USB camera found\n");
815 if((cam
= cpia2_init_camera_struct()) == NULL
)
819 cam
->iface
= interface
->bInterfaceNumber
;
821 ret
= set_alternate(cam
, USBIF_CMDONLY
);
823 ERR("%s: usb_set_interface error (ret = %d)\n", __func__
, ret
);
828 if ((ret
= cpia2_register_camera(cam
)) < 0) {
829 ERR("%s: Failed to register cpia2 camera (ret = %d)\n", __func__
, ret
);
835 if((ret
= cpia2_init_camera(cam
)) < 0) {
836 ERR("%s: failed to initialize cpia2 camera (ret = %d)\n", __func__
, ret
);
837 cpia2_unregister_camera(cam
);
841 LOG(" CPiA Version: %d.%02d (%d.%d)\n",
842 cam
->params
.version
.firmware_revision_hi
,
843 cam
->params
.version
.firmware_revision_lo
,
844 cam
->params
.version
.asic_id
,
845 cam
->params
.version
.asic_rev
);
846 LOG(" CPiA PnP-ID: %04x:%04x:%04x\n",
847 cam
->params
.pnp_id
.vendor
,
848 cam
->params
.pnp_id
.product
,
849 cam
->params
.pnp_id
.device_revision
);
850 LOG(" SensorID: %d.(version %d)\n",
851 cam
->params
.version
.sensor_flags
,
852 cam
->params
.version
.sensor_rev
);
854 usb_set_intfdata(intf
, cam
);
859 /******************************************************************************
863 *****************************************************************************/
864 static void cpia2_usb_disconnect(struct usb_interface
*intf
)
866 struct camera_data
*cam
= usb_get_intfdata(intf
);
867 usb_set_intfdata(intf
, NULL
);
870 DBG("Stopping stream\n");
871 cpia2_usb_stream_stop(cam
);
873 DBG("Unregistering camera\n");
874 cpia2_unregister_camera(cam
);
877 DBG("Wakeup waiting processes\n");
878 cam
->curbuff
->status
= FRAME_READY
;
879 cam
->curbuff
->length
= 0;
880 if (waitqueue_active(&cam
->wq_stream
))
881 wake_up_interruptible(&cam
->wq_stream
);
884 DBG("Releasing interface\n");
885 usb_driver_release_interface(&cpia2_driver
, intf
);
887 if (cam
->open_count
== 0) {
888 DBG("Freeing camera structure\n");
892 LOG("CPiA2 camera disconnected.\n");
896 /******************************************************************************
900 *****************************************************************************/
901 int cpia2_usb_init(void)
903 return usb_register(&cpia2_driver
);
906 /******************************************************************************
910 *****************************************************************************/
911 void cpia2_usb_cleanup(void)
913 schedule_timeout(2 * HZ
);
914 usb_deregister(&cpia2_driver
);