From patchwork Tue Apr 2 17:13:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 860 Return-Path: Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CE188610C5 for ; Tue, 2 Apr 2019 19:12:32 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 6114AFF80A; Tue, 2 Apr 2019 17:12:32 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Apr 2019 19:13:00 +0200 Message-Id: <20190402171309.6447-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190402171309.6447-1-jacopo@jmondi.org> References: <20190402171309.6447-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 04/13] libcamera: ipu3: Cache the sensor sizes X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Apr 2019 17:12:33 -0000 Cache the sensor maximum size and the media bus code used to produce it. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index a870b325f4b3..1e315048738b 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -8,6 +8,8 @@ #include #include +#include + #include #include #include @@ -24,6 +26,22 @@ namespace libcamera { LOG_DEFINE_CATEGORY(IPU3) +static int mediaBusToCIO2Format(unsigned int code) +{ + switch (code) { + case MEDIA_BUS_FMT_SBGGR10_1X10: + return V4L2_PIX_FMT_IPU3_SBGGR10; + case MEDIA_BUS_FMT_SGBRG10_1X10: + return V4L2_PIX_FMT_IPU3_SGBRG10; + case MEDIA_BUS_FMT_SGRBG10_1X10: + return V4L2_PIX_FMT_IPU3_SGRBG10; + case MEDIA_BUS_FMT_SRGGB10_1X10: + return V4L2_PIX_FMT_IPU3_SRGGB10; + default: + return -EINVAL; + } +} + class CIO2Device { public: @@ -44,6 +62,10 @@ public: V4L2Device *output_; V4L2Subdevice *csi2_; V4L2Subdevice *sensor_; + + /* Maximum sizes and the mbus code used to produce them. */ + unsigned int mbusCode_; + Size maxSize_; }; class PipelineHandlerIPU3 : public PipelineHandler @@ -442,6 +464,10 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index) return ret; /* + * Now that we're sure a sensor subdevice is connected, make sure it + * produces at least one image format compatible with CIO2 requirements + * and cache the camera maximum size. + * * \todo Define when to open and close video device nodes, as they * might impact on power consumption. */ @@ -450,6 +476,27 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index) if (ret) return ret; + for (auto it : sensor_->formats(0)) { + int mbusCode = mediaBusToCIO2Format(it.first); + if (mbusCode < 0) + continue; + + for (const SizeRange &size : it.second) { + if (maxSize_.width < size.maxWidth && + maxSize_.height < size.maxHeight) { + maxSize_.width = size.maxWidth; + maxSize_.height = size.maxHeight; + mbusCode_ = mbusCode; + } + } + } + if (maxSize_.width == 0) { + LOG(IPU3, Info) << "Sensor '" << sensor_->entityName() + << "' detected, but no supported image format " + << " found: skip camera creation"; + return -ENODEV; + } + csi2_ = new V4L2Subdevice(csi2Entity); ret = csi2_->open(); if (ret)