From patchwork Fri Dec 3 09:44:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 15004 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0E474BDB13 for ; Fri, 3 Dec 2021 09:44:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B5FCB607DE; Fri, 3 Dec 2021 10:44:38 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="mf1RH6W5"; dkim-atps=neutral Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C69D560710 for ; Fri, 3 Dec 2021 10:44:36 +0100 (CET) Received: by mail-pl1-x634.google.com with SMTP id k4so1710060plx.8 for ; Fri, 03 Dec 2021 01:44:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z4QqmdJUB/xMXj6lpUpiLyim0Gmrw/FIaSyOxP2tj9A=; b=mf1RH6W5fIYIwtmVmNp82txbSVDqJJpA5JioVjt75EHMsTKEqSHu9D9cI5E+dhfMl/ LJW9yn/rV8z/OuARNzZTFJcMziU5qwn+Cu+UiSAmsQV73+XBQBRUkS12cdV2x8z8RHGa +TGzxXAeZtKgHY764eZCrKTrTP0un1aX+8tPc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z4QqmdJUB/xMXj6lpUpiLyim0Gmrw/FIaSyOxP2tj9A=; b=y6UhhCN8WWQ2gfq6AHjuq++7IGKshw8wXZQmn7JGYPXL0dTPRYzhtSOx2THL1n8Kna nNoDYvReJ6H5Qob/puMTxFnLIReSm0q0XrKG3gFoVHtg/ZKXFjek43EguvXs5DpH6qEb CDQbm7JK6JL47hentJW78oU33yTAWb2+KCTh+FUTSYeoB46EWP5IHaAhCJYe1mWFj1Np bRdBlRYd/8zXAa1nUAUJeTMk9G2syH5sJU0Mk2olZiRylzWCSeWMzHNUpaNrbOnLW3sc VQSF3yaZvfGzn+viWWSBDjW7IlnhmrQVr51S1AHSEUi0vxb8Bs97cLTsORMjscKx/2wr SFgg== X-Gm-Message-State: AOAM5303kRiqHAVIgTtrcdtqfmpqHSmaemWXwAaiPiTXwfDNLE3+YPFe gX+97VHL4tpQapW01nUotP40QLRVSNKVow== X-Google-Smtp-Source: ABdhPJw1eXKrFHaDYGsgWR4mnCHTjY6MKhZueE/OhziRm2+SnwF70SSs/xYGwb5UP0opAJM2aDLL8Q== X-Received: by 2002:a17:90a:c286:: with SMTP id f6mr12913665pjt.45.1638524674770; Fri, 03 Dec 2021 01:44:34 -0800 (PST) Received: from localhost ([2401:fa00:1:10:110e:45d1:2f92:6647]) by smtp.gmail.com with UTF8SMTPSA id y6sm2817203pfi.154.2021.12.03.01.44.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Dec 2021 01:44:34 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Dec 2021 17:44:23 +0800 Message-Id: <20211203094426.101454-3-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.384.gca35af8252-goog In-Reply-To: <20211203094426.101454-1-hanlinchen@chromium.org> References: <20211203094426.101454-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 2/5] libcamera: add model() for retrieving model name in V4L2Subdevice 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" CameraSensor retrieves model name from media entity. Move the heuristics method into V4L2Subdevice, so CameraLens can reuse the function. Signed-off-by: Han-Lin Chen Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_subdevice.h | 4 ++ src/libcamera/camera_sensor.cpp | 32 +------------ src/libcamera/v4l2_subdevice.cpp | 53 +++++++++++++++++++++ 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 484fcfdd..a6873b67 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -61,6 +61,8 @@ public: int setFormat(unsigned int pad, V4L2SubdeviceFormat *format, Whence whence = ActiveFormat); + const std::string &model(); + static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); @@ -75,6 +77,8 @@ private: unsigned int code); const MediaEntity *entity_; + + std::string model_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 9fdb8c09..6151b32e 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -347,34 +346,7 @@ void CameraSensor::initTestPatternModes( int CameraSensor::initProperties() { - /* - * 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; - + model_ = subdev_->model(); properties_.set(properties::Model, utils::toAscii(model_)); /* Generate a unique ID for the sensor. */ @@ -832,7 +804,7 @@ int CameraSensor::generateId() /* * Virtual sensors not described in firmware * - * Verify it's a platform device and construct ID from the deive path + * Verify it's a platform device and construct ID from the device path * and model of sensor. */ if (devPath.find("/sys/devices/platform/", 0) == 0) { diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 023e2328..61e15b69 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -442,6 +443,58 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, return 0; } +/** + * \brief Retrieve the model name of the device + * + * The model name allows identification of the specific device model. This can + * be used to infer device characteristics, for instance to determine the + * analogue gain model of a camera sensor based on the sensor model name. + * + * Neither the V4L2 API nor the Media Controller API expose an explicit model + * name. This function implements a heuristics to extract the model name from + * the subdevice's entity name. This should produce accurate results for + * I2C-based devices. If the heuristics can't match a known naming pattern, + * the function returns the full entity name. + * + * \return The model name of the device + */ +const std::string &V4L2Subdevice::model() +{ + if (!model_.empty()) + return model_; + + /* + * Extract model name from the media entity name. + * + * There is no standardized naming scheme for sensor or other 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; + + std::string model; + if (std::regex_search(entityName, match, i2cRegex)) + model_ = entityName.substr(0, entityName.find(' ')); + else + model_ = entityName; + + return model_; +} + /** * \brief Create a new video subdevice instance from \a entity in media device * \a media