Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp618360lqo; Wed, 8 May 2024 09:32:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW6/dbUdB+UpjQj9cpMpn72Pb0Qx3mnY4iv2BJANbhnNvFopv68ggeV+iTeMQ4iBYxNNIUywQjiVNDMbRlIeJF6W1njQCubAPB4YGDDdw== X-Google-Smtp-Source: AGHT+IHClsUUdSfI/VxZgk8EnDAtEDnv3GdP3ySOrlcHNDCwKkVB79cQNiS1JSlnduUA665RdMc0 X-Received: by 2002:a17:906:68c7:b0:a59:b807:330a with SMTP id a640c23a62f3a-a59fb94cd10mr183705766b.32.1715185945212; Wed, 08 May 2024 09:32:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715185945; cv=pass; d=google.com; s=arc-20160816; b=JSzkWDchSevh/bkBZ+TDcmj2//YU4CquywQ4ISYfe4vBVsOnbK+JVA9etWpw491KVY 69q+IXAfDybCBdb0GP9VIhKtsNtFYpJCGZnMQQd2OnYriptOdEdU/w4TUs1PCbFI4xbi Ja+Ou2J6hWCeV+9Q1hyyqAFCmHfDAidRCIiqgYltUMbO+9eB6/WY3VY9xTFODPaho7Or rvLlVxWRq999805Jbejn5sY8+KNwhh3Xu+xM8VSmnZhwLuES7ny7QXdkovOv+MQDLWV1 4Pd5puwCBZrKzv9UV0ty9Z0kxy7O8VBNLpehY2/HZ8w91k3MzYVSBFS6tdnnN9GsZZsB L/EA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=IpqvT/s3hJi/m2NA6vxsDVwPdDU6A01/xZePHqulLGs=; fh=anrMjVuHcaHSJBw6CLwU3a6+fXzzi43XPmAmjsrc9Qk=; b=06HNI/ULOevLYjuEPVCCK7iMdh1zjjityq8pwEDUGMviGTUx4rGT90iwl23ERIgcPc xNXCZi1mQJU7Ak0/ng1rME0UNWrElPU3tYY0fSi3+xDZpz8EBq1Vc7EhevuO/VPjDtQA 6zAhoM0aT50NlPtxtRtfV/8GDSHzH48M+FFPrQZ7M1W5wfJwXEOlsXv9nEaVPWpS0Ggm NI0/sJ050s8465CIaJQYrCqNtnrNeDsmJ3yvYmXs8gF50S5lbkfLiRaydnZaUyhoE+53 ynVkaN8o9/scAkMNJRlSJRl7bGW4FJDNuhSr/qyjkIrGH+WCIjvCzn0b/usWXN4Z1qAC cgZw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@raspberrypi.com header.s=google header.b=d999NY9F; arc=pass (i=1 spf=pass spfdomain=raspberrypi.com dkim=pass dkdomain=raspberrypi.com dmarc=pass fromdomain=raspberrypi.com); spf=pass (google.com: domain of linux-kernel+bounces-173543-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173543-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=raspberrypi.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id rv15-20020a17090710cf00b00a59b1310f9dsi4784515ejb.428.2024.05.08.09.32.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 09:32:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-173543-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=@raspberrypi.com header.s=google header.b=d999NY9F; arc=pass (i=1 spf=pass spfdomain=raspberrypi.com dkim=pass dkdomain=raspberrypi.com dmarc=pass fromdomain=raspberrypi.com); spf=pass (google.com: domain of linux-kernel+bounces-173543-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173543-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=raspberrypi.com 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 0B0951F22F03 for ; Wed, 8 May 2024 16:32:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F0131A2C2D; Wed, 8 May 2024 16:32:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="d999NY9F" Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (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 4EB7C633 for ; Wed, 8 May 2024 16:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715185921; cv=none; b=drvPlspMfb9/BeMk+QNVo7pUJormKNbmhwUQ1RlqwX/78Oc3fmQlXZ05MUdpV7zrirF/IP58RvsO1k2mNgTrH5MxZPcFrvvgM316HETt4SvCsUJDLbpF3gCWwRfKRMNKIWPjE2oCz6VOqohljUPWCXW7Xtt2sJt8r2Z5sdC8SGg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715185921; c=relaxed/simple; bh=HyI7CfR13ETlHE8vYoaiB6VcQcpejXw10JAvJm1BG8k=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=oZESGQ5NYrVmmND8/U7n7a4pkZjOVvWwdSlYHtUxouNFnD5bn+0h6e9ArGZQRZ9Vu3JmqQfNpwl9cc2dLRNmxnXqdSadJJLzKZMwqzOfZKBP/oIlBt8JodCHrPpqcnaZFl6C/sO6fdUQ/N3D6bCq8jn/9opqobUS2g3YSFHTLQA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=d999NY9F; arc=none smtp.client-ip=209.85.219.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-deb99fa47c3so3028351276.2 for ; Wed, 08 May 2024 09:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1715185918; x=1715790718; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=IpqvT/s3hJi/m2NA6vxsDVwPdDU6A01/xZePHqulLGs=; b=d999NY9FedIIIfmjQe7VOeVqo4FZn5382/nd66m1q1iSE5u/tRSawUSkSDCtoAGQuX S6nDtwPsZLMOsGpGshhCWJsS+ceUt6MTOPlsAKTA0vwtXmHTEQqaZa5j5h6w4UgW3DRY HGGPkwVGLyYCt17z7fVMgeOmTiSKRcdauRAVi/tOuvT+fMk6fCwH0Iurg/HQX9T0IXyv DzBnLjW1oyGJhpPSqiyj7txetNy1otSbNGuNLTgIaMQvaO0Qn5WeYkfi/ecFysB98HYt cvaS6xQhW1XRCaCpcli8T7bmxCiC1i5oxArZALaDjKtyByeGQz/NdCM/UtpXMFuvUQMy xmlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715185918; x=1715790718; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IpqvT/s3hJi/m2NA6vxsDVwPdDU6A01/xZePHqulLGs=; b=Oz3iMLe03PYbv61vNJ5pblIaop6k1Lhd1/wLFSH8Z3KLrTvOnft3Po+Z9W5giQV7zK u7NOmw53UsN1LDMlxjLeWnY0ghbiOqatfRpHqsqzMfMQpCtMRnTnHqoHHrBa1EnjoFaW BWyc0cOyk08jZYvFGN6r4DCs+jZad6VwCi7irVYFOAmMrE2y+HPCy7htY4t7Wo4HZkNJ 5ZBcdJvUwb2xtcBW4XscwTf5iIUd1F2K5x8psaWdAp1dqDDuBwIcbt4vDUsbHCSHx7Gj l4ycQXACi5jcPA0uFoKFLkhQ22ekoGlf1s7ir8RYF4rWqyx3hhswdvmdcxNLyuT090I+ HJrw== X-Forwarded-Encrypted: i=1; AJvYcCXhPwR6BGFFFAYbezwxgdmzooMIYQL27RrA/RRZynlksfI+03ni/EDtodCFoKwBJmWgFeBBmLVknajPdEjBL1kL0XRwY5QGqnPdJ1N2 X-Gm-Message-State: AOJu0YxCPHDKDPA7EzffpG3PYKqJzBvSUmHVQWCVPD7QHcKd2UznC4r5 T/BYTTSGr4wQqfBYD9MPsA1zozcdK2GP7yIbgZVzblyZTP2QQHRdqy4LOgpUZfiP+oSZVzG+9Yj 2wAQpUJamV5F5OrAVJufyGoH+90pSw5qbAm0CcQ== X-Received: by 2002:a25:b184:0:b0:de5:8816:2d1c with SMTP id 3f1490d57ef6-debb9e53cebmr3094653276.65.1715185918279; Wed, 08 May 2024 09:31:58 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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> In-Reply-To: From: Dave Stevenson Date: Wed, 8 May 2024 17:31:39 +0100 Message-ID: Subject: Re: [PATCH v2] media: i2c: Fix imx412 exposure control To: Jacopo Mondi Cc: "Bryan O'Donoghue" , 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 Content-Type: text/plain; charset="UTF-8" Hi Jacopo and Bryan On Wed, 8 May 2024 at 13:43, Jacopo Mondi wrote: > > Hi Bryan > > 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 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. > > > > > > 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 patch > > on LKML. > > > > Sounds familiar enough > > > > > > > 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. > > > > > > 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 = imx334->vblank + imx334->cur_mode->height; > > shutter = lpfr - exposure; > > > > ret = imx334_write_reg(imx334, IMX334_REG_SHUTTER, 3, shutter); > > > > > > drivers/media/i2c/imx335.c::imx335_update_exp_gain() > > > > lpfr = imx335->vblank + imx335->cur_mode->height; > > shutter = lpfr - exposure; > > > > ret = imx335_write_reg(imx335, IMX334_REG_SHUTTER, 3, shutter); > > > > > > Looking again I'm inclined to believe the imx334/imx335 stuff is probably > > correct for those sensors, got copied to imx412/imx577 and misapplied to the > > EXPOSURE control in imx412. > > > > Without datasheet/devices it really is hard to tell. Cargo cult at > play most probably. For reference certainly imx327/290/462 which are all siblings in the Sony Starvis family do calculate exposure as exposure = 1 frame period - (SHS1 + 1) * (1H period) So 0 = max exposure and bigger values are shorter exposure time. I'm not saying that the imx412 driver is right in doing this as well, but it seems there is a trend with the Sony Starvis family to program exposure in this different manner. Don't discount it as wrong for all drivers! Dave > > > > > > - ret = imx412_write_reg(imx412, IMX412_REG_EXPOSURE_CIT, 2, shutter); > > > > + ret = imx412_write_reg(imx412, IMX412_REG_EXPOSURE_CIT, 2, exposure); > > > > > > 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 = > > pExposureData->pRegInfo->coarseIntgTimeAddr + 1; > > > > pRegSettingsInfo->regSetting[regCount].registerData = (lineCount & 0xFF); > > > > > 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. > > Sure > > Thanks > j > > > > > --- > > bod > > >