Lines Matching full:cam
37 #define FRAME_SIZE_PER_DESC frame_sizes[cam->cur_alt]
39 static void process_frame(struct camera_data *cam);
47 static void free_sbufs(struct camera_data *cam);
48 static void add_APPn(struct camera_data *cam);
49 static void add_COM(struct camera_data *cam);
50 static int submit_urbs(struct camera_data *cam);
51 static int set_alternate(struct camera_data *cam, unsigned int alt);
52 static int configure_transfer_mode(struct camera_data *cam, unsigned int alt);
78 static void process_frame(struct camera_data *cam) in process_frame() argument
82 unsigned char *inbuff = cam->workbuff->data; in process_frame()
85 cam->workbuff->num, cam->curbuff->num); in process_frame()
87 if(cam->workbuff->length > cam->workbuff->max_length) in process_frame()
88 cam->workbuff->max_length = cam->workbuff->length; in process_frame()
93 cam->workbuff->status = FRAME_ERROR; in process_frame()
101 if(!cam->first_image_seen) { in process_frame()
104 cam->first_image_seen = 1; in process_frame()
105 cam->workbuff->status = FRAME_EMPTY; in process_frame()
108 if (cam->workbuff->length > 3) { in process_frame()
109 if(cam->mmapped && in process_frame()
110 cam->workbuff->length < cam->workbuff->max_length) { in process_frame()
112 memset(cam->workbuff->data+cam->workbuff->length, in process_frame()
113 0, cam->workbuff->max_length- in process_frame()
114 cam->workbuff->length); in process_frame()
116 cam->workbuff->max_length = cam->workbuff->length; in process_frame()
117 cam->workbuff->status = FRAME_READY; in process_frame()
119 if(!cam->mmapped && cam->num_frames > 2) { in process_frame()
133 * cam->num_frames-2 frames before problems in process_frame()
136 cam->curbuff->status = FRAME_EMPTY; in process_frame()
138 cam->curbuff = cam->workbuff; in process_frame()
139 cam->workbuff = cam->workbuff->next; in process_frame()
141 cam->workbuff->num, cam->curbuff->num); in process_frame()
147 cam->workbuff->status = FRAME_ERROR; in process_frame()
157 static void add_APPn(struct camera_data *cam) in add_APPn() argument
159 if(cam->APP_len > 0) { in add_APPn()
160 cam->workbuff->data[cam->workbuff->length++] = 0xFF; in add_APPn()
161 cam->workbuff->data[cam->workbuff->length++] = 0xE0+cam->APPn; in add_APPn()
162 cam->workbuff->data[cam->workbuff->length++] = 0; in add_APPn()
163 cam->workbuff->data[cam->workbuff->length++] = cam->APP_len+2; in add_APPn()
164 memcpy(cam->workbuff->data+cam->workbuff->length, in add_APPn()
165 cam->APP_data, cam->APP_len); in add_APPn()
166 cam->workbuff->length += cam->APP_len; in add_APPn()
176 static void add_COM(struct camera_data *cam) in add_COM() argument
178 if(cam->COM_len > 0) { in add_COM()
179 cam->workbuff->data[cam->workbuff->length++] = 0xFF; in add_COM()
180 cam->workbuff->data[cam->workbuff->length++] = 0xFE; in add_COM()
181 cam->workbuff->data[cam->workbuff->length++] = 0; in add_COM()
182 cam->workbuff->data[cam->workbuff->length++] = cam->COM_len+2; in add_COM()
183 memcpy(cam->workbuff->data+cam->workbuff->length, in add_COM()
184 cam->COM_data, cam->COM_len); in add_COM()
185 cam->workbuff->length += cam->COM_len; in add_COM()
200 struct camera_data *cam = (struct camera_data *) urb->context; in cpia2_usb_complete() local
213 if (!cam->streaming || !video_is_registered(&cam->vdev)) { in cpia2_usb_complete()
215 cam->streaming, video_is_registered(&cam->vdev)); in cpia2_usb_complete()
229 if(cam->workbuff->status == FRAME_READY) { in cpia2_usb_complete()
233 for (ptr = cam->workbuff->next; in cpia2_usb_complete()
234 ptr != cam->workbuff; in cpia2_usb_complete()
243 if (ptr == cam->workbuff) in cpia2_usb_complete()
246 cam->workbuff = ptr; in cpia2_usb_complete()
249 if (cam->workbuff->status == FRAME_EMPTY || in cpia2_usb_complete()
250 cam->workbuff->status == FRAME_ERROR) { in cpia2_usb_complete()
251 cam->workbuff->status = FRAME_READING; in cpia2_usb_complete()
252 cam->workbuff->length = 0; in cpia2_usb_complete()
262 cam->workbuff->status = FRAME_ERROR; in cpia2_usb_complete()
277 cam->workbuff->status = FRAME_ERROR; in cpia2_usb_complete()
283 if(cam->workbuff->status != FRAME_READING) { in cpia2_usb_complete()
289 cam->frame_count++; in cpia2_usb_complete()
292 cam->workbuff->status); in cpia2_usb_complete()
296 if (cam->frame_size < cam->workbuff->length + n) { in cpia2_usb_complete()
298 cam->workbuff->length, n); in cpia2_usb_complete()
299 cam->workbuff->status = FRAME_ERROR; in cpia2_usb_complete()
300 if(cam->workbuff->length > cam->workbuff->max_length) in cpia2_usb_complete()
301 cam->workbuff->max_length = in cpia2_usb_complete()
302 cam->workbuff->length; in cpia2_usb_complete()
306 if (cam->workbuff->length == 0) { in cpia2_usb_complete()
318 cam->workbuff->ts = ktime_get_ns(); in cpia2_usb_complete()
319 cam->workbuff->seq = cam->frame_count++; in cpia2_usb_complete()
320 cam->workbuff->data[0] = 0xFF; in cpia2_usb_complete()
321 cam->workbuff->data[1] = 0xD8; in cpia2_usb_complete()
322 cam->workbuff->length = 2; in cpia2_usb_complete()
323 add_APPn(cam); in cpia2_usb_complete()
324 add_COM(cam); in cpia2_usb_complete()
325 memcpy(cam->workbuff->data+cam->workbuff->length, in cpia2_usb_complete()
327 cam->workbuff->length += n-data_offset; in cpia2_usb_complete()
328 } else if (cam->workbuff->length > 0) { in cpia2_usb_complete()
329 memcpy(cam->workbuff->data + cam->workbuff->length, in cpia2_usb_complete()
331 cam->workbuff->length += n; in cpia2_usb_complete()
334 if ((cam->workbuff->length >= 3) && in cpia2_usb_complete()
335 (cam->workbuff->data[cam->workbuff->length - 3] == 0xFF) && in cpia2_usb_complete()
336 (cam->workbuff->data[cam->workbuff->length - 2] == 0xD9) && in cpia2_usb_complete()
337 (cam->workbuff->data[cam->workbuff->length - 1] == 0xFF)) { in cpia2_usb_complete()
339 cam->workbuff->data[cam->workbuff->length - 1] = 0; in cpia2_usb_complete()
340 cam->workbuff->length -= 1; in cpia2_usb_complete()
341 } else if ((cam->workbuff->length >= 2) && in cpia2_usb_complete()
342 (cam->workbuff->data[cam->workbuff->length - 2] == 0xFF) && in cpia2_usb_complete()
343 (cam->workbuff->data[cam->workbuff->length - 1] == 0xD9)) { in cpia2_usb_complete()
348 DBG("Workbuff image size = %d\n",cam->workbuff->length); in cpia2_usb_complete()
349 process_frame(cam); in cpia2_usb_complete()
353 if (waitqueue_active(&cam->wq_stream)) in cpia2_usb_complete()
354 wake_up_interruptible(&cam->wq_stream); in cpia2_usb_complete()
358 if(cam->streaming) { in cpia2_usb_complete()
360 urb->dev = cam->dev; in cpia2_usb_complete()
371 static int configure_transfer_mode(struct camera_data *cam, unsigned int alt) in configure_transfer_mode() argument
386 if (!video_is_registered(&cam->vdev)) in configure_transfer_mode()
400 cpia2_send_command(cam, &cmd); in configure_transfer_mode()
410 cpia2_send_command(cam, &cmd); in configure_transfer_mode()
421 cam->xfer_mode = XFER_BULK; in configure_transfer_mode()
425 cam->xfer_mode = XFER_ISOC; in configure_transfer_mode()
433 cpia2_send_command(cam, &cmd); in configure_transfer_mode()
443 int cpia2_usb_change_streaming_alternate(struct camera_data *cam, in cpia2_usb_change_streaming_alternate() argument
451 if(alt == cam->params.camera_state.stream_mode) in cpia2_usb_change_streaming_alternate()
454 cpia2_usb_stream_pause(cam); in cpia2_usb_change_streaming_alternate()
456 configure_transfer_mode(cam, alt); in cpia2_usb_change_streaming_alternate()
458 cam->params.camera_state.stream_mode = alt; in cpia2_usb_change_streaming_alternate()
461 cpia2_reset_camera(cam); in cpia2_usb_change_streaming_alternate()
463 cpia2_usb_stream_resume(cam); in cpia2_usb_change_streaming_alternate()
473 static int set_alternate(struct camera_data *cam, unsigned int alt) in set_alternate() argument
477 if(alt == cam->cur_alt) in set_alternate()
480 if (cam->cur_alt != USBIF_CMDONLY) { in set_alternate()
481 DBG("Changing from alt %d to %d\n", cam->cur_alt, USBIF_CMDONLY); in set_alternate()
482 ret = usb_set_interface(cam->dev, cam->iface, USBIF_CMDONLY); in set_alternate()
488 ret = usb_set_interface(cam->dev, cam->iface, alt); in set_alternate()
493 cam->old_alt = cam->cur_alt; in set_alternate()
494 cam->cur_alt = alt; in set_alternate()
503 * Free all cam->sbuf[]. All non-NULL .data and .urb members that are non-NULL
507 static void free_sbufs(struct camera_data *cam) in free_sbufs() argument
512 if(cam->sbuf[i].urb) { in free_sbufs()
513 usb_kill_urb(cam->sbuf[i].urb); in free_sbufs()
514 usb_free_urb(cam->sbuf[i].urb); in free_sbufs()
515 cam->sbuf[i].urb = NULL; in free_sbufs()
517 if(cam->sbuf[i].data) { in free_sbufs()
518 kfree(cam->sbuf[i].data); in free_sbufs()
519 cam->sbuf[i].data = NULL; in free_sbufs()
600 int cpia2_usb_transfer_cmd(struct camera_data *cam, in cpia2_usb_transfer_cmd() argument
605 struct usb_device *udev = cam->dev; in cpia2_usb_transfer_cmd()
648 static int submit_urbs(struct camera_data *cam) in submit_urbs() argument
654 if (cam->sbuf[i].data) in submit_urbs()
656 cam->sbuf[i].data = in submit_urbs()
659 if (!cam->sbuf[i].data) { in submit_urbs()
661 kfree(cam->sbuf[i].data); in submit_urbs()
662 cam->sbuf[i].data = NULL; in submit_urbs()
672 if(cam->sbuf[i].urb) { in submit_urbs()
678 usb_free_urb(cam->sbuf[j].urb); in submit_urbs()
680 kfree(cam->sbuf[j].data); in submit_urbs()
681 cam->sbuf[j].data = NULL; in submit_urbs()
686 cam->sbuf[i].urb = urb; in submit_urbs()
687 urb->dev = cam->dev; in submit_urbs()
688 urb->context = cam; in submit_urbs()
689 urb->pipe = usb_rcvisocpipe(cam->dev, 1 /*ISOC endpoint*/); in submit_urbs()
691 urb->transfer_buffer = cam->sbuf[i].data; in submit_urbs()
708 err = usb_submit_urb(cam->sbuf[i].urb, GFP_KERNEL); in submit_urbs()
723 int cpia2_usb_stream_start(struct camera_data *cam, unsigned int alternate) in cpia2_usb_stream_start() argument
728 if(cam->streaming) in cpia2_usb_stream_start()
731 if (cam->flush) { in cpia2_usb_stream_start()
734 for(i=0; i<cam->num_frames; ++i) { in cpia2_usb_stream_start()
735 cam->buffers[i].status = FRAME_EMPTY; in cpia2_usb_stream_start()
736 cam->buffers[i].length = 0; in cpia2_usb_stream_start()
738 cam->curbuff = &cam->buffers[0]; in cpia2_usb_stream_start()
739 cam->workbuff = cam->curbuff->next; in cpia2_usb_stream_start()
740 cam->flush = false; in cpia2_usb_stream_start()
743 old_alt = cam->params.camera_state.stream_mode; in cpia2_usb_stream_start()
744 cam->params.camera_state.stream_mode = 0; in cpia2_usb_stream_start()
745 ret = cpia2_usb_change_streaming_alternate(cam, alternate); in cpia2_usb_stream_start()
749 cam->params.camera_state.stream_mode = old_alt; in cpia2_usb_stream_start()
750 ret2 = set_alternate(cam, USBIF_CMDONLY); in cpia2_usb_stream_start()
756 cam->frame_count = 0; in cpia2_usb_stream_start()
757 cam->streaming = 1; in cpia2_usb_stream_start()
758 ret = cpia2_usb_stream_resume(cam); in cpia2_usb_stream_start()
768 int cpia2_usb_stream_pause(struct camera_data *cam) in cpia2_usb_stream_pause() argument
771 if(cam->streaming) { in cpia2_usb_stream_pause()
772 free_sbufs(cam); in cpia2_usb_stream_pause()
773 ret = set_alternate(cam, USBIF_CMDONLY); in cpia2_usb_stream_pause()
783 int cpia2_usb_stream_resume(struct camera_data *cam) in cpia2_usb_stream_resume() argument
786 if(cam->streaming) { in cpia2_usb_stream_resume()
787 cam->first_image_seen = 0; in cpia2_usb_stream_resume()
788 ret = set_alternate(cam, cam->params.camera_state.stream_mode); in cpia2_usb_stream_resume()
792 cpia2_do_command(cam, CPIA2_CMD_SET_USER_EFFECTS, TRANSFER_WRITE, in cpia2_usb_stream_resume()
793 cam->params.vp_params.user_effects); in cpia2_usb_stream_resume()
794 ret = submit_urbs(cam); in cpia2_usb_stream_resume()
805 int cpia2_usb_stream_stop(struct camera_data *cam) in cpia2_usb_stream_stop() argument
809 ret = cpia2_usb_stream_pause(cam); in cpia2_usb_stream_stop()
810 cam->streaming = 0; in cpia2_usb_stream_stop()
811 configure_transfer_mode(cam, 0); in cpia2_usb_stream_stop()
826 struct camera_data *cam; in cpia2_usb_probe() local
837 cam = cpia2_init_camera_struct(intf); in cpia2_usb_probe()
838 if (cam == NULL) in cpia2_usb_probe()
841 cam->dev = udev; in cpia2_usb_probe()
842 cam->iface = interface->bInterfaceNumber; in cpia2_usb_probe()
844 ret = set_alternate(cam, USBIF_CMDONLY); in cpia2_usb_probe()
847 kfree(cam); in cpia2_usb_probe()
852 if((ret = cpia2_init_camera(cam)) < 0) { in cpia2_usb_probe()
854 kfree(cam); in cpia2_usb_probe()
858 cam->params.version.firmware_revision_hi, in cpia2_usb_probe()
859 cam->params.version.firmware_revision_lo, in cpia2_usb_probe()
860 cam->params.version.asic_id, in cpia2_usb_probe()
861 cam->params.version.asic_rev); in cpia2_usb_probe()
863 cam->params.pnp_id.vendor, in cpia2_usb_probe()
864 cam->params.pnp_id.product, in cpia2_usb_probe()
865 cam->params.pnp_id.device_revision); in cpia2_usb_probe()
867 cam->params.version.sensor_flags, in cpia2_usb_probe()
868 cam->params.version.sensor_rev); in cpia2_usb_probe()
870 usb_set_intfdata(intf, cam); in cpia2_usb_probe()
872 ret = cpia2_register_camera(cam); in cpia2_usb_probe()
875 kfree(cam); in cpia2_usb_probe()
889 struct camera_data *cam = usb_get_intfdata(intf); in cpia2_usb_disconnect() local
893 cpia2_usb_stream_stop(cam); in cpia2_usb_disconnect()
895 mutex_lock(&cam->v4l2_lock); in cpia2_usb_disconnect()
897 cpia2_unregister_camera(cam); in cpia2_usb_disconnect()
898 v4l2_device_disconnect(&cam->v4l2_dev); in cpia2_usb_disconnect()
899 mutex_unlock(&cam->v4l2_lock); in cpia2_usb_disconnect()
901 if(cam->buffers) { in cpia2_usb_disconnect()
903 cam->curbuff->status = FRAME_READY; in cpia2_usb_disconnect()
904 cam->curbuff->length = 0; in cpia2_usb_disconnect()
905 wake_up_interruptible(&cam->wq_stream); in cpia2_usb_disconnect()
908 v4l2_device_put(&cam->v4l2_dev); in cpia2_usb_disconnect()
915 struct camera_data *cam = usb_get_intfdata(intf); in cpia2_usb_suspend() local
917 mutex_lock(&cam->v4l2_lock); in cpia2_usb_suspend()
918 if (cam->streaming) { in cpia2_usb_suspend()
919 cpia2_usb_stream_stop(cam); in cpia2_usb_suspend()
920 cam->streaming = 1; in cpia2_usb_suspend()
922 mutex_unlock(&cam->v4l2_lock); in cpia2_usb_suspend()
931 struct camera_data *cam = usb_get_intfdata(intf); in cpia2_usb_resume() local
933 mutex_lock(&cam->v4l2_lock); in cpia2_usb_resume()
934 v4l2_ctrl_handler_setup(&cam->hdl); in cpia2_usb_resume()
935 if (cam->streaming) { in cpia2_usb_resume()
936 cam->streaming = 0; in cpia2_usb_resume()
937 cpia2_usb_stream_start(cam, in cpia2_usb_resume()
938 cam->params.camera_state.stream_mode); in cpia2_usb_resume()
940 mutex_unlock(&cam->v4l2_lock); in cpia2_usb_resume()