Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp617105lqo; Wed, 8 May 2024 09:30:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVjFgGome0K2k/TGwbdexyZcqdaeNo/HtfB02CI0bj/fwTr4W8xtKadAtMpbQACsPy7uNs17iEjsWCySI4g2ABID+Q9JKdQUEaWEKdE7g== X-Google-Smtp-Source: AGHT+IFQGRw3TqGftM8iykDjWfvdv0hgOxMCSsjBY2rk+ZC+cOeF0xsxtNFCJnpt1axy0bzSLYvG X-Received: by 2002:a17:902:76c5:b0:1e3:d0fd:236c with SMTP id d9443c01a7336-1eeb03a631amr33788855ad.37.1715185842927; Wed, 08 May 2024 09:30:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715185842; cv=pass; d=google.com; s=arc-20160816; b=GaTOnxYWC7gKKWULwbUol5SPiAgqNFmDTS52Uf2PC9cb39Y+ae1S+UMyS+Ab0k4kn6 E4WFlpFW1bp7SiaeA8NzGdmts4bLW87MbbCOmOlRoEeDOdc1G+7oI7BdRJFqkzQzSP9l EcG1hTIXpLSpulpHmFkgIu57EVH1q2ykPVFZ6MD0KDZOHujzkwkyQK8UnkATxyq69f35 JvecOioLLQUCEcMzfK0MBjhtFbrDtPaQHf0+GjYiC6luG28RLTzZ3mSzNtBW/9b/WdUW KG4+9mEyQwd4njNVZOtlilLpGYky5h0MxCYEJUpg7MrwjCw4f8DoiAyQJcGO+IEFSEtl py4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:message-id:date:to:cc:from:subject:references :in-reply-to:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=QXUsLRuaRv4H7noJA0Ebd9Lx9c7cRJ8aw1ciM1uflu8=; fh=yx0EY4+OKCdSusmwhf5nhYcnr7hZMBNynDlhOF3XpcM=; b=k6FNks3eie1xQ7pLlvPYHZaX3GayHS/DojHD5uJIT8+yFJ7VLJ6SlmbN0YlULW+/OZ /tUaWjTuC38Uc6CF46VcL3BzBypvXpBd5Vqa6NCdd3ogOpX7+FoxznkETGEJLlqWyAUd UOgP+e5R39yeVPLw8oH7FzzhFcJbEQeSgovwn6Lv39NyBN01OB4p55s0hAYe3VRhwrrg v6cf7o8X668yPdiaDPL6aRAfDKTrjPmRGz2Zl481aJwJTJTAUr09Zq2lbbvPDnt/O3Zs bIJZoVr6+CbIB32Q/mJJn1lOrCof43PZLm9JgDOeSY16urFXx5SR/EI016/D0usfoWS8 GS+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=JEhoibij; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-173536-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173536-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id t1-20020a17090340c100b001eb5bc2d9cfsi13083178pld.508.2024.05.08.09.30.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 09:30:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-173536-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=JEhoibij; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-173536-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173536-linux.lists.archive=gmail.com@vger.kernel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 857F3B2390C for ; Wed, 8 May 2024 16:23:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0000812A175; Wed, 8 May 2024 16:23:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JEhoibij" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F1F11F5F3; Wed, 8 May 2024 16:23:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715185413; cv=none; b=sxyFSRbHgc5wcRNc7CQ/jIZIuaBNhz65DOs+KiK/iDtNplORwBdKevWxAVav4ULJAQjl5GfY6K5kVo+S26BTZEdaj2UmLRrTFcWuKgC+uCkIvxTBaUN62LLCHOQiAdk3fUmpWbxbLeCw+MLJPI3C5NL3pKD0z5IuXXoACwRGI2w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715185413; c=relaxed/simple; bh=WelstoePjnDnRChpMtP24IlPVegDX/ryQMkZRwZ5JqI=; h=Content-Type:MIME-Version:In-Reply-To:References:Subject:From:Cc: To:Date:Message-ID; b=OSdnUEaJCC4M5nUp/dJ3R5u1T1Up5nA+qxgifKakbDaM4ieTjiAUGU3T7gGc2oJC76AqB4xlDhcKDM5OR6RICAJxJsWku5YtlnLg6JVUeTfau16O7r9DafB10o5ZkfktUEJWX3G3rFiQNy7+4EgnBCtFCCuld2fQQ2YTj0k9eC8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=JEhoibij; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from pendragon.ideasonboard.com (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 747DCFD6; Wed, 8 May 2024 18:23:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1715185405; bh=WelstoePjnDnRChpMtP24IlPVegDX/ryQMkZRwZ5JqI=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=JEhoibijttr1P6mbGqyI6W3jMX2iMVY/uW1eTQdZIiHiA5oLcdMfj4AgRHtcI7pvX El8fdo53IyKJXDQpdzVaqhfm55r/gJhjFB6HY7gggVCrM0iNM1tD10Gp08+xLiMkbJ Qwq1sQJdxhdJ4NyKjFEQcNZJiR7WNGagXpPcE9Xs= Content-Type: text/plain; charset="utf-8" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: References: <20240506-b4-linux-next-camss-x13s-mmsol-integration-in-test-imx577-fix-v2-1-2e665f072f8f@linaro.org> <20a0300a-ac16-456c-840a-e272f49050a8@linaro.org> Subject: Re: [PATCH v2] media: i2c: Fix imx412 exposure control From: Kieran Bingham Cc: Jacopo Mondi , Sakari Ailus , Mauro Carvalho Chehab , Paul J. Murphy , Martina Krasteva , Daniele Alessandrelli , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org To: Bryan O'Donoghue , Jacopo Mondi Date: Wed, 08 May 2024 17:23:25 +0100 Message-ID: <171518540550.191612.743149233311332771@ping.linuxembedded.co.uk> User-Agent: alot/0.10 Quoting Jacopo Mondi (2024-05-08 13:43:34) > Hi Bryan >=20 > On Wed, May 08, 2024 at 01:30:31PM GMT, Bryan O'Donoghue wrote: > > On 08/05/2024 09:02, Jacopo Mondi wrote: > > > Hi Bryan > > > > > > On Mon, May 06, 2024 at 11:38:26PM GMT, Bryan O'Donoghue wrote: > > > > Currently we have the following algorithm to calculate what value s= hould be > > > > written to the exposure control of imx412. > > > > > > > > lpfr =3D imx412->vblank + imx412->cur_mode->height; > > > > shutter =3D lpfr - exposure; > > > > > > > > The 'shutter' value is given to IMX412_REG_EXPOSURE_CIT however, th= e 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, shutt= er 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, shutt= er 22, lpfr 3546 > > > > > > > > This behaviour results in the image having less exposure as the req= uested > > > > exposure value from user-space increases. > > > > > > > > Other sensor drivers such as ov5675, imx218, hid556 and others take= the > > > > requested exposure value and directly. > > > > > > has the phrase been truncated or is it me reading it wrong ? > > > > Sod's law says no matter how many times you send yourself a patch before > > sending it to LKML you'll find a typo ~ 2 seconds after reading your pa= tch > > on LKML. > > >=20 > Sounds familiar enough >=20 > > > > > > Looking at the range of imx sensors, it appears this particular err= or has > > > > been replicated a number of times but, I haven't so far really dril= led into > > > > each sensor. > > > > > > Ouch, what other driver have the same issue ? > > > > So without data sheet or sensor its hard to say if these are correct or > > incorrect, it's the same basic calculation though. > > > > drivers/media/i2c/imx334.c::imx334_update_exp_gain() > > > > lpfr =3D imx334->vblank + imx334->cur_mode->height; > > shutter =3D lpfr - exposure; > > > > ret =3D imx334_write_reg(imx334, IMX334_REG_SHUTTER, 3, shutter= ); > > > > > > drivers/media/i2c/imx335.c::imx335_update_exp_gain() > > > > lpfr =3D imx335->vblank + imx335->cur_mode->height; > > shutter =3D lpfr - exposure; > > > > ret =3D imx335_write_reg(imx335, IMX334_REG_SHUTTER, 3, shutter= ); Is this a copy / paste error (IMX334), or are you using a downstream/altern= ative driver? Upstream implements this: /** * imx335_update_exp_gain() - Set updated exposure and gain * @imx335: pointer to imx335 device * @exposure: updated exposure value * @gain: updated analog gain value * * Return: 0 if successful, error code otherwise. */ static int imx335_update_exp_gain(struct imx335 *imx335, u32 exposure, u32 = gain) { u32 lpfr, shutter; int ret; lpfr =3D imx335->vblank + imx335->cur_mode->height; shutter =3D lpfr - exposure; dev_dbg(imx335->dev, "Set exp %u, analog gain %u, shutter %u, lpfr %u\n", exposure, gain, shutter, lpfr); ret =3D imx335_write_reg(imx335, IMX335_REG_HOLD, 1, 1); if (ret) return ret; ret =3D imx335_write_reg(imx335, IMX335_REG_LPFR, 3, lpfr); if (ret) goto error_release_group_hold; ret =3D imx335_write_reg(imx335, IMX335_REG_SHUTTER, 3, shutter); if (ret) goto error_release_group_hold; ret =3D imx335_write_reg(imx335, IMX335_REG_AGAIN, 2, gain); error_release_group_hold: imx335_write_reg(imx335, IMX335_REG_HOLD, 1, 0); return ret; } > > > > > > Looking again I'm inclined to believe the imx334/imx335 stuff is probab= ly > > correct for those sensors, got copied to imx412/imx577 and misapplied t= o the > > EXPOSURE control in imx412. We're directly using the IMX335 driver in mainline on the i.MX8MP (and also validated on Raspberry Pi 5). AGC is operational on both those platforms with the sensor, so I have no reason to believe there is any error in the upstream driver: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/dr= ivers/media/i2c/imx335.c -- Kieran > > >=20 > Without datasheet/devices it really is hard to tell. Cargo cult at > play most probably. >=20 > > > > > > - ret =3D imx412_write_reg(imx412, IMX412_REG_EXPOSURE_CIT, 2, shut= ter); > > > > + ret =3D imx412_write_reg(imx412, IMX412_REG_EXPOSURE_CIT, 2, expo= sure); > > > > > > No datasheet here, can you confirm the IMX412_REG_EXPOSURE_CIT > > > register is actually in lines ? > > > > > > Looks like. > > > > From downstream "coarseIntgTimeAddr" > > > > imx577_sensor.xml > > 0x0202 > > > > imx586/imx586_sensor.cpp > > pRegSettingsInfo->regSetting[regCount].registerAddr =3D > > pExposureData->pRegInfo->coarseIntgTimeAddr + 1; > > > > pRegSettingsInfo->regSetting[regCount].registerData =3D (lineCount & 0= xFF); > > > > > Apart from that, as the CID_EXPOSURE control limit are correctly > > > updated when a new VBLANK is set by taking into account the exposure > > > margins, I think writing the control value to the register is the > > > right thing to do (if the register is in lines of course) > > > > > > Reviewed-by: Jacopo Mondi > > > > > > Thanks > > > j > > > > > > > If that's good enough I'll fix the typo and apply your RB. >=20 > Sure >=20 > Thanks > j >=20 > > > > --- > > bod > >