From patchwork Fri Jul 9 14:58:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12889 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 D72F5C3225 for ; Fri, 9 Jul 2021 14:58:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8919A68526; Fri, 9 Jul 2021 16:58:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="XYQdrjXj"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E010F68535 for ; Fri, 9 Jul 2021 16:58:34 +0200 (CEST) Received: by mail-wm1-x331.google.com with SMTP id j34so6494361wms.5 for ; Fri, 09 Jul 2021 07:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9Qm+sWatsYcAykyKyO/dDov0LMdnllNiYyhQV+ZFn1Y=; b=XYQdrjXjjn3mPM9gRuElruCgIgrqsGQ5cA4rab1CneXJgIey3sheJ5imy4jaJgDttR Im6GlufnmaA4cI+1+QjNtimoIZTgu5nYU3GqHfvUSDjWaUqkHtW8z5JhLCOqZrOiEp0O EaANmzxAzVa83RIYPnq8CEJ2XTZ1k+tTqn3aZKtF7Dl7mxBmb/5Rxb+FaXlL6Te7J0gO rU4eQqYsCdtOPvWqpvWH65Vt1WE0kKEBI143br2fhM2g4HywAe2nBHTSD4ZBUQF+Zavj d4NzEKDAor3AetQAAJpNlt4OvMczVwrf+YrIUkFbPPiAVLa1eS2VRTzGajTKiXxyVvvj fPKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9Qm+sWatsYcAykyKyO/dDov0LMdnllNiYyhQV+ZFn1Y=; b=dZapRvSNizHP1vmMOVd1+dh/4tyPKNpPtLhD8ubayTK2gCrgjZzXFulGwBRtwVjBeR ZaZyRQk5YTG1imCVO/wwhEcBLYOeqrzIewUgbF3ltwI4ZwLJjDhrJdEr0NcPseJFuZet IwoHvohkMeu/M8k8j68tphUmZmyUi4VKZhJwDcy4mvhnWudPNHW0jJq8yCLgkcBy6sNJ q/cKMWqj8v16ZfX4/aH+tmWynM8ltdg9VZEMA5nCkggKq92EYc96MpSat7yFixnWd+YF L1t64xZwWJ6w7hFPsdBOpD9KRbJa2NngEy5cC8y8FrI45mk4X1Y2h+rPWdPqzmJC6DuU cs3Q== X-Gm-Message-State: AOAM533RTOEk3L11ypWGeWp92RXI0nQ+BqqEO5/pGmIdd0ActAtSQOQj Y0ug4AnUKT8PHkuGhOausSEVxRxL4VbaKA== X-Google-Smtp-Source: ABdhPJwFZA37iad30KWK6c5GGIGaX941dZQso5vdiJC220HfgK+5zRZgCytNpNPpX22WaWzx9cskag== X-Received: by 2002:a05:600c:a04:: with SMTP id z4mr39782773wmp.103.1625842714366; Fri, 09 Jul 2021 07:58:34 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:35c2:26d3:e217:4410]) by smtp.gmail.com with ESMTPSA id c2sm1480995wrn.28.2021.07.09.07.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 07:58:33 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Fri, 9 Jul 2021 15:58:23 +0100 Message-Id: <20210709145825.2943443-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210709145825.2943443-1-naush@raspberrypi.com> References: <20210709145825.2943443-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 6/8] pipeline: raspberrypi: Use priority write for vblank when writing sensor ctrls 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" When directly writing controls to the sensor device, ensure that VBLANK is written ahead of and before the EXPOSURE control. This is the same priority write mechanism used in DelayedControls. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- .../pipeline/raspberrypi/raspberrypi.cpp | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 082eb1ee1c23..e09328ffa0bc 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -154,6 +154,7 @@ public: void embeddedComplete(uint32_t bufferId); void setIspControls(const ControlList &controls); void setDelayedControls(const ControlList &controls); + void setSensorControls(ControlList &controls); /* bufferComplete signal handlers. */ void unicamBufferDequeue(FrameBuffer *buffer); @@ -828,7 +829,7 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) /* Apply any gain/exposure settings that the IPA may have passed back. */ if (!startConfig.controls.empty()) - data->unicam_[Unicam::Image].dev()->setControls(&startConfig.controls); + data->setSensorControls(startConfig.controls); /* Configure the number of dropped frames required on startup. */ data->dropFrameCount_ = startConfig.dropFrameCount; @@ -1294,22 +1295,20 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config) return -EPIPE; } - if (!controls.empty()) - unicam_[Unicam::Image].dev()->setControls(&controls); - /* * Configure the H/V flip controls based on the combination of * the sensor and user transform. */ if (supportsFlips_) { - ControlList ctrls(unicam_[Unicam::Image].dev()->controls()); - ctrls.set(V4L2_CID_HFLIP, - static_cast(!!(rpiConfig->combinedTransform_ & Transform::HFlip))); - ctrls.set(V4L2_CID_VFLIP, - static_cast(!!(rpiConfig->combinedTransform_ & Transform::VFlip))); - unicam_[Unicam::Image].dev()->setControls(&ctrls); + controls.set(V4L2_CID_HFLIP, + static_cast(!!(rpiConfig->combinedTransform_ & Transform::HFlip))); + controls.set(V4L2_CID_VFLIP, + static_cast(!!(rpiConfig->combinedTransform_ & Transform::VFlip))); } + if (!controls.empty()) + setSensorControls(controls); + return 0; } @@ -1379,6 +1378,28 @@ void RPiCameraData::setDelayedControls(const ControlList &controls) handleState(); } +void RPiCameraData::setSensorControls(ControlList &controls) +{ + /* + * We need to ensure that if both VBLANK and EXPOSURE are present, the + * former must be written ahead of, and separately from EXPOSURE to avoid + * V4L2 rejecting the latter. This is identical to what DelayedControls + * does with the priority write flag. + * + * As a consequence of the below logic, VBLANK gets set twice, and we + * rely on the v4l2 framework to not pass the second control set to the + * driver as the actual control value has not changed. + */ + if (controls.contains(V4L2_CID_EXPOSURE) && controls.contains(V4L2_CID_VBLANK)) { + ControlList vblank_ctrl; + + vblank_ctrl.set(V4L2_CID_VBLANK, controls.get(V4L2_CID_VBLANK)); + unicam_[Unicam::Image].dev()->setControls(&vblank_ctrl); + } + + unicam_[Unicam::Image].dev()->setControls(&controls); +} + void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) { RPi::Stream *stream = nullptr;