From: Ricardo Ribalda <ribalda@chromium.org>
To: Hans de Goede <hansg@kernel.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Len Brown <lenb@kernel.org>,
Robert Moore <robert.moore@intel.com>,
Hans Verkuil <hverkuil@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org,
acpica-devel@lists.linux.dev,
Ricardo Ribalda <ribalda@chromium.org>
Subject: [PATCH v3 11/12] media: uvcvideo: Use current_value for read-only controls
Date: Fri, 26 Sep 2025 13:11:35 +0000 [thread overview]
Message-ID: <20250926-uvc-orientation-v3-11-6dc2fa5b4220@chromium.org> (raw)
In-Reply-To: <20250926-uvc-orientation-v3-0-6dc2fa5b4220@chromium.org>
For read-only controls that do not support GET_MIN, GET_DEF, GET_MAX or
GET_RES use the current value of the control or a constant number if the
current value is not available.
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/usb/uvc/uvc_ctrl.c | 76 +++++++++++++++++++++++++++++-----------
1 file changed, 56 insertions(+), 20 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index 017165a5c94459f1befd4c08f85a2017c58d61e6..e99fdf4bafbea662556798fe345a48b9ffd8467b 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -1548,6 +1548,50 @@ static u32 uvc_get_ctrl_bitmap(struct uvc_control *ctrl,
return ~0;
}
+static s64 uvc_queryctrl_single_boundary(struct uvc_video_chain *chain,
+ struct uvc_control *ctrl,
+ struct uvc_control_mapping *mapping,
+ u8 op)
+{
+ static const u32 query_types[][3] = {
+ {UVC_CTRL_FLAG_GET_DEF, UVC_GET_DEF, UVC_CTRL_DATA_DEF},
+ {UVC_CTRL_FLAG_GET_MIN, UVC_GET_MIN, UVC_CTRL_DATA_MIN},
+ {UVC_CTRL_FLAG_GET_MAX, UVC_GET_MAX, UVC_CTRL_DATA_MAX},
+ {UVC_CTRL_FLAG_GET_RES, UVC_GET_RES, UVC_CTRL_DATA_RES},
+ };
+ int idx = -1;
+
+ for (unsigned int i = 0; i < ARRAY_SIZE(query_types); i++) {
+ if (op == query_types[i][1]) {
+ idx = i;
+ break;
+ }
+ }
+ if (WARN_ON(idx == -1))
+ return 0;
+
+ if (ctrl->info.flags & query_types[idx][0]) {
+ return uvc_mapping_get_s32(mapping, query_types[idx][1],
+ uvc_ctrl_data(ctrl,
+ query_types[idx][2]));
+ }
+
+ /* Use 1 as the default step value. */
+ if (op == UVC_GET_RES)
+ return 1;
+
+ /* Read-only controls can use GET_CUR as min, max and def. */
+ if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR) &&
+ (ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) &&
+ __uvc_ctrl_load_cur(chain, ctrl) == 0) {
+ return uvc_mapping_get_s32(mapping, UVC_GET_CUR,
+ uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT));
+ }
+
+ /* Otherwise, use 0 as last resource. */
+ return 0;
+}
+
/*
* Maximum retry count to avoid spurious errors with controls. Increasing this
* value does no seem to produce better results in the tested hardware.
@@ -1573,11 +1617,9 @@ static int __uvc_queryctrl_boundaries(struct uvc_video_chain *chain,
return ret;
}
- if (ctrl->info.flags & UVC_CTRL_FLAG_GET_DEF)
- v4l2_ctrl->default_value = uvc_mapping_get_s32(mapping,
- UVC_GET_DEF, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF));
- else
- v4l2_ctrl->default_value = 0;
+ v4l2_ctrl->default_value =
+ uvc_queryctrl_single_boundary(chain, ctrl, mapping,
+ UVC_GET_DEF);
switch (mapping->v4l2_type) {
case V4L2_CTRL_TYPE_MENU:
@@ -1608,23 +1650,17 @@ static int __uvc_queryctrl_boundaries(struct uvc_video_chain *chain,
break;
}
- if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN)
- v4l2_ctrl->minimum = uvc_mapping_get_s32(mapping, UVC_GET_MIN,
- uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN));
- else
- v4l2_ctrl->minimum = 0;
+ v4l2_ctrl->minimum =
+ uvc_queryctrl_single_boundary(chain, ctrl, mapping,
+ UVC_GET_MIN);
- if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX)
- v4l2_ctrl->maximum = uvc_mapping_get_s32(mapping, UVC_GET_MAX,
- uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX));
- else
- v4l2_ctrl->maximum = 0;
+ v4l2_ctrl->maximum =
+ uvc_queryctrl_single_boundary(chain, ctrl, mapping,
+ UVC_GET_MAX);
- if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES)
- v4l2_ctrl->step = uvc_mapping_get_s32(mapping, UVC_GET_RES,
- uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
- else
- v4l2_ctrl->step = 0;
+ v4l2_ctrl->step =
+ uvc_queryctrl_single_boundary(chain, ctrl, mapping,
+ UVC_GET_RES);
return 0;
}
--
2.51.0.536.g15c5d4f767-goog
next prev parent reply other threads:[~2025-09-26 13:11 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-26 13:11 [PATCH v3 00/12] media: uvcvideo: Add support for orientation and rotation Ricardo Ribalda
2025-09-26 13:11 ` [PATCH v3 01/12] media: uvcvideo: Always set default_value Ricardo Ribalda
2025-09-26 13:11 ` [PATCH v3 02/12] media: uvcvideo: Set a function for UVC_EXT_GPIO_UNIT Ricardo Ribalda
2025-09-26 13:11 ` [PATCH v3 03/12] media: v4l: fwnode: Support ACPI's _PLD for v4l2_fwnode_device_parse Ricardo Ribalda
2025-09-27 4:37 ` kernel test robot
2025-09-26 13:11 ` [PATCH v3 04/12] ACPI: mipi-disco-img: Do not duplicate rotation info into swnodes Ricardo Ribalda
2025-09-26 13:26 ` Rafael J. Wysocki
2025-09-26 13:11 ` [PATCH v3 05/12] media: ipu-bridge: Use v4l2_fwnode_device_parse helper Ricardo Ribalda
2025-09-26 13:11 ` [PATCH v3 06/12] media: ipu-bridge: Use v4l2_fwnode for unknown rotations Ricardo Ribalda
2025-09-26 13:11 ` [PATCH v3 07/12] dt-bindings: media: Add usb-camera-module Ricardo Ribalda
2025-09-26 16:55 ` Conor Dooley
2025-09-29 8:30 ` Ricardo Ribalda
2025-09-29 18:49 ` Conor Dooley
2025-09-26 13:11 ` [PATCH v3 08/12] media: uvcvideo: Add support for V4L2_CID_CAMERA_ORIENTATION Ricardo Ribalda
2025-09-26 13:11 ` [PATCH v3 09/12] media: uvcvideo: Fill ctrl->info.selector earlier Ricardo Ribalda
2025-09-26 13:11 ` [PATCH v3 10/12] media: uvcvideo: Add uvc_ctrl_query_entity helper Ricardo Ribalda
2025-09-26 13:11 ` Ricardo Ribalda [this message]
2025-09-26 13:11 ` [PATCH v3 12/12] media: uvcvideo: Add support for V4L2_CID_CAMERA_ROTATION Ricardo Ribalda
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=20250926-uvc-orientation-v3-11-6dc2fa5b4220@chromium.org \
--to=ribalda@chromium.org \
--cc=acpica-devel@lists.linux.dev \
--cc=brgl@bgdev.pl \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hansg@kernel.org \
--cc=hverkuil@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=lenb@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=rafael@kernel.org \
--cc=robert.moore@intel.com \
--cc=robh@kernel.org \
--cc=sakari.ailus@linux.intel.com \
/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;
as well as URLs for NNTP newsgroup(s).