From patchwork Fri Nov 26 11:29:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14806 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 62EBEBF415 for ; Fri, 26 Nov 2021 11:29:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 197E660555; Fri, 26 Nov 2021 12:29:22 +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="I4Uphpqa"; dkim-atps=neutral Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 698096011E for ; Fri, 26 Nov 2021 12:29:18 +0100 (CET) Received: by mail-pl1-x629.google.com with SMTP id b11so6485532pld.12 for ; Fri, 26 Nov 2021 03:29:18 -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=Eo24BCzFTNfwI9ZVqRhR4vaLcTMu7CGBWJcis3efd/E=; b=I4UphpqaDnCcuQVHDP4g+e8I7aygtyL/mXrKz1MH73zEXaDcI8fGB5wKaprNgrwVAd ONreeBAeIyu0eXpWyDgC7AGcbtCIe85mgvIbNjg5IAIloSteq3U8dVkFJjOLru/9N6cA 6zaPRaPZqfyeaO/K2JvR3ImFdX7NpKOC8dYFI= 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=Eo24BCzFTNfwI9ZVqRhR4vaLcTMu7CGBWJcis3efd/E=; b=aVlDli0QrQFytO5Mtabo75Ax7ArvroHFfTvCA8LgOw6YGHEYZjdMCPAAcvu1TXlQLL /AFX+EFcqx01kK61mIQyJWeYsMEBMugUcSPdKhmYHUnW1YHLSNrD/pOFDzKEZ2NBVQGX 4R8LJtF9FawhwmvDVIVY0SigM+ShcI1ZPJz/lfGpUilrU3p/39ZuNPuRYBXLWGso7Lgy wsr9wxBdxpxlpo1loE1Is2ZIp8YkIal+lJa5ADSlZm9PF5nJav+auUuJMcu/kDFwLrxJ 9UHfOcZgbr3HJNiWmrwN3mujIcejqUbQuz0fg7yZa0tBpYKjO6fvCnnkzTOk/3PR2abh j6/Q== X-Gm-Message-State: AOAM532+X/tevS5P78RfCQZex0cYgBya/YWuSYZ2aY7rBhiUC3+VQ9cx 6oLKooCpCFmKv+Hz78Wh7joG4w0frlMH0A== X-Google-Smtp-Source: ABdhPJzhsbqKpYs7LEtMJhp9pNDT15yjK/wmGHCI5GwnUYaDrF1iE4xWkGj6Oj4S4LGl31O6ZfG9xw== X-Received: by 2002:a17:90a:909:: with SMTP id n9mr15067185pjn.1.1637926156454; Fri, 26 Nov 2021 03:29:16 -0800 (PST) Received: from localhost ([2401:fa00:1:10:a0de:e637:c058:6824]) by smtp.gmail.com with UTF8SMTPSA id c18sm7133362pfl.201.2021.11.26.03.29.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Nov 2021 03:29:16 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 19:29:01 +0800 Message-Id: <20211126112903.3276056-3-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211126112903.3276056-1-hanlinchen@chromium.org> References: <20211126112903.3276056-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 --- include/libcamera/internal/v4l2_subdevice.h | 5 +++ src/libcamera/camera_sensor.cpp | 13 ++----- src/libcamera/v4l2_subdevice.cpp | 40 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 97b89fb9..794c80c6 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() { return model_; } + static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); @@ -73,8 +75,11 @@ private: std::vector enumPadCodes(unsigned int pad); std::vector enumPadSizes(unsigned int pad, unsigned int code); + void generateModel(); const MediaEntity *entity_; + + std::string model_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 9fdb8c09..3659ff2d 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -366,15 +365,7 @@ int CameraSensor::initProperties() * 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 +823,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..0e194081 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -239,6 +240,7 @@ uint8_t V4L2SubdeviceFormat::bitsPerPixel() const V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity) : V4L2Device(entity->deviceNode()), entity_(entity) { + generateModel(); } V4L2Subdevice::~V4L2Subdevice() @@ -442,6 +444,12 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, return 0; } +/** + * \fn V4L2Subdevice::model() + * \brief Retrieve the model name + * \return The model name of the device + */ + /** * \brief Create a new video subdevice instance from \a entity in media device * \a media @@ -525,4 +533,36 @@ std::vector V4L2Subdevice::enumPadSizes(unsigned int pad, return sizes; } +void V4L2Subdevice::generateModel() +{ + /* + * 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; +} + } /* namespace libcamera */