{"id":891,"url":"https://patchwork.libcamera.org/api/1.1/patches/891/?format=json","web_url":"https://patchwork.libcamera.org/patch/891/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190403080148.11479-6-jacopo@jmondi.org>","date":"2019-04-03T08:01:40","name":"[libcamera-devel,v8,05/13] libcamera: ipu3: Create ImgUDevice class","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"1867e880d0e075fb98a773abbffef4b68901a866","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/891/mbox/","series":[{"id":235,"url":"https://patchwork.libcamera.org/api/1.1/series/235/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=235","date":"2019-04-03T08:01:35","name":"libcamera: ipu3: Add ImgU support","version":8,"mbox":"https://patchwork.libcamera.org/series/235/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/891/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/891/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BFE53611A7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Apr 2019 10:01:13 +0200 (CEST)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id E43836000E;\n\tWed,  3 Apr 2019 08:01:12 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  3 Apr 2019 10:01:40 +0200","Message-Id":"<20190403080148.11479-6-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190403080148.11479-1-jacopo@jmondi.org>","References":"<20190403080148.11479-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v8 05/13] libcamera: ipu3: Create\n\tImgUDevice class","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Wed, 03 Apr 2019 08:01:14 -0000"},"content":"Group ImgU components in a class associated with a camera at camera\nregistration time and provide an intialization method to create and open\nall video devices and subdevices of the ImgU.\n\nStatically assign imgu0 to the first camera and imgu1 to the second one\nand limit support to two cameras. This will have to be revised in the\nfuture.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 154 +++++++++++++++++++++++++--\n 1 file changed, 144 insertions(+), 10 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 1a1517268145..9274d35c8be8 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -26,6 +26,43 @@ namespace libcamera {\n \n LOG_DEFINE_CATEGORY(IPU3)\n \n+class ImgUDevice\n+{\n+public:\n+\tstatic constexpr unsigned int PAD_INPUT = 0;\n+\tstatic constexpr unsigned int PAD_OUTPUT = 2;\n+\tstatic constexpr unsigned int PAD_VF = 3;\n+\tstatic constexpr unsigned int PAD_STAT = 4;\n+\n+\tImgUDevice()\n+\t\t: imgu_(nullptr), input_(nullptr), output_(nullptr),\n+\t\t  viewfinder_(nullptr), stat_(nullptr)\n+\t{\n+\t}\n+\n+\t~ImgUDevice()\n+\t{\n+\t\tdelete imgu_;\n+\t\tdelete input_;\n+\t\tdelete output_;\n+\t\tdelete viewfinder_;\n+\t\tdelete stat_;\n+\t}\n+\n+\tint init(MediaDevice *media, unsigned int index);\n+\n+\tunsigned int index_;\n+\tstd::string name_;\n+\tMediaDevice *media_;\n+\n+\tV4L2Subdevice *imgu_;\n+\tV4L2Device *input_;\n+\tV4L2Device *output_;\n+\tV4L2Device *viewfinder_;\n+\tV4L2Device *stat_;\n+\t/* \\todo Add param video device for 3A tuning */\n+};\n+\n class CIO2Device\n {\n public:\n@@ -88,6 +125,7 @@ private:\n \t\tvoid bufferReady(Buffer *buffer);\n \n \t\tCIO2Device cio2_;\n+\t\tImgUDevice *imgu_;\n \n \t\tStream stream_;\n \t};\n@@ -98,8 +136,10 @@ private:\n \t\t\tPipelineHandler::cameraData(camera));\n \t}\n \n-\tvoid registerCameras();\n+\tint registerCameras();\n \n+\tImgUDevice imgu0_;\n+\tImgUDevice imgu1_;\n \tstd::shared_ptr<MediaDevice> cio2MediaDev_;\n \tstd::shared_ptr<MediaDevice> imguMediaDev_;\n };\n@@ -290,6 +330,8 @@ int PipelineHandlerIPU3::queueRequest(Camera *camera, Request *request)\n \n bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n {\n+\tint ret;\n+\n \tDeviceMatch cio2_dm(\"ipu3-cio2\");\n \tcio2_dm.add(\"ipu3-csi2 0\");\n \tcio2_dm.add(\"ipu3-cio2 0\");\n@@ -345,36 +387,68 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n \t\treturn false;\n \t}\n \n-\tregisterCameras();\n+\tif (imguMediaDev_->open()) {\n+\t\tcio2MediaDev_->close();\n+\t\treturn false;\n+\t}\n+\n+\tif (imguMediaDev_->disableLinks())\n+\t\tgoto error;\n \n+\tret = registerCameras();\n+\n+error:\n \tcio2MediaDev_->close();\n+\timguMediaDev_->close();\n \n-\treturn true;\n+\treturn ret == 0;\n }\n \n-/*\n- * Cameras are created associating an image sensor (represented by a\n- * media entity with function MEDIA_ENT_F_CAM_SENSOR) to one of the four\n- * CIO2 CSI-2 receivers.\n+/**\n+ * \\brief Initialise ImgU and CIO2 devices associated with cameras\n+ *\n+ * Initialise the two ImgU instances and create cameras with an associated\n+ * CIO2 device instance.\n+ *\n+ * \\return 0 on success or a negative error code for error or if no camera\n+ * has been created\n+ * \\retval -ENODEV no camera has been created\n  */\n-void PipelineHandlerIPU3::registerCameras()\n+int PipelineHandlerIPU3::registerCameras()\n {\n+\tint ret;\n+\n+\tret = imgu0_.init(imguMediaDev_.get(), 0);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = imgu1_.init(imguMediaDev_.get(), 1);\n+\tif (ret)\n+\t\treturn ret;\n+\n \t/*\n \t * For each CSI-2 receiver on the IPU3, create a Camera if an\n \t * image sensor is connected to it and the sensor can produce images\n \t * in a compatible format.\n \t */\n \tunsigned int numCameras = 0;\n-\tfor (unsigned int id = 0; id < 4; ++id) {\n+\tfor (unsigned int id = 0; id < 4 && numCameras < 2; ++id) {\n \t\tstd::unique_ptr<IPU3CameraData> data =\n \t\t\tutils::make_unique<IPU3CameraData>(this);\n \t\tstd::set<Stream *> streams{ &data->stream_ };\n \t\tCIO2Device *cio2 = &data->cio2_;\n \n-\t\tint ret = cio2->init(cio2MediaDev_.get(), id);\n+\t\tret = cio2->init(cio2MediaDev_.get(), id);\n \t\tif (ret)\n \t\t\tcontinue;\n \n+\t\t/**\n+\t\t * \\todo Dynamically assign ImgU devices; as of now, limit\n+\t\t * support to two cameras only, and assign imgu0 to the first\n+\t\t * one and imgu1 to the second.\n+\t\t */\n+\t\tdata->imgu_ = numCameras ? &imgu1_ : &imgu0_;\n+\n \t\tstd::string cameraName = cio2->sensor_->entityName() + \" \"\n \t\t\t\t       + std::to_string(id);\n \t\tstd::shared_ptr<Camera> camera = Camera::create(this,\n@@ -393,6 +467,8 @@ void PipelineHandlerIPU3::registerCameras()\n \n \t\tnumCameras++;\n \t}\n+\n+\treturn numCameras ? 0 : -ENODEV;\n }\n \n void PipelineHandlerIPU3::IPU3CameraData::bufferReady(Buffer *buffer)\n@@ -403,6 +479,64 @@ void PipelineHandlerIPU3::IPU3CameraData::bufferReady(Buffer *buffer)\n \tpipe_->completeRequest(camera_, request);\n }\n \n+/* -----------------------------------------------------------------------------\n+ * ImgU Device\n+ */\n+\n+/**\n+ * \\brief Initialize components of the ImgU instance\n+ * \\param[in] mediaDevice The ImgU instance media device\n+ * \\param[in] index The ImgU instance index\n+ *\n+ * Create and open the V4L2 devices and subdevices of the ImgU instance\n+ * with \\a index.\n+ *\n+ * In case of errors the created V4L2Device and V4L2Subdevice instances\n+ * are destroyed at pipeline handler delete time.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int ImgUDevice::init(MediaDevice *media, unsigned int index)\n+{\n+\tint ret;\n+\n+\tindex_ = index;\n+\tname_ = \"ipu3-imgu \" + std::to_string(index_);\n+\tmedia_ = media;\n+\n+\t/*\n+\t * The media entities presence in the media device has been verified\n+\t * by the match() function: no need to check for newly created\n+\t * video devices and subdevice validity here.\n+\t */\n+\timgu_ = V4L2Subdevice::fromEntityName(media, name_);\n+\tret = imgu_->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tinput_ = V4L2Device::fromEntityName(media, name_ + \" input\");\n+\tret = input_->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\toutput_ = V4L2Device::fromEntityName(media, name_ + \" output\");\n+\tret = output_->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tviewfinder_ = V4L2Device::fromEntityName(media, name_ + \" viewfinder\");\n+\tret = viewfinder_->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tstat_ = V4L2Device::fromEntityName(media, name_ + \" 3a stat\");\n+\tret = stat_->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\treturn 0;\n+}\n+\n /*------------------------------------------------------------------------------\n  * CIO2 Device\n  */\n","prefixes":["libcamera-devel","v8","05/13"]}