]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
usb: gadget: uvc: add g_parm and s_parm for frame interval
authorMichael Grzeschik <m.grzeschik@pengutronix.de>
Wed, 16 Oct 2024 13:58:09 +0000 (15:58 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Oct 2024 06:42:22 +0000 (08:42 +0200)
The uvc gadget driver is lacking the information which frame interval
was set by the host. We add this information by implementing the g_parm
and s_parm callbacks.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Link: https://lore.kernel.org/r/20240403-uvc_request_length_by_interval-v7-4-e224bb1035f0@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/uvc.h
drivers/usb/gadget/function/uvc_v4l2.c
drivers/usb/gadget/function/uvc_video.c

index 4f44a607d9f5cb0d264e90befc4d17ad5ef683ba..099038f1088ef66bf3e17ce04820022349de3304 100644 (file)
@@ -105,6 +105,7 @@ struct uvc_video {
        unsigned int width;
        unsigned int height;
        unsigned int imagesize;
+       unsigned int interval;
        struct mutex mutex;     /* protects frame parameters */
 
        unsigned int uvc_num_requests;
index 836b91c73f1857d4eb659c57bfdc3136d1588a50..a3e2ca31510176c1057cc6f9eebd18d045a024f1 100644 (file)
@@ -323,6 +323,56 @@ uvc_v4l2_set_format(struct file *file, void *fh, struct v4l2_format *fmt)
        return ret;
 }
 
+static int uvc_v4l2_g_parm(struct file *file, void *fh,
+                          struct v4l2_streamparm *parm)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct uvc_device *uvc = video_get_drvdata(vdev);
+       struct uvc_video *video = &uvc->video;
+       struct v4l2_fract timeperframe;
+
+       if (!V4L2_TYPE_IS_OUTPUT(parm->type))
+               return -EINVAL;
+
+       /* Return the actual frame period. */
+       timeperframe.numerator = video->interval;
+       timeperframe.denominator = 10000000;
+       v4l2_simplify_fraction(&timeperframe.numerator,
+                              &timeperframe.denominator, 8, 333);
+
+       uvcg_dbg(&uvc->func, "Getting frame interval of %u/%u (%u)\n",
+                timeperframe.numerator, timeperframe.denominator,
+                video->interval);
+
+       parm->parm.output.timeperframe = timeperframe;
+       parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
+
+       return 0;
+}
+
+static int uvc_v4l2_s_parm(struct file *file, void *fh,
+                          struct v4l2_streamparm *parm)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct uvc_device *uvc = video_get_drvdata(vdev);
+       struct uvc_video *video = &uvc->video;
+       struct v4l2_fract timeperframe;
+
+       if (!V4L2_TYPE_IS_OUTPUT(parm->type))
+               return -EINVAL;
+
+       timeperframe = parm->parm.output.timeperframe;
+
+       video->interval = v4l2_fraction_to_interval(timeperframe.numerator,
+                                                   timeperframe.denominator);
+
+       uvcg_dbg(&uvc->func, "Setting frame interval to %u/%u (%u)\n",
+                timeperframe.numerator, timeperframe.denominator,
+                video->interval);
+
+       return 0;
+}
+
 static int
 uvc_v4l2_enum_frameintervals(struct file *file, void *fh,
                struct v4l2_frmivalenum *fival)
@@ -596,6 +646,8 @@ const struct v4l2_ioctl_ops uvc_v4l2_ioctl_ops = {
        .vidioc_dqbuf = uvc_v4l2_dqbuf,
        .vidioc_streamon = uvc_v4l2_streamon,
        .vidioc_streamoff = uvc_v4l2_streamoff,
+       .vidioc_s_parm = uvc_v4l2_s_parm,
+       .vidioc_g_parm = uvc_v4l2_g_parm,
        .vidioc_subscribe_event = uvc_v4l2_subscribe_event,
        .vidioc_unsubscribe_event = uvc_v4l2_unsubscribe_event,
        .vidioc_default = uvc_v4l2_ioctl_default,
index 06055959f7165835583f8575aeec75d36b9801a1..ee7326029d6f9a42a6f5b2dbae5fc40b6246f433 100644 (file)
@@ -784,6 +784,7 @@ int uvcg_video_init(struct uvc_video *video, struct uvc_device *uvc)
        video->width = 320;
        video->height = 240;
        video->imagesize = 320 * 240 * 2;
+       video->interval = 666666;
 
        /* Initialize the video buffers queue. */
        uvcg_queue_init(&video->queue, uvc->v4l2_dev.dev->parent,