From patchwork Thu Mar 3 23:49:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 15411 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 8211CC3261 for ; Thu, 3 Mar 2022 23:50:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5639B61182; Fri, 4 Mar 2022 00:50:18 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Rm9zDpkt"; dkim-atps=neutral Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1FB0E61176 for ; Fri, 4 Mar 2022 00:50:15 +0100 (CET) Received: by mail-wr1-x433.google.com with SMTP id bk29so10163872wrb.4 for ; Thu, 03 Mar 2022 15:50:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=128dFyAg2PNBEd0fhzKmD9q8NNW0ZCeVDo9P+9Rq/4c=; b=Rm9zDpktK7Ias0l7VjZ7Bdz1EtYai+HxVR3h7S4v1daWHz3pJ2e7rdB6Z9fpyVeo5N 7CPU6oQYNpSBkRVHZY5kEKu1mmQQIypmQbBN+fzbLUKoNDks7oWB5Qw3gAOs29pzMACt BLvBl7AS6vAm1n/vcEMFAdfFqojriQXYFYnIzLkFCyRsf6WYvtIS6+Ckj1rLIZYAZvO7 IREdVkItqFB+P/e9Yw69gaJwoz106A9VCIu5/rXR5HQePHScmfELvS1KYUWdsfFHsUaD smNM0tRCSGcqjkHTpLXnSwESJi/35keqEstohSPJeEMygJtfno/BjDQmVjS0k93Jtzpm uqgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=128dFyAg2PNBEd0fhzKmD9q8NNW0ZCeVDo9P+9Rq/4c=; b=Ar0Z8y8lm5pdT52fxUaJqRSq9VEZx31o+tvIsHdZcAGOjIFBNXRcEcuiXwaERs7nQz qBiNBwxGyTgSx78jZp0xOh+0tHw7qtVFWK14ITMDUzMlCBiknsf1L8o/Zr11FUBFUGmV qXq1ExXDbKCpRNfQ5BkeO4JijWHVBSgXOsL5O4PDUcM625vwVLHKSipvDwefzaHpJS+Q 0mFIIh109jp/HVlOaG+S68Hf9NzxAowAicDYVZjjBiWG4eJGmRYb3Wlnv0EHpsUzImOR mvGFNC9y7++C1EIIOzgxqXZ/WtmK8DyedsN9OaA+qkaxzx5zaRS/Kh1hD5AoT0BMKgRK 8APw== X-Gm-Message-State: AOAM531fT3LSGlIuUjSnhIaLgMfNPWFdJUKXkHkfZhdokCn3jd01RIql a3tcO3nYG4PpPnOO9ArBX311SIEHXjPAgg== X-Google-Smtp-Source: ABdhPJwjffwdFySYzQElizKhQ2O5qmZhT79Kklg2SZ+wB09F4tvok3AOFQfVEb2A65av+t1pCAfXKA== X-Received: by 2002:a5d:584d:0:b0:1f0:48d9:692f with SMTP id i13-20020a5d584d000000b001f048d9692fmr5555003wrf.566.1646351414835; Thu, 03 Mar 2022 15:50:14 -0800 (PST) Received: from localhost.localdomain (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161]) by smtp.gmail.com with ESMTPSA id y4-20020adff144000000b001f022290737sm3079779wro.6.2022.03.03.15.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 15:50:14 -0800 (PST) From: Daniel Scally To: libcamera-devel@lists.libcamera.org Date: Thu, 3 Mar 2022 23:49:51 +0000 Message-Id: <20220303234956.1463551-5-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220303234956.1463551-1-djrscally@gmail.com> References: <20220303234956.1463551-1-djrscally@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 4/9] libcamera: camera_sensor: Discover VCMs through ancillary links 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 function to check for and initialise any VCMs linked to the CameraSensor's entity by ancillary links. This should initialise the lens_ member with the linked entity. Call the new function during CameraSensor::init(). Reviewed-by: Laurent Pinchart Signed-off-by: Daniel Scally Reviewed-by: Jean-Michel Hautbois --- Changes in v5: - Add a break to the default case Changes in v4: - Fixed typo (Laurent) Changes in v3: - Fixed some style errors - Replaced the flash case by printing the entity function in the default case. include/libcamera/internal/camera_sensor.h | 1 + src/libcamera/camera_sensor.cpp | 40 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 2fa11567..7fb4eded 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -81,6 +81,7 @@ private: void initTestPatternModes(); int initProperties(); int applyTestPatternMode(controls::draft::TestPatternModeEnum mode); + int discoverAncillaryDevices(); const MediaEntity *entity_; std::unique_ptr subdev_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 64f7f12c..8b4406fe 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -172,6 +172,10 @@ int CameraSensor::init() if (ret) return ret; + ret = discoverAncillaryDevices(); + if (ret) + return ret; + return applyTestPatternMode(controls::draft::TestPatternModeEnum::TestPatternModeOff); } @@ -443,6 +447,42 @@ int CameraSensor::initProperties() return 0; } +/** + * \brief Check for and initialise any ancillary devices + * + * Sensors sometimes have ancillary devices such as a Lens or Flash that could + * be linked to their MediaEntity by the kernel. Search for and handle any + * such device. + * + * \todo Handle MEDIA_ENT_F_FLASH too. + */ +int CameraSensor::discoverAncillaryDevices() +{ + int ret; + + for (MediaEntity *ancillary : entity_->ancillaryEntities()) { + switch (ancillary->function()) { + case MEDIA_ENT_F_LENS: + focusLens_ = std::make_unique(ancillary); + ret = focusLens_->init(); + if (ret) { + LOG(CameraSensor, Error) + << "CameraLens initialisation failed"; + return ret; + } + break; + + default: + LOG(CameraSensor, Warning) + << "Unsupported ancillary entity function " + << ancillary->function(); + break; + } + } + + return 0; +} + /** * \fn CameraSensor::model() * \brief Retrieve the sensor model name