V4L/DVB (11310): cx18: remove intermediate 'ioctl' step

The audio and vbi parts still used an 'ioctl'-like interface. Replace this
with normal functions.

Cc: Andy Walls <awalls@radix.net>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Hans Verkuil 2009-03-30 06:43:13 -03:00 committed by Mauro Carvalho Chehab
parent df1d5ed8a8
commit 41c129a870
4 changed files with 232 additions and 259 deletions

View File

@ -464,82 +464,76 @@ static void set_mute(struct cx18 *cx, int mute)
} }
} }
int cx18_av_audio(struct cx18 *cx, unsigned int cmd, void *arg) int cx18_av_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
{ {
struct cx18 *cx = v4l2_get_subdevdata(sd);
struct cx18_av_state *state = &cx->av_state; struct cx18_av_state *state = &cx->av_state;
struct v4l2_control *ctrl = arg;
int retval; int retval;
u8 v;
switch (cmd) { if (state->aud_input > CX18_AV_AUDIO_SERIAL2) {
case VIDIOC_INT_AUDIO_CLOCK_FREQ: v = cx18_av_read(cx, 0x803) & ~0x10;
{ cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
u8 v; cx18_av_write(cx, 0x8d3, 0x1f);
if (state->aud_input > CX18_AV_AUDIO_SERIAL2) {
v = cx18_av_read(cx, 0x803) & ~0x10;
cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
cx18_av_write(cx, 0x8d3, 0x1f);
}
v = cx18_av_read(cx, 0x810) | 0x1;
cx18_av_write_expect(cx, 0x810, v, v, 0x0f);
retval = set_audclk_freq(cx, *(u32 *)arg);
v = cx18_av_read(cx, 0x810) & ~0x1;
cx18_av_write_expect(cx, 0x810, v, v, 0x0f);
if (state->aud_input > CX18_AV_AUDIO_SERIAL2) {
v = cx18_av_read(cx, 0x803) | 0x10;
cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
}
return retval;
} }
v = cx18_av_read(cx, 0x810) | 0x1;
cx18_av_write_expect(cx, 0x810, v, v, 0x0f);
case VIDIOC_G_CTRL: retval = set_audclk_freq(cx, freq);
switch (ctrl->id) {
case V4L2_CID_AUDIO_VOLUME: v = cx18_av_read(cx, 0x810) & ~0x1;
ctrl->value = get_volume(cx); cx18_av_write_expect(cx, 0x810, v, v, 0x0f);
break; if (state->aud_input > CX18_AV_AUDIO_SERIAL2) {
case V4L2_CID_AUDIO_BASS: v = cx18_av_read(cx, 0x803) | 0x10;
ctrl->value = get_bass(cx); cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
break; }
case V4L2_CID_AUDIO_TREBLE: return retval;
ctrl->value = get_treble(cx); }
break;
case V4L2_CID_AUDIO_BALANCE: int cx18_av_audio_g_ctrl(struct cx18 *cx, struct v4l2_control *ctrl)
ctrl->value = get_balance(cx); {
break; switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE: case V4L2_CID_AUDIO_VOLUME:
ctrl->value = get_mute(cx); ctrl->value = get_volume(cx);
break;
default:
return -EINVAL;
}
break; break;
case V4L2_CID_AUDIO_BASS:
case VIDIOC_S_CTRL: ctrl->value = get_bass(cx);
switch (ctrl->id) { break;
case V4L2_CID_AUDIO_VOLUME: case V4L2_CID_AUDIO_TREBLE:
set_volume(cx, ctrl->value); ctrl->value = get_treble(cx);
break; break;
case V4L2_CID_AUDIO_BASS: case V4L2_CID_AUDIO_BALANCE:
set_bass(cx, ctrl->value); ctrl->value = get_balance(cx);
break; break;
case V4L2_CID_AUDIO_TREBLE: case V4L2_CID_AUDIO_MUTE:
set_treble(cx, ctrl->value); ctrl->value = get_mute(cx);
break; break;
case V4L2_CID_AUDIO_BALANCE: default:
set_balance(cx, ctrl->value); return -EINVAL;
break; }
case V4L2_CID_AUDIO_MUTE: return 0;
set_mute(cx, ctrl->value); }
break;
default: int cx18_av_audio_s_ctrl(struct cx18 *cx, struct v4l2_control *ctrl)
return -EINVAL; {
} switch (ctrl->id) {
case V4L2_CID_AUDIO_VOLUME:
set_volume(cx, ctrl->value);
break;
case V4L2_CID_AUDIO_BASS:
set_bass(cx, ctrl->value);
break;
case V4L2_CID_AUDIO_TREBLE:
set_treble(cx, ctrl->value);
break;
case V4L2_CID_AUDIO_BALANCE:
set_balance(cx, ctrl->value);
break;
case V4L2_CID_AUDIO_MUTE:
set_mute(cx, ctrl->value);
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
} }

View File

@ -413,19 +413,6 @@ void cx18_av_std_setup(struct cx18 *cx)
cx18_av_write(cx, 0x47f, state->slicer_line_delay); cx18_av_write(cx, 0x47f, state->slicer_line_delay);
} }
static int cx18_av_decode_vbi_line(struct v4l2_subdev *sd,
struct v4l2_decode_vbi_line *vbi_line)
{
struct cx18 *cx = v4l2_get_subdevdata(sd);
return cx18_av_vbi(cx, VIDIOC_INT_DECODE_VBI_LINE, vbi_line);
}
static int cx18_av_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
{
struct cx18 *cx = v4l2_get_subdevdata(sd);
return cx18_av_audio(cx, VIDIOC_INT_AUDIO_CLOCK_FREQ, &freq);
}
static void input_change(struct cx18 *cx) static void input_change(struct cx18 *cx)
{ {
struct cx18_av_state *state = &cx->av_state; struct cx18_av_state *state = &cx->av_state;
@ -772,7 +759,7 @@ static int cx18_av_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
case V4L2_CID_AUDIO_TREBLE: case V4L2_CID_AUDIO_TREBLE:
case V4L2_CID_AUDIO_BALANCE: case V4L2_CID_AUDIO_BALANCE:
case V4L2_CID_AUDIO_MUTE: case V4L2_CID_AUDIO_MUTE:
return cx18_av_audio(cx, VIDIOC_S_CTRL, ctrl); return cx18_av_audio_s_ctrl(cx, ctrl);
default: default:
return -EINVAL; return -EINVAL;
@ -802,7 +789,7 @@ static int cx18_av_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
case V4L2_CID_AUDIO_TREBLE: case V4L2_CID_AUDIO_TREBLE:
case V4L2_CID_AUDIO_BALANCE: case V4L2_CID_AUDIO_BALANCE:
case V4L2_CID_AUDIO_MUTE: case V4L2_CID_AUDIO_MUTE:
return cx18_av_audio(cx, VIDIOC_G_CTRL, ctrl); return cx18_av_audio_g_ctrl(cx, ctrl);
default: default:
return -EINVAL; return -EINVAL;
} }
@ -845,13 +832,7 @@ static int cx18_av_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
{ {
struct cx18 *cx = v4l2_get_subdevdata(sd); struct cx18 *cx = v4l2_get_subdevdata(sd);
switch (fmt->type) { return cx18_av_vbi_g_fmt(cx, fmt);
case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
return cx18_av_vbi(cx, VIDIOC_G_FMT, fmt);
default:
return -EINVAL;
}
return 0;
} }
static int cx18_av_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt) static int cx18_av_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
@ -925,10 +906,10 @@ static int cx18_av_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
break; break;
case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
return cx18_av_vbi(cx, VIDIOC_S_FMT, fmt); return cx18_av_vbi_s_fmt(cx, fmt);
case V4L2_BUF_TYPE_VBI_CAPTURE: case V4L2_BUF_TYPE_VBI_CAPTURE:
return cx18_av_vbi(cx, VIDIOC_S_FMT, fmt); return cx18_av_vbi_s_fmt(cx, fmt);
default: default:
return -EINVAL; return -EINVAL;

