From patchwork Tue Nov 30 10:51:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14888 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 584E8BDB13 for ; Tue, 30 Nov 2021 10:52:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 14EF5605BA; Tue, 30 Nov 2021 11:52:11 +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="O6xCgaar"; dkim-atps=neutral Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D55F3605B4 for ; Tue, 30 Nov 2021 11:52:07 +0100 (CET) Received: by mail-pl1-x636.google.com with SMTP id b13so14624120plg.2 for ; Tue, 30 Nov 2021 02:52:07 -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=msPJW3r55nb+G45KIz3gMpKkpg99ieTA6FL6j5NXWwI=; b=O6xCgaarz5R0qcF9uAIb3U5E15RJHzT8nPbGdQQdeC8zpZZiTmsziu/BbwKbID/6pP DPmxh9F0rk5Yo0Ko6mHvzUf4/sk7WMEB8QaWQrN0rPCfutngwnBoqQ352OQ1fk6fYcJ0 k+HUxfOqzoWQMNt5A/VyX0jV27nf4iaDrA1i4= 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=msPJW3r55nb+G45KIz3gMpKkpg99ieTA6FL6j5NXWwI=; b=Alw+Y4qDLNa/U0aLjMh6BXsGFooRPKQFHMPrIz6MPylI6YUGUXLmoMd0OmsIIy/S3b sccan0Be8Y7SjH1TwKICQs6yXYWjKxbQV6VBp5ooPUbVjNS25/apBuaq3hVSkKEE5yFV idTo/EQuqNeyq5hDuKSUB9QiieLXEtrU0ucWcL58hjEKiz6xCzXCJkJ7cnm2YoH76J3v bDsndIzeynuVW57gaHkdp2YqaUAFc1VJbUK5W+ts5Gr/EiUJinwQivhvDeVXHnpFMFI1 gpvigESPjLhm51udhSqoB87TNJnJNo7mW+4HFyL2uCqbSEQBD0EUJJzIue/IptSXYmze dacA== X-Gm-Message-State: AOAM532vGoMPTmwA7jbkOzep+UJG8tu8kmVb+4joad4LxzlnZjeWhpm/ ivwHrMgCIiDzY9pAmqtje+AnPB9JkzS6BQ== X-Google-Smtp-Source: ABdhPJw9H20HYgshJ1g+ofP4Z86tKuV0EwOn8RddUY4Ort478hj7jb2tyQYcH3966sdT8thpCNdiSg== X-Received: by 2002:a17:90b:3a85:: with SMTP id om5mr5154759pjb.28.1638269526201; Tue, 30 Nov 2021 02:52:06 -0800 (PST) Received: from localhost ([2401:fa00:1:10:1659:cd3d:a00c:fa38]) by smtp.gmail.com with UTF8SMTPSA id j16sm1651386pga.32.2021.11.30.02.52.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Nov 2021 02:52:05 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Nov 2021 18:51:55 +0800 Message-Id: <20211130105157.203856-3-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130105157.203856-1-hanlinchen@chromium.org> References: <20211130105157.203856-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 2/4] libcamera: add model() for retriving 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 retrives 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 --- include/libcamera/internal/v4l2_subdevice.h | 4 ++ src/libcamera/camera_sensor.cpp | 32 +--------------- src/libcamera/v4l2_subdevice.cpp | 42 +++++++++++++++++++++ 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 97b89fb9..763c4dec 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); + 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..17ec9fdf 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,47 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, return 0; } +/** + * \brief Retrieve the model name + * \return The model name of the device + */ +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 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