[{"id":4732,"web_url":"https://patchwork.libcamera.org/comment/4732/","msgid":"<20200503013108.GH3012491@oden.dyn.berto.se>","date":"2020-05-03T01:31:08","subject":"Re: [libcamera-devel] [PATCH v1.1 3/3] libcamera: camera_sensor:\n\tPrepare for multi-subdev camera sensors","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your patch.\n\nOn 2020-05-03 01:45:40 +0300, Laurent Pinchart wrote:\n> While most camera sensors are exposed to userspace as a single subdev,\n> this is not always the case. A notable exception is the smiapp driver,\n> which exposes two or three subdevs. The subdev at the output of the\n> camera sensor will thus have more than one pad. Prepare for this by\n> removing the single-pad restriction, and locating the source pad\n> dynamically.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n:-O\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n> Changes since v1:\n> \n> - Correctly test pad direction in init()\n> ---\n>  src/libcamera/camera_sensor.cpp       | 23 ++++++++++++++---------\n>  src/libcamera/include/camera_sensor.h |  2 ++\n>  2 files changed, 16 insertions(+), 9 deletions(-)\n> \n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index d6a823f4d7cd..4154700a19b5 100644\n> --- a/src/libcamera/camera_sensor.cpp\n> +++ b/src/libcamera/camera_sensor.cpp\n> @@ -131,7 +131,7 @@ LOG_DEFINE_CATEGORY(CameraSensor);\n>   * Once constructed the instance must be initialized with init().\n>   */\n>  CameraSensor::CameraSensor(const MediaEntity *entity)\n> -\t: entity_(entity), properties_(properties::properties)\n> +\t: entity_(entity), pad_(UINT_MAX), properties_(properties::properties)\n>  {\n>  }\n>  \n> @@ -152,9 +152,14 @@ CameraSensor::~CameraSensor()\n>   */\n>  int CameraSensor::init()\n>  {\n> -\tint ret;\n> +\tfor (const MediaPad *pad : entity_->pads()) {\n> +\t\tif (pad->flags() & MEDIA_PAD_FL_SOURCE) {\n> +\t\t\tpad_ = pad->index();\n> +\t\t\tbreak;\n> +\t\t}\n> +\t}\n>  \n> -\tif (entity_->pads().size() != 1) {\n> +\tif (pad_ == UINT_MAX) {\n>  \t\tLOG(CameraSensor, Error)\n>  \t\t\t<< \"Sensors with more than one pad are not supported\";\n>  \t\treturn -EINVAL;\n> @@ -197,7 +202,7 @@ int CameraSensor::init()\n>  \n>  \t/* Create and open the subdev. */\n>  \tsubdev_ = std::make_unique<V4L2Subdevice>(entity_);\n> -\tret = subdev_->open();\n> +\tint ret = subdev_->open();\n>  \tif (ret < 0)\n>  \t\treturn ret;\n>  \n> @@ -241,7 +246,7 @@ int CameraSensor::init()\n>  \tproperties_.set(properties::Rotation, propertyValue);\n>  \n>  \t/* Enumerate and cache media bus codes and sizes. */\n> -\tconst ImageFormats formats = subdev_->formats(0);\n> +\tconst ImageFormats formats = subdev_->formats(pad_);\n>  \tif (formats.isEmpty()) {\n>  \t\tLOG(CameraSensor, Error) << \"No image format found\";\n>  \t\treturn -EINVAL;\n> @@ -405,7 +410,7 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &mbu\n>   */\n>  int CameraSensor::setFormat(V4L2SubdeviceFormat *format)\n>  {\n> -\treturn subdev_->setFormat(0, format);\n> +\treturn subdev_->setFormat(pad_, format);\n>  }\n>  \n>  /**\n> @@ -489,7 +494,7 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const\n>  \n>  \t/* Get the active area size. */\n>  \tRectangle rect = {};\n> -\tint ret = subdev_->getSelection(0, V4L2_SEL_TGT_CROP_DEFAULT, &rect);\n> +\tint ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_DEFAULT, &rect);\n>  \tif (ret) {\n>  \t\tLOG(CameraSensor, Error)\n>  \t\t\t<< \"Failed to construct camera sensor info: \"\n> @@ -500,7 +505,7 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const\n>  \tinfo->activeAreaSize = { rect.width, rect.height };\n>  \n>  \t/* It's mandatory for the subdevice to report its crop rectangle. */\n> -\tret = subdev_->getSelection(0, V4L2_SEL_TGT_CROP, &info->analogCrop);\n> +\tret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP, &info->analogCrop);\n>  \tif (ret) {\n>  \t\tLOG(CameraSensor, Error)\n>  \t\t\t<< \"Failed to construct camera sensor info: \"\n> @@ -510,7 +515,7 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const\n>  \n>  \t/* The bit depth and image size depend on the currently applied format. */\n>  \tV4L2SubdeviceFormat format{};\n> -\tret = subdev_->getFormat(0, &format);\n> +\tret = subdev_->getFormat(pad_, &format);\n>  \tif (ret)\n>  \t\treturn ret;\n>  \tinfo->bitsPerPixel = format.bitsPerPixel();\n> diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\n> index 92cd90353e72..24993b74148f 100644\n> --- a/src/libcamera/include/camera_sensor.h\n> +++ b/src/libcamera/include/camera_sensor.h\n> @@ -70,6 +70,8 @@ protected:\n>  private:\n>  \tconst MediaEntity *entity_;\n>  \tstd::unique_ptr<V4L2Subdevice> subdev_;\n> +\tunsigned int pad_;\n> +\n>  \tstd::string model_;\n>  \n>  \tstd::vector<unsigned int> mbusCodes_;\n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x141.google.com (mail-lf1-x141.google.com\n\t[IPv6:2a00:1450:4864:20::141])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D4EA5603F0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  3 May 2020 03:31:09 +0200 (CEST)","by mail-lf1-x141.google.com with SMTP id a4so322069lfh.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 02 May 2020 18:31:09 -0700 (PDT)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\tw21sm4855337lji.26.2020.05.02.18.31.08\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSat, 02 May 2020 18:31:08 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com header.b=\"Af8UatnD\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=+zxWK7CCrSJC7itpSJOnVh8itr48EnqLaQZCAY59FdQ=;\n\tb=Af8UatnDfaxhq0JrCdBPHFxZogY6h6hBGDDqfnIOJmxi/clSDo5D8EX50oqumI+HFE\n\tkYhSf5dppu41yBMBDkDloPUtCC6qzenhs2vs7S42jrXBsEPieuOX+vULVnKT8aLJCMGk\n\tho9nGz31VSLgNGgRYE1ooF/OQ7IBi5vCh2C3ON11atOT8GVz6NIgz3zr1SpG3WoAUmZ7\n\tEB+7D+3TLudm1Cn5ZZIgE6nKlSBm/96LMs/oMVNOyQyUrZ8t1IkzMCiIv4RvmPry63T1\n\tjosOb0NXOvEe6YImqKk/u9HEZKrFmGveF0b4HUDJZgWCPwPTWjgZklsd0IpQzH5Mfwm8\n\tlZIA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=+zxWK7CCrSJC7itpSJOnVh8itr48EnqLaQZCAY59FdQ=;\n\tb=dN4QJhlzJZ4frTWGW0DKZoho8kfH4NtIyTvyDyDERyVp2vOYoTrty3uG2sAnMcvPEC\n\tloopJRmPflaAxTW8itkW2S+LJHGCECpHFsaAcPzYy8PMsDOoxP2+Y4jHU7dgMONibrlA\n\t2jasP7j9GsnhXoKCO7zaUFDstdx3Aoo2L8d3Ls5pBhWwA+7FLIN7dd/Qi5QtvuxrCE7I\n\t91P28R4Ff5GfYynXatB72G0iIn8KY8hikOYgINWTESlqfwb9tXOZ/Qa0pLu4KGEXwCs3\n\tlLjlerntvu59Q831CvJtAIsZrlpx4vLTVSowkMSGkvOshpxy41owPDWSNovQKPbO/U5K\n\t0vqQ==","X-Gm-Message-State":"AGi0PuYn3YG3bvZgj/aeZ5gxBT6v17qNCN9CMBAgQM+3/8EZt/C3wSog\n\t8RL98NJEPL81hucVbXrWOW5AnSOww8k=","X-Google-Smtp-Source":"APiQypKvvM1VP4HuXhRLZStYpxNncTUSOxp5d4YfsV0h/yWk3pv86fikT6SsoUBEZ28RgZVAK95YVg==","X-Received":"by 2002:ac2:47ee:: with SMTP id b14mr2838812lfp.91.1588469469191;\n\tSat, 02 May 2020 18:31:09 -0700 (PDT)","Date":"Sun, 3 May 2020 03:31:08 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200503013108.GH3012491@oden.dyn.berto.se>","References":"<20200502135355.22757-4-laurent.pinchart@ideasonboard.com>\n\t<20200502224540.1725-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200502224540.1725-1-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v1.1 3/3] libcamera: camera_sensor:\n\tPrepare for multi-subdev camera sensors","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>","X-List-Received-Date":"Sun, 03 May 2020 01:31:10 -0000"}}]