V4L/DVB (11309): cx25840: cleanup: remove intermediate 'ioctl' step

The audio and vbi functions where still called through an ioctl-like
interface, even though this is no longer needed with v4l2-subdev. Just
change each 'case' into a proper function and call that directly.

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:26:40 -03:00 committed by Mauro Carvalho Chehab
parent 2c26976d72
commit df1d5ed8a8
4 changed files with 222 additions and 251 deletions

View File

@ -363,75 +363,74 @@ static void set_mute(struct i2c_client *client, int mute)
} }
} }
int cx25840_audio(struct i2c_client *client, unsigned int cmd, void *arg) int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
{ {
struct cx25840_state *state = to_state(i2c_get_clientdata(client)); struct i2c_client *client = v4l2_get_subdevdata(sd);
struct v4l2_control *ctrl = arg; struct cx25840_state *state = to_state(sd);
int retval; int retval;
switch (cmd) { if (!state->is_cx25836)
case VIDIOC_INT_AUDIO_CLOCK_FREQ: cx25840_and_or(client, 0x810, ~0x1, 1);
if (!state->is_cx25836) if (state->aud_input != CX25840_AUDIO_SERIAL) {
cx25840_and_or(client, 0x810, ~0x1, 1); cx25840_and_or(client, 0x803, ~0x10, 0);
if (state->aud_input != CX25840_AUDIO_SERIAL) { cx25840_write(client, 0x8d3, 0x1f);
cx25840_and_or(client, 0x803, ~0x10, 0); }
cx25840_write(client, 0x8d3, 0x1f); retval = set_audclk_freq(client, freq);
} if (state->aud_input != CX25840_AUDIO_SERIAL)
retval = set_audclk_freq(client, *(u32 *)arg); cx25840_and_or(client, 0x803, ~0x10, 0x10);
if (state->aud_input != CX25840_AUDIO_SERIAL) { if (!state->is_cx25836)
cx25840_and_or(client, 0x803, ~0x10, 0x10); cx25840_and_or(client, 0x810, ~0x1, 0);
} return retval;
if (!state->is_cx25836) }
cx25840_and_or(client, 0x810, ~0x1, 0);
return retval;
case VIDIOC_G_CTRL: int cx25840_audio_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
switch (ctrl->id) { {
case V4L2_CID_AUDIO_VOLUME: struct i2c_client *client = v4l2_get_subdevdata(sd);
ctrl->value = get_volume(client);
break; switch (ctrl->id) {
case V4L2_CID_AUDIO_BASS: case V4L2_CID_AUDIO_VOLUME:
ctrl->value = get_bass(client); ctrl->value = get_volume(client);
break;
case V4L2_CID_AUDIO_TREBLE:
ctrl->value = get_treble(client);
break;
case V4L2_CID_AUDIO_BALANCE:
ctrl->value = get_balance(client);
break;
case V4L2_CID_AUDIO_MUTE:
ctrl->value = get_mute(client);
break;
default:
return -EINVAL;
}
break; break;
case V4L2_CID_AUDIO_BASS:
case VIDIOC_S_CTRL: ctrl->value = get_bass(client);
switch (ctrl->id) { break;
case V4L2_CID_AUDIO_VOLUME: case V4L2_CID_AUDIO_TREBLE:
set_volume(client, ctrl->value); ctrl->value = get_treble(client);
break; break;
case V4L2_CID_AUDIO_BASS: case V4L2_CID_AUDIO_BALANCE:
set_bass(client, ctrl->value); ctrl->value = get_balance(client);
break; break;
case V4L2_CID_AUDIO_TREBLE: case V4L2_CID_AUDIO_MUTE:
set_treble(client, ctrl->value); ctrl->value = get_mute(client);
break; break;
case V4L2_CID_AUDIO_BALANCE: default:
set_balance(client, ctrl->value); return -EINVAL;
break; }
case V4L2_CID_AUDIO_MUTE: return 0;
set_mute(client, ctrl->value); }
break;
default: int cx25840_audio_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
return -EINVAL; {
} struct i2c_client *client = v4l2_get_subdevdata(sd);
switch (ctrl->id) {
case V4L2_CID_AUDIO_VOLUME:
set_volume(client, ctrl->value);
break;
case V4L2_CID_AUDIO_BASS:
set_bass(client, ctrl->value);
break;
case V4L2_CID_AUDIO_TREBLE:
set_treble(client, ctrl->value);
break;
case V4L2_CID_AUDIO_BALANCE:
set_balance(client, ctrl->value);
break;
case V4L2_CID_AUDIO_MUTE:
set_mute(client, ctrl->value);
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
} }

View File

@ -775,7 +775,7 @@ static int cx25840_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
case V4L2_CID_AUDIO_MUTE: case V4L2_CID_AUDIO_MUTE:
if (state->is_cx25836) if (state->is_cx25836)
return -EINVAL; return -EINVAL;
return cx25840_audio(client, VIDIOC_S_CTRL, ctrl); return cx25840_audio_s_ctrl(sd, ctrl);
default: default:
return -EINVAL; return -EINVAL;
@ -812,7 +812,7 @@ static int cx25840_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
case V4L2_CID_AUDIO_MUTE: case V4L2_CID_AUDIO_MUTE:
if (state->is_cx25836) if (state->is_cx25836)
return -EINVAL; return -EINVAL;
return cx25840_audio(client, VIDIOC_G_CTRL, ctrl); return cx25840_audio_g_ctrl(sd, ctrl);
default: default:
return -EINVAL; return -EINVAL;
} }
@ -828,7 +828,7 @@ static int cx25840_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
switch (fmt->type) { switch (fmt->type) {
case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
return cx25840_vbi(client, VIDIOC_G_FMT, fmt); return cx25840_vbi_g_fmt(sd, fmt);
default: default:
return -EINVAL; return -EINVAL;
} }
@ -890,10 +890,10 @@ static int cx25840_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 cx25840_vbi(client, VIDIOC_S_FMT, fmt); return cx25840_vbi_s_fmt(sd, fmt);
case V4L2_BUF_TYPE_VBI_CAPTURE: case V4L2_BUF_TYPE_VBI_CAPTURE:
return cx25840_vbi(client, VIDIOC_S_FMT, fmt); return cx25840_vbi_s_fmt(sd, fmt);
default: default:
return -EINVAL; return -EINVAL;
@ -1153,20 +1153,6 @@ static int cx25840_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
} }
#endif #endif
static int cx25840_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
return cx25840_vbi(client, VIDIOC_INT_DECODE_VBI_LINE, vbi);
}
static int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
return cx25840_audio(client, VIDIOC_INT_AUDIO_CLOCK_FREQ, &freq);
}
static int cx25840_s_stream(struct v4l2_subdev *sd, int enable) static int cx25840_s_stream(struct v4l2_subdev *sd, int enable)
{ {
struct cx25840_state *state = to_state(sd); struct cx25840_state *state = to_state(sd);

View File

@ -75,11 +75,15 @@ int cx25840_loadfw(struct i2c_client *client);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/* cx25850-audio.c */ /* cx25850-audio.c */
int cx25840_audio(struct i2c_client *client, unsigned int cmd, void *arg);
void cx25840_audio_set_path(struct i2c_client *client); void cx25840_audio_set_path(struct i2c_client *client);
int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
int cx25840_audio_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
int cx25840_audio_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/* cx25850-vbi.c */ /* cx25850-vbi.c */
int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg); int cx25840_vbi_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt);
int cx25840_vbi_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt);
int cx25840_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi);
#endif #endif

