Patch Detail
Show a patch.
GET /api/patches/26292/?format=api
{ "id": 26292, "url": "https://patchwork.libcamera.org/api/patches/26292/?format=api", "web_url": "https://patchwork.libcamera.org/patch/26292/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260313-mali-cru-v5-1-48f93e431294@ideasonboard.com>", "date": "2026-03-13T16:14:35", "name": "[v5,1/7] libcamera: mali-c55: Add RZG2LCRU class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "976a86e30bf7098c8bbf0606b80b814221bc3a15", "submitter": { "id": 143, "url": "https://patchwork.libcamera.org/api/people/143/?format=api", "name": "Jacopo Mondi", "email": "jacopo.mondi@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/26292/mbox/", "series": [ { "id": 5830, "url": "https://patchwork.libcamera.org/api/series/5830/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5830", "date": "2026-03-13T16:14:34", "name": "libcamera: mali-c55: Add support for memory-to-memory", "version": 5, "mbox": "https://patchwork.libcamera.org/series/5830/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/26292/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/26292/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 49A22C32B5\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 13 Mar 2026 16:14:49 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 51E1C626CC;\n\tFri, 13 Mar 2026 17:14:47 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 583D46261B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 13 Mar 2026 17:14:45 +0100 (CET)", "from [192.168.224.131] (unknown [37.159.122.93])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CE7B8103D;\n\tFri, 13 Mar 2026 17:13:35 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"nHDMBbNY\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1773418416;\n\tbh=EaYAwOaNMgy9veLK7jWa8jDYsMPnnAIy+293/wcP5yk=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=nHDMBbNYvzAvzd8AXUkqkbMyn0PgCcr5hdn3xVWw83ESkQKysNj1+qQjCG6Qz0vVz\n\tyg0cbvWqmvnb3k1VVxAN9DkEK5h76vvQHW5VgpaL802JoL62LtcE8vAbMs82rWtU8s\n\tgYE3k/X5+5epOlhAsOmexxqoY9Vu/www5GspwtmY=", "From": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>", "Date": "Fri, 13 Mar 2026 17:14:35 +0100", "Subject": "[PATCH v5 1/7] libcamera: mali-c55: Add RZG2LCRU class", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "7bit", "Message-Id": "<20260313-mali-cru-v5-1-48f93e431294@ideasonboard.com>", "References": "<20260313-mali-cru-v5-0-48f93e431294@ideasonboard.com>", "In-Reply-To": "<20260313-mali-cru-v5-0-48f93e431294@ideasonboard.com>", "To": "Daniel Scally <dan.scally@ideasonboard.com>, \n\tlibcamera-devel@lists.libcamera.org", "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>", "X-Mailer": "b4 0.14.3", "X-Developer-Signature": "v=1; a=openpgp-sha256; l=9931;\n\ti=jacopo.mondi@ideasonboard.com; h=from:subject:message-id;\n\tbh=ubisEqX/JdmGo8iOHOU9fEWbBd82jLtSOuScAx7m9A4=;\n\tb=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBptDfy+kb7CtebyrXvNOFFw/qfdwetvi/HiE/N2\n\tBb3GZCVysCJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCabQ38gAKCRByNAaPFqFW\n\tPLQND/4vzJneNuqbF3XYqcBROwdKAI0SB4dnMB9je3A+Haah3GyvJjB393YDbQGoju6+YXDSezO\n\thPcuqjAaHJqKG24YUkGZWvale8EgFIE7RV1Nj+q9T62EsoUQxgAqdo/miIXeDAcvLIE4/LqAcUB\n\tcVE4hVNH/ycjzwr+Ii8+0BwvSm2KgtrIGJgZG/YayHjwc9o9t/pe1z3UMtIjCDjVCpePImFoqTr\n\tKRbUu2dsEYNLhdR278jo5FPTGWZsjaIke/vVsG2N39r6yJgEnl51iiXeRv3JfsOu3oq9XYe7RGP\n\thrnGZkNxoRJc6F+THp+x74xbWq7QU1XENQ/BoAJLZVvW/PvS9g6pnyfTtPRnXCNwTXNTzJk1Hh9\n\t6QdxsbckbGVadeq0SoF70IHFE3FquaE/sucU/Viz2E8P/4KWI49GCg2fiUr+91Vg5p3BxCAzcLh\n\tUmffO6Ei4REPmurEPeMk8rIuzlLQLcHY9h9WSUgJNL50XpXnYXabzrPWFvO2pVd/fmgSxcG+wZj\n\tvfIvSKwyg7HG+riYGQXbyqPbGTvm/be1HXVInfegqaaPfyO4DXO9OWcJHpM+nkVh/iIUOQ6wSO9\n\t6e8j7kGQlgNeDnAGpf34lH3UcplHUf7uZqOUN6nsqCn3Yj/oun0L0Wl8lXdhsPn8zCkebZ+GL7a\n\t/PzJe3JMsITUy/g==", "X-Developer-Key": "i=jacopo.mondi@ideasonboard.com; a=openpgp;\n\tfpr=72392EDC88144A65C701EA9BA5826A2587AD026B", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "From: Daniel Scally <dan.scally@ideasonboard.com>\n\nAdd a class allowing us to control the RZ/G2L Camera Receiver Unit.\n\nThe class is named after the media device it handles, which is called\n\"rzg2l_cru\" but the CRU is actually found in other SoCs than the RZ/G2L\none, such as the RZ/V2H(P).\n\nThe RZG2LCRU class models the CSI-2 receiver found on those SoCs and\nallows to add support for memory-to-memory operations on the RZ/V2H(P)\nSoC which integrates a Mali-C55 ISP and a specialized DMA engine named\nIVC that feeds images from memory, where the CRU has saved them.\n\nSigned-off-by: Daniel Scally <dan.scally@ideasonboard.com>\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n src/libcamera/pipeline/mali-c55/meson.build | 3 +-\n src/libcamera/pipeline/mali-c55/rzg2l-cru.cpp | 260 ++++++++++++++++++++++++++\n src/libcamera/pipeline/mali-c55/rzg2l-cru.h | 73 ++++++++\n 3 files changed, 335 insertions(+), 1 deletion(-)", "diff": "diff --git a/src/libcamera/pipeline/mali-c55/meson.build b/src/libcamera/pipeline/mali-c55/meson.build\nindex eba8e5a39054..4e768242602e 100644\n--- a/src/libcamera/pipeline/mali-c55/meson.build\n+++ b/src/libcamera/pipeline/mali-c55/meson.build\n@@ -1,5 +1,6 @@\n # SPDX-License-Identifier: CC0-1.0\n \n libcamera_internal_sources += files([\n- 'mali-c55.cpp'\n+ 'mali-c55.cpp',\n+ 'rzg2l-cru.cpp',\n ])\ndiff --git a/src/libcamera/pipeline/mali-c55/rzg2l-cru.cpp b/src/libcamera/pipeline/mali-c55/rzg2l-cru.cpp\nnew file mode 100644\nindex 000000000000..8f09d1c78058\n--- /dev/null\n+++ b/src/libcamera/pipeline/mali-c55/rzg2l-cru.cpp\n@@ -0,0 +1,260 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2025, Ideas on Board Oy\n+ *\n+ * Pipine handler element for the Renesas RZ/G2L Camera Receiver Unit\n+ */\n+\n+#include \"rzg2l-cru.h\"\n+\n+#include <algorithm>\n+#include <map>\n+\n+#include <linux/videodev2.h>\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/base/regex.h>\n+#include <libcamera/base/utils.h>\n+\n+#include <libcamera/formats.h>\n+#include <libcamera/pixel_format.h>\n+\n+#include \"libcamera/internal/bayer_format.h\"\n+#include \"libcamera/internal/camera_sensor.h\"\n+#include \"libcamera/internal/framebuffer.h\"\n+#include \"libcamera/internal/media_device.h\"\n+#include \"libcamera/internal/request.h\"\n+\n+namespace libcamera {\n+\n+static const std::map<uint8_t, V4L2PixelFormat> bitDepthToFmt{\n+\t{ 10, V4L2PixelFormat(V4L2_PIX_FMT_RAW_CRU10) },\n+\t{ 12, V4L2PixelFormat(V4L2_PIX_FMT_RAW_CRU12) },\n+\t{ 14, V4L2PixelFormat(V4L2_PIX_FMT_RAW_CRU14) },\n+};\n+\n+LOG_DEFINE_CATEGORY(RZG2LCRU)\n+\n+FrameBuffer *RZG2LCRU::queueBuffer(Request *request)\n+{\n+\tFrameBuffer *buffer;\n+\n+\tif (availableBuffers_.empty()) {\n+\t\tLOG(RZG2LCRU, Debug) << \"CRU buffer underrun\";\n+\t\treturn nullptr;\n+\t}\n+\n+\tbuffer = availableBuffers_.front();\n+\n+\tint ret = output_->queueBuffer(buffer);\n+\tif (ret) {\n+\t\tLOG(RZG2LCRU, Error) << \"Failed to queue buffer to CRU\";\n+\t\treturn nullptr;\n+\t}\n+\n+\tavailableBuffers_.pop();\n+\tbuffer->_d()->setRequest(request);\n+\n+\treturn buffer;\n+}\n+\n+void RZG2LCRU::cruReturnBuffer(FrameBuffer *buffer)\n+{\n+\tauto it = std::find_if(buffers_.begin(), buffers_.end(),\n+\t\t\t [&](const auto &b) { return b.get() == buffer; });\n+\tASSERT(it != buffers_.end());\n+\n+\tavailableBuffers_.push(buffer);\n+}\n+\n+int RZG2LCRU::start()\n+{\n+\tint ret = output_->exportBuffers(kBufferCount, &buffers_);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tutils::scope_exit bufferGuard([&] { freeBuffers(); });\n+\n+\tret = output_->importBuffers(kBufferCount);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tfor (std::unique_ptr<FrameBuffer> &buffer : buffers_)\n+\t\tavailableBuffers_.push(buffer.get());\n+\n+\tret = output_->streamOn();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tbufferGuard.release();\n+\n+\treturn 0;\n+}\n+\n+int RZG2LCRU::stop()\n+{\n+\tint ret;\n+\n+\tret = output_->streamOff();\n+\n+\tfreeBuffers();\n+\n+\treturn ret;\n+}\n+\n+void RZG2LCRU::freeBuffers()\n+{\n+\tavailableBuffers_ = {};\n+\tbuffers_.clear();\n+\n+\tif (output_->releaseBuffers())\n+\t\tLOG(RZG2LCRU, Error) << \"Failed to release CRU buffers\";\n+}\n+\n+int RZG2LCRU::configure(V4L2SubdeviceFormat *subdevFormat, V4L2DeviceFormat *inputFormat)\n+{\n+\t/*\n+\t * Set format on the sensor and propagate it up to the CRU video\n+\t * device.\n+\t */\n+\n+\tint ret = sensor_->setFormat(subdevFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = csi2_->setFormat(0, subdevFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = csi2_->getFormat(1, subdevFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = cru_->setFormat(0, subdevFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = cru_->getFormat(1, subdevFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/*\n+\t * The capture device needs to be set with a format that can be produced\n+\t * from the mbus code of the subdevFormat. The CRU and IVC use bayer\n+\t * order agnostic pixel formats, so all we need to do is find the right\n+\t * bitdepth and select the appropriate format.\n+\t */\n+\tBayerFormat bayerFormat = BayerFormat::fromMbusCode(subdevFormat->code);\n+\tif (!bayerFormat.isValid())\n+\t\treturn -EINVAL;\n+\n+\tV4L2DeviceFormat captureFormat;\n+\tcaptureFormat.fourcc = bitDepthToFmt.at(bayerFormat.bitDepth);\n+\tcaptureFormat.size = subdevFormat->size;\n+\n+\tret = output_->setFormat(&captureFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/*\n+\t * We return the format that we set against the output device, as the\n+\t * same format will also need to be set against the Input Video Control\n+\t * Block device.\n+\t */\n+\t*inputFormat = captureFormat;\n+\n+\treturn 0;\n+}\n+\n+void RZG2LCRU::initCRUSizes()\n+{\n+\tSize maxCSI2Size;\n+\n+\t/*\n+\t * Get the maximum supported size on the CSI-2 receiver. We need to\n+\t * query the kernel interface as the size limits differ from RZ/G2L\n+\t * (2800x4095) and RZ/V2H (4096x4096).\n+\t */\n+\tV4L2Subdevice::Formats csi2Formats = csi2_->formats(0);\n+\tif (csi2Formats.empty())\n+\t\treturn;\n+\n+\tfor (const auto &format : csi2Formats) {\n+\t\tfor (const auto &range : format.second) {\n+\t\t\tif (range.max > maxCSI2Size)\n+\t\t\t\tmaxCSI2Size = range.max;\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * Enumerate the sensor supported resolutions and filter out the ones\n+\t * larger than the maximum supported CSI-2 receiver input size.\n+\t */\n+\tV4L2Subdevice::Formats formats = sensor_->device()->formats(0);\n+\tif (formats.empty())\n+\t\treturn;\n+\n+\tfor (const auto &format : formats) {\n+\t\tfor (const auto &range : format.second) {\n+\t\t\tconst Size &max = range.max;\n+\n+\t\t\tif (max.width > maxCSI2Size.width ||\n+\t\t\t max.height > maxCSI2Size.height)\n+\t\t\t\tcontinue;\n+\n+\t\t\tcsi2Sizes_.push_back(max);\n+\t\t}\n+\t}\n+\n+\t/* Sort in increasing order and remove duplicates. */\n+\tstd::sort(csi2Sizes_.begin(), csi2Sizes_.end());\n+\tauto last = std::unique(csi2Sizes_.begin(), csi2Sizes_.end());\n+\tcsi2Sizes_.erase(last, csi2Sizes_.end());\n+\n+\tcsi2Resolution_ = csi2Sizes_.back();\n+}\n+\n+int RZG2LCRU::init(const MediaDevice *media)\n+{\n+\tstatic const std::regex cruRegex(\"cru-ip-[0-9a-f]{8}.cru[0-9]\");\n+\tstatic const std::regex csi2Regex(\"csi-[0-9a-f]{8}.csi2\");\n+\n+\tcsi2_ = V4L2Subdevice::fromEntityName(media, csi2Regex);\n+\tif (!csi2_)\n+\t\treturn -ENODEV;\n+\n+\tint ret = csi2_->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tconst std::vector<MediaPad *> &pads = csi2_->entity()->pads();\n+\tif (pads.empty())\n+\t\treturn -ENODEV;\n+\n+\t/* The receiver has a single sink pad at index 0 */\n+\tMediaPad *sink = pads[0];\n+\tconst std::vector<MediaLink *> &links = sink->links();\n+\tif (links.empty())\n+\t\treturn -ENODEV;\n+\n+\tMediaLink *link = links[0];\n+\tsensor_ = CameraSensorFactoryBase::create(link->source()->entity());\n+\tif (!sensor_)\n+\t\treturn -ENODEV;\n+\n+\tcru_ = V4L2Subdevice::fromEntityName(media, cruRegex);\n+\tret = cru_->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\toutput_ = V4L2VideoDevice::fromEntityName(media, \"CRU output\");\n+\tret = output_->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tinitCRUSizes();\n+\n+\treturn 0;\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/pipeline/mali-c55/rzg2l-cru.h b/src/libcamera/pipeline/mali-c55/rzg2l-cru.h\nnew file mode 100644\nindex 000000000000..1e3cdd879cc5\n--- /dev/null\n+++ b/src/libcamera/pipeline/mali-c55/rzg2l-cru.h\n@@ -0,0 +1,73 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2025, Ideas on Board Oy\n+ *\n+ * Pipine handler element for the Renesas RZ/G2L Camera Receiver Unit\n+ */\n+\n+#pragma once\n+\n+#include <memory>\n+#include <queue>\n+#include <vector>\n+\n+#include <libcamera/base/signal.h>\n+\n+#include \"libcamera/internal/v4l2_subdevice.h\"\n+#include \"libcamera/internal/v4l2_videodevice.h\"\n+\n+namespace libcamera {\n+\n+class CameraSensor;\n+class FrameBuffer;\n+class MediaDevice;\n+class Request;\n+class Size;\n+\n+class RZG2LCRU\n+{\n+public:\n+\tstatic constexpr unsigned int kBufferCount = 4;\n+\n+\tRZG2LCRU() = default;\n+\n+\tconst std::vector<Size> &sizes() const\n+\t{\n+\t\treturn csi2Sizes_;\n+\t}\n+\n+\tint init(const MediaDevice *media);\n+\tconst Size &resolution() const\n+\t{\n+\t\treturn csi2Resolution_;\n+\t}\n+\n+\tCameraSensor *sensor() const { return sensor_.get(); }\n+\tV4L2Subdevice *csi2() const { return csi2_.get(); }\n+\tV4L2Subdevice *cru() const { return cru_.get(); }\n+\n+\tint configure(V4L2SubdeviceFormat *subdevFormat, V4L2DeviceFormat *inputFormat);\n+\tFrameBuffer *queueBuffer(Request *request);\n+\tvoid cruReturnBuffer(FrameBuffer *buffer);\n+\tV4L2VideoDevice *output() { return output_.get(); }\n+\tint start();\n+\tint stop();\n+\n+private:\n+\tvoid freeBuffers();\n+\n+\tvoid initCRUSizes();\n+\n+\tstd::unique_ptr<CameraSensor> sensor_;\n+\tstd::unique_ptr<V4L2Subdevice> csi2_;\n+\tstd::unique_ptr<V4L2Subdevice> cru_;\n+\tstd::unique_ptr<V4L2VideoDevice> output_;\n+\n+\tstd::vector<std::unique_ptr<FrameBuffer>> buffers_;\n+\tstd::queue<FrameBuffer *> availableBuffers_;\n+\n+\tstd::vector<Size> csi2Sizes_;\n+\tSize csi2Resolution_;\n+};\n+\n+} /* namespace libcamera */\n", "prefixes": [ "v5", "1/7" ] }