[media] v4l2 framework: add support for the new dv_timings ioctls

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Hans Verkuil 2012-05-15 08:06:44 -03:00 committed by Mauro Carvalho Chehab
parent 7dcc606b2a
commit 5d7758eed2
4 changed files with 104 additions and 37 deletions

View file

@ -1023,6 +1023,9 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
case VIDIOC_UNSUBSCRIBE_EVENT: case VIDIOC_UNSUBSCRIBE_EVENT:
case VIDIOC_CREATE_BUFS32: case VIDIOC_CREATE_BUFS32:
case VIDIOC_PREPARE_BUF32: case VIDIOC_PREPARE_BUF32:
case VIDIOC_ENUM_DV_TIMINGS:
case VIDIOC_QUERY_DV_TIMINGS:
case VIDIOC_DV_TIMINGS_CAP:
ret = do_video_ioctl(file, cmd, arg); ret = do_video_ioctl(file, cmd, arg);
break; break;

View file

@ -281,6 +281,9 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0), IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0),
IOCTL_INFO(VIDIOC_CREATE_BUFS, INFO_FL_PRIO), IOCTL_INFO(VIDIOC_CREATE_BUFS, INFO_FL_PRIO),
IOCTL_INFO(VIDIOC_PREPARE_BUF, 0), IOCTL_INFO(VIDIOC_PREPARE_BUF, 0),
IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS, 0),
IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS, 0),
IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP, 0),
}; };
#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
@ -368,6 +371,34 @@ static inline void dbgrect(struct video_device *vfd, char *s,
r->width, r->height); r->width, r->height);
}; };
static void dbgtimings(struct video_device *vfd,
const struct v4l2_dv_timings *p)
{
switch (p->type) {
case V4L2_DV_BT_656_1120:
dbgarg2("bt-656/1120:interlaced=%d,"
" pixelclock=%lld,"
" width=%d, height=%d, polarities=%x,"
" hfrontporch=%d, hsync=%d,"
" hbackporch=%d, vfrontporch=%d,"
" vsync=%d, vbackporch=%d,"
" il_vfrontporch=%d, il_vsync=%d,"
" il_vbackporch=%d, standards=%x, flags=%x\n",
p->bt.interlaced, p->bt.pixelclock,
p->bt.width, p->bt.height,
p->bt.polarities, p->bt.hfrontporch,
p->bt.hsync, p->bt.hbackporch,
p->bt.vfrontporch, p->bt.vsync,
p->bt.vbackporch, p->bt.il_vfrontporch,
p->bt.il_vsync, p->bt.il_vbackporch,
p->bt.standards, p->bt.flags);
break;
default:
dbgarg2("Unknown type %d!\n", p->type);
break;
}
}
static inline void v4l_print_pix_fmt(struct video_device *vfd, static inline void v4l_print_pix_fmt(struct video_device *vfd,
struct v4l2_pix_format *fmt) struct v4l2_pix_format *fmt)
{ {
@ -1916,25 +1947,13 @@ static long __video_do_ioctl(struct file *file,
{ {
struct v4l2_dv_timings *p = arg; struct v4l2_dv_timings *p = arg;
dbgtimings(vfd, p);
switch (p->type) { switch (p->type) {
case V4L2_DV_BT_656_1120: case V4L2_DV_BT_656_1120:
dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
" width=%d, height=%d, polarities=%x,"
" hfrontporch=%d, hsync=%d, hbackporch=%d,"
" vfrontporch=%d, vsync=%d, vbackporch=%d,"
" il_vfrontporch=%d, il_vsync=%d,"
" il_vbackporch=%d\n",
p->bt.interlaced, p->bt.pixelclock,
p->bt.width, p->bt.height, p->bt.polarities,
p->bt.hfrontporch, p->bt.hsync,
p->bt.hbackporch, p->bt.vfrontporch,
p->bt.vsync, p->bt.vbackporch,
p->bt.il_vfrontporch, p->bt.il_vsync,
p->bt.il_vbackporch);
ret = ops->vidioc_s_dv_timings(file, fh, p); ret = ops->vidioc_s_dv_timings(file, fh, p);
break; break;
default: default:
dbgarg2("Unknown type %d!\n", p->type); ret = -EINVAL;
break; break;
} }
break; break;
@ -1944,29 +1963,60 @@ static long __video_do_ioctl(struct file *file,
struct v4l2_dv_timings *p = arg; struct v4l2_dv_timings *p = arg;
ret = ops->vidioc_g_dv_timings(file, fh, p); ret = ops->vidioc_g_dv_timings(file, fh, p);
if (!ret)
dbgtimings(vfd, p);
break;
}
case VIDIOC_ENUM_DV_TIMINGS:
{
struct v4l2_enum_dv_timings *p = arg;
if (!ops->vidioc_enum_dv_timings)
break;
ret = ops->vidioc_enum_dv_timings(file, fh, p);
if (!ret) { if (!ret) {
switch (p->type) { dbgarg(cmd, "index=%d: ", p->index);
case V4L2_DV_BT_656_1120: dbgtimings(vfd, &p->timings);
dbgarg2("bt-656/1120:interlaced=%d," }
" pixelclock=%lld," break;
" width=%d, height=%d, polarities=%x," }
" hfrontporch=%d, hsync=%d," case VIDIOC_QUERY_DV_TIMINGS:
" hbackporch=%d, vfrontporch=%d," {
" vsync=%d, vbackporch=%d," struct v4l2_dv_timings *p = arg;
" il_vfrontporch=%d, il_vsync=%d,"
" il_vbackporch=%d\n", if (!ops->vidioc_query_dv_timings)
p->bt.interlaced, p->bt.pixelclock, break;
p->bt.width, p->bt.height,
p->bt.polarities, p->bt.hfrontporch, ret = ops->vidioc_query_dv_timings(file, fh, p);
p->bt.hsync, p->bt.hbackporch, if (!ret)
p->bt.vfrontporch, p->bt.vsync, dbgtimings(vfd, p);
p->bt.vbackporch, p->bt.il_vfrontporch, break;
p->bt.il_vsync, p->bt.il_vbackporch); }
break; case VIDIOC_DV_TIMINGS_CAP:
default: {
dbgarg2("Unknown type %d!\n", p->type); struct v4l2_dv_timings_cap *p = arg;
break;
} if (!ops->vidioc_dv_timings_cap)
break;
ret = ops->vidioc_dv_timings_cap(file, fh, p);
if (ret)
break;
switch (p->type) {
case V4L2_DV_BT_656_1120:
dbgarg(cmd,
"type=%d, width=%u-%u, height=%u-%u, "
"pixelclock=%llu-%llu, standards=%x, capabilities=%x ",
p->type,
p->bt.min_width, p->bt.max_width,
p->bt.min_height, p->bt.max_height,
p->bt.min_pixelclock, p->bt.max_pixelclock,
p->bt.standards, p->bt.capabilities);
break;
default:
dbgarg(cmd, "unknown type ");
break;
} }
break; break;
} }
@ -2215,7 +2265,9 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
err = -EFAULT; err = -EFAULT;
goto out_array_args; goto out_array_args;
} }
if (err < 0) /* VIDIOC_QUERY_DV_TIMINGS can return an error, but still have valid
results that must be returned. */
if (err < 0 && cmd != VIDIOC_QUERY_DV_TIMINGS)
goto out; goto out;
out_array_args: out_array_args:

View file

@ -271,6 +271,12 @@ struct v4l2_ioctl_ops {
struct v4l2_dv_timings *timings); struct v4l2_dv_timings *timings);
int (*vidioc_g_dv_timings) (struct file *file, void *fh, int (*vidioc_g_dv_timings) (struct file *file, void *fh,
struct v4l2_dv_timings *timings); struct v4l2_dv_timings *timings);
int (*vidioc_query_dv_timings) (struct file *file, void *fh,
struct v4l2_dv_timings *timings);
int (*vidioc_enum_dv_timings) (struct file *file, void *fh,
struct v4l2_enum_dv_timings *timings);
int (*vidioc_dv_timings_cap) (struct file *file, void *fh,
struct v4l2_dv_timings_cap *cap);
int (*vidioc_subscribe_event) (struct v4l2_fh *fh, int (*vidioc_subscribe_event) (struct v4l2_fh *fh,
struct v4l2_event_subscription *sub); struct v4l2_event_subscription *sub);

View file

@ -307,6 +307,12 @@ struct v4l2_subdev_video_ops {
struct v4l2_dv_timings *timings); struct v4l2_dv_timings *timings);
int (*g_dv_timings)(struct v4l2_subdev *sd, int (*g_dv_timings)(struct v4l2_subdev *sd,
struct v4l2_dv_timings *timings); struct v4l2_dv_timings *timings);
int (*enum_dv_timings)(struct v4l2_subdev *sd,
struct v4l2_enum_dv_timings *timings);
int (*query_dv_timings)(struct v4l2_subdev *sd,
struct v4l2_dv_timings *timings);
int (*dv_timings_cap)(struct v4l2_subdev *sd,
struct v4l2_dv_timings_cap *cap);
int (*enum_mbus_fmt)(struct v4l2_subdev *sd, unsigned int index, int (*enum_mbus_fmt)(struct v4l2_subdev *sd, unsigned int index,
enum v4l2_mbus_pixelcode *code); enum v4l2_mbus_pixelcode *code);
int (*enum_mbus_fsizes)(struct v4l2_subdev *sd, int (*enum_mbus_fsizes)(struct v4l2_subdev *sd,