From patchwork Tue Apr 28 18:16:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3596 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A392160AF4 for ; Tue, 28 Apr 2020 20:16:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TCVSAzWS"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 18AF372C for ; Tue, 28 Apr 2020 20:16:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1588097814; bh=Mys000+TXrEX3rmHgdxpT7YRh+J5NPJZ/gtSK71fm1Q=; h=From:To:Subject:Date:From; b=TCVSAzWSReN3jhDkc0FB5w+Xyc5nXNN96Tg7HzgnEmsRkPyAjuD2XtHJ1G71sTOpm X7NmNWdcJzwIjan3njKWNtpqG1KbzssqBnv4U7FGz7c29U0IkEM48vScbbXmBT/VJE gDITI6foEFmZZOQwJzK0xPjpP+w/p63Kv1V4MKaE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Apr 2020 21:16:48 +0300 Message-Id: <20200428181650.5071-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.25.3 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/3] libcamera: camera_sensor: Add model() function 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: , X-List-Received-Date: Tue, 28 Apr 2020 18:16:54 -0000 Add a new model() function to the CameraSensor class to report the camera sensor model. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Changes since v1: - Improve heuristics to extract the sensor model - Cache the model in the CameraSensorClass --- src/libcamera/camera_sensor.cpp | 40 +++++++++++++++++++++++++++ src/libcamera/include/camera_sensor.h | 2 ++ 2 files changed, 42 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 70fd5feaae3b..4d1082105504 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -87,6 +88,35 @@ int CameraSensor::init() return -EINVAL; } + /* + * Extract the camera sensor model name from the media entity name. + * + * There is no standardized naming scheme for sensor entities in the + * Linux kernel at the moment. + * + * - The most common rule, used by I2C sensors, associates the model + * name with the I2C bus number and address (e.g. 'imx219 0-0010'). + * + * - When the sensor exposes multiple subdevs, the model name is + * usually followed by a function name, as in the smiapp driver (e.g. + * 'jt8ew9 pixel_array 0-0010'). + * + * - The vimc driver names its sensors 'Sensor A' and 'Sensor B'. + * + * Other schemes probably exist. As a best effort heuristic, use the + * part of the entity name before the first space if the name contains + * an I2C address, and use the full entity name otherwise. + */ + std::string entityName = entity_->name(); + std::regex i2cRegex{ " [0-9]+-[0-9a-f]{4}" }; + std::smatch match; + + if (std::regex_search(entityName, match, i2cRegex)) + model_ = entityName.substr(0, entityName.find(' ')); + else + model_ = entityName; + + /* Open the subdev. */ ret = subdev_->open(); if (ret < 0) return ret; @@ -163,6 +193,16 @@ int CameraSensor::init() return 0; } +/** + * \fn CameraSensor::model() + * \brief Retrieve the sensor model name + * + * The sensor model name is a free-formed string that uniquely identifies the + * sensor model. + * + * \return The sensor model name + */ + /** * \fn CameraSensor::entity() * \brief Retrieve the sensor media entity diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index 5277f7f7fe87..4524661be8ce 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -33,6 +33,7 @@ public: int init(); + const std::string &model() const { return model_; } const MediaEntity *entity() const { return entity_; } const std::vector &mbusCodes() const { return mbusCodes_; } const std::vector &sizes() const { return sizes_; } @@ -54,6 +55,7 @@ protected: private: const MediaEntity *entity_; V4L2Subdevice *subdev_; + std::string model_; std::vector mbusCodes_; std::vector sizes_; From patchwork Tue Apr 28 18:16:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3597 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DFA3A61AD4 for ; Tue, 28 Apr 2020 20:16:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cL3/z9ej"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6E1C097D for ; Tue, 28 Apr 2020 20:16:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1588097814; bh=zDqpu+qaIFcdL1zmm4Y6xSUVso4Rjm7wJOkl353Vw40=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cL3/z9ejXzwsdS5Xc/zBp9XLboMTEdYXM78YCXRkZn3vwWEoHfHp69o1Jyou7NjNR WtxcDpJAkfop2sVonwl5B08FZj3uHTagozwdC/Nhwuo4oh5OhoM++jL4PULwpMBkHw qDBwfFk1Jtb+5AiNtzCfX+A69CGhKAwo+q3KXFF0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Apr 2020 21:16:49 +0300 Message-Id: <20200428181650.5071-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.25.3 In-Reply-To: <20200428181650.5071-1-laurent.pinchart@ideasonboard.com> References: <20200428181650.5071-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/3] test: camera_sensor: Test the model() function 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: , X-List-Received-Date: Tue, 28 Apr 2020 18:16:55 -0000 Verify that the sensor model matches the expected value. The whole model extraction heuristic isn't fully tested as that would require being able to inject different entity names. It is still useful as an initial step. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- test/camera-sensor.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp index 27c190fe7ace..6069d668e495 100644 --- a/test/camera-sensor.cpp +++ b/test/camera-sensor.cpp @@ -61,6 +61,12 @@ protected: int run() { + if (sensor_->model() != "Sensor A") { + cerr << "Incorrect sensor model '" << sensor_->model() + << "'" << endl; + return TestFail; + } + const std::vector &codes = sensor_->mbusCodes(); auto iter = std::find(codes.begin(), codes.end(), MEDIA_BUS_FMT_ARGB8888_1X32); From patchwork Tue Apr 28 18:16:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3598 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 44B1561AD4 for ; Tue, 28 Apr 2020 20:16:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oBQs1PVl"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D0A8D72C for ; Tue, 28 Apr 2020 20:16:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1588097815; bh=R6XxqSQ/B86Zp9AbokCmgZ3DWFpwKDroRTx4E9C1PiY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oBQs1PVl02ecZST1rjwMlU3r4Lz2Gs4FbMjQjoG3YHX4vCzJCRPAodU2x8R30FIU3 HcAvkGyXlYBl220LQkiQKalVXz9fuOTthboOQJVLXueAJRpw+0UvrEaeBe9BP3Vk2k sEJQHL2i3kJjLQRb3AfCWn6O3m4x4N1xpb9+86og= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Apr 2020 21:16:50 +0300 Message-Id: <20200428181650.5071-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.25.3 In-Reply-To: <20200428181650.5071-1-laurent.pinchart@ideasonboard.com> References: <20200428181650.5071-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/3] libcamera: pipeline: vimc: Name camera based on sensor model 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: , X-List-Received-Date: Tue, 28 Apr 2020 18:16:56 -0000 Use the sensor model to create the camera name. The resulting name should still be "VIMC Sensor B", but prepares for support of Sensor A. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/vimc/vimc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index 6707c5a07ae6..ccfd7f86d158 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -394,9 +394,9 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) return false; /* Create and register the camera. */ + std::string name{ "VIMC " + data->sensor_->model() }; std::set streams{ &data->stream_ }; - std::shared_ptr camera = Camera::create(this, "VIMC Sensor B", - streams); + std::shared_ptr camera = Camera::create(this, name, streams); registerCamera(std::move(camera), std::move(data)); return true;