{"id":14888,"url":"https://patchwork.libcamera.org/api/patches/14888/?format=json","web_url":"https://patchwork.libcamera.org/patch/14888/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211130105157.203856-3-hanlinchen@chromium.org>","date":"2021-11-30T10:51:55","name":"[libcamera-devel,v6,2/4] libcamera: add model() for retriving model name in V4L2Subdevice","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"98e08801727500a03b31fb65732a8bdd6da4c61e","submitter":{"id":98,"url":"https://patchwork.libcamera.org/api/people/98/?format=json","name":"Hanlin Chen","email":"hanlinchen@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14888/mbox/","series":[{"id":2782,"url":"https://patchwork.libcamera.org/api/series/2782/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2782","date":"2021-11-30T10:51:53","name":"Introduce Lens class and apply auto focus on ipu3","version":6,"mbox":"https://patchwork.libcamera.org/series/2782/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14888/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14888/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 584E8BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 10:52:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 14EF5605BA;\n\tTue, 30 Nov 2021 11:52:11 +0100 (CET)","from mail-pl1-x636.google.com (mail-pl1-x636.google.com\n\t[IPv6:2607:f8b0:4864:20::636])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D55F3605B4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 11:52:07 +0100 (CET)","by mail-pl1-x636.google.com with SMTP id b13so14624120plg.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 02:52:07 -0800 (PST)","from localhost ([2401:fa00:1:10:1659:cd3d:a00c:fa38])\n\tby smtp.gmail.com with UTF8SMTPSA id\n\tj16sm1651386pga.32.2021.11.30.02.52.05\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tTue, 30 Nov 2021 02:52:05 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"O6xCgaar\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=msPJW3r55nb+G45KIz3gMpKkpg99ieTA6FL6j5NXWwI=;\n\tb=O6xCgaarz5R0qcF9uAIb3U5E15RJHzT8nPbGdQQdeC8zpZZiTmsziu/BbwKbID/6pP\n\tDPmxh9F0rk5Yo0Ko6mHvzUf4/sk7WMEB8QaWQrN0rPCfutngwnBoqQ352OQ1fk6fYcJ0\n\tk+HUxfOqzoWQMNt5A/VyX0jV27nf4iaDrA1i4=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=msPJW3r55nb+G45KIz3gMpKkpg99ieTA6FL6j5NXWwI=;\n\tb=Alw+Y4qDLNa/U0aLjMh6BXsGFooRPKQFHMPrIz6MPylI6YUGUXLmoMd0OmsIIy/S3b\n\tsccan0Be8Y7SjH1TwKICQs6yXYWjKxbQV6VBp5ooPUbVjNS25/apBuaq3hVSkKEE5yFV\n\tidTo/EQuqNeyq5hDuKSUB9QiieLXEtrU0ucWcL58hjEKiz6xCzXCJkJ7cnm2YoH76J3v\n\tbDsndIzeynuVW57gaHkdp2YqaUAFc1VJbUK5W+ts5Gr/EiUJinwQivhvDeVXHnpFMFI1\n\tgpvigESPjLhm51udhSqoB87TNJnJNo7mW+4HFyL2uCqbSEQBD0EUJJzIue/IptSXYmze\n\tdacA==","X-Gm-Message-State":"AOAM532vGoMPTmwA7jbkOzep+UJG8tu8kmVb+4joad4LxzlnZjeWhpm/\n\tivwHrMgCIiDzY9pAmqtje+AnPB9JkzS6BQ==","X-Google-Smtp-Source":"ABdhPJw9H20HYgshJ1g+ofP4Z86tKuV0EwOn8RddUY4Ort478hj7jb2tyQYcH3966sdT8thpCNdiSg==","X-Received":"by 2002:a17:90b:3a85:: with SMTP id\n\tom5mr5154759pjb.28.1638269526201; \n\tTue, 30 Nov 2021 02:52:06 -0800 (PST)","From":"Han-Lin Chen <hanlinchen@chromium.org>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v6 2/4] libcamera: add model() for\n\tretriving model name in V4L2Subdevice","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"CameraSensor retrives model name from media entity. Move the heuristics\nmethod into V4L2Subdevice, so CameraLens can reuse the function.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n---\n include/libcamera/internal/v4l2_subdevice.h |  4 ++\n src/libcamera/camera_sensor.cpp             | 32 +---------------\n src/libcamera/v4l2_subdevice.cpp            | 42 +++++++++++++++++++++\n 3 files changed, 48 insertions(+), 30 deletions(-)","diff":"diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\nindex 97b89fb9..763c4dec 100644\n--- a/include/libcamera/internal/v4l2_subdevice.h\n+++ b/include/libcamera/internal/v4l2_subdevice.h\n@@ -61,6 +61,8 @@ public:\n \tint setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n \t\t      Whence whence = ActiveFormat);\n \n+\tstd::string model();\n+\n \tstatic std::unique_ptr<V4L2Subdevice>\n \tfromEntityName(const MediaDevice *media, const std::string &entity);\n \n@@ -75,6 +77,8 @@ private:\n \t\t\t\t\t    unsigned int code);\n \n \tconst MediaEntity *entity_;\n+\n+\tstd::string model_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex 9fdb8c09..6151b32e 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -13,7 +13,6 @@\n #include <iomanip>\n #include <limits.h>\n #include <math.h>\n-#include <regex>\n #include <string.h>\n \n #include <libcamera/property_ids.h>\n@@ -347,34 +346,7 @@ void CameraSensor::initTestPatternModes(\n \n int CameraSensor::initProperties()\n {\n-\t/*\n-\t * Extract the camera sensor model name from the media entity name.\n-\t *\n-\t * There is no standardized naming scheme for sensor entities in the\n-\t * Linux kernel at the moment.\n-\t *\n-\t * - The most common rule, used by I2C sensors, associates the model\n-\t *   name with the I2C bus number and address (e.g. 'imx219 0-0010').\n-\t *\n-\t * - When the sensor exposes multiple subdevs, the model name is\n-\t *   usually followed by a function name, as in the smiapp driver (e.g.\n-\t *   'jt8ew9 pixel_array 0-0010').\n-\t *\n-\t * - The vimc driver names its sensors 'Sensor A' and 'Sensor B'.\n-\t *\n-\t * Other schemes probably exist. As a best effort heuristic, use the\n-\t * part of the entity name before the first space if the name contains\n-\t * an I2C address, and use the full entity name otherwise.\n-\t */\n-\tstd::string entityName = entity_->name();\n-\tstd::regex i2cRegex{ \" [0-9]+-[0-9a-f]{4}\" };\n-\tstd::smatch match;\n-\n-\tif (std::regex_search(entityName, match, i2cRegex))\n-\t\tmodel_ = entityName.substr(0, entityName.find(' '));\n-\telse\n-\t\tmodel_ = entityName;\n-\n+\tmodel_ = subdev_->model();\n \tproperties_.set(properties::Model, utils::toAscii(model_));\n \n \t/* Generate a unique ID for the sensor. */\n@@ -832,7 +804,7 @@ int CameraSensor::generateId()\n \t/*\n \t * Virtual sensors not described in firmware\n \t *\n-\t * Verify it's a platform device and construct ID from the deive path\n+\t * Verify it's a platform device and construct ID from the device path\n \t * and model of sensor.\n \t */\n \tif (devPath.find(\"/sys/devices/platform/\", 0) == 0) {\ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex 023e2328..17ec9fdf 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -9,6 +9,7 @@\n \n #include <fcntl.h>\n #include <iomanip>\n+#include <regex>\n #include <sstream>\n #include <string.h>\n #include <sys/ioctl.h>\n@@ -442,6 +443,47 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n \treturn 0;\n }\n \n+/**\n+ * \\brief Retrieve the model name\n+ * \\return The model name of the device\n+ */\n+std::string V4L2Subdevice::model()\n+{\n+\tif (!model_.empty())\n+\t\treturn model_;\n+\n+\t/*\n+\t * Extract model name from the media entity name.\n+\t *\n+\t * There is no standardized naming scheme for sensor entities in the\n+\t * Linux kernel at the moment.\n+\t *\n+\t * - The most common rule, used by I2C sensors, associates the model\n+\t *   name with the I2C bus number and address (e.g. 'imx219 0-0010').\n+\t *\n+\t * - When the sensor exposes multiple subdevs, the model name is\n+\t *   usually followed by a function name, as in the smiapp driver (e.g.\n+\t *   'jt8ew9 pixel_array 0-0010').\n+\t *\n+\t * - The vimc driver names its sensors 'Sensor A' and 'Sensor B'.\n+\t *\n+\t * Other schemes probably exist. As a best effort heuristic, use the\n+\t * part of the entity name before the first space if the name contains\n+\t * an I2C address, and use the full entity name otherwise.\n+\t */\n+\tstd::string entityName = entity_->name();\n+\tstd::regex i2cRegex{ \" [0-9]+-[0-9a-f]{4}\" };\n+\tstd::smatch match;\n+\n+\tstd::string model;\n+\tif (std::regex_search(entityName, match, i2cRegex))\n+\t\tmodel_ = entityName.substr(0, entityName.find(' '));\n+\telse\n+\t\tmodel_ = entityName;\n+\n+\treturn model_;\n+}\n+\n /**\n  * \\brief Create a new video subdevice instance from \\a entity in media device\n  * \\a media\n","prefixes":["libcamera-devel","v6","2/4"]}