{"id":846,"url":"https://patchwork.libcamera.org/api/patches/846/?format=json","web_url":"https://patchwork.libcamera.org/patch/846/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20190402162134.3894-5-jacopo@jmondi.org>","date":"2019-04-02T16:21:26","name":"[libcamera-devel,v6,04/12] libcamera: ipu3: Create ImgUDevice class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"b96fac0fdfb634af1be6a3dc8e3844f6a2d6016c","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/846/mbox/","series":[{"id":229,"url":"https://patchwork.libcamera.org/api/series/229/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=229","date":"2019-04-02T16:21:22","name":"libcamera: ipu3: Add ImgU support","version":6,"mbox":"https://patchwork.libcamera.org/series/229/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/846/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/846/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9B2416110E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Apr 2019 18:20:57 +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 relay7-d.mail.gandi.net (Postfix) with ESMTPSA id B23DE20004;\n\tTue,  2 Apr 2019 16:20:56 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  2 Apr 2019 18:21:26 +0200","Message-Id":"<20190402162134.3894-5-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190402162134.3894-1-jacopo@jmondi.org>","References":"<20190402162134.3894-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v6 04/12] 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":"Tue, 02 Apr 2019 16:20:57 -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 1e315048738b..53e6b3b461a1 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -42,6 +42,43 @@ static int mediaBusToCIO2Format(unsigned int code)\n \t}\n }\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@@ -102,6 +139,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@@ -112,8 +150,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@@ -304,6 +344,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@@ -359,36 +401,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@@ -407,6 +481,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@@ -417,6 +493,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 has been verified by the match()\n+\t * function, no need to check for newly created video devices\n+\t * 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","v6","04/12"]}