From patchwork Fri Sep 18 07:59:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 28315 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 23F1DBE175 for ; Fri, 18 Sep 2026 08:07:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 959CA68716; Fri, 18 Sep 2026 10:07:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="TFFPjSSl"; dkim-atps=neutral Received: from mail-wm2-x11.google.com (mail-wm2-x11.google.com [IPv6:2a00:1450:4864:31::11]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D6F426849B for ; Fri, 18 Sep 2026 10:07:40 +0200 (CEST) Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49fbca514f8so223705e9.2 for ; Fri, 18 Sep 2026 01:07:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1789718860; x=1790323660; 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=CUvh61Du7EjaxlpR8gCpn+9wnTbmCkWMDtxvQxb9LrM=; b=TFFPjSSljOJwQswmEwjyNGEnzPfOPDPPJdYYHdilGeL2FIA/vHvHo19H0gplckrJ43 oup3tGjZ+IfTmo0w2zs+xZEE0rmtn6qVBaabTu/rIFOptb7/FSVi1y2tLwF41n9H0umk 6jxXa8r3PjqA84IiZC2+6EgsfDRzwFiTf4W1oxFBFCPZD9ccw4yONnD77oNtjZWX48Ll wyEHk+vvQXb28UUNYy3iMDEGJhjRhxt/876yFHTp9lG8kuQwUAi3KmLWWR+vomOyPSOl t2Ix1F6iOMfW9Sv9AoEO96G3kbpOUJGwEDDNdL8AOUXKTrZBvZQQQ+lOvxBdqA0dXRih H1Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789718860; x=1790323660; 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=CUvh61Du7EjaxlpR8gCpn+9wnTbmCkWMDtxvQxb9LrM=; b=dVbY1zuM8dtVwn5fThCCYzFFz8eFszGGIUu8T81CAuLVB+11+1tPbR6D6cEq7ilkaF LRAPi6vA3c5GSoAnmcgXw4ClT4JHtR/FemHmKnPbfc1HFUKNB7z+O8Y/kIVymj/mba6Y 5cK9rkh92uGfFSviW3u8ks2fZKV98uzXeqXe21pBN8CAn8VdMclDsMmIb85Ez9gC6xo/ umCQ7kH+2dmlmJcfxXIDhSQAj6vnO+CMTMPf1veooTN/maAFULlf4j9Q1iQbEEXhaHt2 rnlVLOsTonvMEHBTdwD2xb9zobR4H/wB7xIwhpydN6fJ7Mf8InTsXLGnOvaLZLhsd35O yxLQ== X-Gm-Message-State: AFuF++mh0dIzjJFWb9hI1iJRDye8380RQIXpck8sqWym7lIwO8vT3xHi vW4kPdXsiAg9hBPqpS8op4GmsD9klVx6UpdcH2S3CSmOhxXP/Fsi3stu0NJ73+NL5Op5NGtx/FK QLjwGZWA= X-Gm-Gg: AYBFou0sd3tTNxHgVwLIGp+24T+8BqL20kByPOT4r0YpsLEWVXMa3I5Ow9Vw428aDwn 8CteqQ9Eygfe0skSpBrfpHYVQjKY3extJ89s75S0YQM9dp6aGbzPQqNP3q8yBIg4NXey2ufRxEi VSwwMFjpSCgzHSrJ+7J3UuB0Nquu4OO1gu0G9kZswSOoak9ggdKYosBt5lGtLvJHWH+ZY2ofxbU vVMTXq7F906/92NtflVOS5G9EkzWmSIr0HyrlLfC0xSQ1ay6qLrcCRMrwnX+x/7F8n0k7MVoM4c Sin8l37Ab1M51MusaEEUXH0lnUM81v4qe6ZVWsjgWt9ES9aMEDtbW5wVa/O7/3h1CBFLbyPe8Xm /BrVQ9DOc1aYHz3D2rmcpmDckWNS83gg5GUoO1PGIBsTn/Wm6asHitdT0hUX+ujBi7py/PpoBcp GtDcXrtl37TQBKWXCtkdQKkKy5jD7VKMjBsFWG++uu0sikptTZX6WSEeAlvm4IbBy5AEah+8Gey HaauB63PIloEBXRZMjBbaCuutRZ2FvYFhAEQtDhD9kNoWzGzI442+fvqDwDW777y7WWIYD5JjFf TMt/bPJsL+dYzvwR/mKbv4F10ud4SEna7YB/djMZxRX/7o+It50GorlGI7Rc0/FVNXIx4aTwmgg N8Vau0mQzhPhy2BOLbQI8HcEPmQwOG0X+N7Y= X-Received: by 2002:a05:600c:3b99:b0:49e:6683:d227 with SMTP id 5b1f17b1804b1-49fc7bbfe4bmr15815225e9.0.1789718859890; 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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 01:07:39 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck Subject: [RFC PATCH v1 03/20] libcamera: camera_sensor: Generate sensor IDs from a media entity Date: Fri, 18 Sep 2026 08:59:41 +0100 Message-ID: <20260918080734.1228227-4-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" Add a CameraSensorFactoryBase::generateId() helper that computes the sensor ID from a MediaEntity using sysfs without opening the device. Update CameraSensorLegacy and CameraSensorRaw to generate the sensor ID with this new helper. This change is in preparation for generating camera IDs at device enumeration time. Signed-off-by: Naushir Patuck --- include/libcamera/internal/camera_sensor.h | 1 + src/libcamera/sensor/camera_sensor.cpp | 27 +++++++++++++++++++ src/libcamera/sensor/camera_sensor_legacy.cpp | 6 ++--- src/libcamera/sensor/camera_sensor_raw.cpp | 3 +-- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 2a2f1f2c936d..17080ba32d37 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -92,6 +92,7 @@ public: virtual ~CameraSensorFactoryBase() = default; static std::unique_ptr create(MediaEntity *entity); + static std::string generateId(const MediaEntity *entity); const std::string &name() const { return name_; } int priority() const { return priority_; } diff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp index 580d3626216c..05654354ea1b 100644 --- a/src/libcamera/sensor/camera_sensor.cpp +++ b/src/libcamera/sensor/camera_sensor.cpp @@ -13,6 +13,7 @@ #include #include "libcamera/internal/media_object.h" +#include "libcamera/internal/sysfs.h" /** * \file camera_sensor.h @@ -474,6 +475,32 @@ std::unique_ptr CameraSensorFactoryBase::create(MediaEntity *entit return nullptr; } +/** + * \brief Generate a unique ID for a camera sensor + * \param[in] entity The media entity that corresponds to the camera sensor + * + * The ID is derived from the firmware description (device tree or ACPI) of the + * device associated with the sensor's media \a entity. It is unique and stable + * as long as the system firmware is not modified. Sensors that the firmware + * does not describe have no ID. + * + * The ID is computed from sysfs only, using the device numbers stored in the + * media graph, without opening or otherwise accessing the sensor device. + * + * \sa sysfs::firmwareNodePath() + * + * \return The sensor ID on success or an empty string on failure + */ +std::string CameraSensorFactoryBase::generateId(const MediaEntity *entity) +{ + const std::string devPath = sysfs::devicePath(entity->deviceMajor(), + entity->deviceMinor()); + if (devPath.empty()) + return {}; + + return sysfs::firmwareNodePath(devPath); +} + /** * \fn CameraSensorFactoryBase::name() * \brief Retrieve the camera sensor factory name diff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp index 83e2c2593215..99661f6fd02e 100644 --- a/src/libcamera/sensor/camera_sensor_legacy.cpp +++ b/src/libcamera/sensor/camera_sensor_legacy.cpp @@ -302,10 +302,8 @@ int CameraSensorLegacy::init() int CameraSensorLegacy::generateId() { - const std::string devPath = subdev_->devicePath(); - /* Try to get ID from firmware description. */ - id_ = sysfs::firmwareNodePath(devPath); + id_ = CameraSensorFactoryBase::generateId(entity_); if (!id_.empty()) return 0; @@ -315,6 +313,8 @@ int CameraSensorLegacy::generateId() * Verify it's a platform device and construct ID from the device path * and model of sensor. */ + const std::string devPath = sysfs::devicePath(entity_->deviceMajor(), + entity_->deviceMinor()); if (devPath.find("/sys/devices/platform/", 0) == 0) { id_ = devPath.substr(strlen("/sys/devices/")) + " " + model(); return 0; diff --git a/src/libcamera/sensor/camera_sensor_raw.cpp b/src/libcamera/sensor/camera_sensor_raw.cpp index 6344a34fc4c5..423b14af2890 100644 --- a/src/libcamera/sensor/camera_sensor_raw.cpp +++ b/src/libcamera/sensor/camera_sensor_raw.cpp @@ -37,7 +37,6 @@ #include "libcamera/internal/camera_sensor_properties.h" #include "libcamera/internal/formats.h" #include "libcamera/internal/media_device.h" -#include "libcamera/internal/sysfs.h" #include "libcamera/internal/v4l2_subdevice.h" namespace libcamera { @@ -571,7 +570,7 @@ int CameraSensorRaw::initProperties() properties_.set(properties::Model, utils::toAscii(model_)); /* Generate a unique ID for the sensor. */ - id_ = sysfs::firmwareNodePath(subdev_->devicePath()); + id_ = CameraSensorFactoryBase::generateId(entity_); if (id_.empty()) { LOG(CameraSensor, Error) << "Can't generate sensor ID"; return -EINVAL;