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 12/12] media: uvcvideo: Add support for V4L2_CID_CAMERA_ROTATION
Date: Fri, 26 Sep 2025 13:11:36 +0000 [thread overview]
Message-ID: <20250926-uvc-orientation-v3-12-6dc2fa5b4220@chromium.org> (raw)
In-Reply-To: <20250926-uvc-orientation-v3-0-6dc2fa5b4220@chromium.org>
Fetch the rotation from the fwnode and map it into a control.
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/usb/uvc/uvc_ctrl.c | 22 ++++++++++++++++---
drivers/media/usb/uvc/uvc_swentity.c | 41 +++++++++++++++++++++++++++++++-----
drivers/media/usb/uvc/uvcvideo.h | 5 +++++
3 files changed, 60 insertions(+), 8 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index e99fdf4bafbea662556798fe345a48b9ffd8467b..99bae519ded8910a37ad2f2112fbcbfdcac671af 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -387,11 +387,18 @@ static const struct uvc_control_info uvc_ctrls[] = {
},
{
.entity = UVC_GUID_SWENTITY,
- .selector = 0,
- .index = 0,
+ .selector = UVC_SWENTITY_ORIENTATION,
+ .index = UVC_SWENTITY_ORIENTATION,
.size = 1,
.flags = UVC_CTRL_FLAG_GET_CUR,
},
+ {
+ .entity = UVC_GUID_SWENTITY,
+ .selector = UVC_SWENTITY_ROTATION,
+ .index = UVC_SWENTITY_ROTATION,
+ .size = 2,
+ .flags = UVC_CTRL_FLAG_GET_CUR,
+ },
};
static const u32 uvc_control_classes[] = {
@@ -1049,7 +1056,7 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = {
{
.id = V4L2_CID_CAMERA_ORIENTATION,
.entity = UVC_GUID_SWENTITY,
- .selector = 0,
+ .selector = UVC_SWENTITY_ORIENTATION,
.size = 8,
.offset = 0,
.v4l2_type = V4L2_CTRL_TYPE_MENU,
@@ -1057,6 +1064,15 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = {
.menu_mask = GENMASK(V4L2_CAMERA_ORIENTATION_EXTERNAL,
V4L2_CAMERA_ORIENTATION_FRONT),
},
+ {
+ .id = V4L2_CID_CAMERA_SENSOR_ROTATION,
+ .entity = UVC_GUID_SWENTITY,
+ .selector = UVC_SWENTITY_ROTATION,
+ .size = 16,
+ .offset = 0,
+ .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
+ .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
+ },
};
/* ------------------------------------------------------------------------
diff --git a/drivers/media/usb/uvc/uvc_swentity.c b/drivers/media/usb/uvc/uvc_swentity.c
index eefc5d08e370515181f74590f2f38189770b01b2..e180568efa802fb348dbf165da62417631ff16fd 100644
--- a/drivers/media/usb/uvc/uvc_swentity.c
+++ b/drivers/media/usb/uvc/uvc_swentity.c
@@ -12,10 +12,11 @@
#include "uvcvideo.h"
-static int uvc_swentity_get_cur(struct uvc_device *dev, struct uvc_entity *entity,
- u8 cs, void *data, u16 size)
+static int uvc_swentity_get_orientation(struct uvc_device *dev,
+ struct uvc_entity *entity, u8 cs,
+ void *data, u16 size)
{
- if (size < 1)
+ if (cs != UVC_SWENTITY_ORIENTATION || size != 1)
return -EINVAL;
switch (entity->swentity.props.orientation) {
@@ -32,6 +33,31 @@ static int uvc_swentity_get_cur(struct uvc_device *dev, struct uvc_entity *entit
return 0;
}
+static int uvc_swentity_get_rotation(struct uvc_device *dev,
+ struct uvc_entity *entity, u8 cs, void *data,
+ u16 size)
+{
+ if (cs != UVC_SWENTITY_ROTATION || size != 2)
+ return -EINVAL;
+
+ ((u8 *)data)[0] = entity->swentity.props.rotation;
+ ((u8 *)data)[1] = entity->swentity.props.rotation >> 8;
+
+ return 0;
+}
+
+static int uvc_swentity_get_cur(struct uvc_device *dev, struct uvc_entity *entity,
+ u8 cs, void *data, u16 size)
+{
+ switch (cs) {
+ case UVC_SWENTITY_ORIENTATION:
+ return uvc_swentity_get_orientation(dev, entity, cs, data, size);
+ case UVC_SWENTITY_ROTATION:
+ return uvc_swentity_get_rotation(dev, entity, cs, data, size);
+ }
+ return -EINVAL;
+}
+
static int uvc_swentity_get_info(struct uvc_device *dev,
struct uvc_entity *entity, u8 cs, u8 *caps)
{
@@ -44,6 +70,7 @@ int uvc_swentity_init(struct uvc_device *dev)
static const u8 uvc_swentity_guid[] = UVC_GUID_SWENTITY;
struct v4l2_fwnode_device_properties props;
struct uvc_entity *unit;
+ u8 controls = 0;
int ret;
ret = v4l2_fwnode_device_parse(&dev->udev->dev, &props);
@@ -51,7 +78,11 @@ int uvc_swentity_init(struct uvc_device *dev)
return dev_err_probe(&dev->intf->dev, ret,
"Can't parse fwnode\n");
- if (props.orientation == V4L2_FWNODE_PROPERTY_UNSET)
+ if (props.orientation != V4L2_FWNODE_PROPERTY_UNSET)
+ controls |= BIT(UVC_SWENTITY_ORIENTATION);
+ if (props.rotation != V4L2_FWNODE_PROPERTY_UNSET)
+ controls |= BIT(UVC_SWENTITY_ROTATION);
+ if (!controls)
return 0;
unit = uvc_alloc_new_entity(dev, UVC_SWENTITY_UNIT,
@@ -63,7 +94,7 @@ int uvc_swentity_init(struct uvc_device *dev)
unit->swentity.props = props;
unit->swentity.bControlSize = 1;
unit->swentity.bmControls = (u8 *)unit + sizeof(*unit);
- unit->swentity.bmControls[0] = 1;
+ unit->swentity.bmControls[0] = controls;
unit->get_cur = uvc_swentity_get_cur;
unit->get_info = uvc_swentity_get_info;
strscpy(unit->name, "SWENTITY", sizeof(unit->name));
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index 04ca5dcce11d902dbfdf32f2a962159ba7940a39..64c9a597cc533ebf3a305060294c7045e32f72b0 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -47,6 +47,11 @@
#define UVC_INVALID_ENTITY_ID 0xffff
+enum {
+ UVC_SWENTITY_ORIENTATION,
+ UVC_SWENTITY_ROTATION
+};
+
/* ------------------------------------------------------------------------
* Driver specific constants.
*/
--
2.51.0.536.g15c5d4f767-goog
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 ` [PATCH v3 11/12] media: uvcvideo: Use current_value for read-only controls Ricardo Ribalda
2025-09-26 13:11 ` Ricardo Ribalda [this message]
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-12-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).