View File

@ -355,11 +355,16 @@ int cx18_av_loadfw(struct cx18 *cx);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/* cx18_av-audio.c */ /* cx18_av-audio.c */
int cx18_av_audio(struct cx18 *cx, unsigned int cmd, void *arg); int cx18_av_audio_g_ctrl(struct cx18 *cx, struct v4l2_control *ctrl);
int cx18_av_audio_s_ctrl(struct cx18 *cx, struct v4l2_control *ctrl);
int cx18_av_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
void cx18_av_audio_set_path(struct cx18 *cx); void cx18_av_audio_set_path(struct cx18 *cx);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/* cx18_av-vbi.c */ /* cx18_av-vbi.c */
int cx18_av_vbi(struct cx18 *cx, unsigned int cmd, void *arg); int cx18_av_decode_vbi_line(struct v4l2_subdev *sd,
struct v4l2_decode_vbi_line *vbi);
int cx18_av_vbi_g_fmt(struct cx18 *cx, struct v4l2_format *fmt);
int cx18_av_vbi_s_fmt(struct cx18 *cx, struct v4l2_format *fmt);
#endif #endif

View File

@ -129,196 +129,189 @@ static int decode_vps(u8 *dst, u8 *p)
return err & 0xf0; return err & 0xf0;
} }
int cx18_av_vbi(struct cx18 *cx, unsigned int cmd, void *arg) int cx18_av_vbi_g_fmt(struct cx18 *cx, struct v4l2_format *fmt)
{ {
struct cx18_av_state *state = &cx->av_state; struct cx18_av_state *state = &cx->av_state;
struct v4l2_format *fmt;
struct v4l2_sliced_vbi_format *svbi; struct v4l2_sliced_vbi_format *svbi;
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;
switch (cmd) { if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
case VIDIOC_G_FMT: return -EINVAL;
{ svbi = &fmt->fmt.sliced;
static u16 lcr2vbi[] = { memset(svbi, 0, sizeof(*svbi));
0, V4L2_SLICED_TELETEXT_B, 0, /* 1 */ /* we're done if raw VBI is active */
0, V4L2_SLICED_WSS_625, 0, /* 4 */ if ((cx18_av_read(cx, 0x404) & 0x10) == 0)
V4L2_SLICED_CAPTION_525, /* 6 */ return 0;
0, 0, V4L2_SLICED_VPS, 0, 0, /* 9 */
0, 0, 0, 0
};
int is_pal = !(state->std & V4L2_STD_525_60);
int i;
fmt = arg; if (is_pal) {
if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) for (i = 7; i <= 23; i++) {
return -EINVAL; u8 v = cx18_av_read(cx, 0x424 + i - 7);
svbi = &fmt->fmt.sliced;
memset(svbi, 0, sizeof(*svbi));
/* we're done if raw VBI is active */
if ((cx18_av_read(cx, 0x404) & 0x10) == 0)
break;
if (is_pal) { svbi->service_lines[0][i] = lcr2vbi[v >> 4];
for (i = 7; i <= 23; i++) { svbi->service_lines[1][i] = lcr2vbi[v & 0xf];
u8 v = cx18_av_read(cx, 0x424 + i - 7); svbi->service_set |= svbi->service_lines[0][i] |
svbi->service_lines[1][i];
svbi->service_lines[0][i] = lcr2vbi[v >> 4]; }
svbi->service_lines[1][i] = lcr2vbi[v & 0xf]; } else {
svbi->service_set |= svbi->service_lines[0][i] | for (i = 10; i <= 21; i++) {
svbi->service_lines[1][i]; u8 v = cx18_av_read(cx, 0x424 + i - 10);
}
} else { svbi->service_lines[0][i] = lcr2vbi[v >> 4];
for (i = 10; i <= 21; i++) { svbi->service_lines[1][i] = lcr2vbi[v & 0xf];
u8 v = cx18_av_read(cx, 0x424 + i - 10); svbi->service_set |= svbi->service_lines[0][i] |
svbi->service_lines[1][i];
svbi->service_lines[0][i] = lcr2vbi[v >> 4];
svbi->service_lines[1][i] = lcr2vbi[v & 0xf];
svbi->service_set |= svbi->service_lines[0][i] |
svbi->service_lines[1][i];
}
} }
break;
} }
return 0;
}
case VIDIOC_S_FMT: int cx18_av_vbi_s_fmt(struct cx18 *cx, struct v4l2_format *fmt)
{ {
int is_pal = !(state->std & V4L2_STD_525_60); struct cx18_av_state *state = &cx->av_state;
int i, x; struct v4l2_sliced_vbi_format *svbi;
u8 lcr[24]; int is_pal = !(state->std & V4L2_STD_525_60);
int i, x;
u8 lcr[24];
fmt = arg; if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE &&
if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE && fmt->type != V4L2_BUF_TYPE_VBI_CAPTURE)
fmt->type != V4L2_BUF_TYPE_VBI_CAPTURE) return -EINVAL;
return -EINVAL; svbi = &fmt->fmt.sliced;
svbi = &fmt->fmt.sliced; if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) { /* raw VBI */
/* raw VBI */ memset(svbi, 0, sizeof(*svbi));
memset(svbi, 0, sizeof(*svbi));
/* Setup standard */
cx18_av_std_setup(cx);
/* VBI Offset */
cx18_av_write(cx, 0x47f, state->slicer_line_delay);
cx18_av_write(cx, 0x404, 0x2e);
break;
}
for (x = 0; x <= 23; x++)
lcr[x] = 0x00;
/* Setup standard */ /* Setup standard */
cx18_av_std_setup(cx); cx18_av_std_setup(cx);
/* Sliced VBI */ /* VBI Offset */
cx18_av_write(cx, 0x404, 0x32); /* Ancillary data */
cx18_av_write(cx, 0x406, 0x13);
cx18_av_write(cx, 0x47f, state->slicer_line_delay); cx18_av_write(cx, 0x47f, state->slicer_line_delay);
cx18_av_write(cx, 0x404, 0x2e);
return 0;
}
/* Force impossible lines to 0 */ for (x = 0; x <= 23; x++)
if (is_pal) { lcr[x] = 0x00;
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++) /* Setup standard */
svbi->service_lines[0][i] = cx18_av_std_setup(cx);
svbi->service_lines[1][i] = 0;
}
/* Build register values for requested service lines */ /* Sliced VBI */
for (i = 7; i <= 23; i++) { cx18_av_write(cx, 0x404, 0x32); /* Ancillary data */
for (x = 0; x <= 1; x++) { cx18_av_write(cx, 0x406, 0x13);
switch (svbi->service_lines[1-x][i]) { cx18_av_write(cx, 0x47f, state->slicer_line_delay);
case V4L2_SLICED_TELETEXT_B:
lcr[i] |= 1 << (4 * x); /* Force impossible lines to 0 */
break; if (is_pal) {
case V4L2_SLICED_WSS_625: for (i = 0; i <= 6; i++)
lcr[i] |= 4 << (4 * x); svbi->service_lines[0][i] =
break; svbi->service_lines[1][i] = 0;
case V4L2_SLICED_CAPTION_525: } else {
lcr[i] |= 6 << (4 * x); for (i = 0; i <= 9; i++)
break; svbi->service_lines[0][i] =
case V4L2_SLICED_VPS: svbi->service_lines[1][i] = 0;
lcr[i] |= 9 << (4 * x);
break; 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 = 0x424; i <= 0x434; i++, x++)
cx18_av_write(cx, i, lcr[6 + x]);
} else {
for (x = 1, i = 0x424; i <= 0x430; i++, x++)
cx18_av_write(cx, i, lcr[9 + x]);
for (i = 0x431; i <= 0x434; i++)
cx18_av_write(cx, i, 0);
}
cx18_av_write(cx, 0x43c, 0x16);
/* FIXME - should match vblank set in cx18_av_std_setup() */
cx18_av_write(cx, 0x474, is_pal ? 0x2a : 26);
break;
} }
case VIDIOC_INT_DECODE_VBI_LINE: if (is_pal) {
{ for (x = 1, i = 0x424; i <= 0x434; i++, x++)
struct v4l2_decode_vbi_line *vbi = arg; cx18_av_write(cx, i, lcr[6 + x]);
u8 *p; } else {
struct vbi_anc_data *anc = (struct vbi_anc_data *) vbi->p; for (x = 1, i = 0x424; i <= 0x430; i++, x++)
int did, sdid, l, err = 0; cx18_av_write(cx, i, lcr[9 + x]);
for (i = 0x431; i <= 0x434; i++)
/* cx18_av_write(cx, i, 0);
* Check for the ancillary data header for sliced VBI
*/
if (anc->preamble[0] ||
anc->preamble[1] != 0xff || anc->preamble[2] != 0xff ||
(anc->did != sliced_vbi_did[0] &&
anc->did != sliced_vbi_did[1])) {
vbi->line = vbi->type = 0;
break;
}
did = anc->did;
sdid = anc->sdid & 0xf;
l = anc->idid[0] & 0x3f;
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 = !odd_parity(p[0]) || !odd_parity(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;
break;
}
} }
cx18_av_write(cx, 0x43c, 0x16);
/* FIXME - should match vblank set in cx18_av_std_setup() */
cx18_av_write(cx, 0x474, is_pal ? 0x2a : 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] != 0xff || anc->preamble[2] != 0xff ||
(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 & 0xf;
l = anc->idid[0] & 0x3f;
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 = !odd_parity(p[0]) || !odd_parity(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; return 0;
} }