From nobody Tue Nov 26 19:43:43 2024 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFFD120C03B for ; Wed, 16 Oct 2024 13:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729087108; cv=none; b=c7bnWn6FnhwPcw8zhOVLDMyY8sE4IPti7vxm5/0D6dURWUEXSCkiH5b0IVMgCfmXZrKw8379G/tsqzkRCLBZQW28sRtdS8JnmBNvLVr3yuJ1VtQpEjNaMOAFxfPWSJbFWtVJW/4rPlpC65/2pKSjy/xjGdgX8/GkD1vZICAl/KY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729087108; c=relaxed/simple; bh=sugFjLlnRL6qi61vWs3XwyGeYuxVHOvvOko5oTWsf7U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gmSo3tbolFoPpaiU0bM6YzdAnFu/aTBmwc5YWBhOVI+XRzVT7alzgj7HXvcGyH8G54BDwzOJiR/qAWoTlwcZTeXZgrD+bVUdJv9rbf6U7y9QR6NCJhLcFTEpPfbn1Ymj4dyGQ+Faid4S+5XuqUcaNotvhxst2ca8chcGkyYVbIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t14Xd-0003H0-L5; Wed, 16 Oct 2024 15:58:21 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t14Xd-002HjD-2O; Wed, 16 Oct 2024 15:58:21 +0200 Received: from localhost ([::1] helo=dude04.red.stw.pengutronix.de) by dude04.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1t14Xc-00BU5S-3A; Wed, 16 Oct 2024 15:58:20 +0200 From: Michael Grzeschik Date: Wed, 16 Oct 2024 15:58:09 +0200 Subject: [PATCH v7 4/9] usb: gadget: uvc: add g_parm and s_parm for frame interval Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240403-uvc_request_length_by_interval-v7-4-e224bb1035f0@pengutronix.de> References: <20240403-uvc_request_length_by_interval-v7-0-e224bb1035f0@pengutronix.de> In-Reply-To: <20240403-uvc_request_length_by_interval-v7-0-e224bb1035f0@pengutronix.de> To: Laurent Pinchart , Daniel Scally , Greg Kroah-Hartman , Avichal Rakesh , Jayant Chowdhary Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Michael Grzeschik X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4059; i=m.grzeschik@pengutronix.de; h=from:subject:message-id; bh=sugFjLlnRL6qi61vWs3XwyGeYuxVHOvvOko5oTWsf7U=; b=owEBbQKS/ZANAwAKAb9pWET5cfSrAcsmYgBnD8Z6M8kB2qi29uojUzyv2o0+HmCnBlKGjLgK1 hc47cGXyf6JAjMEAAEKAB0WIQQV2+2Fpbqd6fvv0Gi/aVhE+XH0qwUCZw/GegAKCRC/aVhE+XH0 qxhjD/9l8DN/jBe8ZWGXSmg0tH9+GFkpZs470MLiZJ5kUhR/2zlQHewf0iMTiE8z0he16/KwVWC v/tIoIymPVONePPrGAHdKCK/hg10cxeOSjJn/OPkFlHTPn9nz5s59jh87g3jJdRG2MhJoLMqbwJ SqLqdXmeXhJjj+ZVmNSM5I3IubhIZa1IqNqQEQf/m6a9upG4nmgCW2ZANvUKLjmHWRE0KtSZt4A FrYxB8uhr2Yahl2bdPJKHYIf4qP17FlQ1n8SPyu8tqRQieALMcopRkKI5kb8/2qicdSidmw5liB eej67Xuaj6uFUcvuAAxoK9TdVgLNMQa9mF8Z2Fj3AMeTt3H2t5g6HcPDveNok1yzghEYA8wvGhy hlgaQjbCIaWxe0GtH7jvpNog9kFrtvhPFr/O+NNrEdwuuN1lIGCP4kyCx1qeLrBKX3QXFYumxZk pkAV2Xgi22wLi/h+Sn5QxkDLKdVV1J5GH/JiHmI6nRdcUqe8SMHfOpKp9/oFnf6MhdmwZQszWXH RvifyKFIj3rtvfbEjvock7U8l54yXrMsV2R8+XfhqtuQusLHyBOCpF7G2Q/CaCzx75nzU/bwYWr nHgE1eMEoGaYPbyUIiMNhVCsR/No/76zB0wA+CnKts/14u0cpEWFtjpxh87sIHoV1n8yLYLuw7W UFVQvsMxgj7y4Bw== X-Developer-Key: i=m.grzeschik@pengutronix.de; a=openpgp; fpr=957BC452CE953D7EA60CF4FC0BE9E3157A1E2C64 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: m.grzeschik@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org 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 --- v5 -> v7: - v4 -> v5: - using !V4L2_TYPE_IS_OUTPUT to check for type - initialzing interval to same default as in configfs - reordered this patch in the series v1 -> v4: - --- drivers/usb/gadget/function/uvc.h | 1 + drivers/usb/gadget/function/uvc_v4l2.c | 52 +++++++++++++++++++++++++++++= ++++ drivers/usb/gadget/function/uvc_video.c | 1 + 3 files changed, 54 insertions(+) diff --git a/drivers/usb/gadget/function/uvc.h b/drivers/usb/gadget/functio= n/uvc.h index 4f44a607d9f5c..099038f1088ef 100644 --- a/drivers/usb/gadget/function/uvc.h +++ b/drivers/usb/gadget/function/uvc.h @@ -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 */ =20 unsigned int uvc_num_requests; diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/fu= nction/uvc_v4l2.c index de1736f834e6b..ab89f1630acb0 100644 --- a/drivers/usb/gadget/function/uvc_v4l2.c +++ b/drivers/usb/gadget/function/uvc_v4l2.c @@ -314,6 +314,56 @@ uvc_v4l2_set_format(struct file *file, void *fh, struc= t v4l2_format *fmt) return ret; } =20 +static int uvc_v4l2_g_parm(struct file *file, void *fh, + struct v4l2_streamparm *parm) +{ + struct video_device *vdev =3D video_devdata(file); + struct uvc_device *uvc =3D video_get_drvdata(vdev); + struct uvc_video *video =3D &uvc->video; + struct v4l2_fract timeperframe; + + if (!V4L2_TYPE_IS_OUTPUT(parm->type)) + return -EINVAL; + + /* Return the actual frame period. */ + timeperframe.numerator =3D video->interval; + timeperframe.denominator =3D 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 =3D timeperframe; + parm->parm.output.capability =3D V4L2_CAP_TIMEPERFRAME; + + return 0; +} + +static int uvc_v4l2_s_parm(struct file *file, void *fh, + struct v4l2_streamparm *parm) +{ + struct video_device *vdev =3D video_devdata(file); + struct uvc_device *uvc =3D video_get_drvdata(vdev); + struct uvc_video *video =3D &uvc->video; + struct v4l2_fract timeperframe; + + if (!V4L2_TYPE_IS_OUTPUT(parm->type)) + return -EINVAL; + + timeperframe =3D parm->parm.output.timeperframe; + + video->interval =3D 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) @@ -587,6 +637,8 @@ const struct v4l2_ioctl_ops uvc_v4l2_ioctl_ops =3D { .vidioc_dqbuf =3D uvc_v4l2_dqbuf, .vidioc_streamon =3D uvc_v4l2_streamon, .vidioc_streamoff =3D uvc_v4l2_streamoff, + .vidioc_s_parm =3D uvc_v4l2_s_parm, + .vidioc_g_parm =3D uvc_v4l2_g_parm, .vidioc_subscribe_event =3D uvc_v4l2_subscribe_event, .vidioc_unsubscribe_event =3D uvc_v4l2_unsubscribe_event, .vidioc_default =3D uvc_v4l2_ioctl_default, diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/f= unction/uvc_video.c index 06055959f7165..ee7326029d6f9 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c @@ -784,6 +784,7 @@ int uvcg_video_init(struct uvc_video *video, struct uvc= _device *uvc) video->width =3D 320; video->height =3D 240; video->imagesize =3D 320 * 240 * 2; + video->interval =3D 666666; =20 /* Initialize the video buffers queue. */ uvcg_queue_init(&video->queue, uvc->v4l2_dev.dev->parent, --=20 2.39.5