From patchwork Fri Mar 13 16:14:38 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 26295 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8E17DC32F0 for ; Fri, 13 Mar 2026 16:14:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 29AF762727; Fri, 13 Mar 2026 17:14:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DY0md4I7"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 59E3B6270C for ; Fri, 13 Mar 2026 17:14:50 +0100 (CET) Received: from [192.168.224.131] (unknown [37.159.122.93]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B462A1934; Fri, 13 Mar 2026 17:13:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1773418421; bh=APUyktNx0MVd4SoGkw/VTrDTc+XxoVQwTfbNIXCEEy4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DY0md4I73mYOqBKzEo77h/dqB6TW7C6j8kgtjl3RFnwdetJljIe7u+yYN81OW6D6A 7Vjg9mhUHMkCn4Zt+xE/Zdc0Cg1bUBXpmJl63ZeEDB+wlwK7qqQ+bqYCU2VO76P3Vn 9vbTMwevK5lDhz3puIlEvxToNPkAPqLzgkL+U1QI= From: Jacopo Mondi Date: Fri, 13 Mar 2026 17:14:38 +0100 Subject: [PATCH v5 4/7] libcamera: mali-c55: Register memory input camera MIME-Version: 1.0 Message-Id: <20260313-mali-cru-v5-4-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 , libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=9819; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=KOQwFbPgOiDmtCmZ7//v9C+mAaBkiNylRVHBHbip3zQ=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBptDfzCFn5VtPPGHQWM4Qc1RAbIvaiuhf6Ef7bx EmEgvuQAdOJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCabQ38wAKCRByNAaPFqFW PNFID/9ewLFuZPpkbErgjcIYRW2xX9zb0xylp1hmWomI6q9i2RR5oR0jobBQiIe7W8OsDBQy+hM DrP3s7vzRmiC2JtoSiGx0tPvlrLdB+CvouQpFcS0pe6VwIh4BWU389lVHygf4usc5Z3m9BCteVc 0WwliyLDAMkkcOMbJN1lJMqJOocnEIeCxp5em/IEnP/hFjxnQsNvQ4rwkCAZUUPK6+llFrjLvMZ rUjOv53FmtQWmTyVdoj5UZ5OgP1J20FKSst3duwFrkmWbe+Kbq5UUjyMxKF23k2Xrrqxtxp1Mob 1tkrV1hq7WRcWps3Jem2L/cs40nGIZkPYQLrDQTpgFT7oppPDbH0lMf1es62yqdZENGyW3WnwNS 3aXNw9HbMNOXCa8wprPM7nr45spkryiVuxTJw20B0Fknyzz9ddSizGXzQx20NuS11TpR/XIy6Rm IPWeiTAANMp9nkW4EdQJRBfeniReRXl5+iChHfVALdDO867vPk3BVRjw+wPpVib+k1EMW7P7o3e Qp0Z7xP9E5KyrmzpKanY8L1DIHGIgQVs7Aq70AERrVXL7xGlXphz58sM66JkmFEi7pIjD4kAz1e gytFfhyQfO1U7CQElkX8VqjyHYzKg5trvGdV42gDLZujHB2QbT6yzb/6Pje4A2p5nFv46lwKU5E tTmC2uHvfAFFbSw== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Daniel Scally Add support to Mali C55 pipeline handler for memory-to-memory camera mode. The Mali-C55, as integrated in the Renesas RZ/V2H(P) SoC, is fed with images saved to memory by the CRU unit and read on behalf of the ISP by the IVC. Update the pipeline handler's match() function to search for the CRU media entity necessary to register a memory input camera. Create and initialize a CameraData instance for the memory camera use case if a valid CRU is found and initialize the IVC components used to feed the ISP with images read from memory. Do not implement camera configuration for the time being to reuce the patch size. It will be provided in the following patches. Signed-off-by: Daniel Scally Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/mali-c55/mali-c55.cpp | 151 ++++++++++++++++++++++++--- 1 file changed, 134 insertions(+), 17 deletions(-) diff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp index 45e23ffd3841..5e93d66b01cd 100644 --- a/src/libcamera/pipeline/mali-c55/mali-c55.cpp +++ b/src/libcamera/pipeline/mali-c55/mali-c55.cpp @@ -44,6 +44,8 @@ #include "libcamera/internal/v4l2_subdevice.h" #include "libcamera/internal/v4l2_videodevice.h" +#include "rzg2l-cru.h" + namespace { bool isFormatRaw(const libcamera::PixelFormat &pixFmt) @@ -105,7 +107,12 @@ public: std::unique_ptr csi2_; std::unique_ptr sensor_; }; - using CameraType = std::variant; + + struct Memory { + std::unique_ptr cru_; + }; + + using CameraType = std::variant; MaliC55CameraData(PipelineHandler *pipe) : Camera::Private(pipe) @@ -116,6 +123,7 @@ public: int initTpg(MediaEntity *entity); int initInline(MediaEntity *entity); + int initMemory(MediaDevice *cruMedia); std::vector sizes(unsigned int mbusCode) const { @@ -125,6 +133,9 @@ public: }, [&](const Inline &in) -> std::vector { return in.sensor_->sizes(mbusCode); + }, + [&](const Memory &mem) -> std::vector { + return mem.cru_->sizes(); } }, input_); } @@ -137,6 +148,9 @@ public: }, [&](const Inline &in) -> V4L2Subdevice * { return in.sensor_->device(); + }, + [&](const Memory &mem) -> V4L2Subdevice * { + return mem.cru_->sensor()->device(); } }, input_); } @@ -150,6 +164,9 @@ public: }, [&](const Inline &in) -> CameraSensor * { return in.sensor_.get(); + }, + [&](const Memory &mem) -> CameraSensor * { + return mem.cru_->sensor(); } }, input_); } @@ -163,6 +180,9 @@ public: }, [&](const Inline &in) -> V4L2Subdevice * { return in.csi2_.get(); + }, + [&](const Memory &mem) -> V4L2Subdevice * { + return mem.cru_->csi2(); } }, input_); } @@ -175,10 +195,26 @@ public: }, [&](const Inline &in) -> Size { return in.sensor_->resolution(); + }, + [&](const Memory &mem) -> Size { + return mem.cru_->resolution(); } }, input_); } + RZG2LCRU *cru() const + { + return std::visit(utils::overloaded{ + [&](auto &) -> RZG2LCRU * { + ASSERT(false); + return nullptr; + }, + [&](const Memory &mem) -> RZG2LCRU * { + return mem.cru_.get(); + }, + }, input_); + } + int pixfmtToMbusCode(const PixelFormat &pixFmt) const; const PixelFormat &bestRawFormat() const; @@ -258,6 +294,21 @@ int MaliC55CameraData::initInline(MediaEntity *sensor) return 0; } +int MaliC55CameraData::initMemory(MediaDevice *cruMedia) +{ + Memory mem; + + mem.cru_ = std::make_unique(); + + int ret = mem.cru_->init(cruMedia); + if (ret) + return ret; + + input_.emplace(std::move(mem)); + + return 0; +} + std::vector MaliC55CameraData::Tpg::sizes(unsigned int mbusCode) const { V4L2Subdevice::Formats formats = sd_->formats(0); @@ -738,11 +789,15 @@ private: const std::string &name); bool registerTPGCamera(MediaLink *link); bool registerSensorCamera(MediaLink *link); + bool registerMemoryInputCamera(); std::shared_ptr media_; + std::shared_ptr cruMedia_; std::unique_ptr isp_; std::unique_ptr stats_; std::unique_ptr params_; + std::unique_ptr ivcSd_; + std::unique_ptr ivc_; std::vector> statsBuffers_; std::queue availableStatsBuffers_; @@ -993,6 +1048,9 @@ int PipelineHandlerMaliC55::configure(Camera *camera, const MediaEntity *csi2Entity = in.csi2_->entity(); return csi2Entity->getPadByIndex(1)->links()[0]->setEnabled(true); }, + [](MaliC55CameraData::Memory &) { + return 0; + } }, data->input_); if (ret) return ret; @@ -1018,6 +1076,9 @@ int PipelineHandlerMaliC55::configure(Camera *camera, return data->csi2()->getFormat(1, &subdevFormat); }, + [](MaliC55CameraData::Memory &) { + return 0; + } }, data->input_); if (ret) return ret; @@ -1691,6 +1752,34 @@ bool PipelineHandlerMaliC55::registerSensorCamera(MediaLink *ispLink) return true; } +bool PipelineHandlerMaliC55::registerMemoryInputCamera() +{ + std::unique_ptr data = + std::make_unique(this); + + int ret = data->initMemory(cruMedia_.get()); + if (ret) + return false; + + CameraSensor *sensor = data->sensor(); + data->properties_ = sensor->properties(); + + const CameraSensorProperties::SensorDelays &delays = sensor->sensorDelays(); + std::unordered_map params = { + { V4L2_CID_ANALOGUE_GAIN, { delays.gainDelay, false } }, + { V4L2_CID_EXPOSURE, { delays.exposureDelay, false } }, + }; + + data->delayedCtrls_ = + std::make_unique(sensor->device(), params); + isp_->frameStart.connect(data->delayedCtrls_.get(), + &DelayedControls::applyControls); + + ivc_->bufferReady.connect(data->cru(), &RZG2LCRU::cruReturnBuffer); + + return registerMaliCamera(std::move(data), sensor->device()->entity()->name()); +} + bool PipelineHandlerMaliC55::match(DeviceEnumerator *enumerator) { const MediaPad *ispSink; @@ -1700,14 +1789,14 @@ bool PipelineHandlerMaliC55::match(DeviceEnumerator *enumerator) * The TPG and the downscale pipe are both optional blocks and may not * be fitted. */ - DeviceMatch dm("mali-c55"); - dm.add("mali-c55 isp"); - dm.add("mali-c55 resizer fr"); - dm.add("mali-c55 fr"); - dm.add("mali-c55 3a stats"); - dm.add("mali-c55 3a params"); - - media_ = acquireMediaDevice(enumerator, dm); + DeviceMatch c55_dm("mali-c55"); + c55_dm.add("mali-c55 isp"); + c55_dm.add("mali-c55 resizer fr"); + c55_dm.add("mali-c55 fr"); + c55_dm.add("mali-c55 3a stats"); + c55_dm.add("mali-c55 3a params"); + + media_ = acquireMediaDevice(enumerator, c55_dm); if (!media_) return false; @@ -1767,6 +1856,25 @@ bool PipelineHandlerMaliC55::match(DeviceEnumerator *enumerator) stats_->bufferReady.connect(this, &PipelineHandlerMaliC55::statsBufferReady); params_->bufferReady.connect(this, &PipelineHandlerMaliC55::paramsBufferReady); + /* + * We also need to search for the rzg2l-cru CSI-2 receiver. If we find + * that then we need to work in memory input mode instead of the inline + * mode. The absence of this match is not necessarily a failure at this + * point...it depends on the media links that we investigate momentarily. + * + * This is a bit hacky, because there could be multiple of these media + * devices and we're just taking the first. We need modular pipelines to + * properly solve the issue. + */ + static const std::regex cruCsi2Regex("csi-[0-9a-f]{8}.csi2"); + static const std::regex cruIpRegex("cru-ip-[0-9a-f]{8}.cru[0-9]"); + + DeviceMatch cruDm("rzg2l_cru"); + cruDm.add(cruCsi2Regex); + cruDm.add(cruIpRegex); + cruDm.add("CRU output"); + cruMedia_ = acquireMediaDevice(enumerator, cruDm); + ispSink = isp_->entity()->getPadByIndex(0); if (!ispSink || ispSink->links().empty()) { LOG(MaliC55, Error) << "ISP sink pad error"; @@ -1780,13 +1888,6 @@ bool PipelineHandlerMaliC55::match(DeviceEnumerator *enumerator) * MEDIA_ENT_F_CAM_SENSOR - The test pattern generator * MEDIA_ENT_F_VID_IF_BRIDGE - A CSI-2 receiver * MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER - An input device - * - * The last one will be unsupported for now. The TPG is relatively easy, - * we just register a Camera for it. If we have a CSI-2 receiver we need - * to check its sink pad and register Cameras for anything connected to - * it (probably...there are some complex situations in which that might - * not be true but let's pretend they don't exist until we come across - * them) */ bool registered; for (MediaLink *link : ispSink->links()) { @@ -1806,7 +1907,23 @@ bool PipelineHandlerMaliC55::match(DeviceEnumerator *enumerator) break; case MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER: - LOG(MaliC55, Warning) << "Memory input not yet supported"; + if (!cruMedia_) + return false; + + ivcSd_ = V4L2Subdevice::fromEntityName(media_.get(), + "rzv2h ivc block"); + if (ivcSd_->open() < 0) + return false; + + ivc_ = V4L2VideoDevice::fromEntityName(media_.get(), + "rzv2h-ivc"); + if (ivc_->open() < 0) + return false; + + registered = registerMemoryInputCamera(); + if (!registered) + return registered; + break; default: LOG(MaliC55, Error) << "Unsupported entity function";