build/patch/kernel/archive/sunxi-6.5/patches.megous/media-sun6i-csi-add-V4L2_CAP_IO_MC-capability.patch

83 lines
2.6 KiB
Diff
Raw Normal View History

From 36711323d3c76f5eb2b3a27b5281b5a484e372c5 Mon Sep 17 00:00:00 2001
From: Adam Pigg <adam@piggz.co.uk>
Date: Tue, 3 Jan 2023 18:52:04 +0000
Subject: [PATCH 053/464] media: sun6i-csi: add V4L2_CAP_IO_MC capability
Advertise the V4L2_CAP_IO_MC flag and update
sun6i_csi_capture_enum_fmt to work with this capability.
With the capability adverstised, the VIDIOC_ENUM_FMT ioctl
implementation is updated to enumerate pixel formats depending
on the supplied mbus_code. If the code is 0, all formats are
enumerated, if not, only pixel formats that match with the supplied
mbus_code are enumeratd.
Signed-off-by: Adam Pigg <adam@piggz.co.uk>
---
.../sunxi/sun6i-csi/sun6i_csi_capture.c | 37 +++++++++++++++++--
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c
index 3863c468a573..c9bdd16b1d05 100644
--- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c
+++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c
@@ -722,13 +722,43 @@ static int sun6i_csi_capture_enum_fmt(struct file *file, void *private,
struct v4l2_fmtdesc *fmtdesc)
{
u32 index = fmtdesc->index;
+ unsigned int i;
if (index >= ARRAY_SIZE(sun6i_csi_capture_formats))
return -EINVAL;
- fmtdesc->pixelformat = sun6i_csi_capture_formats[index].pixelformat;
+ for (i = 0; i < ARRAY_SIZE(sun6i_csi_capture_formats); i++) {
+ const struct sun6i_csi_capture_format *format =
+ &sun6i_csi_capture_formats[i];
- return 0;
+ /*
+ * If a media bus code is specified, only consider formats that
+ * match it.
+ */
+ if (fmtdesc->mbus_code) {
+ unsigned int j;
+
+ if (!format->mbus_codes)
+ continue;
+
+ for (j = 0; format->mbus_codes[j]; j++) {
+ if (fmtdesc->mbus_code == format->mbus_codes[j])
+ break;
+ }
+
+ if (!format->mbus_codes[j])
+ continue;
+ }
+
+ if (index == 0) {
+ fmtdesc->pixelformat = format->pixelformat;
+ return 0;
+ }
+
+ index--;
+ }
+
+ return -EINVAL;
}
static int sun6i_csi_capture_g_fmt(struct file *file, void *private,
@@ -1034,7 +1064,8 @@ int sun6i_csi_capture_setup(struct sun6i_csi_device *csi_dev)
strscpy(video_dev->name, SUN6I_CSI_CAPTURE_NAME,
sizeof(video_dev->name));
- video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
+ video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING
+ | V4L2_CAP_IO_MC;
video_dev->vfl_dir = VFL_DIR_RX;
video_dev->release = video_device_release_empty;
video_dev->fops = &sun6i_csi_capture_fops;
--
2.34.1