From patchwork Thu Oct 28 10:03:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14503 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by patchwork.libcamera.org (Postfix) with ESMTPS id B424EBDB1C for ; Tue, 9 Nov 2021 19:29:41 +0000 (UTC) Received: from pendragon.ideasonboard.com (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B8211FD1 for ; Tue, 9 Nov 2021 20:29:40 +0100 (CET) Authentication-Results: perceval.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Zl7+Gub+"; dkim-atps=neutral Delivered-To: kbingham@ideasonboard.com Received: from perceval.ideasonboard.com by perceval.ideasonboard.com with LMTP id yFXLNHV1emFzBgAA4E0KoQ (envelope-from ) for ; Thu, 28 Oct 2021 12:03:33 +0200 Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by perceval.ideasonboard.com (Postfix) with ESMTPS id C2992513; Thu, 28 Oct 2021 12:03:33 +0200 (CEST) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 58ABE60103; Thu, 28 Oct 2021 12:03:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Zl7+Gub+"; dkim-atps=neutral Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6082F600B6 for ; Thu, 28 Oct 2021 12:03:30 +0200 (CEST) Received: by mail-pg1-x52f.google.com with SMTP id r28so5964027pga.0 for ; Thu, 28 Oct 2021 03:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v3TIv1B+NBMqukcEHLimuJfzih/lGpnEG+7CxByQeSE=; b=Zl7+Gub+W7rkKOp5L8m8GafmFpZUp2/Zjv8gSuVs3ZTW+chV1uuI74y+3ukO/QXCj0 +n05ir1eb4zojujB8S7YpSJqsbXTWt6oJlErieFRx3YdIY284eOE1tG8FqyC4CTMR2Em 3c64Smi6oipZr2gbpROwbFly1Vh/QtboBM/Nk= 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=v3TIv1B+NBMqukcEHLimuJfzih/lGpnEG+7CxByQeSE=; b=GhmdiX4MuFn6zhb3ovfTm9osLb4Chl0LtSuJNL2DxFLeuKVYRn1kaZtLDgyVCY8EMB SBikDRKvy7tqEyuqoa1uUpdQDUUE4GxNRZCQEgxGIzF0YKFfwozpxIDNSe1OdvNUqmmN FrgKJylG5kUDnAIuSLJ4gn4VkVGQuAYuWtGuwPRnE/4xG1q8ONQgcQVpsMmtexKwjKkj 2XU+0tRBH1XnsUgYw3qzKGNlsqen/HxHOABcx8Fsob6gG3yifwcHcT6oNURvOgL6ZkUA Qzjypci9SBDieRo04l1Jr7ww3U0YnAaVsEyfZg4hCXiGMFmGirQ0Y/NCRICITWbXSmM4 LkFw== X-Gm-Message-State: AOAM5338YSrTQllk/HzsINrlNbVXVLJXv+V7PSWs3biQ40oGd3F9Cx1u XygSim6YKIq7NDsBfZj7b1tzoE7668RyD4nb X-Google-Smtp-Source: =?utf-8?q?ABdhPJwLEFuGH4Yz6STOAS5u+Prpk5ko5q0XTjW7w?= =?utf-8?q?QdjDe+gIRhJbVphF2tj5zwFn1vtOBExR3OvuQ=3D=3D?= X-Received: by 2002:a63:a80c:: with SMTP id o12mr2447140pgf.422.1635415408736; Thu, 28 Oct 2021 03:03:28 -0700 (PDT) Received: from localhost ([2401:fa00:1:10:1bc:52e7:6df5:c7cf]) by smtp.gmail.com with UTF8SMTPSA id f4sm2241488pgn.93.2021.10.28.03.03.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Oct 2021 03:03:28 -0700 (PDT) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 18:03:19 +0800 Message-Id: <20211028100319.1097720-4-hanlinchen@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211028100319.1097720-1-hanlinchen@chromium.org> References: <20211028100319.1097720-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] ipu3: ipa: Allow IPA to apply controls to the lens device 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: , Cc: Han-Lin Chen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" X-TUID: 09URPkhGSLE3 Resent-From: Kieran Bingham Resent-To: parsemail@patchwork.libcamera.org Allow IPA to apply controls to the lens device. Signed-off-by: Han-Lin Chen --- meson.build | 6 ++++++ src/libcamera/pipeline/ipu3/cio2.cpp | 30 ++++++++++++++++++++++++++++ src/libcamera/pipeline/ipu3/cio2.h | 3 +++ src/libcamera/pipeline/ipu3/ipu3.cpp | 9 +++++++-- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 7892a9e3..2a4b68a2 100644 --- a/meson.build +++ b/meson.build @@ -108,6 +108,12 @@ if cc.has_argument('-Wno-c99-designator') ] endif +if get_option('android_platform') == 'cros' + common_arguments += [ + '-DOS_CHROMEOS', + ] +endif + c_arguments += common_arguments cpp_arguments += common_arguments diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 59dda56b..143e2a95 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -16,6 +16,7 @@ #include #include +#include "libcamera/internal/camera_lens.h" #include "libcamera/internal/camera_sensor.h" #include "libcamera/internal/framebuffer.h" #include "libcamera/internal/media_device.h" @@ -159,6 +160,35 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index) return -EINVAL; } +#if defined(OS_CHROMEOS) + /* + * \todo Read the lens model from the sensor itself or from a device database. + * For now use default values taken from ChromeOS. + */ + static std::unordered_map sensorLens = { + { "ov13858", "dw9714" }, + { "imx258", "dw9807" }, + { "imx355", "ak7375" } + }; + + auto it = sensorLens.find(sensor_->model()); + if (it != sensorLens.end()) { + const std::vector &entities = media->entities(); + for (auto ent: entities) { + if (ent->function() == MEDIA_ENT_F_LENS) { + lens_ = std::make_unique(ent); + ret = lens_->init(); + if (!ret && lens_->model() == it->second) { + break; + } + lens_.reset(); + } + if (!lens_) + LOG(IPU3, Warning) << "Lens device " << it->second << " not found"; + } + } +#endif + /* * \todo Define when to open and close video device nodes, as they * might impact on power consumption. diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h index ba8f0052..635566c8 100644 --- a/src/libcamera/pipeline/ipu3/cio2.h +++ b/src/libcamera/pipeline/ipu3/cio2.h @@ -18,6 +18,7 @@ namespace libcamera { +class CameraLens; class CameraSensor; class FrameBuffer; class MediaDevice; @@ -52,6 +53,7 @@ public: int stop(); CameraSensor *sensor() { return sensor_.get(); } + CameraLens *lens() { return lens_.get(); } const CameraSensor *sensor() const { return sensor_.get(); } FrameBuffer *queueBuffer(Request *request, FrameBuffer *rawBuffer); @@ -67,6 +69,7 @@ private: void cio2BufferReady(FrameBuffer *buffer); std::unique_ptr sensor_; + std::unique_ptr lens_; std::unique_ptr csi2_; std::unique_ptr output_; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 6a7f5b9a..36e93fb0 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -24,6 +24,7 @@ #include #include "libcamera/internal/camera.h" +#include "libcamera/internal/camera_lens.h" #include "libcamera/internal/camera_sensor.h" #include "libcamera/internal/delayed_controls.h" #include "libcamera/internal/device_enumerator.h" @@ -1250,8 +1251,12 @@ void IPU3CameraData::queueFrameAction(unsigned int id, { switch (action.op) { case ipa::ipu3::ActionSetSensorControls: { - const ControlList &controls = action.sensorControls; - delayedCtrls_->push(controls); + const ControlList &sensorControls = action.sensorControls; + delayedCtrls_->push(sensorControls); + if (cio2_.lens()) { + ControlList& lensControls = const_cast(action.lensControls); + cio2_.lens()->setControls(&lensControls); + } break; } case ipa::ipu3::ActionParamFilled: {