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_;