From patchwork Wed Nov 23 11:36:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 17844 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 E492EBDE6B for ; Wed, 23 Nov 2022 11:36:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0749B6331A; Wed, 23 Nov 2022 12:36:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669203411; bh=Yv3FcNCjx+mp2HRPxn8kQoa0Tn/sOjMGdIOI3i+xSa8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ShJHYC9WChONvTVRHUVxv7ekLO8dJAWx80VRfll03h3zD8NKJRIuePl6K0jcYEHcR 9diGQtfqKHcGOCM2/UPtdzcSM0RWsmHugWs6QcimZ/RhVoc2vYlVPFQtY7236+J+qM PI85Jv9Gw8JTLMXvq4KEZR/X1GLqImZk8CnGCVUEr+KgcYBPp68VOYDSm0HdFt4Vnm n+DleN2SnthrU4XIi8A7lANRxZWW6QdzJp7XpLrmEwfiefmGyZW+t77sZugPcSf+IS ufHhhQVSP1MUR6IqLImYSLS3Amh7VW4SLMY/5j0YpEdId9VF34XoJxqsr//iDPJD70 //sR224cfjTeg== Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4F88663313 for ; Wed, 23 Nov 2022 12:36:49 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ED1bspjk"; dkim-atps=neutral Received: by mail-wm1-x32a.google.com with SMTP id i64-20020a1c3b43000000b003d016c21100so1207807wma.3 for ; Wed, 23 Nov 2022 03:36:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ayiEryo2nEyP7V0oD7bge2QPW9437kXooGA/K6dlQVw=; b=ED1bspjkoA7bNXwETjq5syRlKcyl9dm7cMaSZRTHyb+J4SkSuhJayQ+xgZo8F32Ane CVcl/PyJ6MNdN0DUn3EhWbJk7VPwrI5/OEXwREROb8v/yGr+MPj8IbCbL61oK1P899wC /WRIbrxoRTS1FWbcbl7UohuL+8syd9Cqz0cW+2OJZxv1gX+BR7gvCQy0t90x12G74W2n hyys1uJvrA+5Eqw6ihfWnf3DseophEgXxy/kB5vBqFggObHvh2aYj2L8OaUo8R++Hnk0 5RlGQ0/qxSbWISGigo0vnnt2E8VgjmZxKWbb6qtVirW8n7gcutySe8LOCRnbckbwJhJh R90A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ayiEryo2nEyP7V0oD7bge2QPW9437kXooGA/K6dlQVw=; b=JNI5tS1DnLa3FJrIGQihUG9II51IV7bkteLSLoV4zg6sDfhNeYoJSrGf01uuCi8TN5 9tibZAIQG4tRn/H5k6AKQlWAylmQqmxGpcLL0C89m7/E+5Jo1pN3W5DS7HTKrj5Cd2tm 2GqMutCpOXrYP+1TmOWKvnmodm/XKmyx5Or7HH7DB/U7U6do5t7zV35UIICaVMZ4Isvo CebeKQ9snijUo7f6kcgf6t4zRR/Wumh19kv2ZgDzsjJhtufci2ANrmrmHDIrplhgAT9B Q9sq5QR8INb4gUW0tlSr7hA3RrtdkrQUwF0y8Gk7DvnMPYRmmChugoByvXuZJQyK67Mt iPoA== X-Gm-Message-State: ANoB5plfCyPAJr6w69Aiam8k0BYj4U/Ea+gHU+nGVghQSQK41eCDV9y2 QHReev7U0twtF38HGkvsbVM0+X4Pg56eyw== X-Google-Smtp-Source: AA0mqf5ZKupg5j0Nuoh8fd3/BmPu66ZMRgSEw8iSm0ik8AaWTcqjQqc7umZV0XKAdSapxzGI5hrZoQ== X-Received: by 2002:a1c:f216:0:b0:3c6:c2ae:278b with SMTP id s22-20020a1cf216000000b003c6c2ae278bmr19469779wmc.127.1669203408617; Wed, 23 Nov 2022 03:36:48 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id m9-20020a05600c4f4900b003b95ed78275sm2203219wmq.20.2022.11.23.03.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 03:36:47 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Nov 2022 11:36:44 +0000 Message-Id: <20221123113644.1778-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221123113644.1778-1-david.plowman@raspberrypi.com> References: <20221123113644.1778-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/1] libcamera: camera_sensor: Reset HBLANK when setting the format 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: , X-Patchwork-Original-From: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" We no longer reset the HBLANK in init because we may not own the camera and the operation may fail. Instead, we reset it when we set the camera format so that all pipeline handlers, even ones that do not control HBLANK themselves, will have a well-defined value. Signed-off-by: David Plowman Reviewed-By: Naushir Patuck --- src/libcamera/camera_sensor.cpp | 53 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 572a313a..ec7bb0e7 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -176,32 +176,6 @@ int CameraSensor::init() if (ret) return ret; - /* - * Set HBLANK to the minimum to start with a well-defined line length, - * allowing IPA modules that do not modify HBLANK to use the sensor - * minimum line length in their calculations. - * - * At present, there is no way of knowing if a control is read-only. - * As a workaround, assume that if the minimum and maximum values of - * the V4L2_CID_HBLANK control are the same, it implies the control - * is read-only. - * - * \todo The control API ought to have a flag to specify if a control - * is read-only which could be used below. - */ - const ControlInfo hblank = ctrls.infoMap()->at(V4L2_CID_HBLANK); - const int32_t hblankMin = hblank.min().get(); - const int32_t hblankMax = hblank.max().get(); - - if (hblankMin != hblankMax) { - ControlList ctrl(subdev_->controls()); - - ctrl.set(V4L2_CID_HBLANK, hblankMin); - ret = subdev_->setControls(&ctrl); - if (ret) - return ret; - } - return applyTestPatternMode(controls::draft::TestPatternModeEnum::TestPatternModeOff); } @@ -748,7 +722,32 @@ int CameraSensor::setFormat(V4L2SubdeviceFormat *format) return ret; updateControlInfo(); - return 0; + + /* + * Set HBLANK to the minimum to start with a well-defined line length, + * allowing IPA modules that do not modify HBLANK to use the sensor + * minimum line length in their calculations. + * + * At present, there is no way of knowing if a control is read-only. + * As a workaround, assume that if the minimum and maximum values of + * the V4L2_CID_HBLANK control are the same, it implies the control + * is read-only. + * + * \todo The control API ought to have a flag to specify if a control + * is read-only which could be used below. + */ + const ControlInfo hblank = controls().at(V4L2_CID_HBLANK); + const int32_t hblankMin = hblank.min().get(); + const int32_t hblankMax = hblank.max().get(); + + if (hblankMin != hblankMax) { + ControlList ctrl(subdev_->controls()); + + ctrl.set(V4L2_CID_HBLANK, hblankMin); + ret = subdev_->setControls(&ctrl); + } + + return ret; } /**