1 #include <media/saa7146_vv.h>
2 #include <media/v4l2-chip-ident.h>
4 static int max_memory
= 32;
6 module_param(max_memory
, int, 0644);
7 MODULE_PARM_DESC(max_memory
, "maximum memory usage for capture buffers (default: 32Mb)");
9 #define IS_CAPTURE_ACTIVE(fh) \
10 (((vv->video_status & STATUS_CAPTURE) != 0) && (vv->video_fh == fh))
12 #define IS_OVERLAY_ACTIVE(fh) \
13 (((vv->video_status & STATUS_OVERLAY) != 0) && (vv->video_fh == fh))
15 /* format descriptions for capture and preview */
16 static struct saa7146_format formats
[] = {
18 .name
= "RGB-8 (3-3-2)",
19 .pixelformat
= V4L2_PIX_FMT_RGB332
,
20 .trans
= RGB08_COMPOSED
,
24 .name
= "RGB-16 (5/B-6/G-5/R)",
25 .pixelformat
= V4L2_PIX_FMT_RGB565
,
26 .trans
= RGB16_COMPOSED
,
30 .name
= "RGB-24 (B-G-R)",
31 .pixelformat
= V4L2_PIX_FMT_BGR24
,
32 .trans
= RGB24_COMPOSED
,
36 .name
= "RGB-32 (B-G-R)",
37 .pixelformat
= V4L2_PIX_FMT_BGR32
,
38 .trans
= RGB32_COMPOSED
,
42 .name
= "RGB-32 (R-G-B)",
43 .pixelformat
= V4L2_PIX_FMT_RGB32
,
44 .trans
= RGB32_COMPOSED
,
49 .name
= "Greyscale-8",
50 .pixelformat
= V4L2_PIX_FMT_GREY
,
55 .name
= "YUV 4:2:2 planar (Y-Cb-Cr)",
56 .pixelformat
= V4L2_PIX_FMT_YUV422P
,
57 .trans
= YUV422_DECOMPOSED
,
59 .flags
= FORMAT_BYTE_SWAP
|FORMAT_IS_PLANAR
,
61 .name
= "YVU 4:2:0 planar (Y-Cb-Cr)",
62 .pixelformat
= V4L2_PIX_FMT_YVU420
,
63 .trans
= YUV420_DECOMPOSED
,
65 .flags
= FORMAT_BYTE_SWAP
|FORMAT_IS_PLANAR
,
67 .name
= "YUV 4:2:0 planar (Y-Cb-Cr)",
68 .pixelformat
= V4L2_PIX_FMT_YUV420
,
69 .trans
= YUV420_DECOMPOSED
,
71 .flags
= FORMAT_IS_PLANAR
,
73 .name
= "YUV 4:2:2 (U-Y-V-Y)",
74 .pixelformat
= V4L2_PIX_FMT_UYVY
,
75 .trans
= YUV422_COMPOSED
,
81 /* unfortunately, the saa7146 contains a bug which prevents it from doing on-the-fly byte swaps.
82 due to this, it's impossible to provide additional *packed* formats, which are simply byte swapped
83 (like V4L2_PIX_FMT_YUYV) ... 8-( */
85 static int NUM_FORMATS
= sizeof(formats
)/sizeof(struct saa7146_format
);
87 struct saa7146_format
* saa7146_format_by_fourcc(struct saa7146_dev
*dev
, int fourcc
)
89 int i
, j
= NUM_FORMATS
;
91 for (i
= 0; i
< j
; i
++) {
92 if (formats
[i
].pixelformat
== fourcc
) {
97 DEB_D(("unknown pixelformat:'%4.4s'\n",(char *)&fourcc
));
101 static int vidioc_try_fmt_vid_overlay(struct file
*file
, void *fh
, struct v4l2_format
*f
);
103 int saa7146_start_preview(struct saa7146_fh
*fh
)
105 struct saa7146_dev
*dev
= fh
->dev
;
106 struct saa7146_vv
*vv
= dev
->vv_data
;
107 struct v4l2_format fmt
;
108 int ret
= 0, err
= 0;
110 DEB_EE(("dev:%p, fh:%p\n",dev
,fh
));
112 /* check if we have overlay informations */
113 if( NULL
== fh
->ov
.fh
) {
114 DEB_D(("no overlay data available. try S_FMT first.\n"));
118 /* check if streaming capture is running */
119 if (IS_CAPTURE_ACTIVE(fh
) != 0) {
120 DEB_D(("streaming capture is active.\n"));
124 /* check if overlay is running */
125 if (IS_OVERLAY_ACTIVE(fh
) != 0) {
126 if (vv
->video_fh
== fh
) {
127 DEB_D(("overlay is already active.\n"));
130 DEB_D(("overlay is already active in another open.\n"));
134 if (0 == saa7146_res_get(fh
, RESOURCE_DMA1_HPS
|RESOURCE_DMA2_CLP
)) {
135 DEB_D(("cannot get necessary overlay resources\n"));
139 fmt
.fmt
.win
= fh
->ov
.win
;
140 err
= vidioc_try_fmt_vid_overlay(NULL
, fh
, &fmt
);
142 saa7146_res_free(vv
->video_fh
, RESOURCE_DMA1_HPS
|RESOURCE_DMA2_CLP
);
145 fh
->ov
.win
= fmt
.fmt
.win
;
146 vv
->ov_data
= &fh
->ov
;
148 DEB_D(("%dx%d+%d+%d %s field=%s\n",
149 fh
->ov
.win
.w
.width
,fh
->ov
.win
.w
.height
,
150 fh
->ov
.win
.w
.left
,fh
->ov
.win
.w
.top
,
151 vv
->ov_fmt
->name
,v4l2_field_names
[fh
->ov
.win
.field
]));
153 if (0 != (ret
= saa7146_enable_overlay(fh
))) {
154 DEB_D(("enabling overlay failed: %d\n",ret
));
155 saa7146_res_free(vv
->video_fh
, RESOURCE_DMA1_HPS
|RESOURCE_DMA2_CLP
);
159 vv
->video_status
= STATUS_OVERLAY
;
164 EXPORT_SYMBOL_GPL(saa7146_start_preview
);
166 int saa7146_stop_preview(struct saa7146_fh
*fh
)
168 struct saa7146_dev
*dev
= fh
->dev
;
169 struct saa7146_vv
*vv
= dev
->vv_data
;
171 DEB_EE(("dev:%p, fh:%p\n",dev
,fh
));
173 /* check if streaming capture is running */
174 if (IS_CAPTURE_ACTIVE(fh
) != 0) {
175 DEB_D(("streaming capture is active.\n"));
179 /* check if overlay is running at all */
180 if ((vv
->video_status
& STATUS_OVERLAY
) == 0) {
181 DEB_D(("no active overlay.\n"));
185 if (vv
->video_fh
!= fh
) {
186 DEB_D(("overlay is active, but in another open.\n"));
190 vv
->video_status
= 0;
193 saa7146_disable_overlay(fh
);
195 saa7146_res_free(fh
, RESOURCE_DMA1_HPS
|RESOURCE_DMA2_CLP
);
199 EXPORT_SYMBOL_GPL(saa7146_stop_preview
);
201 /********************************************************************************/
202 /* device controls */
204 static struct v4l2_queryctrl controls
[] = {
206 .id
= V4L2_CID_BRIGHTNESS
,
207 .name
= "Brightness",
211 .default_value
= 128,
212 .type
= V4L2_CTRL_TYPE_INTEGER
,
213 .flags
= V4L2_CTRL_FLAG_SLIDER
,
215 .id
= V4L2_CID_CONTRAST
,
221 .type
= V4L2_CTRL_TYPE_INTEGER
,
222 .flags
= V4L2_CTRL_FLAG_SLIDER
,
224 .id
= V4L2_CID_SATURATION
,
225 .name
= "Saturation",
230 .type
= V4L2_CTRL_TYPE_INTEGER
,
231 .flags
= V4L2_CTRL_FLAG_SLIDER
,
233 .id
= V4L2_CID_VFLIP
,
234 .name
= "Vertical Flip",
237 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
239 .id
= V4L2_CID_HFLIP
,
240 .name
= "Horizontal Flip",
243 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
246 static int NUM_CONTROLS
= sizeof(controls
)/sizeof(struct v4l2_queryctrl
);
248 #define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 0)
250 static struct v4l2_queryctrl
* ctrl_by_id(int id
)
254 for (i
= 0; i
< NUM_CONTROLS
; i
++)
255 if (controls
[i
].id
== id
)
260 /********************************************************************************/
261 /* common pagetable functions */
263 static int saa7146_pgtable_build(struct saa7146_dev
*dev
, struct saa7146_buf
*buf
)
265 struct pci_dev
*pci
= dev
->pci
;
266 struct videobuf_dmabuf
*dma
=videobuf_to_dma(&buf
->vb
);
267 struct scatterlist
*list
= dma
->sglist
;
268 int length
= dma
->sglen
;
269 struct saa7146_format
*sfmt
= saa7146_format_by_fourcc(dev
,buf
->fmt
->pixelformat
);
271 DEB_EE(("dev:%p, buf:%p, sg_len:%d\n",dev
,buf
,length
));
273 if( 0 != IS_PLANAR(sfmt
->trans
)) {
274 struct saa7146_pgtable
*pt1
= &buf
->pt
[0];
275 struct saa7146_pgtable
*pt2
= &buf
->pt
[1];
276 struct saa7146_pgtable
*pt3
= &buf
->pt
[2];
277 __le32
*ptr1
, *ptr2
, *ptr3
;
280 int size
= buf
->fmt
->width
*buf
->fmt
->height
;
281 int i
,p
,m1
,m2
,m3
,o1
,o2
;
283 switch( sfmt
->depth
) {
285 /* create some offsets inside the page table */
286 m1
= ((size
+PAGE_SIZE
)/PAGE_SIZE
)-1;
287 m2
= ((size
+(size
/4)+PAGE_SIZE
)/PAGE_SIZE
)-1;
288 m3
= ((size
+(size
/2)+PAGE_SIZE
)/PAGE_SIZE
)-1;
290 o2
= (size
+(size
/4))%PAGE_SIZE
;
291 DEB_CAP(("size:%d, m1:%d, m2:%d, m3:%d, o1:%d, o2:%d\n",size
,m1
,m2
,m3
,o1
,o2
));
295 /* create some offsets inside the page table */
296 m1
= ((size
+PAGE_SIZE
)/PAGE_SIZE
)-1;
297 m2
= ((size
+(size
/2)+PAGE_SIZE
)/PAGE_SIZE
)-1;
298 m3
= ((2*size
+PAGE_SIZE
)/PAGE_SIZE
)-1;
300 o2
= (size
+(size
/2))%PAGE_SIZE
;
301 DEB_CAP(("size:%d, m1:%d, m2:%d, m3:%d, o1:%d, o2:%d\n",size
,m1
,m2
,m3
,o1
,o2
));
313 /* walk all pages, copy all page addresses to ptr1 */
314 for (i
= 0; i
< length
; i
++, list
++) {
315 for (p
= 0; p
* 4096 < list
->length
; p
++, ptr1
++) {
316 *ptr1
= cpu_to_le32(sg_dma_address(list
) - list
->offset
);
322 printk("ptr1 %d: 0x%08x\n",j,ptr1[j]);
326 /* if we have a user buffer, the first page may not be
327 aligned to a page boundary. */
328 pt1
->offset
= dma
->sglist
->offset
;
329 pt2
->offset
= pt1
->offset
+o1
;
330 pt3
->offset
= pt1
->offset
+o2
;
332 /* create video-dma2 page table */
334 for(i
= m1
; i
<= m2
; i
++, ptr2
++) {
338 for(;i
<1024;i
++,ptr2
++) {
341 /* create video-dma3 page table */
343 for(i
= m2
; i
<= m3
; i
++,ptr3
++) {
347 for(;i
<1024;i
++,ptr3
++) {
350 /* finally: finish up video-dma1 page table */
353 for(i
=m1
;i
<1024;i
++,ptr1
++) {
361 printk("ptr1 %d: 0x%08x\n",j,ptr1[j]);
364 printk("ptr2 %d: 0x%08x\n",j,ptr2[j]);
367 printk("ptr3 %d: 0x%08x\n",j,ptr3[j]);
371 struct saa7146_pgtable
*pt
= &buf
->pt
[0];
372 return saa7146_pgtable_build_single(pci
, pt
, list
, length
);
379 /********************************************************************************/
380 /* file operations */
382 static int video_begin(struct saa7146_fh
*fh
)
384 struct saa7146_dev
*dev
= fh
->dev
;
385 struct saa7146_vv
*vv
= dev
->vv_data
;
386 struct saa7146_format
*fmt
= NULL
;
387 unsigned int resource
;
388 int ret
= 0, err
= 0;
390 DEB_EE(("dev:%p, fh:%p\n",dev
,fh
));
392 if ((vv
->video_status
& STATUS_CAPTURE
) != 0) {
393 if (vv
->video_fh
== fh
) {
394 DEB_S(("already capturing.\n"));
397 DEB_S(("already capturing in another open.\n"));
401 if ((vv
->video_status
& STATUS_OVERLAY
) != 0) {
402 DEB_S(("warning: suspending overlay video for streaming capture.\n"));
403 vv
->ov_suspend
= vv
->video_fh
;
404 err
= saa7146_stop_preview(vv
->video_fh
); /* side effect: video_status is now 0, video_fh is NULL */
406 DEB_D(("suspending video failed. aborting\n"));
411 fmt
= saa7146_format_by_fourcc(dev
,fh
->video_fmt
.pixelformat
);
412 /* we need to have a valid format set here */
415 if (0 != (fmt
->flags
& FORMAT_IS_PLANAR
)) {
416 resource
= RESOURCE_DMA1_HPS
|RESOURCE_DMA2_CLP
|RESOURCE_DMA3_BRS
;
418 resource
= RESOURCE_DMA1_HPS
;
421 ret
= saa7146_res_get(fh
, resource
);
423 DEB_S(("cannot get capture resource %d\n",resource
));
424 if (vv
->ov_suspend
!= NULL
) {
425 saa7146_start_preview(vv
->ov_suspend
);
426 vv
->ov_suspend
= NULL
;
431 /* clear out beginning of streaming bit (rps register 0)*/
432 saa7146_write(dev
, MC2
, MASK_27
);
434 /* enable rps0 irqs */
435 SAA7146_IER_ENABLE(dev
, MASK_27
);
438 vv
->video_status
= STATUS_CAPTURE
;
443 static int video_end(struct saa7146_fh
*fh
, struct file
*file
)
445 struct saa7146_dev
*dev
= fh
->dev
;
446 struct saa7146_vv
*vv
= dev
->vv_data
;
447 struct saa7146_format
*fmt
= NULL
;
449 unsigned int resource
;
451 DEB_EE(("dev:%p, fh:%p\n",dev
,fh
));
453 if ((vv
->video_status
& STATUS_CAPTURE
) != STATUS_CAPTURE
) {
454 DEB_S(("not capturing.\n"));
458 if (vv
->video_fh
!= fh
) {
459 DEB_S(("capturing, but in another open.\n"));
463 fmt
= saa7146_format_by_fourcc(dev
,fh
->video_fmt
.pixelformat
);
464 /* we need to have a valid format set here */
467 if (0 != (fmt
->flags
& FORMAT_IS_PLANAR
)) {
468 resource
= RESOURCE_DMA1_HPS
|RESOURCE_DMA2_CLP
|RESOURCE_DMA3_BRS
;
469 dmas
= MASK_22
| MASK_21
| MASK_20
;
471 resource
= RESOURCE_DMA1_HPS
;
474 spin_lock_irqsave(&dev
->slock
,flags
);
477 saa7146_write(dev
, MC1
, MASK_28
);
479 /* disable rps0 irqs */
480 SAA7146_IER_DISABLE(dev
, MASK_27
);
482 /* shut down all used video dma transfers */
483 saa7146_write(dev
, MC1
, dmas
);
485 spin_unlock_irqrestore(&dev
->slock
, flags
);
488 vv
->video_status
= 0;
490 saa7146_res_free(fh
, resource
);
492 if (vv
->ov_suspend
!= NULL
) {
493 saa7146_start_preview(vv
->ov_suspend
);
494 vv
->ov_suspend
= NULL
;
500 static int vidioc_querycap(struct file
*file
, void *fh
, struct v4l2_capability
*cap
)
502 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
504 strcpy((char *)cap
->driver
, "saa7146 v4l2");
505 strlcpy((char *)cap
->card
, dev
->ext
->name
, sizeof(cap
->card
));
506 sprintf((char *)cap
->bus_info
, "PCI:%s", pci_name(dev
->pci
));
507 cap
->version
= SAA7146_VERSION_CODE
;
509 V4L2_CAP_VIDEO_CAPTURE
|
510 V4L2_CAP_VIDEO_OVERLAY
|
513 cap
->capabilities
|= dev
->ext_vv_data
->capabilities
;
517 static int vidioc_g_fbuf(struct file
*file
, void *fh
, struct v4l2_framebuffer
*fb
)
519 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
520 struct saa7146_vv
*vv
= dev
->vv_data
;
523 fb
->capability
= V4L2_FBUF_CAP_LIST_CLIPPING
;
527 static int vidioc_s_fbuf(struct file
*file
, void *fh
, struct v4l2_framebuffer
*fb
)
529 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
530 struct saa7146_vv
*vv
= dev
->vv_data
;
531 struct saa7146_format
*fmt
;
533 DEB_EE(("VIDIOC_S_FBUF\n"));
535 if (!capable(CAP_SYS_ADMIN
) && !capable(CAP_SYS_RAWIO
))
539 fmt
= saa7146_format_by_fourcc(dev
, fb
->fmt
.pixelformat
);
543 /* planar formats are not allowed for overlay video, clipping and video dma would clash */
544 if (fmt
->flags
& FORMAT_IS_PLANAR
)
545 DEB_S(("planar pixelformat '%4.4s' not allowed for overlay\n",
546 (char *)&fmt
->pixelformat
));
548 /* check if overlay is running */
549 if (IS_OVERLAY_ACTIVE(fh
) != 0) {
550 if (vv
->video_fh
!= fh
) {
551 DEB_D(("refusing to change framebuffer informations while overlay is active in another open.\n"));
560 if (vv
->ov_fb
.fmt
.bytesperline
< vv
->ov_fb
.fmt
.width
) {
561 vv
->ov_fb
.fmt
.bytesperline
= vv
->ov_fb
.fmt
.width
* fmt
->depth
/ 8;
562 DEB_D(("setting bytesperline to %d\n", vv
->ov_fb
.fmt
.bytesperline
));
567 static int vidioc_enum_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_fmtdesc
*f
)
569 if (f
->index
>= NUM_FORMATS
)
571 strlcpy((char *)f
->description
, formats
[f
->index
].name
,
572 sizeof(f
->description
));
573 f
->pixelformat
= formats
[f
->index
].pixelformat
;
577 static int vidioc_queryctrl(struct file
*file
, void *fh
, struct v4l2_queryctrl
*c
)
579 const struct v4l2_queryctrl
*ctrl
;
581 if ((c
->id
< V4L2_CID_BASE
||
582 c
->id
>= V4L2_CID_LASTP1
) &&
583 (c
->id
< V4L2_CID_PRIVATE_BASE
||
584 c
->id
>= V4L2_CID_PRIVATE_LASTP1
))
587 ctrl
= ctrl_by_id(c
->id
);
591 DEB_EE(("VIDIOC_QUERYCTRL: id:%d\n", c
->id
));
596 static int vidioc_g_ctrl(struct file
*file
, void *fh
, struct v4l2_control
*c
)
598 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
599 struct saa7146_vv
*vv
= dev
->vv_data
;
600 const struct v4l2_queryctrl
*ctrl
;
603 ctrl
= ctrl_by_id(c
->id
);
607 case V4L2_CID_BRIGHTNESS
:
608 value
= saa7146_read(dev
, BCS_CTRL
);
609 c
->value
= 0xff & (value
>> 24);
610 DEB_D(("V4L2_CID_BRIGHTNESS: %d\n", c
->value
));
612 case V4L2_CID_CONTRAST
:
613 value
= saa7146_read(dev
, BCS_CTRL
);
614 c
->value
= 0x7f & (value
>> 16);
615 DEB_D(("V4L2_CID_CONTRAST: %d\n", c
->value
));
617 case V4L2_CID_SATURATION
:
618 value
= saa7146_read(dev
, BCS_CTRL
);
619 c
->value
= 0x7f & (value
>> 0);
620 DEB_D(("V4L2_CID_SATURATION: %d\n", c
->value
));
623 c
->value
= vv
->vflip
;
624 DEB_D(("V4L2_CID_VFLIP: %d\n", c
->value
));
627 c
->value
= vv
->hflip
;
628 DEB_D(("V4L2_CID_HFLIP: %d\n", c
->value
));
636 static int vidioc_s_ctrl(struct file
*file
, void *fh
, struct v4l2_control
*c
)
638 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
639 struct saa7146_vv
*vv
= dev
->vv_data
;
640 const struct v4l2_queryctrl
*ctrl
;
642 ctrl
= ctrl_by_id(c
->id
);
644 DEB_D(("unknown control %d\n", c
->id
));
648 switch (ctrl
->type
) {
649 case V4L2_CTRL_TYPE_BOOLEAN
:
650 case V4L2_CTRL_TYPE_MENU
:
651 case V4L2_CTRL_TYPE_INTEGER
:
652 if (c
->value
< ctrl
->minimum
)
653 c
->value
= ctrl
->minimum
;
654 if (c
->value
> ctrl
->maximum
)
655 c
->value
= ctrl
->maximum
;
662 case V4L2_CID_BRIGHTNESS
: {
663 u32 value
= saa7146_read(dev
, BCS_CTRL
);
665 value
|= (c
->value
<< 24);
666 saa7146_write(dev
, BCS_CTRL
, value
);
667 saa7146_write(dev
, MC2
, MASK_22
| MASK_06
);
670 case V4L2_CID_CONTRAST
: {
671 u32 value
= saa7146_read(dev
, BCS_CTRL
);
673 value
|= (c
->value
<< 16);
674 saa7146_write(dev
, BCS_CTRL
, value
);
675 saa7146_write(dev
, MC2
, MASK_22
| MASK_06
);
678 case V4L2_CID_SATURATION
: {
679 u32 value
= saa7146_read(dev
, BCS_CTRL
);
681 value
|= (c
->value
<< 0);
682 saa7146_write(dev
, BCS_CTRL
, value
);
683 saa7146_write(dev
, MC2
, MASK_22
| MASK_06
);
687 /* fixme: we can support changing VFLIP and HFLIP here... */
688 if (IS_CAPTURE_ACTIVE(fh
) != 0) {
689 DEB_D(("V4L2_CID_HFLIP while active capture.\n"));
692 vv
->hflip
= c
->value
;
695 if (IS_CAPTURE_ACTIVE(fh
) != 0) {
696 DEB_D(("V4L2_CID_VFLIP while active capture.\n"));
699 vv
->vflip
= c
->value
;
705 if (IS_OVERLAY_ACTIVE(fh
) != 0) {
706 saa7146_stop_preview(fh
);
707 saa7146_start_preview(fh
);
712 static int vidioc_g_parm(struct file
*file
, void *fh
,
713 struct v4l2_streamparm
*parm
)
715 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
716 struct saa7146_vv
*vv
= dev
->vv_data
;
718 parm
->parm
.capture
.readbuffers
= 1;
719 v4l2_video_std_frame_period(vv
->standard
->id
,
720 &parm
->parm
.capture
.timeperframe
);
724 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*f
)
726 f
->fmt
.pix
= ((struct saa7146_fh
*)fh
)->video_fmt
;
730 static int vidioc_g_fmt_vid_overlay(struct file
*file
, void *fh
, struct v4l2_format
*f
)
732 f
->fmt
.win
= ((struct saa7146_fh
*)fh
)->ov
.win
;
736 static int vidioc_g_fmt_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*f
)
738 f
->fmt
.vbi
= ((struct saa7146_fh
*)fh
)->vbi_fmt
;
742 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*f
)
744 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
745 struct saa7146_vv
*vv
= dev
->vv_data
;
746 struct saa7146_format
*fmt
;
747 enum v4l2_field field
;
751 DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev
, fh
));
753 fmt
= saa7146_format_by_fourcc(dev
, f
->fmt
.pix
.pixelformat
);
757 field
= f
->fmt
.pix
.field
;
758 maxw
= vv
->standard
->h_max_out
;
759 maxh
= vv
->standard
->v_max_out
;
761 if (V4L2_FIELD_ANY
== field
) {
762 field
= (f
->fmt
.pix
.height
> maxh
/ 2)
763 ? V4L2_FIELD_INTERLACED
767 case V4L2_FIELD_ALTERNATE
:
768 vv
->last_field
= V4L2_FIELD_TOP
;
772 case V4L2_FIELD_BOTTOM
:
773 vv
->last_field
= V4L2_FIELD_INTERLACED
;
776 case V4L2_FIELD_INTERLACED
:
777 vv
->last_field
= V4L2_FIELD_INTERLACED
;
780 DEB_D(("no known field mode '%d'.\n", field
));
784 f
->fmt
.pix
.field
= field
;
785 if (f
->fmt
.pix
.width
> maxw
)
786 f
->fmt
.pix
.width
= maxw
;
787 if (f
->fmt
.pix
.height
> maxh
)
788 f
->fmt
.pix
.height
= maxh
;
790 calc_bpl
= (f
->fmt
.pix
.width
* fmt
->depth
) / 8;
792 if (f
->fmt
.pix
.bytesperline
< calc_bpl
)
793 f
->fmt
.pix
.bytesperline
= calc_bpl
;
795 if (f
->fmt
.pix
.bytesperline
> (2 * PAGE_SIZE
* fmt
->depth
) / 8) /* arbitrary constraint */
796 f
->fmt
.pix
.bytesperline
= calc_bpl
;
798 f
->fmt
.pix
.sizeimage
= f
->fmt
.pix
.bytesperline
* f
->fmt
.pix
.height
;
799 DEB_D(("w:%d, h:%d, bytesperline:%d, sizeimage:%d\n", f
->fmt
.pix
.width
,
800 f
->fmt
.pix
.height
, f
->fmt
.pix
.bytesperline
, f
->fmt
.pix
.sizeimage
));
806 static int vidioc_try_fmt_vid_overlay(struct file
*file
, void *fh
, struct v4l2_format
*f
)
808 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
809 struct saa7146_vv
*vv
= dev
->vv_data
;
810 struct v4l2_window
*win
= &f
->fmt
.win
;
811 enum v4l2_field field
;
814 DEB_EE(("dev:%p\n", dev
));
816 if (NULL
== vv
->ov_fb
.base
) {
817 DEB_D(("no fb base set.\n"));
820 if (NULL
== vv
->ov_fmt
) {
821 DEB_D(("no fb fmt set.\n"));
824 if (win
->w
.width
< 48 || win
->w
.height
< 32) {
825 DEB_D(("min width/height. (%d,%d)\n", win
->w
.width
, win
->w
.height
));
828 if (win
->clipcount
> 16) {
829 DEB_D(("clipcount too big.\n"));
834 maxw
= vv
->standard
->h_max_out
;
835 maxh
= vv
->standard
->v_max_out
;
837 if (V4L2_FIELD_ANY
== field
) {
838 field
= (win
->w
.height
> maxh
/ 2)
839 ? V4L2_FIELD_INTERLACED
844 case V4L2_FIELD_BOTTOM
:
845 case V4L2_FIELD_ALTERNATE
:
848 case V4L2_FIELD_INTERLACED
:
851 DEB_D(("no known field mode '%d'.\n", field
));
856 if (win
->w
.width
> maxw
)
858 if (win
->w
.height
> maxh
)
859 win
->w
.height
= maxh
;
864 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *__fh
, struct v4l2_format
*f
)
866 struct saa7146_fh
*fh
= __fh
;
867 struct saa7146_dev
*dev
= fh
->dev
;
868 struct saa7146_vv
*vv
= dev
->vv_data
;
871 DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev
, fh
));
872 if (IS_CAPTURE_ACTIVE(fh
) != 0) {
873 DEB_EE(("streaming capture is active\n"));
876 err
= vidioc_try_fmt_vid_cap(file
, fh
, f
);
879 fh
->video_fmt
= f
->fmt
.pix
;
880 DEB_EE(("set to pixelformat '%4.4s'\n", (char *)&fh
->video_fmt
.pixelformat
));
884 static int vidioc_s_fmt_vid_overlay(struct file
*file
, void *__fh
, struct v4l2_format
*f
)
886 struct saa7146_fh
*fh
= __fh
;
887 struct saa7146_dev
*dev
= fh
->dev
;
888 struct saa7146_vv
*vv
= dev
->vv_data
;
891 DEB_EE(("V4L2_BUF_TYPE_VIDEO_OVERLAY: dev:%p, fh:%p\n", dev
, fh
));
892 err
= vidioc_try_fmt_vid_overlay(file
, fh
, f
);
895 fh
->ov
.win
= f
->fmt
.win
;
896 fh
->ov
.nclips
= f
->fmt
.win
.clipcount
;
897 if (fh
->ov
.nclips
> 16)
899 if (copy_from_user(fh
->ov
.clips
, f
->fmt
.win
.clips
,
900 sizeof(struct v4l2_clip
) * fh
->ov
.nclips
)) {
904 /* fh->ov.fh is used to indicate that we have valid overlay informations, too */
907 /* check if our current overlay is active */
908 if (IS_OVERLAY_ACTIVE(fh
) != 0) {
909 saa7146_stop_preview(fh
);
910 saa7146_start_preview(fh
);
915 static int vidioc_g_std(struct file
*file
, void *fh
, v4l2_std_id
*norm
)
917 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
918 struct saa7146_vv
*vv
= dev
->vv_data
;
920 *norm
= vv
->standard
->id
;
924 /* the saa7146 supfhrts (used in conjunction with the saa7111a for example)
925 PAL / NTSC / SECAM. if your hardware does not (or does more)
926 -- override this function in your extension */
930 struct v4l2_standard *e = arg;
933 if( e->index < dev->ext_vv_data->num_stds ) {
934 DEB_EE(("VIDIOC_ENUMSTD: index:%d\n",e->index));
935 v4l2_video_std_construct(e, dev->ext_vv_data->stds[e->index].id, dev->ext_vv_data->stds[e->index].name);
942 static int vidioc_s_std(struct file
*file
, void *fh
, v4l2_std_id
*id
)
944 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
945 struct saa7146_vv
*vv
= dev
->vv_data
;
949 DEB_EE(("VIDIOC_S_STD\n"));
951 if ((vv
->video_status
& STATUS_CAPTURE
) == STATUS_CAPTURE
) {
952 DEB_D(("cannot change video standard while streaming capture is active\n"));
956 if ((vv
->video_status
& STATUS_OVERLAY
) != 0) {
957 vv
->ov_suspend
= vv
->video_fh
;
958 err
= saa7146_stop_preview(vv
->video_fh
); /* side effect: video_status is now 0, video_fh is NULL */
960 DEB_D(("suspending video failed. aborting\n"));
965 for (i
= 0; i
< dev
->ext_vv_data
->num_stds
; i
++)
966 if (*id
& dev
->ext_vv_data
->stds
[i
].id
)
968 if (i
!= dev
->ext_vv_data
->num_stds
) {
969 vv
->standard
= &dev
->ext_vv_data
->stds
[i
];
970 if (NULL
!= dev
->ext_vv_data
->std_callback
)
971 dev
->ext_vv_data
->std_callback(dev
, vv
->standard
);
975 if (vv
->ov_suspend
!= NULL
) {
976 saa7146_start_preview(vv
->ov_suspend
);
977 vv
->ov_suspend
= NULL
;
981 DEB_EE(("VIDIOC_S_STD: standard not found.\n"));
985 DEB_EE(("VIDIOC_S_STD: set to standard to '%s'\n", vv
->standard
->name
));
989 static int vidioc_overlay(struct file
*file
, void *fh
, unsigned int on
)
993 DEB_D(("VIDIOC_OVERLAY on:%d\n", on
));
995 err
= saa7146_start_preview(fh
);
997 err
= saa7146_stop_preview(fh
);
1001 static int vidioc_reqbufs(struct file
*file
, void *__fh
, struct v4l2_requestbuffers
*b
)
1003 struct saa7146_fh
*fh
= __fh
;
1005 if (b
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1006 return videobuf_reqbufs(&fh
->video_q
, b
);
1007 if (b
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
)
1008 return videobuf_reqbufs(&fh
->vbi_q
, b
);
1012 static int vidioc_querybuf(struct file
*file
, void *__fh
, struct v4l2_buffer
*buf
)
1014 struct saa7146_fh
*fh
= __fh
;
1016 if (buf
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1017 return videobuf_querybuf(&fh
->video_q
, buf
);
1018 if (buf
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
)
1019 return videobuf_querybuf(&fh
->vbi_q
, buf
);
1023 static int vidioc_qbuf(struct file
*file
, void *__fh
, struct v4l2_buffer
*buf
)
1025 struct saa7146_fh
*fh
= __fh
;
1027 if (buf
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1028 return videobuf_qbuf(&fh
->video_q
, buf
);
1029 if (buf
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
)
1030 return videobuf_qbuf(&fh
->vbi_q
, buf
);
1034 static int vidioc_dqbuf(struct file
*file
, void *__fh
, struct v4l2_buffer
*buf
)
1036 struct saa7146_fh
*fh
= __fh
;
1038 if (buf
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1039 return videobuf_dqbuf(&fh
->video_q
, buf
, file
->f_flags
& O_NONBLOCK
);
1040 if (buf
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
)
1041 return videobuf_dqbuf(&fh
->vbi_q
, buf
, file
->f_flags
& O_NONBLOCK
);
1045 static int vidioc_streamon(struct file
*file
, void *__fh
, enum v4l2_buf_type type
)
1047 struct saa7146_fh
*fh
= __fh
;
1050 DEB_D(("VIDIOC_STREAMON, type:%d\n", type
));
1052 err
= video_begin(fh
);
1055 if (type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1056 return videobuf_streamon(&fh
->video_q
);
1057 if (type
== V4L2_BUF_TYPE_VBI_CAPTURE
)
1058 return videobuf_streamon(&fh
->vbi_q
);
1062 static int vidioc_streamoff(struct file
*file
, void *__fh
, enum v4l2_buf_type type
)
1064 struct saa7146_fh
*fh
= __fh
;
1065 struct saa7146_dev
*dev
= fh
->dev
;
1066 struct saa7146_vv
*vv
= dev
->vv_data
;
1069 DEB_D(("VIDIOC_STREAMOFF, type:%d\n", type
));
1071 /* ugly: we need to copy some checks from video_end(),
1072 because videobuf_streamoff() relies on the capture running.
1073 check and fix this */
1074 if ((vv
->video_status
& STATUS_CAPTURE
) != STATUS_CAPTURE
) {
1075 DEB_S(("not capturing.\n"));
1079 if (vv
->video_fh
!= fh
) {
1080 DEB_S(("capturing, but in another open.\n"));
1085 if (type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1086 err
= videobuf_streamoff(&fh
->video_q
);
1087 else if (type
== V4L2_BUF_TYPE_VBI_CAPTURE
)
1088 err
= videobuf_streamoff(&fh
->vbi_q
);
1090 DEB_D(("warning: videobuf_streamoff() failed.\n"));
1091 video_end(fh
, file
);
1093 err
= video_end(fh
, file
);
1098 static int vidioc_g_chip_ident(struct file
*file
, void *__fh
,
1099 struct v4l2_dbg_chip_ident
*chip
)
1101 struct saa7146_fh
*fh
= __fh
;
1102 struct saa7146_dev
*dev
= fh
->dev
;
1104 chip
->ident
= V4L2_IDENT_NONE
;
1106 if (chip
->match
.type
== V4L2_CHIP_MATCH_HOST
&& !chip
->match
.addr
) {
1107 chip
->ident
= V4L2_IDENT_SAA7146
;
1110 return v4l2_device_call_until_err(&dev
->v4l2_dev
, 0,
1111 core
, g_chip_ident
, chip
);
1114 const struct v4l2_ioctl_ops saa7146_video_ioctl_ops
= {
1115 .vidioc_querycap
= vidioc_querycap
,
1116 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
1117 .vidioc_enum_fmt_vid_overlay
= vidioc_enum_fmt_vid_cap
,
1118 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
1119 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
1120 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
1121 .vidioc_g_fmt_vid_overlay
= vidioc_g_fmt_vid_overlay
,
1122 .vidioc_try_fmt_vid_overlay
= vidioc_try_fmt_vid_overlay
,
1123 .vidioc_s_fmt_vid_overlay
= vidioc_s_fmt_vid_overlay
,
1124 .vidioc_g_fmt_vbi_cap
= vidioc_g_fmt_vbi_cap
,
1125 .vidioc_g_chip_ident
= vidioc_g_chip_ident
,
1127 .vidioc_overlay
= vidioc_overlay
,
1128 .vidioc_g_fbuf
= vidioc_g_fbuf
,
1129 .vidioc_s_fbuf
= vidioc_s_fbuf
,
1130 .vidioc_reqbufs
= vidioc_reqbufs
,
1131 .vidioc_querybuf
= vidioc_querybuf
,
1132 .vidioc_qbuf
= vidioc_qbuf
,
1133 .vidioc_dqbuf
= vidioc_dqbuf
,
1134 .vidioc_g_std
= vidioc_g_std
,
1135 .vidioc_s_std
= vidioc_s_std
,
1136 .vidioc_queryctrl
= vidioc_queryctrl
,
1137 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1138 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1139 .vidioc_streamon
= vidioc_streamon
,
1140 .vidioc_streamoff
= vidioc_streamoff
,
1141 .vidioc_g_parm
= vidioc_g_parm
,
1144 /*********************************************************************************/
1145 /* buffer handling functions */
1147 static int buffer_activate (struct saa7146_dev
*dev
,
1148 struct saa7146_buf
*buf
,
1149 struct saa7146_buf
*next
)
1151 struct saa7146_vv
*vv
= dev
->vv_data
;
1153 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
1154 saa7146_set_capture(dev
,buf
,next
);
1156 mod_timer(&vv
->video_q
.timeout
, jiffies
+BUFFER_TIMEOUT
);
1160 static void release_all_pagetables(struct saa7146_dev
*dev
, struct saa7146_buf
*buf
)
1162 saa7146_pgtable_free(dev
->pci
, &buf
->pt
[0]);
1163 saa7146_pgtable_free(dev
->pci
, &buf
->pt
[1]);
1164 saa7146_pgtable_free(dev
->pci
, &buf
->pt
[2]);
1167 static int buffer_prepare(struct videobuf_queue
*q
,
1168 struct videobuf_buffer
*vb
, enum v4l2_field field
)
1170 struct file
*file
= q
->priv_data
;
1171 struct saa7146_fh
*fh
= file
->private_data
;
1172 struct saa7146_dev
*dev
= fh
->dev
;
1173 struct saa7146_vv
*vv
= dev
->vv_data
;
1174 struct saa7146_buf
*buf
= (struct saa7146_buf
*)vb
;
1177 DEB_CAP(("vbuf:%p\n",vb
));
1180 if (fh
->video_fmt
.width
< 48 ||
1181 fh
->video_fmt
.height
< 32 ||
1182 fh
->video_fmt
.width
> vv
->standard
->h_max_out
||
1183 fh
->video_fmt
.height
> vv
->standard
->v_max_out
) {
1184 DEB_D(("w (%d) / h (%d) out of bounds.\n",fh
->video_fmt
.width
,fh
->video_fmt
.height
));
1188 size
= fh
->video_fmt
.sizeimage
;
1189 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< size
) {
1190 DEB_D(("size mismatch.\n"));
1194 DEB_CAP(("buffer_prepare [size=%dx%d,bytes=%d,fields=%s]\n",
1195 fh
->video_fmt
.width
,fh
->video_fmt
.height
,size
,v4l2_field_names
[fh
->video_fmt
.field
]));
1196 if (buf
->vb
.width
!= fh
->video_fmt
.width
||
1197 buf
->vb
.bytesperline
!= fh
->video_fmt
.bytesperline
||
1198 buf
->vb
.height
!= fh
->video_fmt
.height
||
1199 buf
->vb
.size
!= size
||
1200 buf
->vb
.field
!= field
||
1201 buf
->vb
.field
!= fh
->video_fmt
.field
||
1202 buf
->fmt
!= &fh
->video_fmt
) {
1203 saa7146_dma_free(dev
,q
,buf
);
1206 if (VIDEOBUF_NEEDS_INIT
== buf
->vb
.state
) {
1207 struct saa7146_format
*sfmt
;
1209 buf
->vb
.bytesperline
= fh
->video_fmt
.bytesperline
;
1210 buf
->vb
.width
= fh
->video_fmt
.width
;
1211 buf
->vb
.height
= fh
->video_fmt
.height
;
1212 buf
->vb
.size
= size
;
1213 buf
->vb
.field
= field
;
1214 buf
->fmt
= &fh
->video_fmt
;
1215 buf
->vb
.field
= fh
->video_fmt
.field
;
1217 sfmt
= saa7146_format_by_fourcc(dev
,buf
->fmt
->pixelformat
);
1219 release_all_pagetables(dev
, buf
);
1220 if( 0 != IS_PLANAR(sfmt
->trans
)) {
1221 saa7146_pgtable_alloc(dev
->pci
, &buf
->pt
[0]);
1222 saa7146_pgtable_alloc(dev
->pci
, &buf
->pt
[1]);
1223 saa7146_pgtable_alloc(dev
->pci
, &buf
->pt
[2]);
1225 saa7146_pgtable_alloc(dev
->pci
, &buf
->pt
[0]);
1228 err
= videobuf_iolock(q
,&buf
->vb
, &vv
->ov_fb
);
1231 err
= saa7146_pgtable_build(dev
,buf
);
1235 buf
->vb
.state
= VIDEOBUF_PREPARED
;
1236 buf
->activate
= buffer_activate
;
1241 DEB_D(("error out.\n"));
1242 saa7146_dma_free(dev
,q
,buf
);
1247 static int buffer_setup(struct videobuf_queue
*q
, unsigned int *count
, unsigned int *size
)
1249 struct file
*file
= q
->priv_data
;
1250 struct saa7146_fh
*fh
= file
->private_data
;
1252 if (0 == *count
|| *count
> MAX_SAA7146_CAPTURE_BUFFERS
)
1253 *count
= MAX_SAA7146_CAPTURE_BUFFERS
;
1255 *size
= fh
->video_fmt
.sizeimage
;
1257 /* check if we exceed the "max_memory" parameter */
1258 if( (*count
* *size
) > (max_memory
*1048576) ) {
1259 *count
= (max_memory
*1048576) / *size
;
1262 DEB_CAP(("%d buffers, %d bytes each.\n",*count
,*size
));
1267 static void buffer_queue(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
1269 struct file
*file
= q
->priv_data
;
1270 struct saa7146_fh
*fh
= file
->private_data
;
1271 struct saa7146_dev
*dev
= fh
->dev
;
1272 struct saa7146_vv
*vv
= dev
->vv_data
;
1273 struct saa7146_buf
*buf
= (struct saa7146_buf
*)vb
;
1275 DEB_CAP(("vbuf:%p\n",vb
));
1276 saa7146_buffer_queue(fh
->dev
,&vv
->video_q
,buf
);
1279 static void buffer_release(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
1281 struct file
*file
= q
->priv_data
;
1282 struct saa7146_fh
*fh
= file
->private_data
;
1283 struct saa7146_dev
*dev
= fh
->dev
;
1284 struct saa7146_buf
*buf
= (struct saa7146_buf
*)vb
;
1286 DEB_CAP(("vbuf:%p\n",vb
));
1288 saa7146_dma_free(dev
,q
,buf
);
1290 release_all_pagetables(dev
, buf
);
1293 static struct videobuf_queue_ops video_qops
= {
1294 .buf_setup
= buffer_setup
,
1295 .buf_prepare
= buffer_prepare
,
1296 .buf_queue
= buffer_queue
,
1297 .buf_release
= buffer_release
,
1300 /********************************************************************************/
1301 /* file operations */
1303 static void video_init(struct saa7146_dev
*dev
, struct saa7146_vv
*vv
)
1305 INIT_LIST_HEAD(&vv
->video_q
.queue
);
1307 init_timer(&vv
->video_q
.timeout
);
1308 vv
->video_q
.timeout
.function
= saa7146_buffer_timeout
;
1309 vv
->video_q
.timeout
.data
= (unsigned long)(&vv
->video_q
);
1310 vv
->video_q
.dev
= dev
;
1312 /* set some default values */
1313 vv
->standard
= &dev
->ext_vv_data
->stds
[0];
1315 /* FIXME: what's this? */
1316 vv
->current_hps_source
= SAA7146_HPS_SOURCE_PORT_A
;
1317 vv
->current_hps_sync
= SAA7146_HPS_SYNC_PORT_A
;
1321 static int video_open(struct saa7146_dev
*dev
, struct file
*file
)
1323 struct saa7146_fh
*fh
= file
->private_data
;
1324 struct saa7146_format
*sfmt
;
1326 fh
->video_fmt
.width
= 384;
1327 fh
->video_fmt
.height
= 288;
1328 fh
->video_fmt
.pixelformat
= V4L2_PIX_FMT_BGR24
;
1329 fh
->video_fmt
.bytesperline
= 0;
1330 fh
->video_fmt
.field
= V4L2_FIELD_ANY
;
1331 sfmt
= saa7146_format_by_fourcc(dev
,fh
->video_fmt
.pixelformat
);
1332 fh
->video_fmt
.sizeimage
= (fh
->video_fmt
.width
* fh
->video_fmt
.height
* sfmt
->depth
)/8;
1334 videobuf_queue_sg_init(&fh
->video_q
, &video_qops
,
1335 &dev
->pci
->dev
, &dev
->slock
,
1336 V4L2_BUF_TYPE_VIDEO_CAPTURE
,
1337 V4L2_FIELD_INTERLACED
,
1338 sizeof(struct saa7146_buf
),
1339 file
, &dev
->v4l2_lock
);
1345 static void video_close(struct saa7146_dev
*dev
, struct file
*file
)
1347 struct saa7146_fh
*fh
= file
->private_data
;
1348 struct saa7146_vv
*vv
= dev
->vv_data
;
1349 struct videobuf_queue
*q
= &fh
->video_q
;
1352 if (IS_CAPTURE_ACTIVE(fh
) != 0) {
1353 err
= video_end(fh
, file
);
1354 } else if (IS_OVERLAY_ACTIVE(fh
) != 0) {
1355 err
= saa7146_stop_preview(fh
);
1360 /* hmm, why is this function declared void? */
1365 static void video_irq_done(struct saa7146_dev
*dev
, unsigned long st
)
1367 struct saa7146_vv
*vv
= dev
->vv_data
;
1368 struct saa7146_dmaqueue
*q
= &vv
->video_q
;
1370 spin_lock(&dev
->slock
);
1371 DEB_CAP(("called.\n"));
1373 /* only finish the buffer if we have one... */
1374 if( NULL
!= q
->curr
) {
1375 saa7146_buffer_finish(dev
,q
,VIDEOBUF_DONE
);
1377 saa7146_buffer_next(dev
,q
,0);
1379 spin_unlock(&dev
->slock
);
1382 static ssize_t
video_read(struct file
*file
, char __user
*data
, size_t count
, loff_t
*ppos
)
1384 struct saa7146_fh
*fh
= file
->private_data
;
1385 struct saa7146_dev
*dev
= fh
->dev
;
1386 struct saa7146_vv
*vv
= dev
->vv_data
;
1389 DEB_EE(("called.\n"));
1391 if ((vv
->video_status
& STATUS_CAPTURE
) != 0) {
1392 /* fixme: should we allow read() captures while streaming capture? */
1393 if (vv
->video_fh
== fh
) {
1394 DEB_S(("already capturing.\n"));
1397 DEB_S(("already capturing in another open.\n"));
1401 ret
= video_begin(fh
);
1406 ret
= videobuf_read_one(&fh
->video_q
, data
, count
, ppos
,
1407 file
->f_flags
& O_NONBLOCK
);
1409 video_end(fh
, file
);
1411 ret
= video_end(fh
, file
);
1414 /* restart overlay if it was active before */
1415 if (vv
->ov_suspend
!= NULL
) {
1416 saa7146_start_preview(vv
->ov_suspend
);
1417 vv
->ov_suspend
= NULL
;
1423 struct saa7146_use_ops saa7146_video_uops
= {
1426 .release
= video_close
,
1427 .irq_done
= video_irq_done
,