Commit 01f1e44f authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

V4L/DVB (6088): cx2341x: some controls can't be changed while the device is busy

The driver should now pass the 'busy' state of the device to the cx2341x 
module whenever controls are set or tried. -EBUSY will be returned if 
the device is busy and the user attempts to modify certain 'dangerous' 
controls. It concerns controls that change the audio or video 
compression mode and bitrates.

The cx88-blackbird and pvrusb2 drivers currently always pass '0' (not busy)
to the cx2341x, effectively keeping the old behavior for now.
Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent ea115d54
...@@ -190,17 +190,21 @@ static int cx2341x_get_ctrl(struct cx2341x_mpeg_params *params, ...@@ -190,17 +190,21 @@ static int cx2341x_get_ctrl(struct cx2341x_mpeg_params *params,
/* Map the control ID to the correct field in the cx2341x_mpeg_params /* Map the control ID to the correct field in the cx2341x_mpeg_params
struct. Return -EINVAL if the ID is unknown, else return 0. */ struct. Return -EINVAL if the ID is unknown, else return 0. */
static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, int busy,
struct v4l2_ext_control *ctrl) struct v4l2_ext_control *ctrl)
{ {
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
if (busy)
return -EBUSY;
params->audio_sampling_freq = ctrl->value; params->audio_sampling_freq = ctrl->value;
break; break;
case V4L2_CID_MPEG_AUDIO_ENCODING: case V4L2_CID_MPEG_AUDIO_ENCODING:
params->audio_encoding = ctrl->value; params->audio_encoding = ctrl->value;
break; break;
case V4L2_CID_MPEG_AUDIO_L2_BITRATE: case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
if (busy)
return -EBUSY;
params->audio_l2_bitrate = ctrl->value; params->audio_l2_bitrate = ctrl->value;
break; break;
case V4L2_CID_MPEG_AUDIO_MODE: case V4L2_CID_MPEG_AUDIO_MODE:
...@@ -245,6 +249,8 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, ...@@ -245,6 +249,8 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params,
params->video_gop_closure = ctrl->value; params->video_gop_closure = ctrl->value;
break; break;
case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
if (busy)
return -EBUSY;
/* MPEG-1 only allows CBR */ /* MPEG-1 only allows CBR */
if (params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1 && if (params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1 &&
ctrl->value != V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) ctrl->value != V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)
...@@ -252,9 +258,13 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, ...@@ -252,9 +258,13 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params,
params->video_bitrate_mode = ctrl->value; params->video_bitrate_mode = ctrl->value;
break; break;
case V4L2_CID_MPEG_VIDEO_BITRATE: case V4L2_CID_MPEG_VIDEO_BITRATE:
if (busy)
return -EBUSY;
params->video_bitrate = ctrl->value; params->video_bitrate = ctrl->value;
break; break;
case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
if (busy)
return -EBUSY;
params->video_bitrate_peak = ctrl->value; params->video_bitrate_peak = ctrl->value;
break; break;
case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION:
...@@ -267,6 +277,8 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, ...@@ -267,6 +277,8 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params,
params->video_mute_yuv = ctrl->value; params->video_mute_yuv = ctrl->value;
break; break;
case V4L2_CID_MPEG_STREAM_TYPE: case V4L2_CID_MPEG_STREAM_TYPE:
if (busy)
return -EBUSY;
params->stream_type = ctrl->value; params->stream_type = ctrl->value;
params->video_encoding = params->video_encoding =
(params->stream_type == V4L2_MPEG_STREAM_TYPE_MPEG1_SS || (params->stream_type == V4L2_MPEG_STREAM_TYPE_MPEG1_SS ||
...@@ -631,7 +643,7 @@ static void cx2341x_calc_audio_properties(struct cx2341x_mpeg_params *params) ...@@ -631,7 +643,7 @@ static void cx2341x_calc_audio_properties(struct cx2341x_mpeg_params *params)
(params->audio_crc << 14); (params->audio_crc << 14);
} }
int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, int busy,
struct v4l2_ext_controls *ctrls, unsigned int cmd) struct v4l2_ext_controls *ctrls, unsigned int cmd)
{ {
int err = 0; int err = 0;
...@@ -663,7 +675,7 @@ int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, ...@@ -663,7 +675,7 @@ int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params,
err = v4l2_ctrl_check(ctrl, &qctrl, menu_items); err = v4l2_ctrl_check(ctrl, &qctrl, menu_items);
if (err) if (err)
break; break;
err = cx2341x_set_ctrl(params, ctrl); err = cx2341x_set_ctrl(params, busy, ctrl);
if (err) if (err)
break; break;
} }
......
...@@ -876,7 +876,7 @@ static int vidioc_g_ext_ctrls (struct file *file, void *priv, ...@@ -876,7 +876,7 @@ static int vidioc_g_ext_ctrls (struct file *file, void *priv,
if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
return -EINVAL; return -EINVAL;
return cx2341x_ext_ctrls(&dev->params, f, VIDIOC_G_EXT_CTRLS); return cx2341x_ext_ctrls(&dev->params, 0, f, VIDIOC_G_EXT_CTRLS);
} }
static int vidioc_s_ext_ctrls (struct file *file, void *priv, static int vidioc_s_ext_ctrls (struct file *file, void *priv,
...@@ -889,7 +889,7 @@ static int vidioc_s_ext_ctrls (struct file *file, void *priv, ...@@ -889,7 +889,7 @@ static int vidioc_s_ext_ctrls (struct file *file, void *priv,
if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
return -EINVAL; return -EINVAL;
p = dev->params; p = dev->params;
err = cx2341x_ext_ctrls(&p, f, VIDIOC_S_EXT_CTRLS); err = cx2341x_ext_ctrls(&p, 0, f, VIDIOC_S_EXT_CTRLS);
if (!err) { if (!err) {
err = cx2341x_update(dev, blackbird_mbox_func, &dev->params, &p); err = cx2341x_update(dev, blackbird_mbox_func, &dev->params, &p);
dev->params = p; dev->params = p;
...@@ -907,7 +907,7 @@ static int vidioc_try_ext_ctrls (struct file *file, void *priv, ...@@ -907,7 +907,7 @@ static int vidioc_try_ext_ctrls (struct file *file, void *priv,
if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
return -EINVAL; return -EINVAL;
p = dev->params; p = dev->params;
err = cx2341x_ext_ctrls(&p, f, VIDIOC_TRY_EXT_CTRLS); err = cx2341x_ext_ctrls(&p, 0, f, VIDIOC_TRY_EXT_CTRLS);
return err; return err;
} }
......
...@@ -232,7 +232,7 @@ int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg) ...@@ -232,7 +232,7 @@ int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg)
IVTV_DEBUG_IOCTL("VIDIOC_S_EXT_CTRLS\n"); IVTV_DEBUG_IOCTL("VIDIOC_S_EXT_CTRLS\n");
if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) { if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
struct cx2341x_mpeg_params p = itv->params; struct cx2341x_mpeg_params p = itv->params;
int err = cx2341x_ext_ctrls(&p, arg, cmd); int err = cx2341x_ext_ctrls(&p, atomic_read(&itv->capturing), arg, cmd);
if (err) if (err)
return err; return err;
...@@ -282,7 +282,7 @@ int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg) ...@@ -282,7 +282,7 @@ int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg)
} }
IVTV_DEBUG_IOCTL("VIDIOC_G_EXT_CTRLS\n"); IVTV_DEBUG_IOCTL("VIDIOC_G_EXT_CTRLS\n");
if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG)
return cx2341x_ext_ctrls(&itv->params, arg, cmd); return cx2341x_ext_ctrls(&itv->params, 0, arg, cmd);
return -EINVAL; return -EINVAL;
} }
...@@ -292,7 +292,7 @@ int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg) ...@@ -292,7 +292,7 @@ int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg)
IVTV_DEBUG_IOCTL("VIDIOC_TRY_EXT_CTRLS\n"); IVTV_DEBUG_IOCTL("VIDIOC_TRY_EXT_CTRLS\n");
if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG)
return cx2341x_ext_ctrls(&itv->params, arg, cmd); return cx2341x_ext_ctrls(&itv->params, atomic_read(&itv->capturing), arg, cmd);
return -EINVAL; return -EINVAL;
} }
......
...@@ -492,7 +492,7 @@ static int ctrl_cx2341x_get(struct pvr2_ctrl *cptr,int *vp) ...@@ -492,7 +492,7 @@ static int ctrl_cx2341x_get(struct pvr2_ctrl *cptr,int *vp)
cs.controls = &c1; cs.controls = &c1;
cs.count = 1; cs.count = 1;
c1.id = cptr->info->v4l_id; c1.id = cptr->info->v4l_id;
ret = cx2341x_ext_ctrls(&cptr->hdw->enc_ctl_state,&cs, ret = cx2341x_ext_ctrls(&cptr->hdw->enc_ctl_state, 0, &cs,
VIDIOC_G_EXT_CTRLS); VIDIOC_G_EXT_CTRLS);
if (ret) return ret; if (ret) return ret;
*vp = c1.value; *vp = c1.value;
...@@ -510,7 +510,7 @@ static int ctrl_cx2341x_set(struct pvr2_ctrl *cptr,int m,int v) ...@@ -510,7 +510,7 @@ static int ctrl_cx2341x_set(struct pvr2_ctrl *cptr,int m,int v)
cs.count = 1; cs.count = 1;
c1.id = cptr->info->v4l_id; c1.id = cptr->info->v4l_id;
c1.value = v; c1.value = v;
ret = cx2341x_ext_ctrls(&cptr->hdw->enc_ctl_state,&cs, ret = cx2341x_ext_ctrls(&cptr->hdw->enc_ctl_state, 0, &cs,
VIDIOC_S_EXT_CTRLS); VIDIOC_S_EXT_CTRLS);
if (ret) return ret; if (ret) return ret;
cptr->hdw->enc_stale = !0; cptr->hdw->enc_stale = !0;
...@@ -2478,7 +2478,7 @@ static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw) ...@@ -2478,7 +2478,7 @@ static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
cs.count = 1; cs.count = 1;
c1.id = V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ; c1.id = V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ;
c1.value = hdw->srate_val; c1.value = hdw->srate_val;
cx2341x_ext_ctrls(&hdw->enc_ctl_state,&cs,VIDIOC_S_EXT_CTRLS); cx2341x_ext_ctrls(&hdw->enc_ctl_state, 0, &cs,VIDIOC_S_EXT_CTRLS);
} }
/* Scan i2c core at this point - before we clear all the dirty /* Scan i2c core at this point - before we clear all the dirty
......
...@@ -716,6 +716,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste ...@@ -716,6 +716,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste
case V4L2_CID_AUDIO_MUTE: case V4L2_CID_AUDIO_MUTE:
case V4L2_CID_AUDIO_LOUDNESS: case V4L2_CID_AUDIO_LOUDNESS:
case V4L2_CID_MPEG_AUDIO_MUTE: case V4L2_CID_MPEG_AUDIO_MUTE:
case V4L2_CID_MPEG_VIDEO_MUTE:
case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
case V4L2_CID_MPEG_VIDEO_PULLDOWN: case V4L2_CID_MPEG_VIDEO_PULLDOWN:
qctrl->type = V4L2_CTRL_TYPE_BOOLEAN; qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
......
...@@ -91,7 +91,7 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func, ...@@ -91,7 +91,7 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
int cx2341x_ctrl_query(struct cx2341x_mpeg_params *params, int cx2341x_ctrl_query(struct cx2341x_mpeg_params *params,
struct v4l2_queryctrl *qctrl); struct v4l2_queryctrl *qctrl);
const char **cx2341x_ctrl_get_menu(u32 id); const char **cx2341x_ctrl_get_menu(u32 id);
int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, int busy,
struct v4l2_ext_controls *ctrls, unsigned int cmd); struct v4l2_ext_controls *ctrls, unsigned int cmd);
void cx2341x_fill_defaults(struct cx2341x_mpeg_params *p); void cx2341x_fill_defaults(struct cx2341x_mpeg_params *p);
void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix); void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment