// SPDX-License-Identifier: GPL-2.0-or-later
/*
* cx18 ADEC VBI functions
*
* Derived from cx25840 - vbi . c
*
* Copyright ( C ) 2007 Hans Verkuil < hverkuil @ xs4all . nl >
*/
#include <linux/bitops.h>
#include "cx18-driver.h"
/*
* For sliced VBI output , we set up to use VIP - 1 . 1 , 8 - bit mode ,
* NN counts 1 byte Dwords , an IDID with the VBI line # in it .
* Thus , according to the VIP - 2 Spec , our VBI ancillary data lines
* ( should ! ) look like :
* 4 byte EAV code : 0 xff 0 x00 0 x00 0 xRP
* unknown number of possible idle bytes
* 3 byte Anc data preamble : 0 x00 0 xff 0 xff
* 1 byte data identifier : ne010iii ( parity bits , 010 , DID bits )
* 1 byte secondary data id : nessssss ( parity bits , SDID bits )
* 1 byte data word count : necccccc ( parity bits , NN Dword count )
* 2 byte Internal DID : VBI - line - # 0 x80
* NN data bytes
* 1 byte checksum
* Fill bytes needed to fil out to 4 * NN bytes of payload
*
* The RP codes for EAVs when in VIP - 1 . 1 mode , not in raw mode , &
* in the vertical blanking interval are :
* 0 xb0 ( Task 0 VerticalBlank HorizontalBlank 0 0 0 0 )
* 0 xf0 ( Task EvenField VerticalBlank HorizontalBlank 0 0 0 0 )
*
* Since the V bit is only allowed to toggle in the EAV RP code , just
* before the first active region line and for active lines , they are :
* 0 x90 ( Task 0 0 HorizontalBlank 0 0 0 0 )
* 0 xd0 ( Task EvenField 0 HorizontalBlank 0 0 0 0 )
*
* The user application DID bytes we care about are :
* 0 x91 ( 1 0 010 0 ! ActiveLine AncDataPresent )
* 0 x55 ( 0 1 010 2 ndField ! ActiveLine AncDataPresent )
*
*/
static const u8 sliced_vbi_did[2 ] = { 0 x91, 0 x55 };
struct vbi_anc_data {
/* u8 eav[4]; */
/* u8 idle[]; Variable number of idle bytes */
u8 preamble[3 ];
u8 did;
u8 sdid;
u8 data_count;
u8 idid[2 ];
u8 payload[]; /* data_count of payload */
/* u8 checksum; */
/* u8 fill[]; Variable number of fill bytes */
};
static int decode_vps(u8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0 x0a, 0 x02, 0 x82, 0 xc2, 0 x4a, 0 x42, 0 xc2,
0 xc0, 0 x48, 0 x40, 0 xc0, 0 x84, 0 x0c, 0 x04, 0 x84,
0 x80, 0 x08, 0 x00, 0 x80, 0 xc0, 0 x48, 0 x40, 0 xc0,
0 xe0, 0 x68, 0 x60, 0 xe0, 0 xa4, 0 x2c, 0 x24, 0 xa4,
0 xa0, 0 x28, 0 x20, 0 xa0, 0 xe0, 0 x68, 0 x60, 0 xe0,
0 xf0, 0 x78, 0 x70, 0 xf0, 0 xb4, 0 x3c, 0 x34, 0 xb4,
0 xb0, 0 x38, 0 x30, 0 xb0, 0 xf0, 0 x78, 0 x70, 0 xf0,
0 xd2, 0 x5a, 0 x52, 0 xd2, 0 x96, 0 x1e, 0 x16, 0 x96,
0 x92, 0 x1a, 0 x12, 0 x92, 0 xd2, 0 x5a, 0 x52, 0 xd2,
0 xd0, 0 x58, 0 x50, 0 xd0, 0 x94, 0 x1c, 0 x14, 0 x94,
0 x90, 0 x18, 0 x10, 0 x90, 0 xd0, 0 x58, 0 x50, 0 xd0,
0 xf0, 0 x78, 0 x70, 0 xf0, 0 xb4, 0 x3c, 0 x34, 0 xb4,
0 xb0, 0 x38, 0 x30, 0 xb0, 0 xf0, 0 x78, 0 x70, 0 xf0,
};
u8 c, err = 0 ;
int i;
for (i = 0 ; i < 2 * 13 ; i += 2 ) {
err |= biphase_tbl[p[i]] | biphase_tbl[p[i + 1 ]];
c = (biphase_tbl[p[i + 1 ]] & 0 xf) |
((biphase_tbl[p[i]] & 0 xf) << 4 );
dst[i / 2 ] = c;
}
return err & 0 xf0;
}
int cx18_av_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
{
struct cx18 *cx = v4l2_get_subdevdata(sd);
struct cx18_av_state *state = &cx->av_state;
static const u16 lcr2vbi[] = {
0 , V4L2_SLICED_TELETEXT_B, 0 , /* 1 */
0 , V4L2_SLICED_WSS_625, 0 , /* 4 */
V4L2_SLICED_CAPTION_525, /* 6 */
0 , 0 , V4L2_SLICED_VPS, 0 , 0 , /* 9 */
0 , 0 , 0 , 0
};
int is_pal = !(state->std & V4L2_STD_525_60);
int i;
memset(svbi->service_lines, 0 , sizeof (svbi->service_lines));
svbi->service_set = 0 ;
/* we're done if raw VBI is active */
if ((cx18_av_read(cx, 0 x404) & 0 x10) == 0 )
return 0 ;
if (is_pal) {
for (i = 7 ; i <= 23 ; i++) {
u8 v = cx18_av_read(cx, 0 x424 + i - 7 );
svbi->service_lines[0 ][i] = lcr2vbi[v >> 4 ];
svbi->service_lines[1 ][i] = lcr2vbi[v & 0 xf];
svbi->service_set |= svbi->service_lines[0 ][i] |
svbi->service_lines[1 ][i];
}
} else {
for (i = 10 ; i <= 21 ; i++) {
u8 v = cx18_av_read(cx, 0 x424 + i - 10 );
svbi->service_lines[0 ][i] = lcr2vbi[v >> 4 ];
svbi->service_lines[1 ][i] = lcr2vbi[v & 0 xf];
svbi->service_set |= svbi->service_lines[0 ][i] |
svbi->service_lines[1 ][i];
}
}
return 0 ;
}
int cx18_av_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt)
{
struct cx18 *cx = v4l2_get_subdevdata(sd);
struct cx18_av_state *state = &cx->av_state;
/* Setup standard */
cx18_av_std_setup(cx);
/* VBI Offset */
cx18_av_write(cx, 0 x47f, state->slicer_line_delay);
cx18_av_write(cx, 0 x404, 0 x2e);
return 0 ;
}
int cx18_av_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
{
struct cx18 *cx = v4l2_get_subdevdata(sd);
struct cx18_av_state *state = &cx->av_state;
int is_pal = !(state->std & V4L2_STD_525_60);
int i, x;
u8 lcr[24 ];
for (x = 0 ; x <= 23 ; x++)
lcr[x] = 0 x00;
/* Setup standard */
cx18_av_std_setup(cx);
/* Sliced VBI */
cx18_av_write(cx, 0 x404, 0 x32); /* Ancillary data */
cx18_av_write(cx, 0 x406, 0 x13);
cx18_av_write(cx, 0 x47f, state->slicer_line_delay);
/* Force impossible lines to 0 */
if (is_pal) {
for (i = 0 ; i <= 6 ; i++)
svbi->service_lines[0 ][i] =
svbi->service_lines[1 ][i] = 0 ;
} else {
for (i = 0 ; i <= 9 ; i++)
svbi->service_lines[0 ][i] =
svbi->service_lines[1 ][i] = 0 ;
for (i = 22 ; i <= 23 ; i++)
svbi->service_lines[0 ][i] =
svbi->service_lines[1 ][i] = 0 ;
}
/* Build register values for requested service lines */
for (i = 7 ; i <= 23 ; i++) {
for (x = 0 ; x <= 1 ; x++) {
switch (svbi->service_lines[1 -x][i]) {
case V4L2_SLICED_TELETEXT_B:
lcr[i] |= 1 << (4 * x);
break ;
case V4L2_SLICED_WSS_625:
lcr[i] |= 4 << (4 * x);
break ;
case V4L2_SLICED_CAPTION_525:
lcr[i] |= 6 << (4 * x);
break ;
case V4L2_SLICED_VPS:
lcr[i] |= 9 << (4 * x);
break ;
}
}
}
if (is_pal) {
for (x = 1 , i = 0 x424; i <= 0 x434; i++, x++)
cx18_av_write(cx, i, lcr[6 + x]);
} else {
for (x = 1 , i = 0 x424; i <= 0 x430; i++, x++)
cx18_av_write(cx, i, lcr[9 + x]);
for (i = 0 x431; i <= 0 x434; i++)
cx18_av_write(cx, i, 0 );
}
cx18_av_write(cx, 0 x43c, 0 x16);
/* Should match vblank set in cx18_av_std_setup() */
cx18_av_write(cx, 0 x474, is_pal ? 38 : 26 );
return 0 ;
}
int cx18_av_decode_vbi_line(struct v4l2_subdev *sd,
struct v4l2_decode_vbi_line *vbi)
{
struct cx18 *cx = v4l2_get_subdevdata(sd);
struct cx18_av_state *state = &cx->av_state;
struct vbi_anc_data *anc = (struct vbi_anc_data *)vbi->p;
u8 *p;
int did, sdid, l, err = 0 ;
/*
* Check for the ancillary data header for sliced VBI
*/
if (anc->preamble[0 ] ||
anc->preamble[1 ] != 0 xff || anc->preamble[2 ] != 0 xff ||
(anc->did != sliced_vbi_did[0 ] &&
anc->did != sliced_vbi_did[1 ])) {
vbi->line = vbi->type = 0 ;
return 0 ;
}
did = anc->did;
sdid = anc->sdid & 0 xf;
l = anc->idid[0 ] & 0 x3f;
l += state->slicer_line_offset;
p = anc->payload;
/* Decode the SDID set by the slicer */
switch (sdid) {
case 1 :
sdid = V4L2_SLICED_TELETEXT_B;
break ;
case 4 :
sdid = V4L2_SLICED_WSS_625;
break ;
case 6 :
sdid = V4L2_SLICED_CAPTION_525;
err = !parity8(p[0 ]) || !parity8(p[1 ]);
break ;
case 9 :
sdid = V4L2_SLICED_VPS;
if (decode_vps(p, p) != 0 )
err = 1 ;
break ;
default :
sdid = 0 ;
err = 1 ;
break ;
}
vbi->type = err ? 0 : sdid;
vbi->line = err ? 0 : l;
vbi->is_second_field = err ? 0 : (did == sliced_vbi_did[1 ]);
vbi->p = p;
return 0 ;
}
Messung V0.5 in Prozent C=93 H=73 G=83
¤ Dauer der Verarbeitung: 0.6 Sekunden
¤
*© Formatika GbR, Deutschland