[media] cx88: fix VBI support
authorHans Verkuil <hans.verkuil@cisco.com>
Sat, 20 Sep 2014 12:24:58 +0000 (09:24 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Mon, 3 Nov 2014 10:36:40 +0000 (08:36 -0200)
Now works with both NTSC and PAL. Tested with CC/XDS for NTSC and
teletext/WSS for PAL. The start lines were wrong, the WSS signal
wasn't captured and there was no difference between NTSC and PAL
w.r.t. the count[] values so NTSC returned way too many lines.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/pci/cx88/cx88-vbi.c
drivers/media/pci/cx88/cx88.h

index 042f54597a9bfa4ad46d2af3e9a344dfadaf5bf2..6ab6e27648f638fcf49ca48a603b5b324125aeef 100644 (file)
@@ -23,20 +23,22 @@ int cx8800_vbi_fmt (struct file *file, void *priv,
        f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
        f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
        f->fmt.vbi.offset = 244;
-       f->fmt.vbi.count[0] = VBI_LINE_COUNT;
-       f->fmt.vbi.count[1] = VBI_LINE_COUNT;
 
        if (dev->core->tvnorm & V4L2_STD_525_60) {
                /* ntsc */
                f->fmt.vbi.sampling_rate = 28636363;
                f->fmt.vbi.start[0] = 10;
                f->fmt.vbi.start[1] = 273;
+               f->fmt.vbi.count[0] = VBI_LINE_NTSC_COUNT;
+               f->fmt.vbi.count[1] = VBI_LINE_NTSC_COUNT;
 
        } else if (dev->core->tvnorm & V4L2_STD_625_50) {
                /* pal */
                f->fmt.vbi.sampling_rate = 35468950;
-               f->fmt.vbi.start[0] = 7 -1;
-               f->fmt.vbi.start[1] = 319 -1;
+               f->fmt.vbi.start[0] = V4L2_VBI_ITU_625_F1_START + 5;
+               f->fmt.vbi.start[1] = V4L2_VBI_ITU_625_F2_START + 5;
+               f->fmt.vbi.count[0] = VBI_LINE_PAL_COUNT;
+               f->fmt.vbi.count[1] = VBI_LINE_PAL_COUNT;
        }
        return 0;
 }
@@ -111,8 +113,13 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
                           unsigned int *num_buffers, unsigned int *num_planes,
                           unsigned int sizes[], void *alloc_ctxs[])
 {
+       struct cx8800_dev *dev = q->drv_priv;
+
        *num_planes = 1;
-       sizes[0] = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
+       if (dev->core->tvnorm & V4L2_STD_525_60)
+               sizes[0] = VBI_LINE_NTSC_COUNT * VBI_LINE_LENGTH * 2;
+       else
+               sizes[0] = VBI_LINE_PAL_COUNT * VBI_LINE_LENGTH * 2;
        return 0;
 }
 
@@ -122,10 +129,15 @@ static int buffer_prepare(struct vb2_buffer *vb)
        struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
        struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
        struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0);
+       unsigned int lines;
        unsigned int size;
        int rc;
 
-       size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2;
+       if (dev->core->tvnorm & V4L2_STD_525_60)
+               lines = VBI_LINE_NTSC_COUNT;
+       else
+               lines = VBI_LINE_PAL_COUNT;
+       size = lines * VBI_LINE_LENGTH * 2;
        if (vb2_plane_size(vb, 0) < size)
                return -EINVAL;
        vb2_set_plane_payload(vb, 0, size);
@@ -135,9 +147,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
                return -EIO;
 
        cx88_risc_buffer(dev->pci, &buf->risc, sgt->sgl,
-                        0, VBI_LINE_LENGTH * VBI_LINE_COUNT,
+                        0, VBI_LINE_LENGTH * lines,
                         VBI_LINE_LENGTH, 0,
-                        VBI_LINE_COUNT);
+                        lines);
        return 0;
 }
 
index 2fa4aa93e5034ccf361c9b67d7f247c63cc4fe97..3b0ae754f16588b86ab8695aabeedbd9aa3795fd 100644 (file)
@@ -61,7 +61,8 @@
 #define FORMAT_FLAGS_PACKED       0x01
 #define FORMAT_FLAGS_PLANAR       0x02
 
-#define VBI_LINE_COUNT              17
+#define VBI_LINE_PAL_COUNT              18
+#define VBI_LINE_NTSC_COUNT             12
 #define VBI_LINE_LENGTH           2048
 
 #define AUD_RDS_LINES               4