View File

@ -82,199 +82,181 @@ static int decode_vps(u8 * dst, u8 * p)
return err & 0xf0; return err & 0xf0;
} }
int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg) int cx25840_vbi_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
{ {
struct cx25840_state *state = to_state(i2c_get_clientdata(client)); struct i2c_client *client = v4l2_get_subdevdata(sd);
struct v4l2_format *fmt; struct cx25840_state *state = to_state(sd);
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 ((cx25840_read(client, 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 = cx25840_read(client, 0x424 + i - 7);
svbi = &fmt->fmt.sliced;
memset(svbi, 0, sizeof(*svbi));
/* we're done if raw VBI is active */
if ((cx25840_read(client, 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 = cx25840_read(client, 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];
svbi->service_set |=
svbi->service_lines[0][i] | svbi->service_lines[1][i];
}
} }
else { } else {
for (i = 10; i <= 21; i++) { for (i = 10; i <= 21; i++) {
u8 v = cx25840_read(client, 0x424 + i - 10); u8 v = cx25840_read(client, 0x424 + i - 10);
svbi->service_lines[0][i] = lcr2vbi[v >> 4]; svbi->service_lines[0][i] = lcr2vbi[v >> 4];
svbi->service_lines[1][i] = lcr2vbi[v & 0xf]; svbi->service_lines[1][i] = lcr2vbi[v & 0xf];
svbi->service_set |= svbi->service_set |= svbi->service_lines[0][i] |
svbi->service_lines[0][i] | svbi->service_lines[1][i]; svbi->service_lines[1][i];
}
} }
break;
} }
return 0;
}
case VIDIOC_S_FMT: int cx25840_vbi_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
{ {
int is_pal = !(state->std & V4L2_STD_525_60); struct i2c_client *client = v4l2_get_subdevdata(sd);
int vbi_offset = is_pal ? 1 : 0; struct cx25840_state *state = to_state(sd);
int i, x; struct v4l2_sliced_vbi_format *svbi;
u8 lcr[24]; int is_pal = !(state->std & V4L2_STD_525_60);
int vbi_offset = is_pal ? 1 : 0;
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 */
cx25840_std_setup(client);
/* VBI Offset */
cx25840_write(client, 0x47f, vbi_offset);
cx25840_write(client, 0x404, 0x2e);
break;
}
for (x = 0; x <= 23; x++)
lcr[x] = 0x00;
/* Setup standard */ /* Setup standard */
cx25840_std_setup(client); cx25840_std_setup(client);
/* Sliced VBI */ /* VBI Offset */
cx25840_write(client, 0x404, 0x32); /* Ancillary data */
cx25840_write(client, 0x406, 0x13);
cx25840_write(client, 0x47f, vbi_offset); cx25840_write(client, 0x47f, vbi_offset);
cx25840_write(client, 0x404, 0x2e);
if (is_pal) { return 0;
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;
}
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++) {
cx25840_write(client, i, lcr[6 + x]);
}
}
else {
for (x = 1, i = 0x424; i <= 0x430; i++, x++) {
cx25840_write(client, i, lcr[9 + x]);
}
for (i = 0x431; i <= 0x434; i++) {
cx25840_write(client, i, 0);
}
}
cx25840_write(client, 0x43c, 0x16);
if (is_pal) {
cx25840_write(client, 0x474, 0x2a);
} else {
cx25840_write(client, 0x474, 0x22);
}
break;
} }
case VIDIOC_INT_DECODE_VBI_LINE: for (x = 0; x <= 23; x++)
{ lcr[x] = 0x00;
struct v4l2_decode_vbi_line *vbi = arg;
u8 *p = vbi->p;
int id1, id2, l, err = 0;
if (p[0] || p[1] != 0xff || p[2] != 0xff || /* Setup standard */
(p[3] != 0x55 && p[3] != 0x91)) { cx25840_std_setup(client);
vbi->line = vbi->type = 0;
break;
}
p += 4; /* Sliced VBI */
id1 = p[-1]; cx25840_write(client, 0x404, 0x32); /* Ancillary data */
id2 = p[0] & 0xf; cx25840_write(client, 0x406, 0x13);
l = p[2] & 0x3f; cx25840_write(client, 0x47f, vbi_offset);
l += state->vbi_line_offset;
p += 4;
switch (id2) { if (is_pal) {
case 1: for (i = 0; i <= 6; i++)
id2 = V4L2_SLICED_TELETEXT_B; svbi->service_lines[0][i] =
break; svbi->service_lines[1][i] = 0;
case 4: } else {
id2 = V4L2_SLICED_WSS_625; for (i = 0; i <= 9; i++)
break; svbi->service_lines[0][i] =
case 6: svbi->service_lines[1][i] = 0;
id2 = V4L2_SLICED_CAPTION_525;
err = !odd_parity(p[0]) || !odd_parity(p[1]); for (i = 22; i <= 23; i++)
break; svbi->service_lines[0][i] =
case 9: svbi->service_lines[1][i] = 0;
id2 = V4L2_SLICED_VPS; }
if (decode_vps(p, p) != 0) {
err = 1; 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;
} }
break;
default:
id2 = 0;
err = 1;
break;
} }
vbi->type = err ? 0 : id2;
vbi->line = err ? 0 : l;
vbi->is_second_field = err ? 0 : (id1 == 0x55);
vbi->p = p;
break;
}
} }
if (is_pal) {
for (x = 1, i = 0x424; i <= 0x434; i++, x++)
cx25840_write(client, i, lcr[6 + x]);
} else {
for (x = 1, i = 0x424; i <= 0x430; i++, x++)
cx25840_write(client, i, lcr[9 + x]);
for (i = 0x431; i <= 0x434; i++)
cx25840_write(client, i, 0);
}
cx25840_write(client, 0x43c, 0x16);
cx25840_write(client, 0x474, is_pal ? 0x2a : 0x22);
return 0;
}
int cx25840_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi)
{
struct cx25840_state *state = to_state(sd);
u8 *p = vbi->p;
int id1, id2, l, err = 0;
if (p[0] || p[1] != 0xff || p[2] != 0xff ||
(p[3] != 0x55 && p[3] != 0x91)) {
vbi->line = vbi->type = 0;
return 0;
}
p += 4;
id1 = p[-1];
id2 = p[0] & 0xf;
l = p[2] & 0x3f;
l += state->vbi_line_offset;
p += 4;
switch (id2) {
case 1:
id2 = V4L2_SLICED_TELETEXT_B;
break;
case 4:
id2 = V4L2_SLICED_WSS_625;
break;
case 6:
id2 = V4L2_SLICED_CAPTION_525;
err = !odd_parity(p[0]) || !odd_parity(p[1]);
break;
case 9:
id2 = V4L2_SLICED_VPS;
if (decode_vps(p, p) != 0)
err = 1;
break;
default:
id2 = 0;
err = 1;
break;
}
vbi->type = err ? 0 : id2;
vbi->line = err ? 0 : l;
vbi->is_second_field = err ? 0 : (id1 == 0x55);
vbi->p = p;
return 0; return 0;
} }