Lines Matching refs:pdev

119 static void pwc_isoc_cleanup(struct pwc_device *pdev);
164 struct pwc_frame_buf *pwc_get_next_fill_buf(struct pwc_device *pdev) in pwc_get_next_fill_buf() argument
169 spin_lock_irqsave(&pdev->queued_bufs_lock, flags); in pwc_get_next_fill_buf()
170 if (list_empty(&pdev->queued_bufs)) in pwc_get_next_fill_buf()
173 buf = list_entry(pdev->queued_bufs.next, struct pwc_frame_buf, list); in pwc_get_next_fill_buf()
176 spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags); in pwc_get_next_fill_buf()
180 static void pwc_snapshot_button(struct pwc_device *pdev, int down) in pwc_snapshot_button() argument
189 if (pdev->button_dev) { in pwc_snapshot_button()
190 input_report_key(pdev->button_dev, KEY_CAMERA, down); in pwc_snapshot_button()
191 input_sync(pdev->button_dev); in pwc_snapshot_button()
196 static void pwc_frame_complete(struct pwc_device *pdev) in pwc_frame_complete() argument
198 struct pwc_frame_buf *fbuf = pdev->fill_buf; in pwc_frame_complete()
204 if (pdev->type == 730) { in pwc_frame_complete()
209 pdev->drop_frames += 2; in pwc_frame_complete()
211 if ((ptr[0] ^ pdev->vmirror) & 0x01) { in pwc_frame_complete()
212 pwc_snapshot_button(pdev, ptr[0] & 0x01); in pwc_frame_complete()
214 if ((ptr[0] ^ pdev->vmirror) & 0x02) { in pwc_frame_complete()
220 pdev->vmirror = ptr[0] & 0x03; in pwc_frame_complete()
231 pdev->drop_frames++; in pwc_frame_complete()
232 } else if (pdev->type == 740 || pdev->type == 720) { in pwc_frame_complete()
234 if ((ptr[0] ^ pdev->vmirror) & 0x01) { in pwc_frame_complete()
235 pwc_snapshot_button(pdev, ptr[0] & 0x01); in pwc_frame_complete()
237 pdev->vmirror = ptr[0] & 0x03; in pwc_frame_complete()
241 if (pdev->drop_frames > 0) { in pwc_frame_complete()
242 pdev->drop_frames--; in pwc_frame_complete()
245 if (fbuf->filled < pdev->frame_total_size) { in pwc_frame_complete()
250 fbuf->vb.v4l2_buf.sequence = pdev->vframe_count; in pwc_frame_complete()
252 pdev->fill_buf = NULL; in pwc_frame_complete()
253 pdev->vsync = 0; in pwc_frame_complete()
256 pdev->vframe_count++; in pwc_frame_complete()
264 struct pwc_device *pdev = (struct pwc_device *)urb->context; in pwc_isoc_handler() local
274 if (pdev->fill_buf == NULL) in pwc_isoc_handler()
275 pdev->fill_buf = pwc_get_next_fill_buf(pdev); in pwc_isoc_handler()
292 if (++pdev->visoc_errors > MAX_ISOC_ERRORS) in pwc_isoc_handler()
295 if (pdev->fill_buf) { in pwc_isoc_handler()
296 vb2_buffer_done(&pdev->fill_buf->vb, in pwc_isoc_handler()
298 pdev->fill_buf = NULL; in pwc_isoc_handler()
301 pdev->vsync = 0; /* Drop the current frame */ in pwc_isoc_handler()
306 pdev->visoc_errors = 0; in pwc_isoc_handler()
321 if (flen > 0 && pdev->vsync) { in pwc_isoc_handler()
322 struct pwc_frame_buf *fbuf = pdev->fill_buf; in pwc_isoc_handler()
324 if (pdev->vsync == 1) { in pwc_isoc_handler()
326 pdev->vsync = 2; in pwc_isoc_handler()
329 if (flen + fbuf->filled > pdev->frame_total_size) { in pwc_isoc_handler()
332 pdev->frame_total_size); in pwc_isoc_handler()
333 pdev->vsync = 0; /* Let's wait for an EOF */ in pwc_isoc_handler()
340 if (flen < pdev->vlast_packet_size) { in pwc_isoc_handler()
342 if (pdev->vsync == 2) in pwc_isoc_handler()
343 pwc_frame_complete(pdev); in pwc_isoc_handler()
344 if (pdev->fill_buf == NULL) in pwc_isoc_handler()
345 pdev->fill_buf = pwc_get_next_fill_buf(pdev); in pwc_isoc_handler()
346 if (pdev->fill_buf) { in pwc_isoc_handler()
347 pdev->fill_buf->filled = 0; in pwc_isoc_handler()
348 pdev->vsync = 1; in pwc_isoc_handler()
351 pdev->vlast_packet_size = flen; in pwc_isoc_handler()
360 static int pwc_isoc_init(struct pwc_device *pdev) in pwc_isoc_init() argument
369 if (pdev->iso_init) in pwc_isoc_init()
372 pdev->vsync = 0; in pwc_isoc_init()
373 pdev->vlast_packet_size = 0; in pwc_isoc_init()
374 pdev->fill_buf = NULL; in pwc_isoc_init()
375 pdev->vframe_count = 0; in pwc_isoc_init()
376 pdev->visoc_errors = 0; in pwc_isoc_init()
377 udev = pdev->udev; in pwc_isoc_init()
382 ret = pwc_set_video_mode(pdev, pdev->width, pdev->height, pdev->pixfmt, in pwc_isoc_init()
383 pdev->vframes, &compression, 1); in pwc_isoc_init()
388 idesc = usb_altnum_to_altsetting(intf, pdev->valternate); in pwc_isoc_init()
393 pdev->vmax_packet_size = -1; in pwc_isoc_init()
395 if ((idesc->endpoint[i].desc.bEndpointAddress & 0xF) == pdev->vendpoint) { in pwc_isoc_init()
396 pdev->vmax_packet_size = le16_to_cpu(idesc->endpoint[i].desc.wMaxPacketSize); in pwc_isoc_init()
401 if (pdev->vmax_packet_size < 0 || pdev->vmax_packet_size > ISO_MAX_FRAME_SIZE) { in pwc_isoc_init()
407 PWC_DEBUG_OPEN("Setting alternate interface %d\n", pdev->valternate); in pwc_isoc_init()
408 ret = usb_set_interface(pdev->udev, 0, pdev->valternate); in pwc_isoc_init()
421 pdev->iso_init = 1; in pwc_isoc_init()
422 pwc_isoc_cleanup(pdev); in pwc_isoc_init()
425 pdev->urbs[i] = urb; in pwc_isoc_init()
430 urb->pipe = usb_rcvisocpipe(udev, pdev->vendpoint); in pwc_isoc_init()
438 pdev->iso_init = 1; in pwc_isoc_init()
439 pwc_isoc_cleanup(pdev); in pwc_isoc_init()
444 urb->context = pdev; in pwc_isoc_init()
449 urb->iso_frame_desc[j].length = pdev->vmax_packet_size; in pwc_isoc_init()
455 ret = usb_submit_urb(pdev->urbs[i], GFP_KERNEL); in pwc_isoc_init()
458 pdev->iso_init = 1; in pwc_isoc_init()
459 pwc_isoc_cleanup(pdev); in pwc_isoc_init()
464 pdev->iso_init = 1; in pwc_isoc_init()
465 pwc_isoc_cleanup(pdev); in pwc_isoc_init()
468 PWC_DEBUG_MEMORY("URB 0x%p submitted.\n", pdev->urbs[i]); in pwc_isoc_init()
472 pdev->iso_init = 1; in pwc_isoc_init()
477 static void pwc_iso_stop(struct pwc_device *pdev) in pwc_iso_stop() argument
483 if (pdev->urbs[i]) { in pwc_iso_stop()
484 PWC_DEBUG_MEMORY("Unlinking URB %p\n", pdev->urbs[i]); in pwc_iso_stop()
485 usb_kill_urb(pdev->urbs[i]); in pwc_iso_stop()
490 static void pwc_iso_free(struct pwc_device *pdev) in pwc_iso_free() argument
496 if (pdev->urbs[i]) { in pwc_iso_free()
498 if (pdev->urbs[i]->transfer_buffer) { in pwc_iso_free()
499 usb_free_coherent(pdev->udev, in pwc_iso_free()
500 pdev->urbs[i]->transfer_buffer_length, in pwc_iso_free()
501 pdev->urbs[i]->transfer_buffer, in pwc_iso_free()
502 pdev->urbs[i]->transfer_dma); in pwc_iso_free()
504 usb_free_urb(pdev->urbs[i]); in pwc_iso_free()
505 pdev->urbs[i] = NULL; in pwc_iso_free()
510 static void pwc_isoc_cleanup(struct pwc_device *pdev) in pwc_isoc_cleanup() argument
514 if (pdev->iso_init == 0) in pwc_isoc_cleanup()
517 pwc_iso_stop(pdev); in pwc_isoc_cleanup()
518 pwc_iso_free(pdev); in pwc_isoc_cleanup()
519 usb_set_interface(pdev->udev, 0, 0); in pwc_isoc_cleanup()
521 pdev->iso_init = 0; in pwc_isoc_cleanup()
525 static void pwc_cleanup_queued_bufs(struct pwc_device *pdev) in pwc_cleanup_queued_bufs() argument
529 spin_lock_irqsave(&pdev->queued_bufs_lock, flags); in pwc_cleanup_queued_bufs()
530 while (!list_empty(&pdev->queued_bufs)) { in pwc_cleanup_queued_bufs()
533 buf = list_entry(pdev->queued_bufs.next, struct pwc_frame_buf, in pwc_cleanup_queued_bufs()
538 spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags); in pwc_cleanup_queued_bufs()
574 int pwc_test_n_set_capt_file(struct pwc_device *pdev, struct file *file) in pwc_test_n_set_capt_file() argument
578 mutex_lock(&pdev->capt_file_lock); in pwc_test_n_set_capt_file()
579 if (pdev->capt_file != NULL && in pwc_test_n_set_capt_file()
580 pdev->capt_file != file) { in pwc_test_n_set_capt_file()
584 pdev->capt_file = file; in pwc_test_n_set_capt_file()
586 mutex_unlock(&pdev->capt_file_lock); in pwc_test_n_set_capt_file()
592 struct pwc_device *pdev = container_of(v, struct pwc_device, v4l2_dev); in pwc_video_release() local
594 v4l2_ctrl_handler_free(&pdev->ctrl_handler); in pwc_video_release()
595 kfree(pdev->ctrl_buf); in pwc_video_release()
596 kfree(pdev); in pwc_video_release()
601 struct pwc_device *pdev = video_drvdata(file); in pwc_video_close() local
603 if (pdev->capt_file == file) { in pwc_video_close()
604 vb2_queue_release(&pdev->vb_queue); in pwc_video_close()
605 pdev->capt_file = NULL; in pwc_video_close()
613 struct pwc_device *pdev = video_drvdata(file); in pwc_video_read() local
615 if (!pdev->udev) in pwc_video_read()
618 if (pwc_test_n_set_capt_file(pdev, file)) in pwc_video_read()
621 return vb2_read(&pdev->vb_queue, buf, count, ppos, in pwc_video_read()
627 struct pwc_device *pdev = video_drvdata(file); in pwc_video_poll() local
629 if (!pdev->udev) in pwc_video_poll()
632 return vb2_poll(&pdev->vb_queue, file, wait); in pwc_video_poll()
637 struct pwc_device *pdev = video_drvdata(file); in pwc_video_mmap() local
639 if (pdev->capt_file != file) in pwc_video_mmap()
642 return vb2_mmap(&pdev->vb_queue, vma); in pwc_video_mmap()
652 struct pwc_device *pdev = vb2_get_drv_priv(vq); in queue_setup() local
662 size = pwc_get_size(pdev, MAX_WIDTH, MAX_HEIGHT); in queue_setup()
683 struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue); in buffer_prepare() local
686 if (!pdev->udev) in buffer_prepare()
694 struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue); in buffer_finish() local
702 return pwc_decompress(pdev, buf); in buffer_finish()
714 struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue); in buffer_queue() local
718 spin_lock_irqsave(&pdev->queued_bufs_lock, flags); in buffer_queue()
720 if (pdev->udev) in buffer_queue()
721 list_add_tail(&buf->list, &pdev->queued_bufs); in buffer_queue()
724 spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags); in buffer_queue()
729 struct pwc_device *pdev = vb2_get_drv_priv(vq); in start_streaming() local
732 mutex_lock(&pdev->udevlock); in start_streaming()
733 if (!pdev->udev) { in start_streaming()
739 pwc_camera_power(pdev, 1); in start_streaming()
740 pwc_set_leds(pdev, leds[0], leds[1]); in start_streaming()
742 r = pwc_isoc_init(pdev); in start_streaming()
745 pwc_set_leds(pdev, 0, 0); in start_streaming()
746 pwc_camera_power(pdev, 0); in start_streaming()
748 pwc_cleanup_queued_bufs(pdev); in start_streaming()
751 mutex_unlock(&pdev->udevlock); in start_streaming()
757 struct pwc_device *pdev = vb2_get_drv_priv(vq); in stop_streaming() local
759 mutex_lock(&pdev->udevlock); in stop_streaming()
760 if (pdev->udev) { in stop_streaming()
761 pwc_set_leds(pdev, 0, 0); in stop_streaming()
762 pwc_camera_power(pdev, 0); in stop_streaming()
763 pwc_isoc_cleanup(pdev); in stop_streaming()
765 mutex_unlock(&pdev->udevlock); in stop_streaming()
767 pwc_cleanup_queued_bufs(pdev); in stop_streaming()
793 struct pwc_device *pdev = NULL; in usb_pwc_probe() local
1051 pdev = kzalloc(sizeof(struct pwc_device), GFP_KERNEL); in usb_pwc_probe()
1052 if (pdev == NULL) { in usb_pwc_probe()
1056 pdev->type = type_id; in usb_pwc_probe()
1057 pdev->features = features; in usb_pwc_probe()
1058 pwc_construct(pdev); /* set min/max sizes correct */ in usb_pwc_probe()
1060 mutex_init(&pdev->capt_file_lock); in usb_pwc_probe()
1061 mutex_init(&pdev->udevlock); in usb_pwc_probe()
1062 spin_lock_init(&pdev->queued_bufs_lock); in usb_pwc_probe()
1063 INIT_LIST_HEAD(&pdev->queued_bufs); in usb_pwc_probe()
1065 pdev->udev = udev; in usb_pwc_probe()
1066 pdev->power_save = my_power_save; in usb_pwc_probe()
1069 memset(&pdev->vb_queue, 0, sizeof(pdev->vb_queue)); in usb_pwc_probe()
1070 pdev->vb_queue.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in usb_pwc_probe()
1071 pdev->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; in usb_pwc_probe()
1072 pdev->vb_queue.drv_priv = pdev; in usb_pwc_probe()
1073 pdev->vb_queue.buf_struct_size = sizeof(struct pwc_frame_buf); in usb_pwc_probe()
1074 pdev->vb_queue.ops = &pwc_vb_queue_ops; in usb_pwc_probe()
1075 pdev->vb_queue.mem_ops = &vb2_vmalloc_memops; in usb_pwc_probe()
1076 vb2_queue_init(&pdev->vb_queue); in usb_pwc_probe()
1079 memcpy(&pdev->vdev, &pwc_template, sizeof(pwc_template)); in usb_pwc_probe()
1080 strcpy(pdev->vdev.name, name); in usb_pwc_probe()
1081 set_bit(V4L2_FL_USE_FH_PRIO, &pdev->vdev.flags); in usb_pwc_probe()
1082 video_set_drvdata(&pdev->vdev, pdev); in usb_pwc_probe()
1084 pdev->release = le16_to_cpu(udev->descriptor.bcdDevice); in usb_pwc_probe()
1085 PWC_DEBUG_PROBE("Release: %04x\n", pdev->release); in usb_pwc_probe()
1088 pdev->ctrl_buf = kmalloc(sizeof(pdev->cmd_buf), GFP_KERNEL); in usb_pwc_probe()
1089 if (!pdev->ctrl_buf) { in usb_pwc_probe()
1097 if (pwc_get_cmos_sensor(pdev, &rc) >= 0) { in usb_pwc_probe()
1099 pdev->vdev.name, in usb_pwc_probe()
1105 pwc_set_leds(pdev, 0, 0); in usb_pwc_probe()
1108 rc = pwc_set_video_mode(pdev, MAX_WIDTH, MAX_HEIGHT, in usb_pwc_probe()
1114 rc = pwc_init_controls(pdev); in usb_pwc_probe()
1121 pwc_camera_power(pdev, 0); in usb_pwc_probe()
1124 pdev->v4l2_dev.release = pwc_video_release; in usb_pwc_probe()
1125 rc = v4l2_device_register(&intf->dev, &pdev->v4l2_dev); in usb_pwc_probe()
1131 pdev->v4l2_dev.ctrl_handler = &pdev->ctrl_handler; in usb_pwc_probe()
1132 pdev->vdev.v4l2_dev = &pdev->v4l2_dev; in usb_pwc_probe()
1134 rc = video_register_device(&pdev->vdev, VFL_TYPE_GRABBER, -1); in usb_pwc_probe()
1139 PWC_INFO("Registered as %s.\n", video_device_node_name(&pdev->vdev)); in usb_pwc_probe()
1143 pdev->button_dev = input_allocate_device(); in usb_pwc_probe()
1144 if (!pdev->button_dev) { in usb_pwc_probe()
1150 usb_make_path(udev, pdev->button_phys, sizeof(pdev->button_phys)); in usb_pwc_probe()
1151 strlcat(pdev->button_phys, "/input0", sizeof(pdev->button_phys)); in usb_pwc_probe()
1153 pdev->button_dev->name = "PWC snapshot button"; in usb_pwc_probe()
1154 pdev->button_dev->phys = pdev->button_phys; in usb_pwc_probe()
1155 usb_to_input_id(pdev->udev, &pdev->button_dev->id); in usb_pwc_probe()
1156 pdev->button_dev->dev.parent = &pdev->udev->dev; in usb_pwc_probe()
1157 pdev->button_dev->evbit[0] = BIT_MASK(EV_KEY); in usb_pwc_probe()
1158 pdev->button_dev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA); in usb_pwc_probe()
1160 rc = input_register_device(pdev->button_dev); in usb_pwc_probe()
1162 input_free_device(pdev->button_dev); in usb_pwc_probe()
1163 pdev->button_dev = NULL; in usb_pwc_probe()
1171 video_unregister_device(&pdev->vdev); in usb_pwc_probe()
1173 v4l2_device_unregister(&pdev->v4l2_dev); in usb_pwc_probe()
1175 v4l2_ctrl_handler_free(&pdev->ctrl_handler); in usb_pwc_probe()
1177 kfree(pdev->ctrl_buf); in usb_pwc_probe()
1178 kfree(pdev); in usb_pwc_probe()
1186 struct pwc_device *pdev = container_of(v, struct pwc_device, v4l2_dev); in usb_pwc_disconnect() local
1188 mutex_lock(&pdev->udevlock); in usb_pwc_disconnect()
1190 pwc_isoc_cleanup(pdev); in usb_pwc_disconnect()
1191 pdev->udev = NULL; in usb_pwc_disconnect()
1192 mutex_unlock(&pdev->udevlock); in usb_pwc_disconnect()
1194 pwc_cleanup_queued_bufs(pdev); in usb_pwc_disconnect()
1196 video_unregister_device(&pdev->vdev); in usb_pwc_disconnect()
1197 v4l2_device_unregister(&pdev->v4l2_dev); in usb_pwc_disconnect()
1200 if (pdev->button_dev) in usb_pwc_disconnect()
1201 input_unregister_device(pdev->button_dev); in usb_pwc_disconnect()
1204 v4l2_device_put(&pdev->v4l2_dev); in usb_pwc_disconnect()