V4L/DVB (10446): cx18: Finally get sliced VBI working - for 525 line 60 Hz systems at least

Sliced VBI, in the manner that ivtv implements it as a separate data stream,
now works for 525 line 60 Hz systems like NTSC-M.  It may work for 625 line
50 Hz systems, but I have more engineering work to do, to verify it is operating
properly.  Sliced data insertion into the MPEG PS should be working, but is
untested.

Signed-off-by: Andy Walls <awalls@radix.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
diff --git a/drivers/media/video/cx18/cx18-streams.c b/drivers/media/video/cx18/cx18-streams.c
index a8dcc0f..778aa0c 100644
--- a/drivers/media/video/cx18/cx18-streams.c
+++ b/drivers/media/video/cx18/cx18-streams.c
@@ -360,9 +360,16 @@
 	if (raw) {
 		lines = cx->vbi.count * 2;
 	} else {
-		lines = cx->is_60hz ? 24 : 38;
-		if (cx->is_60hz)
-			lines += 2;
+		/*
+		 * For 525/60 systems, according to the VIP 2 & BT.656 std:
+		 * The EAV RP code's Field bit toggles on line 4, a few lines
+		 * after the Vertcal Blank bit has already toggled.
+		 * Tell the encoder to capture 21-4+1=18 lines per field,
+		 * since we want lines 10 through 21.
+		 *
+		 * FIXME - revisit for 625/50 systems
+		 */
+		lines = cx->is_60hz ? (21 - 4 + 1) * 2 : 38;
 	}
 
 	data[0] = s->handle;
@@ -402,9 +409,13 @@
 		 *
 		 * Since the V bit is only allowed to toggle in the EAV RP code,
 		 * just before the first active region line, these two
-		 * are problematic and we have to ignore them:
+		 * are problematic:
 		 * 0x90 (Task                         HorizontalBlank)
 		 * 0xd0 (Task EvenField               HorizontalBlank)
+		 *
+		 * We have set the digitzer to consider the first active line
+		 * as part of VerticalBlank as well so we don't have to look for
+		 * these problem codes nor lose the last line of sliced data.
 		 */
 		data[4] = 0xB0F0B0F0;
 		/*