From patchwork Tue Nov 23 12:37:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14708 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 824BEBF415 for ; Tue, 23 Nov 2021 12:38:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3422B60394; Tue, 23 Nov 2021 13:38:13 +0100 (CET) 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="Jpc+N5kE"; dkim-atps=neutral Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9B0C86022F for ; Tue, 23 Nov 2021 13:38:10 +0100 (CET) Received: by mail-pl1-x62d.google.com with SMTP id o14so16957256plg.5 for ; Tue, 23 Nov 2021 04:38:10 -0800 (PST) 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=Wts5FaHlWgEzLQTSI6cOeLZs+nV4J2NqWI0WqjNYSw0=; b=Jpc+N5kEEAjvEjqBdv6M8m8udGp0Yh1GtoVksxOz/hjsVKYTfcYUbm34H41YQ7e/ok TPvnRQDwAa6xlbfFpkrwG0nVDNxIbiLQKciOpfzFBQYErPfn8JE3ktsMKz15hGCbtxYS yxF8RIltZarHtC1yd5kPGQ2u91Sruar4z4cec= 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=Wts5FaHlWgEzLQTSI6cOeLZs+nV4J2NqWI0WqjNYSw0=; b=Vgl5VrAvZnUFw9Yil+DULrrsKkPmbt5okIOo2HPw502xQNfGYf79rfU3wxl8cP21n7 3JUqgXsxwgzpNiGsTAiQPgvJny/H2ZUdnDxWW05GjRpCCMD4uEdD2tKhZSSPtkwARicf Uzqx/T7jubJsfKSC1b73CSqu8UIISSRpqbrWGDt9REVWtBaGeCBwfl9RFzacCpjUZxM1 kMuI9SJB/gI+YL5bJjtxxTJBXbXBq/3/EQ4MYdPhBo0yWHnHqDy1Xs+loJrOc4qldpg9 VE09dO4MbT7g/8jV86dnQCXSk8vdnCe8t2C/RlcCSShEM9x6d+8XTWhCim3CgyNGyizl YJrA== X-Gm-Message-State: AOAM5339tZ7Yydzp06yaQEL72oX2I07ohwrLo59Cp0z93eajeobkE6o0 NXHE1xrP82DtPh5i6NgLWAY+PQ2pl7d+lg== X-Google-Smtp-Source: ABdhPJwSd7bDO0VT8HpIVGKDTP47XCLN4FTTe/oknQvbGhl2ucYdUzu+pjEIzeFOBAPmVCkh2wAyLg== X-Received: by 2002:a17:90a:e60b:: with SMTP id j11mr2542259pjy.52.1637671088458; Tue, 23 Nov 2021 04:38:08 -0800 (PST) Received: from localhost ([2401:fa00:1:10:8aa3:febd:fadf:4199]) by smtp.gmail.com with UTF8SMTPSA id u22sm12985033pfi.187.2021.11.23.04.38.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Nov 2021 04:38:08 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Nov 2021 20:37:51 +0800 Message-Id: <20211123123751.3194696-5-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211123123751.3194696-1-hanlinchen@chromium.org> References: <20211123123751.3194696-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Allow IPA to apply controls to the lens device. Signed-off-by: Han-Lin Chen --- src/libcamera/pipeline/ipu3/cio2.cpp | 29 ++++++++++++++++++++++++++++ src/libcamera/pipeline/ipu3/cio2.h | 3 +++ src/libcamera/pipeline/ipu3/ipu3.cpp | 12 ++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 59dda56b..59b2f586 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,34 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index) return -EINVAL; } + /* + * \todo Read the lens model from the sensor itself or from a device + * database. For now use default values taken from ChromeOS database. + */ + 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"; + } + } + /* * \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 c65afdb2..6e04ec8f 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" @@ -1238,8 +1239,15 @@ 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); + + const ControlList lensControls = action.lensControls; + const ControlValue &focusValue = + lensControls.get(V4L2_CID_FOCUS_ABSOLUTE); + if (!focusValue.isNone() && cio2_.lens()) + cio2_.lens()->setFocusPostion(focusValue.get()); + break; } case ipa::ipu3::ActionParamFilled: {