1 /* Linux driver for Philips webcam
2 USB and Video4Linux interface part.
3 (C) 1999-2004 Nemosoft Unv.
4 (C) 2004-2006 Luc Saillard (luc@saillard.org)
6 NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
7 driver and thus may have bugs that are not present in the original version.
8 Please send bug reports and support requests to <luc@saillard.org>.
9 The decompression routines have been implemented by reverse-engineering the
10 Nemosoft binary pwcx module. Caveat emptor.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <linux/errno.h>
29 #include <linux/init.h>
31 #include <linux/module.h>
32 #include <linux/poll.h>
33 #include <linux/vmalloc.h>
38 static struct v4l2_queryctrl pwc_controls
[] = {
40 .id
= V4L2_CID_BRIGHTNESS
,
41 .type
= V4L2_CTRL_TYPE_INTEGER
,
49 .id
= V4L2_CID_CONTRAST
,
50 .type
= V4L2_CTRL_TYPE_INTEGER
,
58 .id
= V4L2_CID_SATURATION
,
59 .type
= V4L2_CTRL_TYPE_INTEGER
,
68 .type
= V4L2_CTRL_TYPE_INTEGER
,
76 .id
= V4L2_CID_RED_BALANCE
,
77 .type
= V4L2_CTRL_TYPE_INTEGER
,
85 .id
= V4L2_CID_BLUE_BALANCE
,
86 .type
= V4L2_CTRL_TYPE_INTEGER
,
94 .id
= V4L2_CID_AUTO_WHITE_BALANCE
,
95 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
96 .name
= "Auto White Balance",
103 .id
= V4L2_CID_EXPOSURE
,
104 .type
= V4L2_CTRL_TYPE_INTEGER
,
105 .name
= "Shutter Speed (Exposure)",
109 .default_value
= 200,
112 .id
= V4L2_CID_AUTOGAIN
,
113 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
114 .name
= "Auto Gain Enabled",
122 .type
= V4L2_CTRL_TYPE_INTEGER
,
123 .name
= "Gain Level",
130 .id
= V4L2_CID_PRIVATE_SAVE_USER
,
131 .type
= V4L2_CTRL_TYPE_BUTTON
,
132 .name
= "Save User Settings",
139 .id
= V4L2_CID_PRIVATE_RESTORE_USER
,
140 .type
= V4L2_CTRL_TYPE_BUTTON
,
141 .name
= "Restore User Settings",
148 .id
= V4L2_CID_PRIVATE_RESTORE_FACTORY
,
149 .type
= V4L2_CTRL_TYPE_BUTTON
,
150 .name
= "Restore Factory Settings",
157 .id
= V4L2_CID_PRIVATE_COLOUR_MODE
,
158 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
159 .name
= "Colour mode",
166 .id
= V4L2_CID_PRIVATE_AUTOCONTOUR
,
167 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
168 .name
= "Auto contour",
175 .id
= V4L2_CID_PRIVATE_CONTOUR
,
176 .type
= V4L2_CTRL_TYPE_INTEGER
,
184 .id
= V4L2_CID_PRIVATE_BACKLIGHT
,
185 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
186 .name
= "Backlight compensation",
193 .id
= V4L2_CID_PRIVATE_FLICKERLESS
,
194 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
195 .name
= "Flickerless",
202 .id
= V4L2_CID_PRIVATE_NOISE_REDUCTION
,
203 .type
= V4L2_CTRL_TYPE_INTEGER
,
204 .name
= "Noise reduction",
213 static void pwc_vidioc_fill_fmt(const struct pwc_device
*pdev
, struct v4l2_format
*f
)
215 memset(&f
->fmt
.pix
, 0, sizeof(struct v4l2_pix_format
));
216 f
->fmt
.pix
.width
= pdev
->view
.x
;
217 f
->fmt
.pix
.height
= pdev
->view
.y
;
218 f
->fmt
.pix
.field
= V4L2_FIELD_NONE
;
219 if (pdev
->pixfmt
== V4L2_PIX_FMT_YUV420
) {
220 f
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_YUV420
;
221 f
->fmt
.pix
.bytesperline
= (f
->fmt
.pix
.width
* 3)/2;
222 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
224 /* vbandlength contains 4 lines ... */
225 f
->fmt
.pix
.bytesperline
= pdev
->vbandlength
/4;
226 f
->fmt
.pix
.sizeimage
= pdev
->frame_size
+ sizeof(struct pwc_raw_frame
);
227 if (DEVICE_USE_CODEC1(pdev
->type
))
228 f
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_PWC1
;
230 f
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_PWC2
;
232 PWC_DEBUG_IOCTL("pwc_vidioc_fill_fmt() "
233 "width=%d, height=%d, bytesperline=%d, sizeimage=%d, pixelformat=%c%c%c%c\n",
236 f
->fmt
.pix
.bytesperline
,
237 f
->fmt
.pix
.sizeimage
,
238 (f
->fmt
.pix
.pixelformat
)&255,
239 (f
->fmt
.pix
.pixelformat
>>8)&255,
240 (f
->fmt
.pix
.pixelformat
>>16)&255,
241 (f
->fmt
.pix
.pixelformat
>>24)&255);
244 /* ioctl(VIDIOC_TRY_FMT) */
245 static int pwc_vidioc_try_fmt(struct pwc_device
*pdev
, struct v4l2_format
*f
)
247 if (f
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
248 PWC_DEBUG_IOCTL("Bad video type must be V4L2_BUF_TYPE_VIDEO_CAPTURE\n");
252 switch (f
->fmt
.pix
.pixelformat
) {
253 case V4L2_PIX_FMT_YUV420
:
255 case V4L2_PIX_FMT_PWC1
:
256 if (DEVICE_USE_CODEC23(pdev
->type
)) {
257 PWC_DEBUG_IOCTL("codec1 is only supported for old pwc webcam\n");
261 case V4L2_PIX_FMT_PWC2
:
262 if (DEVICE_USE_CODEC1(pdev
->type
)) {
263 PWC_DEBUG_IOCTL("codec23 is only supported for new pwc webcam\n");
268 PWC_DEBUG_IOCTL("Unsupported pixel format\n");
273 if (f
->fmt
.pix
.width
> pdev
->view_max
.x
)
274 f
->fmt
.pix
.width
= pdev
->view_max
.x
;
275 else if (f
->fmt
.pix
.width
< pdev
->view_min
.x
)
276 f
->fmt
.pix
.width
= pdev
->view_min
.x
;
278 if (f
->fmt
.pix
.height
> pdev
->view_max
.y
)
279 f
->fmt
.pix
.height
= pdev
->view_max
.y
;
280 else if (f
->fmt
.pix
.height
< pdev
->view_min
.y
)
281 f
->fmt
.pix
.height
= pdev
->view_min
.y
;
286 /* ioctl(VIDIOC_SET_FMT) */
287 static int pwc_vidioc_set_fmt(struct pwc_device
*pdev
, struct v4l2_format
*f
)
289 int ret
, fps
, snapshot
, compression
, pixelformat
;
291 ret
= pwc_vidioc_try_fmt(pdev
, f
);
295 pixelformat
= f
->fmt
.pix
.pixelformat
;
296 compression
= pdev
->vcompression
;
299 if (f
->fmt
.pix
.priv
) {
300 compression
= (f
->fmt
.pix
.priv
& PWC_QLT_MASK
) >> PWC_QLT_SHIFT
;
301 snapshot
= !!(f
->fmt
.pix
.priv
& PWC_FPS_SNAPSHOT
);
302 fps
= (f
->fmt
.pix
.priv
& PWC_FPS_FRMASK
) >> PWC_FPS_SHIFT
;
307 if (pixelformat
!= V4L2_PIX_FMT_YUV420
&&
308 pixelformat
!= V4L2_PIX_FMT_PWC1
&&
309 pixelformat
!= V4L2_PIX_FMT_PWC2
)
315 PWC_DEBUG_IOCTL("Trying to set format to: width=%d height=%d fps=%d "
316 "compression=%d snapshot=%d format=%c%c%c%c\n",
317 f
->fmt
.pix
.width
, f
->fmt
.pix
.height
, fps
,
318 compression
, snapshot
,
320 (pixelformat
>>8)&255,
321 (pixelformat
>>16)&255,
322 (pixelformat
>>24)&255);
324 ret
= pwc_set_video_mode(pdev
,
331 PWC_DEBUG_IOCTL("pwc_set_video_mode(), return=%d\n", ret
);
336 pdev
->pixfmt
= pixelformat
;
338 pwc_vidioc_fill_fmt(pdev
, f
);
344 static int pwc_querycap(struct file
*file
, void *fh
, struct v4l2_capability
*cap
)
346 struct video_device
*vdev
= video_devdata(file
);
347 struct pwc_device
*pdev
= video_drvdata(file
);
349 strcpy(cap
->driver
, PWC_NAME
);
350 strlcpy(cap
->card
, vdev
->name
, sizeof(cap
->card
));
351 usb_make_path(pdev
->udev
, cap
->bus_info
, sizeof(cap
->bus_info
));
352 cap
->version
= PWC_VERSION_CODE
;
354 V4L2_CAP_VIDEO_CAPTURE
|
360 static int pwc_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*i
)
362 if (i
->index
) /* Only one INPUT is supported */
365 strcpy(i
->name
, "usb");
369 static int pwc_g_input(struct file
*file
, void *fh
, unsigned int *i
)
375 static int pwc_s_input(struct file
*file
, void *fh
, unsigned int i
)
377 return i
? -EINVAL
: 0;
380 static int pwc_queryctrl(struct file
*file
, void *fh
, struct v4l2_queryctrl
*c
)
386 if (id
& V4L2_CTRL_FLAG_NEXT_CTRL
) {
387 id
&= V4L2_CTRL_ID_MASK
;
390 for (i
= 0; i
< ARRAY_SIZE(pwc_controls
); i
++) {
391 if (pwc_controls
[i
].id
< id
)
394 && pwc_controls
[i
].id
> pwc_controls
[idx
].id
)
400 memcpy(c
, &pwc_controls
[idx
], sizeof pwc_controls
[0]);
403 for (i
= 0; i
< sizeof(pwc_controls
) / sizeof(struct v4l2_queryctrl
); i
++) {
404 if (pwc_controls
[i
].id
== c
->id
) {
405 PWC_DEBUG_IOCTL("ioctl(VIDIOC_QUERYCTRL) found\n");
406 memcpy(c
, &pwc_controls
[i
], sizeof(struct v4l2_queryctrl
));
413 static int pwc_g_ctrl(struct file
*file
, void *fh
, struct v4l2_control
*c
)
415 struct pwc_device
*pdev
= video_drvdata(file
);
419 case V4L2_CID_BRIGHTNESS
:
420 c
->value
= pwc_get_brightness(pdev
);
424 case V4L2_CID_CONTRAST
:
425 c
->value
= pwc_get_contrast(pdev
);
429 case V4L2_CID_SATURATION
:
430 ret
= pwc_get_saturation(pdev
, &c
->value
);
435 c
->value
= pwc_get_gamma(pdev
);
439 case V4L2_CID_RED_BALANCE
:
440 ret
= pwc_get_red_gain(pdev
, &c
->value
);
445 case V4L2_CID_BLUE_BALANCE
:
446 ret
= pwc_get_blue_gain(pdev
, &c
->value
);
451 case V4L2_CID_AUTO_WHITE_BALANCE
:
452 ret
= pwc_get_awb(pdev
);
455 c
->value
= (ret
== PWC_WB_MANUAL
) ? 0 : 1;
458 ret
= pwc_get_agc(pdev
, &c
->value
);
463 case V4L2_CID_AUTOGAIN
:
464 ret
= pwc_get_agc(pdev
, &c
->value
);
467 c
->value
= (c
->value
< 0) ? 1 : 0;
469 case V4L2_CID_EXPOSURE
:
470 ret
= pwc_get_shutter_speed(pdev
, &c
->value
);
474 case V4L2_CID_PRIVATE_COLOUR_MODE
:
475 ret
= pwc_get_colour_mode(pdev
, &c
->value
);
479 case V4L2_CID_PRIVATE_AUTOCONTOUR
:
480 ret
= pwc_get_contour(pdev
, &c
->value
);
483 c
->value
= (c
->value
== -1 ? 1 : 0);
485 case V4L2_CID_PRIVATE_CONTOUR
:
486 ret
= pwc_get_contour(pdev
, &c
->value
);
491 case V4L2_CID_PRIVATE_BACKLIGHT
:
492 ret
= pwc_get_backlight(pdev
, &c
->value
);
496 case V4L2_CID_PRIVATE_FLICKERLESS
:
497 ret
= pwc_get_flicker(pdev
, &c
->value
);
500 c
->value
= (c
->value
? 1 : 0);
502 case V4L2_CID_PRIVATE_NOISE_REDUCTION
:
503 ret
= pwc_get_dynamic_noise(pdev
, &c
->value
);
508 case V4L2_CID_PRIVATE_SAVE_USER
:
509 case V4L2_CID_PRIVATE_RESTORE_USER
:
510 case V4L2_CID_PRIVATE_RESTORE_FACTORY
:
516 static int pwc_s_ctrl(struct file
*file
, void *fh
, struct v4l2_control
*c
)
518 struct pwc_device
*pdev
= video_drvdata(file
);
522 case V4L2_CID_BRIGHTNESS
:
524 ret
= pwc_set_brightness(pdev
, c
->value
);
528 case V4L2_CID_CONTRAST
:
530 ret
= pwc_set_contrast(pdev
, c
->value
);
534 case V4L2_CID_SATURATION
:
535 ret
= pwc_set_saturation(pdev
, c
->value
);
541 ret
= pwc_set_gamma(pdev
, c
->value
);
545 case V4L2_CID_RED_BALANCE
:
547 ret
= pwc_set_red_gain(pdev
, c
->value
);
551 case V4L2_CID_BLUE_BALANCE
:
553 ret
= pwc_set_blue_gain(pdev
, c
->value
);
557 case V4L2_CID_AUTO_WHITE_BALANCE
:
558 c
->value
= (c
->value
== 0) ? PWC_WB_MANUAL
: PWC_WB_AUTO
;
559 ret
= pwc_set_awb(pdev
, c
->value
);
563 case V4L2_CID_EXPOSURE
:
565 ret
= pwc_set_shutter_speed(pdev
, c
->value
? 0 : 1, c
->value
);
569 case V4L2_CID_AUTOGAIN
:
570 /* autogain off means nothing without a gain */
573 ret
= pwc_set_agc(pdev
, c
->value
, 0);
579 ret
= pwc_set_agc(pdev
, 0, c
->value
);
583 case V4L2_CID_PRIVATE_SAVE_USER
:
584 if (pwc_save_user(pdev
))
587 case V4L2_CID_PRIVATE_RESTORE_USER
:
588 if (pwc_restore_user(pdev
))
591 case V4L2_CID_PRIVATE_RESTORE_FACTORY
:
592 if (pwc_restore_factory(pdev
))
595 case V4L2_CID_PRIVATE_COLOUR_MODE
:
596 ret
= pwc_set_colour_mode(pdev
, c
->value
);
600 case V4L2_CID_PRIVATE_AUTOCONTOUR
:
601 c
->value
= (c
->value
== 1) ? -1 : 0;
602 ret
= pwc_set_contour(pdev
, c
->value
);
606 case V4L2_CID_PRIVATE_CONTOUR
:
608 ret
= pwc_set_contour(pdev
, c
->value
);
612 case V4L2_CID_PRIVATE_BACKLIGHT
:
613 ret
= pwc_set_backlight(pdev
, c
->value
);
617 case V4L2_CID_PRIVATE_FLICKERLESS
:
618 ret
= pwc_set_flicker(pdev
, c
->value
);
621 case V4L2_CID_PRIVATE_NOISE_REDUCTION
:
622 ret
= pwc_set_dynamic_noise(pdev
, c
->value
);
631 static int pwc_enum_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_fmtdesc
*f
)
633 struct pwc_device
*pdev
= video_drvdata(file
);
635 /* We only support two format: the raw format, and YUV */
639 f
->pixelformat
= pdev
->type
<= 646 ? V4L2_PIX_FMT_PWC1
: V4L2_PIX_FMT_PWC2
;
640 f
->flags
= V4L2_FMT_FLAG_COMPRESSED
;
641 strlcpy(f
->description
, "Raw Philips Webcam", sizeof(f
->description
));
644 f
->pixelformat
= V4L2_PIX_FMT_YUV420
;
645 strlcpy(f
->description
, "4:2:0, planar, Y-Cb-Cr", sizeof(f
->description
));
653 static int pwc_g_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*f
)
655 struct pwc_device
*pdev
= video_drvdata(file
);
657 PWC_DEBUG_IOCTL("ioctl(VIDIOC_G_FMT) return size %dx%d\n",
658 pdev
->image
.x
, pdev
->image
.y
);
659 pwc_vidioc_fill_fmt(pdev
, f
);
663 static int pwc_try_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*f
)
665 struct pwc_device
*pdev
= video_drvdata(file
);
667 return pwc_vidioc_try_fmt(pdev
, f
);
670 static int pwc_s_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*f
)
672 struct pwc_device
*pdev
= video_drvdata(file
);
674 return pwc_vidioc_set_fmt(pdev
, f
);
677 static int pwc_reqbufs(struct file
*file
, void *fh
, struct v4l2_requestbuffers
*rb
)
681 PWC_DEBUG_IOCTL("ioctl(VIDIOC_REQBUFS) count=%d\n", rb
->count
);
682 if (rb
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
684 if (rb
->memory
!= V4L2_MEMORY_MMAP
)
687 nbuffers
= rb
->count
;
690 else if (nbuffers
> pwc_mbufs
)
691 nbuffers
= pwc_mbufs
;
692 /* Force to use our # of buffers */
693 rb
->count
= pwc_mbufs
;
697 static int pwc_querybuf(struct file
*file
, void *fh
, struct v4l2_buffer
*buf
)
699 struct pwc_device
*pdev
= video_drvdata(file
);
702 PWC_DEBUG_IOCTL("ioctl(VIDIOC_QUERYBUF) index=%d\n", buf
->index
);
703 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
704 PWC_DEBUG_IOCTL("ioctl(VIDIOC_QUERYBUF) Bad type\n");
708 if (index
< 0 || index
>= pwc_mbufs
) {
709 PWC_DEBUG_IOCTL("ioctl(VIDIOC_QUERYBUF) Bad index %d\n", buf
->index
);
713 buf
->m
.offset
= index
* pdev
->len_per_image
;
714 if (pdev
->pixfmt
!= V4L2_PIX_FMT_YUV420
)
715 buf
->bytesused
= pdev
->frame_size
+ sizeof(struct pwc_raw_frame
);
717 buf
->bytesused
= pdev
->view
.size
;
718 buf
->field
= V4L2_FIELD_NONE
;
719 buf
->memory
= V4L2_MEMORY_MMAP
;
720 /*buf->flags = V4L2_BUF_FLAG_MAPPED;*/
721 buf
->length
= pdev
->len_per_image
;
723 PWC_DEBUG_READ("VIDIOC_QUERYBUF: index=%d\n", buf
->index
);
724 PWC_DEBUG_READ("VIDIOC_QUERYBUF: m.offset=%d\n", buf
->m
.offset
);
725 PWC_DEBUG_READ("VIDIOC_QUERYBUF: bytesused=%d\n", buf
->bytesused
);
730 static int pwc_qbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*buf
)
732 PWC_DEBUG_IOCTL("ioctl(VIDIOC_QBUF) index=%d\n", buf
->index
);
733 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
735 if (buf
->memory
!= V4L2_MEMORY_MMAP
)
737 if (buf
->index
>= pwc_mbufs
)
740 buf
->flags
|= V4L2_BUF_FLAG_QUEUED
;
741 buf
->flags
&= ~V4L2_BUF_FLAG_DONE
;
746 static int pwc_dqbuf(struct file
*file
, void *fh
, struct v4l2_buffer
*buf
)
748 DECLARE_WAITQUEUE(wait
, current
);
749 struct pwc_device
*pdev
= video_drvdata(file
);
752 PWC_DEBUG_IOCTL("ioctl(VIDIOC_DQBUF)\n");
754 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
757 add_wait_queue(&pdev
->frameq
, &wait
);
758 while (pdev
->full_frames
== NULL
) {
759 if (pdev
->error_status
) {
760 remove_wait_queue(&pdev
->frameq
, &wait
);
761 set_current_state(TASK_RUNNING
);
762 return -pdev
->error_status
;
765 if (signal_pending(current
)) {
766 remove_wait_queue(&pdev
->frameq
, &wait
);
767 set_current_state(TASK_RUNNING
);
770 mutex_unlock(&pdev
->modlock
);
772 set_current_state(TASK_INTERRUPTIBLE
);
773 mutex_lock(&pdev
->modlock
);
775 remove_wait_queue(&pdev
->frameq
, &wait
);
776 set_current_state(TASK_RUNNING
);
778 PWC_DEBUG_IOCTL("VIDIOC_DQBUF: frame ready.\n");
779 /* Decompress data in pdev->images[pdev->fill_image] */
780 ret
= pwc_handle_frame(pdev
);
783 PWC_DEBUG_IOCTL("VIDIOC_DQBUF: after pwc_handle_frame\n");
785 buf
->index
= pdev
->fill_image
;
786 if (pdev
->pixfmt
!= V4L2_PIX_FMT_YUV420
)
787 buf
->bytesused
= pdev
->frame_size
+ sizeof(struct pwc_raw_frame
);
789 buf
->bytesused
= pdev
->view
.size
;
790 buf
->flags
= V4L2_BUF_FLAG_MAPPED
;
791 buf
->field
= V4L2_FIELD_NONE
;
792 do_gettimeofday(&buf
->timestamp
);
794 buf
->memory
= V4L2_MEMORY_MMAP
;
795 buf
->m
.offset
= pdev
->fill_image
* pdev
->len_per_image
;
796 buf
->length
= pdev
->len_per_image
;
797 pwc_next_image(pdev
);
799 PWC_DEBUG_IOCTL("VIDIOC_DQBUF: buf->index=%d\n", buf
->index
);
800 PWC_DEBUG_IOCTL("VIDIOC_DQBUF: buf->length=%d\n", buf
->length
);
801 PWC_DEBUG_IOCTL("VIDIOC_DQBUF: m.offset=%d\n", buf
->m
.offset
);
802 PWC_DEBUG_IOCTL("VIDIOC_DQBUF: bytesused=%d\n", buf
->bytesused
);
803 PWC_DEBUG_IOCTL("VIDIOC_DQBUF: leaving\n");
808 static int pwc_streamon(struct file
*file
, void *fh
, enum v4l2_buf_type i
)
810 struct pwc_device
*pdev
= video_drvdata(file
);
812 return pwc_isoc_init(pdev
);
815 static int pwc_streamoff(struct file
*file
, void *fh
, enum v4l2_buf_type i
)
817 struct pwc_device
*pdev
= video_drvdata(file
);
819 pwc_isoc_cleanup(pdev
);
823 static int pwc_enum_framesizes(struct file
*file
, void *fh
,
824 struct v4l2_frmsizeenum
*fsize
)
826 struct pwc_device
*pdev
= video_drvdata(file
);
827 unsigned int i
= 0, index
= fsize
->index
;
829 if (fsize
->pixel_format
== V4L2_PIX_FMT_YUV420
) {
830 for (i
= 0; i
< PSZ_MAX
; i
++) {
831 if (pdev
->image_mask
& (1UL << i
)) {
833 fsize
->type
= V4L2_FRMSIZE_TYPE_DISCRETE
;
834 fsize
->discrete
.width
= pwc_image_sizes
[i
].x
;
835 fsize
->discrete
.height
= pwc_image_sizes
[i
].y
;
840 } else if (fsize
->index
== 0 &&
841 ((fsize
->pixel_format
== V4L2_PIX_FMT_PWC1
&& DEVICE_USE_CODEC1(pdev
->type
)) ||
842 (fsize
->pixel_format
== V4L2_PIX_FMT_PWC2
&& DEVICE_USE_CODEC23(pdev
->type
)))) {
844 fsize
->type
= V4L2_FRMSIZE_TYPE_DISCRETE
;
845 fsize
->discrete
.width
= pdev
->abs_max
.x
;
846 fsize
->discrete
.height
= pdev
->abs_max
.y
;
852 static int pwc_enum_frameintervals(struct file
*file
, void *fh
,
853 struct v4l2_frmivalenum
*fival
)
855 struct pwc_device
*pdev
= video_drvdata(file
);
859 for (i
= 0; i
< PSZ_MAX
; i
++) {
860 if (pwc_image_sizes
[i
].x
== fival
->width
&&
861 pwc_image_sizes
[i
].y
== fival
->height
) {
867 /* TODO: Support raw format */
868 if (size
< 0 || fival
->pixel_format
!= V4L2_PIX_FMT_YUV420
)
871 i
= pwc_get_fps(pdev
, fival
->index
, size
);
875 fival
->type
= V4L2_FRMIVAL_TYPE_DISCRETE
;
876 fival
->discrete
.numerator
= 1;
877 fival
->discrete
.denominator
= i
;
882 static long pwc_default(struct file
*file
, void *fh
, bool valid_prio
,
885 struct pwc_device
*pdev
= video_drvdata(file
);
887 return pwc_ioctl(pdev
, cmd
, arg
);
890 const struct v4l2_ioctl_ops pwc_ioctl_ops
= {
891 .vidioc_querycap
= pwc_querycap
,
892 .vidioc_enum_input
= pwc_enum_input
,
893 .vidioc_g_input
= pwc_g_input
,
894 .vidioc_s_input
= pwc_s_input
,
895 .vidioc_enum_fmt_vid_cap
= pwc_enum_fmt_vid_cap
,
896 .vidioc_g_fmt_vid_cap
= pwc_g_fmt_vid_cap
,
897 .vidioc_s_fmt_vid_cap
= pwc_s_fmt_vid_cap
,
898 .vidioc_try_fmt_vid_cap
= pwc_try_fmt_vid_cap
,
899 .vidioc_queryctrl
= pwc_queryctrl
,
900 .vidioc_g_ctrl
= pwc_g_ctrl
,
901 .vidioc_s_ctrl
= pwc_s_ctrl
,
902 .vidioc_reqbufs
= pwc_reqbufs
,
903 .vidioc_querybuf
= pwc_querybuf
,
904 .vidioc_qbuf
= pwc_qbuf
,
905 .vidioc_dqbuf
= pwc_dqbuf
,
906 .vidioc_streamon
= pwc_streamon
,
907 .vidioc_streamoff
= pwc_streamoff
,
908 .vidioc_enum_framesizes
= pwc_enum_framesizes
,
909 .vidioc_enum_frameintervals
= pwc_enum_frameintervals
,
910 .vidioc_default
= pwc_default
,
914 /* vim: set cino= formatoptions=croql cindent shiftwidth=8 tabstop=8: */