[{"id":21549,"web_url":"https://patchwork.libcamera.org/comment/21549/","msgid":"<163845572125.2211244.1002158626885491351@Monstersaurus>","date":"2021-12-02T14:35:21","subject":"Re: [libcamera-devel] [PATCH v7 2/5] libcamera: add model() for\n\tretriving model name in V4L2Subdevice","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"in $SUBJECT\n s/retriving/retrieving/\n\nQuoting Han-Lin Chen (2021-12-02 14:03:14)\n> CameraSensor retrives model name from media entity. Move the heuristics\n\ns/retrives/retrieves/\n\n\nCan be fixed while applying though.\n\n--\nKieran\n\n\n> method into V4L2Subdevice, so CameraLens can reuse the function.\n> \n> Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\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(-)\n> \n> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\n> index 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>         int setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n>                       Whence whence = ActiveFormat);\n>  \n> +       std::string model();\n> +\n>         static std::unique_ptr<V4L2Subdevice>\n>         fromEntityName(const MediaDevice *media, const std::string &entity);\n>  \n> @@ -75,6 +77,8 @@ private:\n>                                             unsigned int code);\n>  \n>         const MediaEntity *entity_;\n> +\n> +       std::string model_;\n>  };\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index 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> -       /*\n> -        * Extract the camera sensor model name from the media entity name.\n> -        *\n> -        * There is no standardized naming scheme for sensor entities in the\n> -        * Linux kernel at the moment.\n> -        *\n> -        * - The most common rule, used by I2C sensors, associates the model\n> -        *   name with the I2C bus number and address (e.g. 'imx219 0-0010').\n> -        *\n> -        * - When the sensor exposes multiple subdevs, the model name is\n> -        *   usually followed by a function name, as in the smiapp driver (e.g.\n> -        *   'jt8ew9 pixel_array 0-0010').\n> -        *\n> -        * - The vimc driver names its sensors 'Sensor A' and 'Sensor B'.\n> -        *\n> -        * Other schemes probably exist. As a best effort heuristic, use the\n> -        * part of the entity name before the first space if the name contains\n> -        * an I2C address, and use the full entity name otherwise.\n> -        */\n> -       std::string entityName = entity_->name();\n> -       std::regex i2cRegex{ \" [0-9]+-[0-9a-f]{4}\" };\n> -       std::smatch match;\n> -\n> -       if (std::regex_search(entityName, match, i2cRegex))\n> -               model_ = entityName.substr(0, entityName.find(' '));\n> -       else\n> -               model_ = entityName;\n> -\n> +       model_ = subdev_->model();\n>         properties_.set(properties::Model, utils::toAscii(model_));\n>  \n>         /* Generate a unique ID for the sensor. */\n> @@ -832,7 +804,7 @@ int CameraSensor::generateId()\n>         /*\n>          * Virtual sensors not described in firmware\n>          *\n> -        * Verify it's a platform device and construct ID from the deive path\n> +        * Verify it's a platform device and construct ID from the device path\n>          * and model of sensor.\n>          */\n>         if (devPath.find(\"/sys/devices/platform/\", 0) == 0) {\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index 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>         return 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> +       if (!model_.empty())\n> +               return model_;\n> +\n> +       /*\n> +        * Extract model name from the media entity name.\n> +        *\n> +        * There is no standardized naming scheme for sensor entities in the\n> +        * Linux kernel at the moment.\n> +        *\n> +        * - The most common rule, used by I2C sensors, associates the model\n> +        *   name with the I2C bus number and address (e.g. 'imx219 0-0010').\n> +        *\n> +        * - When the sensor exposes multiple subdevs, the model name is\n> +        *   usually followed by a function name, as in the smiapp driver (e.g.\n> +        *   'jt8ew9 pixel_array 0-0010').\n> +        *\n> +        * - The vimc driver names its sensors 'Sensor A' and 'Sensor B'.\n> +        *\n> +        * Other schemes probably exist. As a best effort heuristic, use the\n> +        * part of the entity name before the first space if the name contains\n> +        * an I2C address, and use the full entity name otherwise.\n> +        */\n> +       std::string entityName = entity_->name();\n> +       std::regex i2cRegex{ \" [0-9]+-[0-9a-f]{4}\" };\n> +       std::smatch match;\n> +\n> +       std::string model;\n> +       if (std::regex_search(entityName, match, i2cRegex))\n> +               model_ = entityName.substr(0, entityName.find(' '));\n> +       else\n> +               model_ = entityName;\n> +\n> +       return model_;\n> +}\n> +\n>  /**\n>   * \\brief Create a new video subdevice instance from \\a entity in media device\n>   * \\a media\n> -- \n> 2.34.1.400.ga245620fadb-goog\n>","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 6DB1DBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  2 Dec 2021 14:35:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B32C660836;\n\tThu,  2 Dec 2021 15:35:24 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BE3CF6011A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  2 Dec 2021 15:35:23 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 52B96D8C;\n\tThu,  2 Dec 2021 15:35:23 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Qvq7L6BJ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638455723;\n\tbh=oV9ig/tDzfxf4/2IktjS0/OQFMOSaPHhvqQqcYwlZg8=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=Qvq7L6BJapWMWCLYIrTmQenDEwqx7edFXPUV8JZ2qtJpyn/qlZOBU3/PqBhsEOSbQ\n\tLv3InvmzB1V45EEJfYp6xOAZdmjfDEOsCUg2TzMhaxuNJH3pJLUboIuv2gqvKYW4X4\n\tgQvd1H1C62KUMuPSkmwlo1E0k1KNUp7g6itmnm1E=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20211202140317.3118364-3-hanlinchen@chromium.org>","References":"<20211202140317.3118364-1-hanlinchen@chromium.org>\n\t<20211202140317.3118364-3-hanlinchen@chromium.org>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Han-Lin Chen <hanlinchen@chromium.org>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 02 Dec 2021 14:35:21 +0000","Message-ID":"<163845572125.2211244.1002158626885491351@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v7 2/5] 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>"}},{"id":21551,"web_url":"https://patchwork.libcamera.org/comment/21551/","msgid":"<c991f37b-b95d-79cf-ce9f-1fea3695f867@ideasonboard.com>","date":"2021-12-02T16:56:56","subject":"Re: [libcamera-devel] [PATCH v7 2/5] libcamera: add model() for\n\tretriving model name in V4L2Subdevice","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Han-Lin,\n\nThank you for the patch.\n\nOn 12/2/21 7:33 PM, Han-Lin Chen wrote:\n> CameraSensor retrives model name from media entity. Move the heuristics\n> method into V4L2Subdevice, so CameraLens can reuse the function.\n>\n> Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\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(-)\n>\n> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\n> index 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\nShould we const it?\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\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 */\n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index 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) {\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index 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","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 14315BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  2 Dec 2021 16:57:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3A4BF60592;\n\tThu,  2 Dec 2021 17:57:04 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8321C6011A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  2 Dec 2021 17:57:02 +0100 (CET)","from [192.168.1.106] (unknown [103.251.226.170])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5B43130C;\n\tThu,  2 Dec 2021 17:57:01 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ovuhduza\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638464222;\n\tbh=YMefdNLiZBQX9V3wfZLlE3QW5wqb9wgfjht+glz7nYo=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=ovuhduzakBB3vw+24kOmhttxM23JyujdWAYI9v2Q27ZnzBXn/N125eyFWkxttUr1S\n\tWaOP1Ku9qTEkfQsdxQe3JWJ2eODXAo2foNuSfhH9CxXJdKKv+Q9G4mReNalkavBa0Z\n\tpGWM8TKenFiywy1IqlPkjjHsUGrLjwU+1xk8FcxI=","To":"Han-Lin Chen <hanlinchen@chromium.org>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20211202140317.3118364-1-hanlinchen@chromium.org>\n\t<20211202140317.3118364-3-hanlinchen@chromium.org>","From":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<c991f37b-b95d-79cf-ce9f-1fea3695f867@ideasonboard.com>","Date":"Thu, 2 Dec 2021 22:26:56 +0530","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.10.2","MIME-Version":"1.0","In-Reply-To":"<20211202140317.3118364-3-hanlinchen@chromium.org>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Transfer-Encoding":"7bit","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH v7 2/5] 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>"}},{"id":21557,"web_url":"https://patchwork.libcamera.org/comment/21557/","msgid":"<Yalo4yNNbu9qro8c@pendragon.ideasonboard.com>","date":"2021-12-03T00:46:27","subject":"Re: [libcamera-devel] [PATCH v7 2/5] libcamera: add model() for\n\tretriving model name in V4L2Subdevice","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Han-lin,\n\nThank you for the patch.\n\nOn Thu, Dec 02, 2021 at 10:03:14PM +0800, Han-Lin Chen wrote:\n> CameraSensor retrives model name from media entity. Move the heuristics\n> method into V4L2Subdevice, so CameraLens can reuse the function.\n> \n> Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\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(-)\n> \n> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\n> index 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\nLet's make it\n\n\tconst std::string &model();\n\nto avoid copies.\n\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 */\n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index 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) {\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index 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\nAs there's no concept of model name in the V4L2 subdev API, I think this\nwould benefit for some more information.\n\n/**\n * \\brief Retrieve the model name of the device\n *\n * The model name allows identification of the specific device model. This can\n * be used to infer device characteristics, for instance to determine the\n * analogue gain model of a camera sensor based on the sensor model name.\n *\n * Neither the V4L2 API nor the Media Controller API expose an explicit model\n * name. This function implements a heuristics to extract the model name from\n * the subdevice's entity name. This should produce accurate results for\n * I2C-based devices. If the heuristics can't match a known naming pattern,\n * the function returns the full entity name.\n *\n * \\return The model name of the device\n */\n\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\nIt's not just sensors anymore, s/sensor/sensor or other/\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\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","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 78346BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Dec 2021 00:46:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 902FD607DE;\n\tFri,  3 Dec 2021 01:46:56 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5094160118\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Dec 2021 01:46:54 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B2E1AA59;\n\tFri,  3 Dec 2021 01:46:53 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"u6Z34+Gp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638492413;\n\tbh=7ajX0ngD3g4rxbplio+zSuZuHn8IrEtzu9iSLfGf1z4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=u6Z34+Gpr1CJuBln9gd5ynH2eisfxCUDYB9T3apjhecWDmChX9OdOQizLy/E1tITY\n\tRqJ6nYvkabQHymIdp0y8Av3YTP/ABwbndSkRaQtWkWagrAUC2WqwLMNrvPpQMr0zqF\n\tjMQpv10TtQ3Eb8rWGYyBmXHWVM4cLriJpX2j2xXA=","Date":"Fri, 3 Dec 2021 02:46:27 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Han-Lin Chen <hanlinchen@chromium.org>","Message-ID":"<Yalo4yNNbu9qro8c@pendragon.ideasonboard.com>","References":"<20211202140317.3118364-1-hanlinchen@chromium.org>\n\t<20211202140317.3118364-3-hanlinchen@chromium.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211202140317.3118364-3-hanlinchen@chromium.org>","Subject":"Re: [libcamera-devel] [PATCH v7 2/5] 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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]