1 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7 #include <linux/module.h>
9 static int max_memory = 32;
12 MODULE_PARM_DESC(max_memory,
"maximum memory usage for capture buffers (default: 32Mb)");
14 #define IS_CAPTURE_ACTIVE(fh) \
15 (((vv->video_status & STATUS_CAPTURE) != 0) && (vv->video_fh == fh))
17 #define IS_OVERLAY_ACTIVE(fh) \
18 (((vv->video_status & STATUS_OVERLAY) != 0) && (vv->video_fh == fh))
23 .name =
"RGB-8 (3-3-2)",
29 .name =
"RGB-16 (5/B-6/G-5/R)",
35 .name =
"RGB-24 (B-G-R)",
41 .name =
"RGB-32 (B-G-R)",
47 .name =
"RGB-32 (R-G-B)",
54 .name =
"Greyscale-8",
60 .name =
"YUV 4:2:2 planar (Y-Cb-Cr)",
66 .name =
"YVU 4:2:0 planar (Y-Cb-Cr)",
72 .name =
"YUV 4:2:0 planar (Y-Cb-Cr)",
78 .name =
"YUV 4:2:2 (U-Y-V-Y)",
96 for (i = 0; i <
j; i++) {
102 DEB_D(
"unknown pixelformat:'%4.4s'\n", (
char *)&fourcc);
115 DEB_EE(
"dev:%p, fh:%p\n", dev, fh);
119 DEB_D(
"no overlay data available. try S_FMT first.\n");
125 DEB_D(
"streaming capture is active\n");
132 DEB_D(
"overlay is already active\n");
135 DEB_D(
"overlay is already active in another open\n");
140 DEB_D(
"cannot get necessary overlay resources\n");
145 err = vidioc_try_fmt_vid_overlay(
NULL, fh, &fmt);
152 DEB_D(
"%dx%d+%d+%d %s field=%s\n",
153 vv->
ov.win.w.width, vv->
ov.win.w.height,
154 vv->
ov.win.w.left, vv->
ov.win.w.top,
158 DEB_D(
"enabling overlay failed: %d\n", ret);
175 DEB_EE(
"dev:%p, fh:%p\n", dev, fh);
179 DEB_D(
"streaming capture is active\n");
185 DEB_D(
"no active overlay\n");
190 DEB_D(
"overlay is active, but in another open\n");
216 DEB_EE(
"dev:%p, buf:%p, sg_len:%d\n", dev, buf, length);
222 __le32 *ptr1, *ptr2, *ptr3;
226 int i,
p,m1,m2,m3,o1,
o2;
228 switch( sfmt->
depth ) {
236 DEB_CAP(
"size:%d, m1:%d, m2:%d, m3:%d, o1:%d, o2:%d\n",
237 size, m1, m2, m3, o1, o2);
247 DEB_CAP(
"size:%d, m1:%d, m2:%d, m3:%d, o1:%d, o2:%d\n",
248 size, m1, m2, m3, o1, o2);
261 for (i = 0; i <
length; i++, list++) {
262 for (p = 0; p * 4096 < list->
length; p++, ptr1++) {
281 for(i = m1; i <= m2 ; i++, ptr2++) {
285 for(;i<1024;i++,ptr2++) {
290 for(i = m2; i <= m3; i++,ptr3++) {
294 for(;i<1024;i++,ptr3++) {
300 for(i=m1;i<1024;i++,ptr1++) {
337 DEB_EE(
"dev:%p, fh:%p\n", dev, fh);
341 DEB_S(
"already capturing\n");
344 DEB_S(
"already capturing in another open\n");
349 DEB_S(
"warning: suspending overlay video for streaming capture\n");
353 DEB_D(
"suspending video failed. aborting\n");
370 DEB_S(
"cannot get capture resource %d\n", resource);
382 SAA7146_IER_ENABLE(dev,
MASK_27);
398 DEB_EE(
"dev:%p, fh:%p\n", dev, fh);
401 DEB_S(
"not capturing\n");
406 DEB_S(
"capturing, but in another open\n");
427 SAA7146_IER_DISABLE(dev,
MASK_27);
432 spin_unlock_irqrestore(&dev->
slock, flags);
488 DEB_EE(
"VIDIOC_S_FBUF\n");
500 DEB_S(
"planar pixelformat '%4.4s' not allowed for overlay\n",
506 DEB_D(
"refusing to change framebuffer informations while overlay is active in another open\n");
515 if (vv->
ov_fb.fmt.bytesperline < vv->
ov_fb.fmt.width) {
517 DEB_D(
"setting bytesperline to %d\n", vv->
ov_fb.fmt.bytesperline);
522 static int vidioc_enum_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_fmtdesc *
f)
543 val |= (ctrl->
val << 24);
551 val |= (ctrl->
val << 16);
559 val |= (ctrl->
val << 0);
590 static int vidioc_g_parm(
struct file *file,
void *fh,
604 static int vidioc_g_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_format *f)
613 static int vidioc_g_fmt_vid_overlay(
struct file *file,
void *fh,
struct v4l2_format *f)
622 static int vidioc_g_fmt_vbi_cap(
struct file *file,
void *fh,
struct v4l2_format *f)
631 static int vidioc_try_fmt_vid_cap(
struct file *file,
void *fh,
struct v4l2_format *f)
640 DEB_EE(
"V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh);
651 field = (f->
fmt.
pix.height > maxh / 2)
669 DEB_D(
"no known field mode '%d'\n", field);
675 if (f->
fmt.
pix.width > maxw)
677 if (f->
fmt.
pix.height > maxh)
682 if (f->
fmt.
pix.bytesperline < calc_bpl)
683 f->
fmt.
pix.bytesperline = calc_bpl;
686 f->
fmt.
pix.bytesperline = calc_bpl;
689 DEB_D(
"w:%d, h:%d, bytesperline:%d, sizeimage:%d\n",
697 static int vidioc_try_fmt_vid_overlay(
struct file *file,
void *fh,
struct v4l2_format *f)
708 DEB_D(
"no fb base set\n");
712 DEB_D(
"no fb fmt set\n");
715 if (win->
w.width < 48 || win->
w.height < 32) {
716 DEB_D(
"min width/height. (%d,%d)\n",
717 win->
w.width, win->
w.height);
721 DEB_D(
"clipcount too big\n");
730 field = (win->
w.height > maxh / 2)
743 DEB_D(
"no known field mode '%d'\n", field);
748 if (win->
w.width > maxw)
750 if (win->
w.height > maxh)
751 win->
w.height = maxh;
756 static int vidioc_s_fmt_vid_cap(
struct file *file,
void *__fh,
struct v4l2_format *f)
763 DEB_EE(
"V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh);
765 DEB_EE(
"streaming capture is active\n");
768 err = vidioc_try_fmt_vid_cap(file, fh, f);
772 DEB_EE(
"set to pixelformat '%4.4s'\n",
777 static int vidioc_s_fmt_vid_overlay(
struct file *file,
void *__fh,
struct v4l2_format *f)
784 DEB_EE(
"V4L2_BUF_TYPE_VIDEO_OVERLAY: dev:%p, fh:%p\n", dev, fh);
785 err = vidioc_try_fmt_vid_overlay(file, fh, f);
789 vv->
ov.nclips = f->
fmt.
win.clipcount;
790 if (vv->
ov.nclips > 16)
808 static int vidioc_g_std(
struct file *file,
void *fh,
v4l2_std_id *norm)
835 static int vidioc_s_std(
struct file *file,
void *fh,
v4l2_std_id *
id)
845 DEB_D(
"cannot change video standard while streaming capture is active\n");
853 DEB_D(
"suspending video failed. aborting\n");
874 DEB_EE(
"VIDIOC_S_STD: standard not found\n");
878 DEB_EE(
"VIDIOC_S_STD: set to standard to '%s'\n", vv->
standard->name);
882 static int vidioc_overlay(
struct file *file,
void *fh,
unsigned int on)
886 DEB_D(
"VIDIOC_OVERLAY on:%d\n", on);
905 static int vidioc_querybuf(
struct file *file,
void *__fh,
struct v4l2_buffer *buf)
916 static int vidioc_qbuf(
struct file *file,
void *__fh,
struct v4l2_buffer *buf)
927 static int vidioc_dqbuf(
struct file *file,
void *__fh,
struct v4l2_buffer *buf)
938 static int vidioc_streamon(
struct file *file,
void *__fh,
enum v4l2_buf_type type)
943 DEB_D(
"VIDIOC_STREAMON, type:%d\n", type);
945 err = video_begin(fh);
955 static int vidioc_streamoff(
struct file *file,
void *__fh,
enum v4l2_buf_type type)
962 DEB_D(
"VIDIOC_STREAMOFF, type:%d\n", type);
968 DEB_S(
"not capturing\n");
973 DEB_S(
"capturing, but in another open\n");
983 DEB_D(
"warning: videobuf_streamoff() failed\n");
991 static int vidioc_g_chip_ident(
struct file *file,
void *__fh,
1008 core, g_chip_ident, chip);
1097 DEB_D(
"w (%d) / h (%d) out of bounds\n",
1103 if (0 != buf->
vb.baddr && buf->
vb.bsize < size) {
1104 DEB_D(
"size mismatch\n");
1108 DEB_CAP(
"buffer_prepare [size=%dx%d,bytes=%d,fields=%s]\n",
1112 buf->
vb.bytesperline != vv->
video_fmt.bytesperline ||
1114 buf->
vb.size != size ||
1115 buf->
vb.field != field ||
1124 buf->
vb.bytesperline = vv->
video_fmt.bytesperline;
1134 release_all_pagetables(dev, buf);
1146 err = saa7146_pgtable_build(dev,buf);
1156 DEB_D(
"error out\n");
1162 static int buffer_setup(
struct videobuf_queue *q,
unsigned int *
count,
unsigned int *size)
1174 if( (*count * *size) > (max_memory*1048576) ) {
1175 *count = (max_memory*1048576) / *size;
1178 DEB_CAP(
"%d buffers, %d bytes each\n", *count, *size);
1206 release_all_pagetables(dev, buf);
1210 .buf_setup = buffer_setup,
1211 .buf_prepare = buffer_prepare,
1212 .buf_queue = buffer_queue,
1213 .buf_release = buffer_release,
1237 static int video_open(
struct saa7146_dev *dev,
struct file *file)
1252 static void video_close(
struct saa7146_dev *dev,
struct file *file)
1268 static void video_irq_done(
struct saa7146_dev *dev,
unsigned long st)
1273 spin_lock(&dev->
slock);
1282 spin_unlock(&dev->
slock);
1285 static ssize_t video_read(
struct file *file,
char __user *
data,
size_t count, loff_t *ppos)
1297 DEB_S(
"already capturing\n");
1300 DEB_S(
"already capturing in another open\n");
1304 ret = video_begin(fh);
1329 .release = video_close,
1330 .irq_done = video_irq_done,