Show a patch.

GET /api/patches/26407/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 26407,
    "url": "https://patchwork.libcamera.org/api/patches/26407/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/26407/",
    "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": "<20260401-mali-cru-v8-1-44c48f990e28@ideasonboard.com>",
    "date": "2026-04-01T16:25:50",
    "name": "[v8,1/8] libcamera: mali-c55: Add RZG2LCRU class",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "317a9a370fb4388fc0af9e593746fb6a73f0ba20",
    "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/26407/mbox/",
    "series": [
        {
            "id": 5864,
            "url": "https://patchwork.libcamera.org/api/series/5864/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5864",
            "date": "2026-04-01T16:25:49",
            "name": "libcamera: mali-c55: Add support for memory-to-memory",
            "version": 8,
            "mbox": "https://patchwork.libcamera.org/series/5864/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/26407/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/26407/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 7C72AC32BB\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  1 Apr 2026 16:26:07 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2A83862D65;\n\tWed,  1 Apr 2026 18:26:03 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C6E962D58\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  1 Apr 2026 18:26:01 +0200 (CEST)",
            "from [100.93.44.16] (net-93-65-100-155.cust.vodafonedsl.it\n\t[93.65.100.155])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B6E96F04;\n\tWed,  1 Apr 2026 18:24:37 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"CUNNXT+M\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1775060677;\n\tbh=cPNFG01nfL/fFep4yGdJzWBDfo5rH8weIzKgIeOBJvw=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=CUNNXT+MMz5NXgJLqVOK9QuGllxDn+d8azRg3vfk6zaX+LyHzcM03G9+X9AkDBvgW\n\tgmymDndMQTwpEV1xcjBWBkW5/TFTNKmWTRgkqDxKrbhlmbn1B7QFxoJij2wldw9f3N\n\tn5y37u+4EID2Fp50VqHBahpuPc/ZdbydIuXWfNZE=",
        "From": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "Date": "Wed, 01 Apr 2026 18:25:50 +0200",
        "Subject": "[PATCH v8 1/8] libcamera: mali-c55: Add RZG2LCRU class",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "7bit",
        "Message-Id": "<20260401-mali-cru-v8-1-44c48f990e28@ideasonboard.com>",
        "References": "<20260401-mali-cru-v8-0-44c48f990e28@ideasonboard.com>",
        "In-Reply-To": "<20260401-mali-cru-v8-0-44c48f990e28@ideasonboard.com>",
        "To": "Daniel Scally <dan.scally@ideasonboard.com>, \n\tlibcamera-devel@lists.libcamera.org",
        "Cc": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "X-Mailer": "b4 0.14.3",
        "X-Developer-Signature": "v=1; a=openpgp-sha256; l=9802;\n\ti=jacopo.mondi@ideasonboard.com; h=from:subject:message-id;\n\tbh=l/27g48AuepEqwXR256i1nph+XEQELQu6hC3lLzVaV8=;\n\tb=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBpzUcW7ZWVEYc0JN0SANbw6xKAHKUvJcVZY9e1d\n\tAa9oMPi1+qJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCac1HFgAKCRByNAaPFqFW\n\tPL9BEADDdhSMwSqANi/cBqxP34bMHAZgz+lkargT6PABTjmsM61yQOwrwNxTWZ+i4wB6Y1RjQQl\n\tMq0V5VPdoZj8+55pTOrcgkPv34G55X+nYr1ZwGnqhD1JH3/cBBID9x6rISF7uRNs6Qw/of2MbpZ\n\tRwkliTyKfCQp7JFTOm8/+6r6bgYatRYVT92d9LZPkt65lzeJgfD6hLKhuYU4BXbqPwmaz3hTznz\n\tVW2MIfQ48dkcwtqdjBP4v5PdygS60RUXj9oNvrt0v5o83ab6FF3P/4W7sT8imslwSUHWvkB98jJ\n\tHu3W/D3Zn9beDKwKL4numa2zdMAUy8V/eS6KsI9v7PHSEHovtyIY/1bqLRvI+SXau+K6eh1jCBl\n\tdG7NxdNS53H5FrhlOf6AHVj/m3Ue5YNbfy/2oMzuTDsbvodEHa92IjA2FJa1+T510RLWYctvTH9\n\tCyCsghDUPJGRVQSFZYfDnVdgmDDqwmi4H/Vctk1bDvRj0+5zXg2KeWAHAh8/N+/AylJsnk6mMFg\n\tf1hLCGD0MYEygvmYbXFQKb+KAHhnFwc12vniBFQjphtSjuHGtvjaKV+goz4hHu9P/nMu6e2GF4n\n\ttvRfp3EejVrhG0rAd7Ds9Q7gKHkoIXZD7y+a15M++UfUaKso6BVyP/oS9q0aU1yq/cuAhXobLUm\n\tL6NtPtyYS3pGqog==",
        "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 | 253 ++++++++++++++++++++++++++\n src/libcamera/pipeline/mali-c55/rzg2l-cru.h   |  70 +++++++\n 3 files changed, 325 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..9cb7cc3f10c6\n--- /dev/null\n+++ b/src/libcamera/pipeline/mali-c55/rzg2l-cru.cpp\n@@ -0,0 +1,253 @@\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_.back();\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_back();\n+\tbuffer->_d()->setRequest(request);\n+\n+\treturn buffer;\n+}\n+\n+void RZG2LCRU::returnBuffer(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_back(buffer);\n+}\n+\n+int RZG2LCRU::start(unsigned int bufferCount)\n+{\n+\tint ret = output_->exportBuffers(bufferCount, &buffers_);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tutils::scope_exit bufferGuard([&] { freeBuffers(); });\n+\n+\tret = output_->importBuffers(bufferCount);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tfor (std::unique_ptr<FrameBuffer> &buffer : buffers_)\n+\t\tavailableBuffers_.push_back(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+\treturn output_->streamOff();\n+}\n+\n+int RZG2LCRU::freeBuffers()\n+{\n+\tavailableBuffers_.clear();\n+\tbuffers_.clear();\n+\n+\treturn output_->releaseBuffers();\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..8bd4c027adda\n--- /dev/null\n+++ b/src/libcamera/pipeline/mali-c55/rzg2l-cru.h\n@@ -0,0 +1,70 @@\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 <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+\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+\tV4L2VideoDevice *output() { return output_.get(); }\n+\n+\tint configure(V4L2SubdeviceFormat *subdevFormat, V4L2DeviceFormat *inputFormat);\n+\tFrameBuffer *queueBuffer(Request *request);\n+\tvoid returnBuffer(FrameBuffer *buffer);\n+\tint freeBuffers();\n+\n+\tint start(unsigned int bufferCount);\n+\tint stop();\n+\n+private:\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::vector<FrameBuffer *> availableBuffers_;\n+\n+\tstd::vector<Size> csi2Sizes_;\n+\tSize csi2Resolution_;\n+};\n+\n+} /* namespace libcamera */\n",
    "prefixes": [
        "v8",
        "1/8"
    ]
}