From: Yunke Cao <yunkec@google.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Tomasz Figa <tfiga@chromium.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Ricardo Ribalda <ribalda@chromium.org>,
linux-media@vger.kernel.org, Yunke Cao <yunkec@google.com>
Subject: [PATCH v1 5/6] media: uvcvideo: Initialize roi to default value
Date: Mon, 16 May 2022 18:22:08 +0900 [thread overview]
Message-ID: <20220516092209.1801656-6-yunkec@google.com> (raw)
In-Reply-To: <20220516092209.1801656-1-yunkec@google.com>
For the devices we tested with, firmwares have wrong initial
ROI configuration. Initialize roi by setting to default value.
Signed-off-by: Yunke Cao <yunkec@google.com>
---
drivers/media/usb/uvc/uvc_ctrl.c | 39 ++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index c3d816985f13..f90b425a0a20 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -2505,6 +2505,40 @@ static void uvc_ctrl_prune_entity(struct uvc_device *dev,
}
}
+static int uvc_ctrl_init_roi(struct uvc_device *dev, struct uvc_control *ctrl)
+{
+ int ret;
+
+ ret = uvc_query_ctrl(dev, UVC_GET_DEF, ctrl->entity->id, dev->intfnum,
+ UVC_CT_REGION_OF_INTEREST_CONTROL,
+ uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF),
+ ctrl->info.size);
+ if (ret)
+ goto out;
+
+ /*
+ * Some firmwares have wrong GET_CURRENT configuration. E.g. it's
+ * below GET_MIN, or have rectangle coordinates mixed up. This
+ * causes problems sometimes, because we are unable to set
+ * auto-controls value without first setting ROI rectangle to
+ * valid configuration.
+ *
+ * We expect that default configuration is always correct and
+ * is within the GET_MIN / GET_MAX boundaries.
+ *
+ * Set current ROI configuration to GET_DEF, so that we will
+ * always have properly configured ROI.
+ */
+ ret = uvc_query_ctrl(dev, UVC_SET_CUR, 1, dev->intfnum,
+ UVC_CT_REGION_OF_INTEREST_CONTROL,
+ uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF),
+ ctrl->info.size);
+out:
+ if (ret)
+ dev_err(&dev->udev->dev, "Failed to fixup ROI (%d).\n", ret);
+ return ret;
+}
+
/*
* Add control information and hardcoded stock control mappings to the given
* device.
@@ -2537,6 +2571,11 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain,
* GET_INFO on standard controls.
*/
uvc_ctrl_get_flags(chain->dev, ctrl, &ctrl->info);
+
+ if (ctrl->info.selector ==
+ UVC_CT_REGION_OF_INTEREST_CONTROL &&
+ uvc_entity_match_guid(ctrl->entity, camera_entity))
+ uvc_ctrl_init_roi(chain->dev, ctrl);
break;
}
}
--
2.36.0.550.gb090851708-goog
next prev parent reply other threads:[~2022-05-16 9:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-16 9:22 [PATCH v1 0/6] media: Implement UVC v1.5 ROI Yunke Cao
2022-05-16 9:22 ` [PATCH v1 1/6] media: v4l2_ctrl: Add region of interest rectangle control Yunke Cao
2022-05-16 9:22 ` [PATCH v1 2/6] media: v4l2_ctrl: Add region of interest auto control Yunke Cao
2022-05-16 9:22 ` [PATCH v1 3/6] media: v4l2_ctrl: Add V4L2_CTRL_WHICH_MIN/MAX_VAL Yunke Cao
2022-05-16 9:22 ` [PATCH v1 4/6] media: uvcvideo: implement UVC v1.5 ROI Yunke Cao
2022-05-16 9:22 ` Yunke Cao [this message]
2022-05-16 13:25 ` [PATCH v1 5/6] media: uvcvideo: Initialize roi to default value kernel test robot
2022-05-16 9:22 ` [PATCH v1 6/6] media: vivid: Add a roi rectangle control Yunke Cao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220516092209.1801656-6-yunkec@google.com \
--to=yunkec@google.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=ribalda@chromium.org \
--cc=senozhatsky@chromium.org \
--cc=tfiga@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox