Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp176211lqh; Mon, 6 May 2024 15:33:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWHGTHKgev5ZNYGKlGZuv2ev/Gvvto4LoWLzeVGQgRDjUebDBE9IXmxQ571afMzKY2jfLtnqbFv9bGq1DtkRxcEsHoZ2DfnDqoisX96pQ== X-Google-Smtp-Source: AGHT+IGWWowT4bIF+e++WDtoVYe5Z5OpfpN5RTh6Tvs1R7DgwC3Pyth0kWtBhrGnaeSBhTJkYyPF X-Received: by 2002:a17:906:18e2:b0:a59:c345:17fb with SMTP id a640c23a62f3a-a59e4cbc7a7mr75638066b.5.1715034837841; Mon, 06 May 2024 15:33:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715034837; cv=pass; d=google.com; s=arc-20160816; b=Tn0oziEAzwX8v7JPOKawuUWVarAkh2HFJUJ0hARpsYW8vdHiPVPYwwO2QLV+B1ACfn LBobYgxThebDCJ7KhOuPe+CuuCVIjdpp8207DlWQoeALkJywSyxKsaX+ht362utQJ4q3 DzMkDHshkhj2rQjNBcPrCpXLc2c63m39aUJYjSuWiKp9glqFDWXnkkz2P0EJGX+kEMpy OE6tSpa3rd0oP8eMWE3goSqOKNEKTJfG8zdpliWRX3JwFPeyUB9wtd+BGKgOPBir2a6q 09dCTB/tHtG7AsTi9Ldb8rBypkDdeKhyY1ZEIL+4bRr4Re7KEO8ZWSD9U24DbCwuxxN4 NrLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=L93aTq+yntQGwFV5vIt1XMlXm8vhsrvaK9kqXIrRNHA=; fh=SWb9U2/49XqDHuiH+jTjHH2TTI/3e4LsuRz4A0kHBJU=; b=jb5XMzbF3za5neMvUBMcsdvLBNxgANsfHhzF/zVEMmlHc6vP2zzQzf/nlzM4toJNy9 INxrBpry2yRT5o9UPYQlw/GlVbFefGRmdHOwq7lIuxsPn3YDPEwOOpGamInEnuecKfjk I/2u/Nmia2Rq5zTaJ0+Dyh064XPCsWtW5UiEBkY8VRHPRu9U45RHa26++cYarnpkC8OW 1W1OBqOVUtImS/edSne8m5hxONhG05VxUhNSF24SvR1zY6fC/EgCHMwUYAi4eWGzGk7n AqIW/a5VsF1+tc8Xa07zLRqi0ZQvk1pmQ0Lj2dY2kVjRK65CkzMgGJpaC4R6PZ4tQXq0 SO1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fv1GChc/"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-170471-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170471-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id x17-20020a1709060a5100b00a59afce5a36si2979958ejf.909.2024.05.06.15.33.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 15:33:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170471-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fv1GChc/"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-170471-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170471-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6465C1F2121C for ; Mon, 6 May 2024 22:33:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C95A158DD6; Mon, 6 May 2024 22:33:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Fv1GChc/" Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6478642A8A for ; Mon, 6 May 2024 22:33:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715034828; cv=none; b=RnQ+43JPGfrPOw/rMHVK4Afo8sBg78in1hAjBWGH6Pcp0e3np8WaCIwQxBp3pBsEfZE5dNmLwiwh2kewhbXclRQO0fspnbG4EZ/jVsyYpawZ5WfEHszAzpYvej4kmmtMu4RpNHNG1JqP1PDqSMJN2TX0KjE8HVq7xOmcMteg+TM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715034828; c=relaxed/simple; bh=XbeaIHre143E4vysQmGrzt4tNC6G3/zMv2H2o4AQ/yc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=ZEA5rAoHllgyt94ooetnWjD4deicBFdUwuvz/Y4OfDp25YyuQ9BtTsmgvrEadbCdpYjsayX/QCWKHrvhSldIlxMh06v0hzEV7KDwpo+pf0mSX/yOXeD5LPiMGM9vu6RtStL+CiijYSxZ9Ye7Qs++wpwSdUrqjePPHBPU3n8J/R4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Fv1GChc/; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-41dc9c83e57so26770015e9.0 for ; Mon, 06 May 2024 15:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715034824; x=1715639624; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=L93aTq+yntQGwFV5vIt1XMlXm8vhsrvaK9kqXIrRNHA=; b=Fv1GChc/VhBKk7SHWj4sf1HvYNnhAikjgJGgjuwEZI0EzgmUAu73ID9imCMzrJRe6r L8X+FHjLtlo1iKMVL5Cj81HHl0oZJMy0ZTQcLG2jRFnvRZ1WSroFWUtB3g/O6swRp1FL HMF29RjYQSIOUAmxiPsLvqtwzjlRSGoSVWBfEW9Xqg2AaWkFilZ8YYag42Qzsjsff79h gIO6i3oqXQQrQnnUL2r5utRudyY29AkYr0GbyBsyEqsMoXbuILWwaiOGEUJ/8IlP7llN O8A4ZbHC0x36xnd6VcYZrz46F/MUE85ZgHzO1QUt4bUNaY7i/gMSoByFakQDVY9IoFDd VYvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715034824; x=1715639624; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=L93aTq+yntQGwFV5vIt1XMlXm8vhsrvaK9kqXIrRNHA=; b=bxgmDCWh4HKWw/6qkGN3hDmPXtxGBvb0hOKDR9Y4Oryy9Ecaz2LgwKVoYxY0PXPwBb OaU670EwS9wiFI0bb3nHkJsBA1S9g68a1P8z54waP91gJGZkMLxfIwgCXaeKAYBiAtqe n625r8tiqVhb029Np2ayXiuM+PdJ4rLx8OjoqPwGiuaf63Qc68iSUqBpO17nFBi3982O 13OxHTEdpMHrU8MFG843lT57ecRLV/TevCcj/T5aab/FjqesleX8wQQdmNXs4vHaLuGm Nn0vmYDhYzba6+X+te+AGKkUzlKHnHnEfZAxJvP3whDvTrUEiYc+4D0yQu6tvsMoUBgq lJ+w== X-Forwarded-Encrypted: i=1; AJvYcCUoXjgtJyGCeAbEQuvU52g/CiAztS0ZHIs8VsISOk6jPmlolslGdZ6UQoKaEY79baku0jpNYVzi4dmbcJUf9P1GABfYYMmmUEIKkoXm X-Gm-Message-State: AOJu0YwM31mWldDD3zqsL3Ijyntlu0wybAPPQuJuDorpQ069/7zZRfvc RVPVad6SSJJ2415PQhRAW/BTuOubZKbqikJx2HMRAw3s8mSK2hGZiOFDKIKk22E= X-Received: by 2002:a05:600c:4f14:b0:41b:8c5c:31b9 with SMTP id l20-20020a05600c4f1400b0041b8c5c31b9mr775530wmq.14.1715034823704; Mon, 06 May 2024 15:33:43 -0700 (PDT) Received: from [127.0.0.1] ([176.61.106.227]) by smtp.gmail.com with ESMTPSA id be11-20020a05600c1e8b00b00418f7605249sm17264766wmb.24.2024.05.06.15.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 15:33:43 -0700 (PDT) From: Bryan O'Donoghue Date: Mon, 06 May 2024 23:33:39 +0100 Subject: [PATCH] media: i2c: Fix imx42 exposure control Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240506-b4-linux-next-camss-x13s-mmsol-integration-in-test-imx577-fix-v1-1-4b3a9426bde8@linaro.org> X-B4-Tracking: v=1; b=H4sIAMJaOWYC/x2NQQrCMBBFr1Jm7UBS0wS8iriIdVIHmlQyqQRK7 +7g7r+/eO8AocokcBsOqPRl4a0o2MsA8zuWhZBfyjCa0ZnJeHw6XLnsHQv1hnPMItjtVTBn2Vb k0mipsalGNzaShpz7FAIm7phsIvImGO8saONTSe9///44zx+klMhNjwAAAA== To: Sakari Ailus , Mauro Carvalho Chehab , "Paul J. Murphy" , Martina Krasteva , Daniele Alessandrelli Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Bryan O'Donoghue X-Mailer: b4 0.13-dev-26615 Currently we have the following algorithm to calculate what value should be written to the exposure control of imx412. lpfr = imx412->vblank + imx412->cur_mode->height; shutter = lpfr - exposure; The 'shutter' value is given to IMX412_REG_EXPOSURE_CIT however, the above algorithm will result in the value given to IMX412_REG_EXPOSURE_CIT decreasing as the requested exposure value from user-space goes up. e.g. [ 2255.713989] imx412 20-001a: Received exp 1608, analog gain 0 [ 2255.714002] imx412 20-001a: Set exp 1608, analog gain 0, shutter 1938, lpfr 3546 [ 2256.302770] imx412 20-001a: Received exp 2586, analog gain 100 [ 2256.302800] imx412 20-001a: Set exp 2586, analog gain 100, shutter 960, lpfr 3546 [ 2256.753755] imx412 20-001a: Received exp 3524, analog gain 110 [ 2256.753772] imx412 20-001a: Set exp 3524, analog gain 110, shutter 22, lpfr 3546 This behaviour results in the image having less exposure as the requested exposure value from user-space increases. Other sensor drivers such as ov5675, imx218, hid556 and others take the requested exposure value and directly. Take the example of the above cited sensor drivers and directly apply the requested exposure value from user-space. The 'lpfr' variable still functions as before but the 'shutter' variable can be dispensed with as a result. Once done a similar run of the test application requesting higher exposure looks like this, with 'exp' written directly to the sensor. [ 133.207884] imx412 20-001a: Received exp 1608, analog gain 0 [ 133.207899] imx412 20-001a: Set exp 1608, analog gain 0, lpfr 3546 [ 133.905309] imx412 20-001a: Received exp 2844, analog gain 100 [ 133.905344] imx412 20-001a: Set exp 2844, analog gain 100, lpfr 3546 [ 134.241705] imx412 20-001a: Received exp 3524, analog gain 110 [ 134.241775] imx412 20-001a: Set exp 3524, analog gain 110, lpfr 3546 The result is then setting the sensor exposure to lower values results in darker, less exposure images and vice versa with higher exposure values. Fixes: 9214e86c0cc1 ("media: i2c: Add imx412 camera sensor driver") Tested-by: Bryan O'Donoghue # qrb5165-rb5/imx577 Signed-off-by: Bryan O'Donoghue --- Using libcamera/SoftISP on a Qualcomm RB5 with the imx577 sensor I found that unlike on other platforms such as the Lenovo x13s/ov5675 the image was constantly getting darker and darker. At first I assumed a bug in SoftISP but, looking into the code it appeared SoftISP was requesting higher and higher exposure values which resulted in the image getting progressively darker. To my mind the software contract between user-space and kernel should be increasing exposure requests always meant higher exposure but, to be certain I asked around on IRC. Those polled agreed in principle that the software contract was consistent across sensors. Looking at the range of imx sensors, it appears this particular error has been replicated a number of times but, I haven't so far really drilled into each sensor. As a first pass I'm submitting the fix for the sensor I have but, I expect if this fix is acceptable upstream it should be pushed to most of the imx sensors with what seems to be copy/paste code for the exposure. --- drivers/media/i2c/imx412.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/imx412.c b/drivers/media/i2c/imx412.c index 0efce329525e4..7d1f7af0a9dff 100644 --- a/drivers/media/i2c/imx412.c +++ b/drivers/media/i2c/imx412.c @@ -542,14 +542,13 @@ static int imx412_update_controls(struct imx412 *imx412, */ static int imx412_update_exp_gain(struct imx412 *imx412, u32 exposure, u32 gain) { - u32 lpfr, shutter; + u32 lpfr; int ret; lpfr = imx412->vblank + imx412->cur_mode->height; - shutter = lpfr - exposure; - dev_dbg(imx412->dev, "Set exp %u, analog gain %u, shutter %u, lpfr %u", - exposure, gain, shutter, lpfr); + dev_dbg(imx412->dev, "Set exp %u, analog gain %u, lpfr %u", + exposure, gain, lpfr); ret = imx412_write_reg(imx412, IMX412_REG_HOLD, 1, 1); if (ret) @@ -559,7 +558,7 @@ static int imx412_update_exp_gain(struct imx412 *imx412, u32 exposure, u32 gain) if (ret) goto error_release_group_hold; - ret = imx412_write_reg(imx412, IMX412_REG_EXPOSURE_CIT, 2, shutter); + ret = imx412_write_reg(imx412, IMX412_REG_EXPOSURE_CIT, 2, exposure); if (ret) goto error_release_group_hold; --- base-commit: ff3959189f1b97e99497183d76ab9b007bec4c88 change-id: 20240506-b4-linux-next-camss-x13s-mmsol-integration-in-test-imx577-fix-f1fee6070641 Best regards, -- Bryan O'Donoghue