Lines Matching refs:pdev
119 static void pwc_isoc_cleanup(struct pwc_device *pdev);
187 static struct pwc_frame_buf *pwc_get_next_fill_buf(struct pwc_device *pdev) in pwc_get_next_fill_buf() argument
192 spin_lock_irqsave(&pdev->queued_bufs_lock, flags); in pwc_get_next_fill_buf()
193 if (list_empty(&pdev->queued_bufs)) in pwc_get_next_fill_buf()
196 buf = list_entry(pdev->queued_bufs.next, struct pwc_frame_buf, list); in pwc_get_next_fill_buf()
199 spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags); in pwc_get_next_fill_buf()
203 static void pwc_snapshot_button(struct pwc_device *pdev, int down) in pwc_snapshot_button() argument
212 if (pdev->button_dev) { in pwc_snapshot_button()
213 input_report_key(pdev->button_dev, KEY_CAMERA, down); in pwc_snapshot_button()
214 input_sync(pdev->button_dev); in pwc_snapshot_button()
219 static void pwc_frame_complete(struct pwc_device *pdev) in pwc_frame_complete() argument
221 struct pwc_frame_buf *fbuf = pdev->fill_buf; in pwc_frame_complete()
227 if (pdev->type == 730) { in pwc_frame_complete()
232 pdev->drop_frames += 2; 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 if ((ptr[0] ^ pdev->vmirror) & 0x02) { in pwc_frame_complete()
243 pdev->vmirror = ptr[0] & 0x03; in pwc_frame_complete()
254 pdev->drop_frames++; in pwc_frame_complete()
255 } else if (pdev->type == 740 || pdev->type == 720) { in pwc_frame_complete()
257 if ((ptr[0] ^ pdev->vmirror) & 0x01) { in pwc_frame_complete()
258 pwc_snapshot_button(pdev, ptr[0] & 0x01); in pwc_frame_complete()
260 pdev->vmirror = ptr[0] & 0x03; in pwc_frame_complete()
264 if (pdev->drop_frames > 0) { in pwc_frame_complete()
265 pdev->drop_frames--; in pwc_frame_complete()
268 if (fbuf->filled < pdev->frame_total_size) { in pwc_frame_complete()
273 fbuf->vb.sequence = pdev->vframe_count; in pwc_frame_complete()
275 pdev->fill_buf = NULL; in pwc_frame_complete()
276 pdev->vsync = 0; in pwc_frame_complete()
279 pdev->vframe_count++; in pwc_frame_complete()
287 struct pwc_device *pdev = (struct pwc_device *)urb->context; in pwc_isoc_handler() local
292 trace_pwc_handler_enter(urb, pdev); in pwc_isoc_handler()
301 if (pdev->fill_buf == NULL) in pwc_isoc_handler()
302 pdev->fill_buf = pwc_get_next_fill_buf(pdev); in pwc_isoc_handler()
319 if (++pdev->visoc_errors > MAX_ISOC_ERRORS) in pwc_isoc_handler()
322 if (pdev->fill_buf) { in pwc_isoc_handler()
323 vb2_buffer_done(&pdev->fill_buf->vb.vb2_buf, in pwc_isoc_handler()
325 pdev->fill_buf = NULL; in pwc_isoc_handler()
328 pdev->vsync = 0; /* Drop the current frame */ in pwc_isoc_handler()
333 pdev->visoc_errors = 0; in pwc_isoc_handler()
353 if (flen > 0 && pdev->vsync) { in pwc_isoc_handler()
354 struct pwc_frame_buf *fbuf = pdev->fill_buf; in pwc_isoc_handler()
356 if (pdev->vsync == 1) { in pwc_isoc_handler()
358 pdev->vsync = 2; in pwc_isoc_handler()
361 if (flen + fbuf->filled > pdev->frame_total_size) { in pwc_isoc_handler()
364 pdev->frame_total_size); in pwc_isoc_handler()
365 pdev->vsync = 0; /* Let's wait for an EOF */ in pwc_isoc_handler()
372 if (flen < pdev->vlast_packet_size) { in pwc_isoc_handler()
374 if (pdev->vsync == 2) in pwc_isoc_handler()
375 pwc_frame_complete(pdev); in pwc_isoc_handler()
376 if (pdev->fill_buf == NULL) in pwc_isoc_handler()
377 pdev->fill_buf = pwc_get_next_fill_buf(pdev); in pwc_isoc_handler()
378 if (pdev->fill_buf) { in pwc_isoc_handler()
379 pdev->fill_buf->filled = 0; in pwc_isoc_handler()
380 pdev->vsync = 1; in pwc_isoc_handler()
383 pdev->vlast_packet_size = flen; in pwc_isoc_handler()
392 trace_pwc_handler_exit(urb, pdev); in pwc_isoc_handler()
400 static int pwc_isoc_init(struct pwc_device *pdev) in pwc_isoc_init() argument
409 pdev->vsync = 0; in pwc_isoc_init()
410 pdev->vlast_packet_size = 0; in pwc_isoc_init()
411 pdev->fill_buf = NULL; in pwc_isoc_init()
412 pdev->vframe_count = 0; in pwc_isoc_init()
413 pdev->visoc_errors = 0; in pwc_isoc_init()
414 udev = pdev->udev; in pwc_isoc_init()
419 ret = pwc_set_video_mode(pdev, pdev->width, pdev->height, pdev->pixfmt, in pwc_isoc_init()
420 pdev->vframes, &compression, 1); in pwc_isoc_init()
425 idesc = usb_altnum_to_altsetting(intf, pdev->valternate); in pwc_isoc_init()
430 pdev->vmax_packet_size = -1; in pwc_isoc_init()
432 if ((idesc->endpoint[i].desc.bEndpointAddress & 0xF) == pdev->vendpoint) { in pwc_isoc_init()
433 pdev->vmax_packet_size = le16_to_cpu(idesc->endpoint[i].desc.wMaxPacketSize); in pwc_isoc_init()
438 if (pdev->vmax_packet_size < 0 || pdev->vmax_packet_size > ISO_MAX_FRAME_SIZE) { in pwc_isoc_init()
444 PWC_DEBUG_OPEN("Setting alternate interface %d\n", pdev->valternate); in pwc_isoc_init()
445 ret = usb_set_interface(pdev->udev, 0, pdev->valternate); in pwc_isoc_init()
457 pwc_isoc_cleanup(pdev); in pwc_isoc_init()
460 pdev->urbs[i] = urb; in pwc_isoc_init()
465 urb->pipe = usb_rcvisocpipe(udev, pdev->vendpoint); in pwc_isoc_init()
473 pwc_isoc_cleanup(pdev); in pwc_isoc_init()
477 urb->context = pdev; in pwc_isoc_init()
482 urb->iso_frame_desc[j].length = pdev->vmax_packet_size; in pwc_isoc_init()
488 ret = usb_submit_urb(pdev->urbs[i], GFP_KERNEL); in pwc_isoc_init()
491 pwc_isoc_cleanup(pdev); in pwc_isoc_init()
496 pwc_isoc_cleanup(pdev); in pwc_isoc_init()
499 PWC_DEBUG_MEMORY("URB 0x%p submitted.\n", pdev->urbs[i]); in pwc_isoc_init()
507 static void pwc_iso_stop(struct pwc_device *pdev) in pwc_iso_stop() argument
513 if (pdev->urbs[i]) { in pwc_iso_stop()
514 PWC_DEBUG_MEMORY("Unlinking URB %p\n", pdev->urbs[i]); in pwc_iso_stop()
515 usb_kill_urb(pdev->urbs[i]); in pwc_iso_stop()
520 static void pwc_iso_free(struct pwc_device *pdev) in pwc_iso_free() argument
526 struct urb *urb = pdev->urbs[i]; in pwc_iso_free()
536 pdev->urbs[i] = NULL; in pwc_iso_free()
542 static void pwc_isoc_cleanup(struct pwc_device *pdev) in pwc_isoc_cleanup() argument
546 pwc_iso_stop(pdev); in pwc_isoc_cleanup()
547 pwc_iso_free(pdev); in pwc_isoc_cleanup()
548 usb_set_interface(pdev->udev, 0, 0); in pwc_isoc_cleanup()
554 static void pwc_cleanup_queued_bufs(struct pwc_device *pdev, in pwc_cleanup_queued_bufs() argument
559 spin_lock_irqsave(&pdev->queued_bufs_lock, flags); in pwc_cleanup_queued_bufs()
560 while (!list_empty(&pdev->queued_bufs)) { in pwc_cleanup_queued_bufs()
563 buf = list_entry(pdev->queued_bufs.next, struct pwc_frame_buf, in pwc_cleanup_queued_bufs()
568 spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags); in pwc_cleanup_queued_bufs()
606 struct pwc_device *pdev = container_of(v, struct pwc_device, v4l2_dev); in pwc_video_release() local
608 v4l2_ctrl_handler_free(&pdev->ctrl_handler); in pwc_video_release()
609 v4l2_device_unregister(&pdev->v4l2_dev); in pwc_video_release()
610 kfree(pdev->ctrl_buf); in pwc_video_release()
611 kfree(pdev); in pwc_video_release()
621 struct pwc_device *pdev = vb2_get_drv_priv(vq); in queue_setup() local
631 size = pwc_get_size(pdev, MAX_WIDTH, MAX_HEIGHT); in queue_setup()
654 struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue); in buffer_prepare() local
657 if (!pdev->udev) in buffer_prepare()
665 struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue); in buffer_finish() local
677 pwc_decompress(pdev, buf); in buffer_finish()
692 struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue); in buffer_queue() local
699 if (!pdev->udev) { in buffer_queue()
704 spin_lock_irqsave(&pdev->queued_bufs_lock, flags); in buffer_queue()
705 list_add_tail(&buf->list, &pdev->queued_bufs); in buffer_queue()
706 spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags); in buffer_queue()
711 struct pwc_device *pdev = vb2_get_drv_priv(vq); in start_streaming() local
714 if (!pdev->udev) in start_streaming()
717 if (mutex_lock_interruptible(&pdev->v4l2_lock)) in start_streaming()
720 pwc_camera_power(pdev, 1); in start_streaming()
721 pwc_set_leds(pdev, leds[0], leds[1]); in start_streaming()
723 r = pwc_isoc_init(pdev); in start_streaming()
726 pwc_set_leds(pdev, 0, 0); in start_streaming()
727 pwc_camera_power(pdev, 0); in start_streaming()
729 pwc_cleanup_queued_bufs(pdev, VB2_BUF_STATE_QUEUED); in start_streaming()
731 mutex_unlock(&pdev->v4l2_lock); in start_streaming()
738 struct pwc_device *pdev = vb2_get_drv_priv(vq); in stop_streaming() local
740 mutex_lock(&pdev->v4l2_lock); in stop_streaming()
741 if (pdev->udev) { in stop_streaming()
742 pwc_set_leds(pdev, 0, 0); in stop_streaming()
743 pwc_camera_power(pdev, 0); in stop_streaming()
744 pwc_isoc_cleanup(pdev); in stop_streaming()
747 pwc_cleanup_queued_bufs(pdev, VB2_BUF_STATE_ERROR); in stop_streaming()
748 if (pdev->fill_buf) in stop_streaming()
749 vb2_buffer_done(&pdev->fill_buf->vb.vb2_buf, in stop_streaming()
751 mutex_unlock(&pdev->v4l2_lock); in stop_streaming()
777 struct pwc_device *pdev = NULL; in usb_pwc_probe() local
1032 pdev = kzalloc(sizeof(struct pwc_device), GFP_KERNEL); in usb_pwc_probe()
1033 if (pdev == NULL) { in usb_pwc_probe()
1037 pdev->type = type_id; in usb_pwc_probe()
1038 pdev->features = features; in usb_pwc_probe()
1039 pwc_construct(pdev); /* set min/max sizes correct */ in usb_pwc_probe()
1041 mutex_init(&pdev->v4l2_lock); in usb_pwc_probe()
1042 mutex_init(&pdev->vb_queue_lock); in usb_pwc_probe()
1043 spin_lock_init(&pdev->queued_bufs_lock); in usb_pwc_probe()
1044 INIT_LIST_HEAD(&pdev->queued_bufs); in usb_pwc_probe()
1046 pdev->udev = udev; in usb_pwc_probe()
1047 pdev->power_save = my_power_save; in usb_pwc_probe()
1050 pdev->vb_queue.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in usb_pwc_probe()
1051 pdev->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; in usb_pwc_probe()
1052 pdev->vb_queue.drv_priv = pdev; in usb_pwc_probe()
1053 pdev->vb_queue.buf_struct_size = sizeof(struct pwc_frame_buf); in usb_pwc_probe()
1054 pdev->vb_queue.ops = &pwc_vb_queue_ops; in usb_pwc_probe()
1055 pdev->vb_queue.mem_ops = &vb2_vmalloc_memops; in usb_pwc_probe()
1056 pdev->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in usb_pwc_probe()
1057 rc = vb2_queue_init(&pdev->vb_queue); in usb_pwc_probe()
1064 pdev->vdev = pwc_template; in usb_pwc_probe()
1065 strscpy(pdev->vdev.name, name, sizeof(pdev->vdev.name)); in usb_pwc_probe()
1066 pdev->vdev.queue = &pdev->vb_queue; in usb_pwc_probe()
1067 pdev->vdev.queue->lock = &pdev->vb_queue_lock; in usb_pwc_probe()
1068 video_set_drvdata(&pdev->vdev, pdev); in usb_pwc_probe()
1070 pdev->release = le16_to_cpu(udev->descriptor.bcdDevice); in usb_pwc_probe()
1071 PWC_DEBUG_PROBE("Release: %04x\n", pdev->release); in usb_pwc_probe()
1074 pdev->ctrl_buf = kmalloc(sizeof(pdev->cmd_buf), GFP_KERNEL); in usb_pwc_probe()
1075 if (!pdev->ctrl_buf) { in usb_pwc_probe()
1083 if (pwc_get_cmos_sensor(pdev, &rc) >= 0) { in usb_pwc_probe()
1085 pdev->vdev.name, in usb_pwc_probe()
1091 pwc_set_leds(pdev, 0, 0); in usb_pwc_probe()
1094 rc = pwc_set_video_mode(pdev, MAX_WIDTH, MAX_HEIGHT, in usb_pwc_probe()
1100 rc = pwc_init_controls(pdev); in usb_pwc_probe()
1107 pwc_camera_power(pdev, 0); in usb_pwc_probe()
1110 pdev->v4l2_dev.release = pwc_video_release; in usb_pwc_probe()
1111 rc = v4l2_device_register(&intf->dev, &pdev->v4l2_dev); in usb_pwc_probe()
1117 pdev->v4l2_dev.ctrl_handler = &pdev->ctrl_handler; in usb_pwc_probe()
1118 pdev->vdev.v4l2_dev = &pdev->v4l2_dev; in usb_pwc_probe()
1119 pdev->vdev.lock = &pdev->v4l2_lock; in usb_pwc_probe()
1120 pdev->vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | in usb_pwc_probe()
1123 rc = video_register_device(&pdev->vdev, VFL_TYPE_VIDEO, -1); in usb_pwc_probe()
1128 PWC_INFO("Registered as %s.\n", video_device_node_name(&pdev->vdev)); in usb_pwc_probe()
1132 pdev->button_dev = input_allocate_device(); in usb_pwc_probe()
1133 if (!pdev->button_dev) { in usb_pwc_probe()
1138 usb_make_path(udev, pdev->button_phys, sizeof(pdev->button_phys)); in usb_pwc_probe()
1139 strlcat(pdev->button_phys, "/input0", sizeof(pdev->button_phys)); in usb_pwc_probe()
1141 pdev->button_dev->name = "PWC snapshot button"; in usb_pwc_probe()
1142 pdev->button_dev->phys = pdev->button_phys; in usb_pwc_probe()
1143 usb_to_input_id(pdev->udev, &pdev->button_dev->id); in usb_pwc_probe()
1144 pdev->button_dev->dev.parent = &pdev->udev->dev; in usb_pwc_probe()
1145 pdev->button_dev->evbit[0] = BIT_MASK(EV_KEY); in usb_pwc_probe()
1146 pdev->button_dev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA); in usb_pwc_probe()
1148 rc = input_register_device(pdev->button_dev); in usb_pwc_probe()
1150 input_free_device(pdev->button_dev); in usb_pwc_probe()
1151 pdev->button_dev = NULL; in usb_pwc_probe()
1160 video_unregister_device(&pdev->vdev); in usb_pwc_probe()
1163 v4l2_device_unregister(&pdev->v4l2_dev); in usb_pwc_probe()
1165 v4l2_ctrl_handler_free(&pdev->ctrl_handler); in usb_pwc_probe()
1167 kfree(pdev->ctrl_buf); in usb_pwc_probe()
1168 kfree(pdev); in usb_pwc_probe()
1176 struct pwc_device *pdev = container_of(v, struct pwc_device, v4l2_dev); in usb_pwc_disconnect() local
1178 mutex_lock(&pdev->vb_queue_lock); in usb_pwc_disconnect()
1179 mutex_lock(&pdev->v4l2_lock); in usb_pwc_disconnect()
1181 if (pdev->vb_queue.streaming) in usb_pwc_disconnect()
1182 pwc_isoc_cleanup(pdev); in usb_pwc_disconnect()
1183 pdev->udev = NULL; in usb_pwc_disconnect()
1185 v4l2_device_disconnect(&pdev->v4l2_dev); in usb_pwc_disconnect()
1186 video_unregister_device(&pdev->vdev); in usb_pwc_disconnect()
1187 mutex_unlock(&pdev->v4l2_lock); in usb_pwc_disconnect()
1188 mutex_unlock(&pdev->vb_queue_lock); in usb_pwc_disconnect()
1191 if (pdev->button_dev) in usb_pwc_disconnect()
1192 input_unregister_device(pdev->button_dev); in usb_pwc_disconnect()
1195 v4l2_device_put(&pdev->v4l2_dev); in usb_pwc_disconnect()