From patchwork Mon Dec 30 06:11:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 13923072 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 10FD319882F; Mon, 30 Dec 2024 06:11:53 +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=1735539115; cv=none; b=UiM/x+FIw20FBLjYL5DoN1WTVC9FtWHmdehmAI/IzkI40d5jRUj53Qtrm3W/WzrKQd6C48X8v/bo9t9xu5WWB+Y7fpbdijSpXLXeRN7sYyZg13TRVaxwRKFLinsmRgPbzo/dXr375TZm2XhiblWtmhD86TzQyG1Qh0LBbDBhkCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735539115; c=relaxed/simple; bh=gw6U2JG+YSx5CmmarPuDTvS/aLofbuq/YU0A8rIgCgU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QPeAulxvv1tBEKp2BXCRuRKL+gNWLA37zfYD8cnQeo3NopYDsYKiCgppqujY2yAgfFG6HZzSizWozFtAjOB3UEOE3MHuf956oYLnUKGgUG5OvBMq+gON9wsgaPs6OtBqWp/QjAHNt6xpsj1W2CSvl1vFfB8Mjey9CNFRvaxRYZw= 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=hJDtJrj5; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hJDtJrj5" Received: from mail.ideasonboard.com (unknown [223.190.82.226]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C1AEE3DC; Mon, 30 Dec 2024 07:11:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1735539066; bh=gw6U2JG+YSx5CmmarPuDTvS/aLofbuq/YU0A8rIgCgU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hJDtJrj5Wz+DD/bqap7iKYO6NaVDR8Rizh4IyEVB1DDqjidCz3bd2BYGj1eWZsrBL aQPOPmlUmzH1aPcdn7jmc5axFBNOnQJW/KAf37zu9gWjv4hYFDa0OI/ZYAAj/4Nb6L eHyS170fyMnVXvS0fuVFM6elVfwC2KzMm6M569Ec= From: Jai Luthra Date: Mon, 30 Dec 2024 11:41:18 +0530 Subject: [PATCH v5 1/5] media: i2c: imx219: Correct the minimum vblanking value Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241230-imx219_fixes-v5-1-98446d816489@ideasonboard.com> References: <20241230-imx219_fixes-v5-0-98446d816489@ideasonboard.com> In-Reply-To: <20241230-imx219_fixes-v5-0-98446d816489@ideasonboard.com> To: Dave Stevenson , Sakari Ailus , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Jacopo Mondi , Laurent Pinchart , Jai Luthra , David Plowman X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1008; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=iw258IJ7itA4hKvQDhU7RsL6SbTVrRcFIMh4c4XZiEs=; b=owEBbQKS/ZANAwAIAUPekfkkmnFFAcsmYgBncjmKR9L+iU4Q++jezKImstToHcifsQHjMEEQX zyRpWmGtP2JAjMEAAEIAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCZ3I5igAKCRBD3pH5JJpx RWNGEACo0bxH8xODh/mIU1CsHsJTJtw8V4feva5C582D8ta52ql1xnbrcrGFC7nuZ65cUW+d6il lAaHN7OYg+PY10GSIZJ6NUElcjyuBV54zZUaE04SsCpoA2aZZol7PwWRuaFCvNIpPnopWMrFH81 PASp2aV2etm4PlQDgH9c/z3cODHZG21vNbcRzJH5rEU4E2VqMJn+b7+4t++c/3ecUkLns27J6J7 6r4Iu6wNpp2omnY3K4QPh2maCa0GLIFH+3TwxnDEjG55ZtH/2c0y3W2DgC14ORGTSpCciond/nt 8M7hnIq2T9/pGD0/ctDexzIhnwxuUMEWQDt4PLvTtQafPDCM3mOXZHoALXZIHjinp2dy0TUpRnN MKTSIhGs2T74quVC991prqeFgTkLsIxtgpFgTWt+1enZgikNbpDCRgH7qPXM9LqcHX/fW3Gt9Sp 1BmPS1m1+d8AIlBGqyZrzFOuUHXOYkM7rUtrAVH2D6WFVvA8JXpW0K7CNbplzSe1IqVtFqJy9NZ eVKzqr5J+ik7I2+hnY4+zi188GIXe7d+IrBGml7ledM6s4IIM134ewK1IXfyCw0Pj2cn/9cu+li nKZEJVE50G8krp0ORelJo70R10Q5EPLktvTvxKdp/4F8ev9Qi+wNaZsu1QHKiZpJs0FLNCj0HPA peEoSX2nbpHjFZA== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: David Plowman The datasheet for this sensor documents the minimum vblanking as being 32 lines. It does fix some problems with occasional black lines at the bottom of images (tested on Raspberry Pi). Signed-off-by: David Plowman Reviewed-by: Jacopo Mondi Reviewed-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/media/i2c/imx219.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c index 2d54cea113e19f68e1553ffb2e4c78491dc80acf..0486bbc046cb9c36afd911eb799c1b010a01d496 100644 --- a/drivers/media/i2c/imx219.c +++ b/drivers/media/i2c/imx219.c @@ -73,7 +73,7 @@ #define IMX219_REG_VTS CCI_REG16(0x0160) #define IMX219_VTS_MAX 0xffff -#define IMX219_VBLANK_MIN 4 +#define IMX219_VBLANK_MIN 32 /* HBLANK control - read only */ #define IMX219_PPL_DEFAULT 3448 From patchwork Mon Dec 30 06:11:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 13923073 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 2D55719C546; Mon, 30 Dec 2024 06:12:07 +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=1735539129; cv=none; b=ULqbSyZEdgiwg6/vzKBJ481cl4n9dEffe7iuFHr8PpSrtivebalNoiIGEhKofgJOL3XSdNFMEwZLa7K75ULmXJMgBN2nM2TWem/OgeZMKzhd6lEUwP1tWJFU8C/RKJ+aLyLbqcFXexhxUag26nNIyMCYd2bA5vlRkNCIeLsbOLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735539129; c=relaxed/simple; bh=IENB0nUvzRyRVKBYXng5EyAoZcEesCtDNNIx0/27H4A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AbuDm7+B8b0LcoteEBzj7gkwivLLqI8Aml5SbGw7hCR12DT+O7zrR2vzw7cSYOZZdtZ8NpZCAPRzqnz+4rKWPmfGCzMvq4ab6cLHc4MXYNMFgBCdK+OkFj8eNv/NDkYmisKIFqGAoBU66LCCPwIOR9/LwIu3U+eTVAAU+9bbHtM= 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=f8NVcU+q; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="f8NVcU+q" Received: from mail.ideasonboard.com (unknown [223.190.82.226]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D7C493DC; Mon, 30 Dec 2024 07:11:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1735539080; bh=IENB0nUvzRyRVKBYXng5EyAoZcEesCtDNNIx0/27H4A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=f8NVcU+qIpJV0YKsh73ng6LX1GP+tmstdGAXUuaeqGmBQiKsD0zK+9nHx4W27wjWh ubl5sKDsME3/3dKybs7I4qyHuqGdaYl3qPNwdx5gn4UOZhCAlABcDT9mgK6eeT6PsN 1+OCvdPQQhsv4ggoVU7YIxn51mw0k0keVC6K8K/w= From: Jai Luthra Date: Mon, 30 Dec 2024 11:41:19 +0530 Subject: [PATCH v5 2/5] media: i2c: imx219: Rename VTS to FRM_LENGTH Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241230-imx219_fixes-v5-2-98446d816489@ideasonboard.com> References: <20241230-imx219_fixes-v5-0-98446d816489@ideasonboard.com> In-Reply-To: <20241230-imx219_fixes-v5-0-98446d816489@ideasonboard.com> To: Dave Stevenson , Sakari Ailus , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Jacopo Mondi , Laurent Pinchart , Jai Luthra X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3675; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=IENB0nUvzRyRVKBYXng5EyAoZcEesCtDNNIx0/27H4A=; b=owEBbQKS/ZANAwAIAUPekfkkmnFFAcsmYgBncjmKCEIMIUqZR20vY8jtFmPaj7x23T5RFnmgd N8NSp1P/0aJAjMEAAEIAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCZ3I5igAKCRBD3pH5JJpx RVHvEACvBg/FeJjmh0unfbJ2ELHXM+UcJCV2oA2Fvy9PU+gfqhSFdK1YWAYNZxCSo49D05PovIs MM8AmSmz20yV0dY1Jl+G4J+Lj5p19PT1/4xBOgN/EHkkI+9cG0WIeHwDa0PB68onuenINWKTeWQ 0KjfUEZJF6tL3vrTNd/SdJDkQHVmI/Ja0VeGjhnR6xW6YiIHEjB9xM+zGSqPJdfVQfGBOhFVPaH BNwVklyvGyeqYOUQVcNeCZ6MVzPr76jOLhjfW3Pezfi7UIAIGOQ48GqErE52plP9KheTClxAniL p+zFYciCTzOAkdtU7FaLtlbYqQ77EAVoiFDP1fyFpbdCNt9KzXq8iZtRiZkiW/4LfQCyVuEqTLz po7ZEusngb126lFn6l26aX6sPZnj/9yz9rlhwLaxheyNgzPzcUgYuN8R1ozxLaRBXQPF6NFtMZE 7yvwNqhD8x2Eq8Gjddcr2pigQ0M6kBoM+gQXXIxJ/5pn9Tb6REf2i8TUDCqEq4KyrH2cj1kc7dG Nm5Rq3Yyn17cOtLFvroDUgo1W85O8s4Sy41O5m6MDEKSlvEwhTMZ4DoI7RFAn1LIDsaEAEi7sPm HqZsGpv9w3QgY6TdAAv/dYTWd1VHrAf5p/tgrRJbbjenTWm6cn11iFgns2vhc6liEV3nw3MyseA /pwmmKnbViRYueg== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 The IMX219 datasheet uses the terms FRM_LENGTH and LINE_LENGTH instead of VTS/HTS. Signed-off-by: Jai Luthra Reviewed-by: Dave Stevenson --- drivers/media/i2c/imx219.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c index 0486bbc046cb9c36afd911eb799c1b010a01d496..8565b1b030be2ee24bcc37415e99ee4ef83cc683 100644 --- a/drivers/media/i2c/imx219.c +++ b/drivers/media/i2c/imx219.c @@ -70,9 +70,8 @@ #define IMX219_EXPOSURE_MAX 65535 /* V_TIMING internal */ -#define IMX219_REG_VTS CCI_REG16(0x0160) -#define IMX219_VTS_MAX 0xffff - +#define IMX219_REG_FRM_LENGTH CCI_REG16(0x0160) +#define IMX219_FLL_MAX 0xffff #define IMX219_VBLANK_MIN 32 /* HBLANK control - read only */ @@ -154,7 +153,7 @@ struct imx219_mode { unsigned int height; /* V-timing */ - unsigned int vts_def; + unsigned int fll_def; }; static const struct cci_reg_sequence imx219_common_regs[] = { @@ -289,25 +288,25 @@ static const struct imx219_mode supported_modes[] = { /* 8MPix 15fps mode */ .width = 3280, .height = 2464, - .vts_def = 3526, + .fll_def = 3526, }, { /* 1080P 30fps cropped */ .width = 1920, .height = 1080, - .vts_def = 1763, + .fll_def = 1763, }, { /* 2x2 binned 30fps mode */ .width = 1640, .height = 1232, - .vts_def = 1763, + .fll_def = 1763, }, { /* 640x480 30fps mode */ .width = 640, .height = 480, - .vts_def = 1763, + .fll_def = 1763, }, }; @@ -418,7 +417,7 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) imx219->hflip->val | imx219->vflip->val << 1, &ret); break; case V4L2_CID_VBLANK: - cci_write(imx219->regmap, IMX219_REG_VTS, + cci_write(imx219->regmap, IMX219_REG_FRM_LENGTH, format->height + ctrl->val, &ret); break; case V4L2_CID_TEST_PATTERN_RED: @@ -493,15 +492,15 @@ static int imx219_init_controls(struct imx219 *imx219) /* Initial vblank/hblank/exposure parameters based on current mode */ imx219->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, V4L2_CID_VBLANK, IMX219_VBLANK_MIN, - IMX219_VTS_MAX - mode->height, 1, - mode->vts_def - mode->height); + IMX219_FLL_MAX - mode->height, 1, + mode->fll_def - mode->height); hblank = IMX219_PPL_DEFAULT - mode->width; imx219->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, V4L2_CID_HBLANK, hblank, hblank, 1, hblank); if (imx219->hblank) imx219->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; - exposure_max = mode->vts_def - 4; + exposure_max = mode->fll_def - 4; exposure_def = (exposure_max < IMX219_EXPOSURE_DEFAULT) ? exposure_max : IMX219_EXPOSURE_DEFAULT; imx219->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, @@ -847,12 +846,12 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd, /* Update limits and set FPS to default */ __v4l2_ctrl_modify_range(imx219->vblank, IMX219_VBLANK_MIN, - IMX219_VTS_MAX - mode->height, 1, - mode->vts_def - mode->height); + IMX219_FLL_MAX - mode->height, 1, + mode->fll_def - mode->height); __v4l2_ctrl_s_ctrl(imx219->vblank, - mode->vts_def - mode->height); + mode->fll_def - mode->height); /* Update max exposure while meeting expected vblanking */ - exposure_max = mode->vts_def - 4; + exposure_max = mode->fll_def - 4; exposure_def = (exposure_max < IMX219_EXPOSURE_DEFAULT) ? exposure_max : IMX219_EXPOSURE_DEFAULT; __v4l2_ctrl_modify_range(imx219->exposure, From patchwork Mon Dec 30 06:11:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 13923074 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 14C4419C546; Mon, 30 Dec 2024 06:12:22 +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=1735539143; cv=none; b=lP/vYXBvk2gS1BbWKIYxrdZA6fyEmC1GN4Iu+x0bTem63Emv7gXMt77J6WtLBS+WuOUh4p0sTGJW4Yya6UlRWv2RmPZLsNCaVKullrSyKmiIjv9IhaQH1/u1a4zuM23mRlp3hmk6W0qkRdj1SfGXyRwviKF9VwX9RVIk3PFUjNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735539143; c=relaxed/simple; bh=1fDSuUMI0Cdk1Zam669O5fJ6eaoCw+NsZLJk96wJXB8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Qjv8hdQo6pNKVMGIBR34r52OEsDjRo1fNrC1g3m4WT5oFRVJKLoU1HYUJ98QsRwA6wM+5l6nSpAwT10Y8ovoZ8iutxsf0DQwoptvYYZKtrxbNyUgf1jExRhsIf5aMkFmAkzlh1l5Z79RuZ9BSnty5S9kH49wuD15/7d2EcxIatc= 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=LFG1lJZf; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="LFG1lJZf" Received: from mail.ideasonboard.com (unknown [223.190.82.226]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 440FD3DC; Mon, 30 Dec 2024 07:11:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1735539094; bh=1fDSuUMI0Cdk1Zam669O5fJ6eaoCw+NsZLJk96wJXB8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LFG1lJZf1SNbw7b4glTNvA5BlcYWMqHdL1MB0dp8WwUQdX5lMklyyc0damfch+Spv Sk1YsZKxRBGZk39tu1bk1DU+buHX4T/kCxwM44xtE3WkFvB9oEL7cUlZhAJUmECIJY /LPB0T8xIUAI7MtnrdpZl/ye9XPoDrsvrME/eLCY= From: Jai Luthra Date: Mon, 30 Dec 2024 11:41:20 +0530 Subject: [PATCH v5 3/5] media: i2c: imx219: make HBLANK r/w to allow longer exposures Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241230-imx219_fixes-v5-3-98446d816489@ideasonboard.com> References: <20241230-imx219_fixes-v5-0-98446d816489@ideasonboard.com> In-Reply-To: <20241230-imx219_fixes-v5-0-98446d816489@ideasonboard.com> To: Dave Stevenson , Sakari Ailus , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Jacopo Mondi , Laurent Pinchart , Jai Luthra X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5371; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=po0UcbbPjvedRrNUGAeWRXzY5q5ZoiwB/fj3hUJEa2s=; b=owEBbQKS/ZANAwAIAUPekfkkmnFFAcsmYgBncjmKsA7Zq0rzyy1TgfZK7oqI4A/bnLWIiE+M/ BJTsZCBpvuJAjMEAAEIAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCZ3I5igAKCRBD3pH5JJpx ReE1EACrufTO23PZ8F89Cz1NlB/J+qCvzZPDWdB14bs0aUJVw8k9CU8yH+1MJpX+dfBjvqjUebA YRWqNP5olYf/Fn8LzS+kq0l4xmbN0OSsSvTXo8TYSiRxf45jnVBl+c7vWB1qgoWkHAr0MkD2Qub E4j/f3ZxjGIZHpiT4m15dIez8iPt7HRgbC7WHqUj6q8wAR4XSiB134Ea2dMWiyxHpy9W2lyLO6M iKyzC4ONtfFM/EPW9GycUQ38OglBNxThIJjAUS5MJ5eepBUXustk5Z+xvsYWdWkq8fQrboQ8f7C RBtp+T2fR1hr/L757g70jy9c5hWwZNPXBn93lzLHmP3ijSx7dYjsDtOD3HAGSBcS2nQ6v3OiL5r OddGeipBNoeAv3DAEo5yH02/BdGFm1RksChwg/ztE9kqI+U27sFokRLDGEJRx63YI3hN+wuyKRp zJ/o9hUpAMVUkF/0Ghb1F3y2/r9KKwNJcG8lcLTv7QTvuijWsDn0WfuHpkK5+1moP6kfrHE7DX4 30bK1Wciom+mu5G2Ov9e+0wB8k5Ni+1yv6ymFmvdusXvsi0oMrcBIE9OwoGSRkPBD411VFOiuky sBw6tJVUEwT4Ckbc+uu+Nwbi/T46xXkTMD/tX2S/risCOM7FGZ8qBlAsDmtGYqf5lAGvrmaiQk5 nrKmY9/x4spCI/A== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson The HBLANK control was read-only, and always configured such that the sensor line length register was 3448. This limited the maximum exposure time that could be achieved to around 1.26 secs. Make HBLANK read/write so that the line time can be extended, and thereby allow longer exposures (and slower frame rates). Retain the overall line length setting when changing modes rather than resetting it to a default. Signed-off-by: Dave Stevenson Reviewed-by: Jacopo Mondi Signed-off-by: Jai Luthra --- drivers/media/i2c/imx219.c | 49 +++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c index 8565b1b030be2ee24bcc37415e99ee4ef83cc683..9682a74feb3b7b74cd2ca54779323396c77cd5a5 100644 --- a/drivers/media/i2c/imx219.c +++ b/drivers/media/i2c/imx219.c @@ -73,11 +73,10 @@ #define IMX219_REG_FRM_LENGTH CCI_REG16(0x0160) #define IMX219_FLL_MAX 0xffff #define IMX219_VBLANK_MIN 32 +#define IMX219_REG_LINE_LENGTH CCI_REG16(0x0162) +#define IMX219_LLP_MIN 0x0d78 +#define IMX219_LLP_MAX 0x7ff0 -/* HBLANK control - read only */ -#define IMX219_PPL_DEFAULT 3448 - -#define IMX219_REG_LINE_LENGTH_A CCI_REG16(0x0162) #define IMX219_REG_X_ADD_STA_A CCI_REG16(0x0164) #define IMX219_REG_X_ADD_END_A CCI_REG16(0x0166) #define IMX219_REG_Y_ADD_STA_A CCI_REG16(0x0168) @@ -191,7 +190,7 @@ static const struct cci_reg_sequence imx219_common_regs[] = { { CCI_REG8(0x479b), 0x0e }, /* Frame Bank Register Group "A" */ - { IMX219_REG_LINE_LENGTH_A, 3448 }, + { IMX219_REG_LINE_LENGTH, IMX219_LLP_MIN }, { IMX219_REG_X_ODD_INC_A, 1 }, { IMX219_REG_Y_ODD_INC_A, 1 }, @@ -420,6 +419,10 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) cci_write(imx219->regmap, IMX219_REG_FRM_LENGTH, format->height + ctrl->val, &ret); break; + case V4L2_CID_HBLANK: + cci_write(imx219->regmap, IMX219_REG_LINE_LENGTH, + format->width + ctrl->val, &ret); + break; case V4L2_CID_TEST_PATTERN_RED: cci_write(imx219->regmap, IMX219_REG_TESTP_RED, ctrl->val, &ret); @@ -465,7 +468,7 @@ static int imx219_init_controls(struct imx219 *imx219) const struct imx219_mode *mode = &supported_modes[0]; struct v4l2_ctrl_handler *ctrl_hdlr; struct v4l2_fwnode_device_properties props; - int exposure_max, exposure_def, hblank; + int exposure_max, exposure_def; int i, ret; ctrl_hdlr = &imx219->ctrl_handler; @@ -489,17 +492,16 @@ static int imx219_init_controls(struct imx219 *imx219) if (imx219->link_freq) imx219->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; - /* Initial vblank/hblank/exposure parameters based on current mode */ + /* Initial blanking and exposure. Limits are updated during set_fmt */ imx219->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, V4L2_CID_VBLANK, IMX219_VBLANK_MIN, IMX219_FLL_MAX - mode->height, 1, mode->fll_def - mode->height); - hblank = IMX219_PPL_DEFAULT - mode->width; imx219->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, - V4L2_CID_HBLANK, hblank, hblank, - 1, hblank); - if (imx219->hblank) - imx219->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; + V4L2_CID_HBLANK, + IMX219_LLP_MIN - mode->width, + IMX219_LLP_MAX - mode->width, 1, + IMX219_LLP_MIN - mode->width); exposure_max = mode->fll_def - 4; exposure_def = (exposure_max < IMX219_EXPOSURE_DEFAULT) ? exposure_max : IMX219_EXPOSURE_DEFAULT; @@ -815,6 +817,10 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *format; struct v4l2_rect *crop; unsigned int bin_h, bin_v; + u32 prev_line_len; + + format = v4l2_subdev_state_get_format(state, 0); + prev_line_len = format->width + imx219->hblank->val; mode = v4l2_find_nearest_size(supported_modes, ARRAY_SIZE(supported_modes), @@ -822,8 +828,6 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd, fmt->format.width, fmt->format.height); imx219_update_pad_format(imx219, mode, &fmt->format, fmt->format.code); - - format = v4l2_subdev_state_get_format(state, 0); *format = fmt->format; /* @@ -859,13 +863,18 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd, exposure_max, imx219->exposure->step, exposure_def); /* - * Currently PPL is fixed to IMX219_PPL_DEFAULT, so hblank - * depends on mode->width only, and is not changeble in any - * way other than changing the mode. + * Retain PPL setting from previous mode so that the + * line time does not change on a mode change. + * Limits have to be recomputed as the controls define + * the blanking only, so PPL values need to have the + * mode width subtracted. */ - hblank = IMX219_PPL_DEFAULT - mode->width; - __v4l2_ctrl_modify_range(imx219->hblank, hblank, hblank, 1, - hblank); + hblank = prev_line_len - mode->width; + __v4l2_ctrl_modify_range(imx219->hblank, + IMX219_LLP_MIN - mode->width, + IMX219_LLP_MAX - mode->width, 1, + IMX219_LLP_MIN - mode->width); + __v4l2_ctrl_s_ctrl(imx219->hblank, hblank); } return 0; From patchwork Mon Dec 30 06:11:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 13923075 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 3C86A19882F; Mon, 30 Dec 2024 06:12:36 +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=1735539157; cv=none; b=ij63LmcMdtam1HX1VE6TcjP6olBvtto4AhrfDDdhA6heE/faB+Xwi2mMcrVOrO5l1z/4jrfZhroqr97jYEu+rGV7rH73pRItIx39SPHrKHm/wom6Ippcq3UYY8FPdHQ/4qu/W0JC1236nJAc/goo1j/dRa3tkzaJDB0GBkomhIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735539157; c=relaxed/simple; bh=/zuK+IMKWUpsPxYK9SeLgzl0Ed82qSbZNYmxPYheVTI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W9vPAhm76VKT+GSS2nBwGzIw+NLRIK5tqDApenMEZxTuH3gGscZgrL9g0f9cDY/0J9/2Bswlcb7CRPCfyXPlOir+KZo3pbWZ13Ahce+EkSctNeoV6RTSgPJBey9qsXeDqUo/pF04iORk79n9G7vpvDqm/YvUslMDIbsxC6xquWU= 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=XEXgFnfl; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XEXgFnfl" Received: from mail.ideasonboard.com (unknown [223.190.82.226]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 511AC3DC; Mon, 30 Dec 2024 07:11:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1735539108; bh=/zuK+IMKWUpsPxYK9SeLgzl0Ed82qSbZNYmxPYheVTI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XEXgFnflhnVidsxjb6V5leh8fg6zi8ozPOzbo9oJBE7zInB0Tytpj8DAAkwHXI+dT ENVqw6HcGTn8mfH2M0wZ0j89N8u+UnNG/OsJeN5omfuc0WafC8PkXgfeLJryz6OFef jno1osjRb9zyeKGeyvpIYlXRLtAtP+R1xjXYetjo= From: Jai Luthra Date: Mon, 30 Dec 2024 11:41:21 +0530 Subject: [PATCH v5 4/5] media: i2c: imx219: Increase minimum LLP to fix blocky artefacts Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241230-imx219_fixes-v5-4-98446d816489@ideasonboard.com> References: <20241230-imx219_fixes-v5-0-98446d816489@ideasonboard.com> In-Reply-To: <20241230-imx219_fixes-v5-0-98446d816489@ideasonboard.com> To: Dave Stevenson , Sakari Ailus , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Jacopo Mondi , Laurent Pinchart , Jai Luthra X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1772; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=/zuK+IMKWUpsPxYK9SeLgzl0Ed82qSbZNYmxPYheVTI=; b=kA0DAAgBQ96R+SSacUUByyZiAGdyOYuhZFG2vPQf9iVDj4b872Yc0vGbOftOLWxcui7rq8h8H YkCMwQAAQgAHRYhBE3g2Bjl1XXo1FqvxUPekfkkmnFFBQJncjmLAAoJEEPekfkkmnFFIDUP/235 SrmbWpglvjOM1grxWaxkavyLA7cANjLgm2o7n241Ljf7tHlSVLpGBfPApI3hALhXjisfr6HxTxa GMl8tnxfVqWIHTPb+W46s4zMqWZi1cB7jlMNdbjYYvf3GfSMRPCn5VbuWqHEuMdtoYLvXkWqiI3 OAuGoJC3Y2xaNeSV8CqrygUlrB5OlyXu+mUhC1xQJc9AhvIKJh2V6owY87nAT/Lh+3bhlakzPyQ X/iao7Qqr5KY4HwOl2GnePoNZHBSUnnKla3D46t6M6Zuxs9fnfrtn94YZWdERJJQkUsWZstrcim yQhShPlZoEb0Y67LmR1AbYWPwsJ93fSOYx4OcXI+Ls0HPeCHUtIJQ+sD6AgUe2bIaYlRFfPIAnY In2rZzYNxReN9A6PfmRL9PhK3yWP3FD2Nja0mFR/gJ98eCYRD6G7fmOrhJgJDKSfeMysitEAWJZ 6yQyFehwWnWf2kK3wjdiP6NlALOJN19dyyM7endLtJGaDBWPOGjkarklZzaRAjypvQ0Kd6wLlVG i9URkDdJqQyQSKf5ZNk6KTe8Q6dmfPQ2BjihWdhCdVCCIbPeD9MLEPdS2TcmwQEPyqAJhux3ryG TbvsI4W8U2sjF4MqbLxVlD/pK/b2bwSlf0xazHRzkV+NfEU9lYWSSK8sdYHZgdYRPi+QU0tvw6/ Op+2C X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 The sensor's internal ADC supports a minimum line length of 3448 pixels, which may be too small to use with analog binning, where ADC operates on two lines together. Switch to a higher minimum line length of 3560 pixels to fix the blocky artefacts seen with analog binning [1]. To keep the same default framerate as before for all the modes, lower the default fll value to compensate for the increase in llp. [1]: https://github.com/raspberrypi/rpicam-apps/issues/281#issuecomment-1082894118 Signed-off-by: Jai Luthra --- drivers/media/i2c/imx219.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c index 9682a74feb3b7b74cd2ca54779323396c77cd5a5..5cbd7b90bed28bcf59debdba6dfc76bcd34eb9b4 100644 --- a/drivers/media/i2c/imx219.c +++ b/drivers/media/i2c/imx219.c @@ -74,7 +74,7 @@ #define IMX219_FLL_MAX 0xffff #define IMX219_VBLANK_MIN 32 #define IMX219_REG_LINE_LENGTH CCI_REG16(0x0162) -#define IMX219_LLP_MIN 0x0d78 +#define IMX219_LLP_MIN 0x0de8 #define IMX219_LLP_MAX 0x7ff0 #define IMX219_REG_X_ADD_STA_A CCI_REG16(0x0164) @@ -287,25 +287,25 @@ static const struct imx219_mode supported_modes[] = { /* 8MPix 15fps mode */ .width = 3280, .height = 2464, - .fll_def = 3526, + .fll_def = 3415, }, { /* 1080P 30fps cropped */ .width = 1920, .height = 1080, - .fll_def = 1763, + .fll_def = 1707, }, { /* 2x2 binned 30fps mode */ .width = 1640, .height = 1232, - .fll_def = 1763, + .fll_def = 1707, }, { /* 640x480 30fps mode */ .width = 640, .height = 480, - .fll_def = 1763, + .fll_def = 1707, }, }; From patchwork Mon Dec 30 06:11:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 13923076 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 B726919C540; Mon, 30 Dec 2024 06:12:51 +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=1735539173; cv=none; b=mN/pApkijXx97CcuPlhxIOnie39Z22jnKSUq3JJwJ5sguwnr1cVR0o58pmBJf2roSoX27P4XbULbIvodcl8/hXI2KyYiKfxic33YzjulkqwtPw9eQt8da2w8b/1Ul3W1Eu8C9GdLxRsTyfv1uBlA/eZ9kC5V5ill028YvasP67E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735539173; c=relaxed/simple; bh=vaIACIxTAULei+Rf8/xxa2Gt+ViMXC96v1k+m8hqYv8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oiDxToGktWgT8GbIpOg2EBRrmATbkpCgTZkZ0GJ/TxekP0njFpZVbnPiyb8z/90YS6BU1lRKdH179wvAsrfliC/UKoEa1yAYFqYKG8/pQWBJdcpkaUTtb45UD5R6HHf1UtreCnLUBjhnfJeBEnNB35AMEWqSFobS4IALkl18nqA= 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=A+n3Ehpy; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="A+n3Ehpy" Received: from mail.ideasonboard.com (unknown [223.190.82.226]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A619C3DC; Mon, 30 Dec 2024 07:12:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1735539124; bh=vaIACIxTAULei+Rf8/xxa2Gt+ViMXC96v1k+m8hqYv8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=A+n3EhpycbKFiLDz5KW4jFwbOEGB2+YAE9+skZXExzXyFxtD2a1HGPY+RH4ZkdU0c 7G+ruO9tYFGn5RvLERk+PmY/uxRg5D0/M8lTIzHUaFI3yxsiM2hYbB+TG4tg77m/gp 9qt8H8PolF8oXAup6PGCoRnZaS+RuZeLoi69chvY= From: Jai Luthra Date: Mon, 30 Dec 2024 11:41:22 +0530 Subject: [PATCH v5 5/5] media: i2c: imx219: Scale the pixel rate for analog binning Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241230-imx219_fixes-v5-5-98446d816489@ideasonboard.com> References: <20241230-imx219_fixes-v5-0-98446d816489@ideasonboard.com> In-Reply-To: <20241230-imx219_fixes-v5-0-98446d816489@ideasonboard.com> To: Dave Stevenson , Sakari Ailus , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Jacopo Mondi , Laurent Pinchart , Jai Luthra , Naushir Patuck , Vinay Varma X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7468; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=vaIACIxTAULei+Rf8/xxa2Gt+ViMXC96v1k+m8hqYv8=; b=owEBbQKS/ZANAwAIAUPekfkkmnFFAcsmYgBncjmLfpKwhu3gGTnXJteTuv8nWBSnrCE739TRv OPxx+pilhWJAjMEAAEIAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCZ3I5iwAKCRBD3pH5JJpx RcIzEACOWD6gWEO2bRF1Aa/hEtD47vri/cvVtV9owMOUJ5dmQoeLCKT5Ym1dlO4u6Vvh63kNoLb vUkGc5xgJe4R9QQ2AtK1rfvOPzQInM6gvqumss695b/TgjYDx0zAIohjnpTzAoelf3OxQlJyKMj SOULtSxYF0kKtVhgV5ofb2NHzVjpbmKbhLunn1kkp2gLSDwaZrQdaQ1O2xQ5M/1Ae2GFdiVfBYs AZQnKXVR8KiY15MyVapxTSunVh0mJ3DPiJfnkWpNZP1y4koin1dsVrZSzp+W869baXXD1/QeEkk PSfVlfKC8rNGU2t6goKHPDpwKcdZ4pF3i6AEvHPYf03e2H2rVvqm1ivT/qPE/gwiTm+/2KmrRBh QB8xrM0tv6IpPovFVee6qwNoDBfoCiRQsIepIlUOTI0qVWJvMYNfEIUluaGeOaux5YkEg1Ht1O+ fWYkowV/aR5cEKo03kRakisTsjCLCsnlGpsCQEfuG2MBiwrxifSN8bn2URAvXmt+Qcjr2HWTNVR Ae9FylRA8Ym00Q2UkMQq3JIDIVROPLJ43SOooWidicxjwUKT0kdPkS+h+7JzrpBHjkNRrdpNfbd dh8BhXkNjpUHUpteo2awPbJHUPHWnU/9pQeioe7TDYsGvbOu7VjSRcu5i20C1+YvLAsSvlNikVB zERAxE4734M0TLw== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 When the analog binning mode is used for high framerate operation, the pixel rate is effectively doubled. Account for this when setting up the pixel clock rate, and applying the vblank and exposure controls. The previous logic only used analog binning for RAW8, but normal binning limits the framerate on RAW10 480p [1]. So with this patch we switch to using special binning (with 2x pixel rate) wherever possible. [1]: https://github.com/raspberrypi/linux/issues/5493 Co-developed-by: Naushir Patuck Signed-off-by: Naushir Patuck Co-developed-by: Vinay Varma Signed-off-by: Vinay Varma Signed-off-by: Jai Luthra --- drivers/media/i2c/imx219.c | 126 +++++++++++++++++++++++++++++---------------- 1 file changed, 81 insertions(+), 45 deletions(-) diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c index 5cbd7b90bed28bcf59debdba6dfc76bcd34eb9b4..ec08c63005e3ce4f28d19579f9502a397a52988c 100644 --- a/drivers/media/i2c/imx219.c +++ b/drivers/media/i2c/imx219.c @@ -144,6 +144,12 @@ #define IMX219_PIXEL_ARRAY_WIDTH 3280U #define IMX219_PIXEL_ARRAY_HEIGHT 2464U +enum binning_mode { + BINNING_NONE = IMX219_BINNING_NONE, + BINNING_X2 = IMX219_BINNING_X2, + BINNING_ANALOG_X2 = IMX219_BINNING_X2_ANALOG, +}; + /* Mode : resolution and related config&values */ struct imx219_mode { /* Frame width */ @@ -296,13 +302,13 @@ static const struct imx219_mode supported_modes[] = { .fll_def = 1707, }, { - /* 2x2 binned 30fps mode */ + /* 2x2 binned 60fps mode */ .width = 1640, .height = 1232, .fll_def = 1707, }, { - /* 640x480 30fps mode */ + /* 640x480 60fps mode */ .width = 640, .height = 480, .fll_def = 1707, @@ -357,6 +363,59 @@ static u32 imx219_get_format_code(struct imx219 *imx219, u32 code) return imx219_mbus_formats[i]; } +static u32 imx219_get_format_bpp(const struct v4l2_mbus_framefmt *format) +{ + switch (format->code) { + case MEDIA_BUS_FMT_SRGGB8_1X8: + case MEDIA_BUS_FMT_SGRBG8_1X8: + case MEDIA_BUS_FMT_SGBRG8_1X8: + case MEDIA_BUS_FMT_SBGGR8_1X8: + return 8; + + case MEDIA_BUS_FMT_SRGGB10_1X10: + case MEDIA_BUS_FMT_SGRBG10_1X10: + case MEDIA_BUS_FMT_SGBRG10_1X10: + case MEDIA_BUS_FMT_SBGGR10_1X10: + default: + return 10; + } +} + +static enum binning_mode imx219_get_binning(struct imx219 *imx219, u8 *bin_h, + u8 *bin_v) +{ + struct v4l2_subdev_state *state = + v4l2_subdev_get_locked_active_state(&imx219->sd); + const struct v4l2_mbus_framefmt *format = + v4l2_subdev_state_get_format(state, 0); + const struct v4l2_rect *crop = v4l2_subdev_state_get_crop(state, 0); + + *bin_h = crop->width / format->width; + *bin_v = crop->height / format->height; + + if (*bin_h == 2 && *bin_v == 2) + return BINNING_ANALOG_X2; + else if (*bin_h == 2 || *bin_v == 2) + /* + * Don't use analog binning if only one dimension + * is binned, as it crops the other dimension + */ + return BINNING_X2; + else + return BINNING_NONE; +} + +static inline u32 imx219_get_rate_factor(struct imx219 *imx219) +{ + u8 bin_h, bin_v; + enum binning_mode binning = imx219_get_binning(imx219, &bin_h, &bin_v); + + if (binning == BINNING_ANALOG_X2) + return 2; + + return 1; +} + /* ----------------------------------------------------------------------------- * Controls */ @@ -368,10 +427,12 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); const struct v4l2_mbus_framefmt *format; struct v4l2_subdev_state *state; + u32 rate_factor; int ret = 0; state = v4l2_subdev_get_locked_active_state(&imx219->sd); format = v4l2_subdev_state_get_format(state, 0); + rate_factor = imx219_get_rate_factor(imx219); if (ctrl->id == V4L2_CID_VBLANK) { int exposure_max, exposure_def; @@ -400,7 +461,7 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) break; case V4L2_CID_EXPOSURE: cci_write(imx219->regmap, IMX219_REG_EXPOSURE, - ctrl->val, &ret); + ctrl->val / rate_factor, &ret); break; case V4L2_CID_DIGITAL_GAIN: cci_write(imx219->regmap, IMX219_REG_DIGITAL_GAIN, @@ -417,7 +478,7 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl) break; case V4L2_CID_VBLANK: cci_write(imx219->regmap, IMX219_REG_FRM_LENGTH, - format->height + ctrl->val, &ret); + (format->height + ctrl->val) / rate_factor, &ret); break; case V4L2_CID_HBLANK: cci_write(imx219->regmap, IMX219_REG_LINE_LENGTH, @@ -588,29 +649,14 @@ static int imx219_set_framefmt(struct imx219 *imx219, { const struct v4l2_mbus_framefmt *format; const struct v4l2_rect *crop; - unsigned int bpp; - u64 bin_h, bin_v; + enum binning_mode binning; + u8 bin_h, bin_v; + u32 bpp; int ret = 0; format = v4l2_subdev_state_get_format(state, 0); crop = v4l2_subdev_state_get_crop(state, 0); - - switch (format->code) { - case MEDIA_BUS_FMT_SRGGB8_1X8: - case MEDIA_BUS_FMT_SGRBG8_1X8: - case MEDIA_BUS_FMT_SGBRG8_1X8: - case MEDIA_BUS_FMT_SBGGR8_1X8: - bpp = 8; - break; - - case MEDIA_BUS_FMT_SRGGB10_1X10: - case MEDIA_BUS_FMT_SGRBG10_1X10: - case MEDIA_BUS_FMT_SGBRG10_1X10: - case MEDIA_BUS_FMT_SBGGR10_1X10: - default: - bpp = 10; - break; - } + bpp = imx219_get_format_bpp(format); cci_write(imx219->regmap, IMX219_REG_X_ADD_STA_A, crop->left - IMX219_PIXEL_ARRAY_LEFT, &ret); @@ -621,28 +667,11 @@ static int imx219_set_framefmt(struct imx219 *imx219, cci_write(imx219->regmap, IMX219_REG_Y_ADD_END_A, crop->top - IMX219_PIXEL_ARRAY_TOP + crop->height - 1, &ret); - switch (crop->width / format->width) { - case 1: - default: - bin_h = IMX219_BINNING_NONE; - break; - case 2: - bin_h = bpp == 8 ? IMX219_BINNING_X2_ANALOG : IMX219_BINNING_X2; - break; - } - - switch (crop->height / format->height) { - case 1: - default: - bin_v = IMX219_BINNING_NONE; - break; - case 2: - bin_v = bpp == 8 ? IMX219_BINNING_X2_ANALOG : IMX219_BINNING_X2; - break; - } - - cci_write(imx219->regmap, IMX219_REG_BINNING_MODE_H, bin_h, &ret); - cci_write(imx219->regmap, IMX219_REG_BINNING_MODE_V, bin_v, &ret); + binning = imx219_get_binning(imx219, &bin_h, &bin_v); + cci_write(imx219->regmap, IMX219_REG_BINNING_MODE_H, + (bin_h == 2) ? binning : BINNING_NONE, &ret); + cci_write(imx219->regmap, IMX219_REG_BINNING_MODE_V, + (bin_v == 2) ? binning : BINNING_NONE, &ret); cci_write(imx219->regmap, IMX219_REG_X_OUTPUT_SIZE, format->width, &ret); @@ -847,6 +876,7 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd, int exposure_max; int exposure_def; int hblank; + int pixel_rate; /* Update limits and set FPS to default */ __v4l2_ctrl_modify_range(imx219->vblank, IMX219_VBLANK_MIN, @@ -875,6 +905,12 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd, IMX219_LLP_MAX - mode->width, 1, IMX219_LLP_MIN - mode->width); __v4l2_ctrl_s_ctrl(imx219->hblank, hblank); + + /* Scale the pixel rate based on the mode specific factor */ + pixel_rate = imx219_get_pixel_rate(imx219) * + imx219_get_rate_factor(imx219); + __v4l2_ctrl_modify_range(imx219->pixel_rate, pixel_rate, + pixel_rate, 1, pixel_rate); } return 0;