[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250926-uvc-orientation-v3-12-6dc2fa5b4220@chromium.org>
Date: Fri, 26 Sep 2025 13:11:36 +0000
From: Ricardo Ribalda <ribalda@...omium.org>
To: Hans de Goede <hansg@...nel.org>,
Laurent Pinchart <laurent.pinchart@...asonboard.com>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
Sakari Ailus <sakari.ailus@...ux.intel.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>,
Linus Walleij <linus.walleij@...aro.org>,
Bartosz Golaszewski <brgl@...ev.pl>,
"Rafael J. Wysocki" <rafael@...nel.org>, Len Brown <lenb@...nel.org>,
Robert Moore <robert.moore@...el.com>, Hans Verkuil <hverkuil@...nel.org>
Cc: linux-media@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-usb@...r.kernel.org, devicetree@...r.kernel.org,
linux-gpio@...r.kernel.org, linux-acpi@...r.kernel.org,
acpica-devel@...ts.linux.dev, Ricardo Ribalda <ribalda@...omium.org>
Subject: [PATCH v3 12/12] media: uvcvideo: Add support for
V4L2_CID_CAMERA_ROTATION
Fetch the rotation from the fwnode and map it into a control.
Signed-off-by: Ricardo Ribalda <ribalda@...omium.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
Powered by blists - more mailing lists