From patchwork Fri Sep 18 07:59:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 28314 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 7BE73C3292 for ; Fri, 18 Sep 2026 08:07:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6BDF068707; Fri, 18 Sep 2026 10:07:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Gbp7xuFn"; dkim-atps=neutral Received: from mail-wr2-x10.google.com (mail-wr2-x10.google.com [IPv6:2a00:1450:4864:30::10]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BC74F686C6 for ; Fri, 18 Sep 2026 10:07:39 +0200 (CEST) Received: by mail-wr2-x10.google.com with SMTP id ffacd0b85a97d-485843116d2so53039f8f.1 for ; Fri, 18 Sep 2026 01:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1789718859; x=1790323659; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ZWhMINbuK4baItUqch+JY7Iq/0TW3FnKP6ajxJKtPzE=; b=Gbp7xuFnP9w7r/Ug/LaioYoc5DDugcBf3k0blu80IS8/dK273OssahePcNkRi6zD2v w4nn5mMxs7tsSYmYfRZTBxdykWNwH8pzHURA9cS8OEVCATw7XPD7e2vmXhIVKDqGcpwN khl4FODbLtEB1OCVax5rcnRHnZFH0tmYvZeODJSEhC8M5W9sVIJEQq4n1SrmmiS+Af/W 4UVMS8RMbczXAJcUG+ov4Qt8OTMFlSNL+pXCJTlvQF2NT6E2/V+tH5MB3IKHsZa6UcnZ 9r/nj8u/GRWqNJYYHDzibAB25J9fkcxdu6OVkqk8sNko6Ci+4ewmaYhIlejb3uMzHlsc dOlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789718859; x=1790323659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ZWhMINbuK4baItUqch+JY7Iq/0TW3FnKP6ajxJKtPzE=; b=fDVVa25rasIB1yshFrRqQ85ULhAb/HwkBUvsvFqhBR1aJYVWLTSaOWDNUbnFIXK9F4 NHSuXSfqjJgbKS4efmj01afM9YH3ExJNhlmLzcLiSPBUpz5Mtvx4/r7QsWzYrz3VUuP9 j6nTDXJKiOBHit1YW7/Ea/uAhBOl/cWLpGy+QWDwrqicQziXF1E3DjrXYXcIlGi/hzJM nS1pNgennzLGskklJ5sFFe5Y5dM3Q1fO1eW1hEY11f9zW8zt5fUEk1MWICsttqDlHVsE soFRIduXAjmbbMne0eBFnuxRv/5wz4h+7tVixCwCY1e2iIeDp43/L3sCEQsDLk42Jm30 EZuw== X-Gm-Message-State: AFuF++niK8wOdLAZtKrDDUlKcicqRqbIKFsnfKwU7cop5zwc5iKQq1T9 DPdsphEmIYxCcwFqELCJAPunRWmSAzxFJvISML8xJ9SoGPkuIGvFciNlYAR3mzsWJx3FBRdaUYc Idz/pIco= X-Gm-Gg: AYBFou1qRG97TG37Asiwf7cCOuj85fdzHQNB/ZkeGSGr2dQTFwSDYyHPZqnkYs7uZWj gIqNfG0y1E9JkQfLukXZQ6e8wguA0v0QQXCa5fqqsQwPyXJAYnGSD8PfMgbZLVw+RnB7rUv452S 4ZgMTp5dvZZvYBG3I8YzeklfKNWpyPyP/z3575VbwGtAiAgrjTJgBYtamXngkgXeRppvYiuiCB9 3H26OG2oDxXsIk1czDttkdRtf9Ahln1Mgtfuql7AFVjTiEl4DmpScFvrZQUNbtm9qzY/N6K4CbA ygly76c2tcAR3vwiFphTnZ26bKBH5KfCy4twa1oD0L4UEe1SaiRt0W8rC0pPvfkuDiuXYnlc4aC EoS0ccn3DakZhwMpmI8xJuogi7eSPEoePysUQVg1yLLXKGw+lJ4xBPstK7eYgvKmHKiDUrzI4xc vts+k+cnPWyF53jfQDCJuhvMUOCn3H09W2uOA0juzIIexk+7dDfhxQJDJ7AgHzqwWNO0wnfJGcP tDwxWsRcQnAoKLecZCckmwUyUEUE2F0lYZy2HIW22YQLRvXmSTk9Z5XRkP4pjGpVNXNuaG2CIMC mFeYzLJBI8rLTeVd4p0bXHKQCV1iQJPFpK1fJpYMUtXLEcB+3MxbAfFttZOJMWrIVnESiz5Yy81 zck2dS0hNeRCIbvxSHa++P8cOucQ58JhP0dg= X-Received: by 2002:a05:600c:83cd:b0:49e:6806:5712 with SMTP id 5b1f17b1804b1-49fc7ddb90emr11955315e9.2.1789718859239; Fri, 18 Sep 2026 01:07:39 -0700 (PDT) Received: from naush-dell.pitowers.org ([2a00:1098:3142:1f:45e3:df8b:2b18:6253]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-487203f077fsm1742230f8f.26.2026.09.18.01.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 01:07:38 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck Subject: [RFC PATCH v1 02/20] libcamera: v4l2_subdevice: Refactor the model name derivation Date: Fri, 18 Sep 2026 08:59:40 +0100 Message-ID: <20260918080734.1228227-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260918080734.1228227-1-naush@raspberrypi.com> References: <20260918080734.1228227-1-naush@raspberrypi.com> MIME-Version: 1.0 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" The heuristic that derives a model name in V4L2Subdevice::model() operates on the media entity name only, but is only reachable through a V4L2Subdevice instance. Move it to a static modelFromEntityName() helper and reimplement model() in terms of it, so that a model name can be derived from an entity name without instantiating a subdevice. Signed-off-by: Naushir Patuck --- include/libcamera/internal/v4l2_subdevice.h | 1 + src/libcamera/v4l2_subdevice.cpp | 60 ++++++++++++--------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index c37a82afa881..9593d4f45f64 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -160,6 +160,7 @@ public: int setRouting(Routing *routing, Whence whence = ActiveFormat); const std::string &model(); + static std::string modelFromEntityName(const std::string &entityName); const V4L2SubdeviceCapability &caps() const { return caps_; } static std::unique_ptr diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index a69de154e8bb..703c82d7f715 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -1702,38 +1702,46 @@ int V4L2Subdevice::setRouting(Routing *routing, Whence whence) */ const std::string &V4L2Subdevice::model() { - if (!model_.empty()) - return model_; + if (model_.empty()) + model_ = modelFromEntityName(entity_->name()); - /* - * 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. - */ - const std::string &entityName = entity_->name(); + return model_; +} + +/** + * \brief Derive a model name from a media entity name + * \param[in] entityName The name of the media entity + * + * 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. + * + * This function operates on the entity name alone, so that a model name can + * be derived without instantiating a subdevice. + * + * \return The model name + */ +std::string V4L2Subdevice::modelFromEntityName(const std::string &entityName) +{ static const 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; + return entityName.substr(0, entityName.find(' ')); - return model_; + return entityName; } /**