From patchwork Wed Mar 27 22:20:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Garcia X-Patchwork-Id: 783839 Received: from mail-108-mta153.mxroute.com (mail-108-mta153.mxroute.com [136.175.108.153]) (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 E311B153822 for ; Wed, 27 Mar 2024 22:26:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=136.175.108.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578364; cv=none; b=r5m6YpJ1EWfIBJ6PIzv3B7ivuIxIquUUnMJ5PX/RkXG2QeXbhmfG+VIZd+3/iaVvQMW4jc7BKEKudLR9DLVHYnkZp24pJjihRibS4qt2ngK9/F8goEhPo75uI04ytxgErfUAJRu0il2ET1Em5gXDfQnq9gz7uIl88Zq+vDc9l1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578364; c=relaxed/simple; bh=AdHweroZnT+pHzZ/vSg+ukBfbmEglEx27aSOBLZQSiA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PVprE+jJM9gMnx6yP+rrSuJSpHql8DRUGAjfCTaSTJ2PHcVZNG5CzZiwDyMVS4O9qbdgE172FZt3YeKwIEo3fRPIP2onr7eaiSbR615LtkFbtkBUrJDirVoBUn6jSYF72HLsotnbBIMeBrurEzoQtcmre7xIwLf7Mfs/u0SK4wc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com; spf=pass smtp.mailfrom=luigi311.com; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b=vV8EWvL2; arc=none smtp.client-ip=136.175.108.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=luigi311.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b="vV8EWvL2" Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta153.mxroute.com (ZoneMTA) with ESMTPSA id 18e82005e750003bea.010 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 27 Mar 2024 22:20:46 +0000 X-Zone-Loop: dbe4589b9bb3ff4af3fc74c05b0c159edc397f62b769 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=luigi311.com; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=oPBK+fqL/hsM837Y3buk53bLBMvRdlTlsTvv2J3d9qk=; b=vV8EWvL2zYFXA8MhOAwfFxeG+E L2VmoRtonsoQuddXRSAw/GDqP9EFVH3uJhmHP6EpLVj+HjqWj9saXiu9Jel8fKvQBJSh5e1iQt4sh iLjeACpLqvZHEoCBOWFj446zlj44PVwhLJWmSdlbiowcNZ4OQzkwaQKPHkO1g3qfOPzQ/UYTtlxvS VxwZCTIxw21NVEcmYva5FNHxZaX91loxdzAdR1KYxvX7hJrdjgb7HqMjztZwRzkiNzFuBP58biA37 jQybOfZKAXMBcpY3glnEXik44CUYLCQxJXEga39pkvRgT+fvwiwjNQgH5dhpc0nN7wnxsEk43peeO k4st52Gw==; From: git@luigi311.com To: linux-media@vger.kernel.org Cc: dave.stevenson@raspberrypi.com, jacopo.mondi@ideasonboard.com, mchehab@kernel.org, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, sakari.ailus@linux.intel.com, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x@xnux.eu Subject: [PATCH 01/23] media: i2c: imx258: Remove unused defines Date: Wed, 27 Mar 2024 16:20:13 -0600 Message-ID: <20240327222035.47208-2-git@luigi311.com> In-Reply-To: <20240327222035.47208-1-git@luigi311.com> References: <20240327222035.47208-1-git@luigi311.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authenticated-Id: personal@luigi311.com From: Dave Stevenson The IMX258_FLL_* defines are unused. Remove them. Signed-off-by: Dave Stevenson Reviewed-by: Jacopo Mondi --- drivers/media/i2c/imx258.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index a577afb530b7..2dbafd21dd70 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -29,12 +29,6 @@ #define IMX258_VTS_30FPS_VGA 0x034c #define IMX258_VTS_MAX 0xffff -/*Frame Length Line*/ -#define IMX258_FLL_MIN 0x08a6 -#define IMX258_FLL_MAX 0xffff -#define IMX258_FLL_STEP 1 -#define IMX258_FLL_DEFAULT 0x0c98 - /* HBLANK control - read only */ #define IMX258_PPL_DEFAULT 5352 From patchwork Wed Mar 27 22:20:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luis Garcia X-Patchwork-Id: 783429 Received: from mail-108-mta157.mxroute.com (mail-108-mta157.mxroute.com [136.175.108.157]) (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 07A55154444 for ; Wed, 27 Mar 2024 22:26:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=136.175.108.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578370; cv=none; b=rjxQaBvhFTkmQKQzSBh+YOsJNAHdjLCf1F/Mj1Ct6j5U8AOTYzBuwmUxzwXxpBJeOzFxkrv9yKHwRj8U1tV7j2CUOzgXP5f3XuY3kEeOsPinv6JNsc5mCeOb/f1uTYttgMs4oOCBx1URvIxUaj5MbYVlXBgmbNm05KkJRmv2Fn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578370; c=relaxed/simple; bh=jNP2p08WMq4rAvPD5G7zFc0QqU8Ssu6AvUGSAXAqNqE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bfnL5/0VXwb5gQscO1KfAIuI06/jLY8b77lZLLqX9mcqbc0FsCJgu6nj/mW4HTgv8Ij3T8ObKF6UuCs2Q6NSbg+JDcErsne2EKv/w6/iknRkZVqLt4h/wLgIZArE4Y4l6ltmURONFnFNpUUAqSv22+Rl9Vneff8vU2trdCjy7TI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com; spf=pass smtp.mailfrom=luigi311.com; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b=B9ff2Ubw; arc=none smtp.client-ip=136.175.108.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=luigi311.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b="B9ff2Ubw" Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta157.mxroute.com (ZoneMTA) with ESMTPSA id 18e82006d5c0003bea.010 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 27 Mar 2024 22:20:49 +0000 X-Zone-Loop: 844d6272af5a9a16b273286cb2f7eabf295281c3bfcb DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=luigi311.com; s=x; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=pF+o/HwmqytRK3VcYcqwANjTHrDtZUjVJoHdG1r7wW4=; b=B9ff2UbwQIo2dGt/8jliHkC86K 1X65lupM9IL10DCFtqVqNnxhhE6T1t9Sawp0WHl1NMRiVEWhndkcJN3NyPJMOZUm8f7AzGMP2126I vwil6teubbCObwrkk0WhXa0eTDBrs5eVJqsItdxpT5f8CtD5l4QgViLmAGAmGGyJf0drQwbgKOFTz UMqQf0+bydgTl6NpyiCDTZhHX00czOLICnstXJbobPZqoCkPmIK+92aWBBBxRgypzJvYWiyQQmozH vIGWL6ig70yumWRfLP3w//kM7vva3W0T3uyoCXlYzNSWQFwHegtCtDnpPFVY4Db4fSgMOmMaHM7Jj d3zbq4Mg==; From: git@luigi311.com To: linux-media@vger.kernel.org Cc: dave.stevenson@raspberrypi.com, jacopo.mondi@ideasonboard.com, mchehab@kernel.org, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, sakari.ailus@linux.intel.com, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x@xnux.eu Subject: [PATCH 02/23] media: i2c: imx258: Make image geometry meet sensor requirements Date: Wed, 27 Mar 2024 16:20:14 -0600 Message-ID: <20240327222035.47208-3-git@luigi311.com> In-Reply-To: <20240327222035.47208-1-git@luigi311.com> References: <20240327222035.47208-1-git@luigi311.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authenticated-Id: personal@luigi311.com From: Dave Stevenson The output image is defined as being 4208x3118 pixels in size. Y_ADD_STA register was set to 0, and Y_ADD_END to 3118, giving 3119 lines total. The datasheet lists a requirement for Y_ADD_STA to be a multiple of a power of 2 depending on binning/scaling mode (2 for full pixel, 4 for x2-bin/scale, 8 for (x2-bin)+(x2-subsample) or x4-bin, or 16 for (x4-bin)+(x2-subsample)). (Y_ADD_END – Y_ADD_STA + 1) also has to be a similar power of 2. The current configuration for the full res modes breaks that second requirement, and we can't increase Y_ADD_STA to 1 to retain exactly the same field of view as that then breaks the first requirement. For the binned modes, they are worse off as 3118 is not a multiple of 4. Increase the main mode to 4208x3120 so that it is the same FOV as the binned modes, with Y_ADD_STA at 0. Fix Y_ADD_STA and Y_ADD_END for the binned modes so that they meet the sensor requirements. This does change the Bayer order as the default configuration is for H&V flips to be enabled, so readout is from Y_STA_END to Y_ADD_STA, and this patch has changed Y_STA_END. Signed-off-by: Dave Stevenson Reviewed-by: Jacopo Mondi --- drivers/media/i2c/imx258.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 2dbafd21dd70..4a7048d834c6 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -111,7 +111,7 @@ struct imx258_mode { struct imx258_reg_list reg_list; }; -/* 4208x3118 needs 1267Mbps/lane, 4 lanes */ +/* 4208x3120 needs 1267Mbps/lane, 4 lanes */ static const struct imx258_reg mipi_data_rate_1267mbps[] = { { 0x0301, 0x05 }, { 0x0303, 0x02 }, @@ -148,7 +148,7 @@ static const struct imx258_reg mipi_data_rate_640mbps[] = { { 0x0823, 0x00 }, }; -static const struct imx258_reg mode_4208x3118_regs[] = { +static const struct imx258_reg mode_4208x3120_regs[] = { { 0x0136, 0x13 }, { 0x0137, 0x33 }, { 0x3051, 0x00 }, @@ -210,7 +210,7 @@ static const struct imx258_reg mode_4208x3118_regs[] = { { 0x0348, 0x10 }, { 0x0349, 0x6F }, { 0x034A, 0x0C }, - { 0x034B, 0x2E }, + { 0x034B, 0x2F }, { 0x0381, 0x01 }, { 0x0383, 0x01 }, { 0x0385, 0x01 }, @@ -329,7 +329,7 @@ static const struct imx258_reg mode_2104_1560_regs[] = { { 0x0348, 0x10 }, { 0x0349, 0x6F }, { 0x034A, 0x0C }, - { 0x034B, 0x2E }, + { 0x034B, 0x2F }, { 0x0381, 0x01 }, { 0x0383, 0x01 }, { 0x0385, 0x01 }, @@ -448,7 +448,7 @@ static const struct imx258_reg mode_1048_780_regs[] = { { 0x0348, 0x10 }, { 0x0349, 0x6F }, { 0x034A, 0x0C }, - { 0x034B, 0x2E }, + { 0x034B, 0x2F }, { 0x0381, 0x01 }, { 0x0383, 0x01 }, { 0x0385, 0x01 }, @@ -562,12 +562,12 @@ static const struct imx258_link_freq_config link_freq_configs[] = { static const struct imx258_mode supported_modes[] = { { .width = 4208, - .height = 3118, + .height = 3120, .vts_def = IMX258_VTS_30FPS, .vts_min = IMX258_VTS_30FPS, .reg_list = { - .num_of_regs = ARRAY_SIZE(mode_4208x3118_regs), - .regs = mode_4208x3118_regs, + .num_of_regs = ARRAY_SIZE(mode_4208x3120_regs), + .regs = mode_4208x3120_regs, }, .link_freq_index = IMX258_LINK_FREQ_1267MBPS, }, @@ -707,7 +707,7 @@ static int imx258_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) /* Initialize try_fmt */ try_fmt->width = supported_modes[0].width; try_fmt->height = supported_modes[0].height; - try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; + try_fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10; try_fmt->field = V4L2_FIELD_NONE; return 0; @@ -819,7 +819,7 @@ static int imx258_enum_mbus_code(struct v4l2_subdev *sd, if (code->index > 0) return -EINVAL; - code->code = MEDIA_BUS_FMT_SGRBG10_1X10; + code->code = MEDIA_BUS_FMT_SBGGR10_1X10; return 0; } @@ -831,7 +831,7 @@ static int imx258_enum_frame_size(struct v4l2_subdev *sd, if (fse->index >= ARRAY_SIZE(supported_modes)) return -EINVAL; - if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10) + if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10) return -EINVAL; fse->min_width = supported_modes[fse->index].width; @@ -847,7 +847,7 @@ static void imx258_update_pad_format(const struct imx258_mode *mode, { fmt->format.width = mode->width; fmt->format.height = mode->height; - fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; + fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10; fmt->format.field = V4L2_FIELD_NONE; } @@ -894,7 +894,7 @@ static int imx258_set_pad_format(struct v4l2_subdev *sd, mutex_lock(&imx258->mutex); /* Only one raw bayer(GBRG) order is supported */ - fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; + fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10; mode = v4l2_find_nearest_size(supported_modes, ARRAY_SIZE(supported_modes), width, height, From patchwork Wed Mar 27 22:20:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Garcia X-Patchwork-Id: 783838 Received: from mail-108-mta49.mxroute.com (mail-108-mta49.mxroute.com [136.175.108.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 DD47E154435 for ; Wed, 27 Mar 2024 22:26:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=136.175.108.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578370; cv=none; b=B0pdS9crFzQ2Hq0aV10aXZbo/4Rq74QikIID6CTCuLH7MynLozuBQ76BtvAg9CDJFwzITp6UsQJueFWfv9F3hqUi0WqV9xp7+uYiwUUZGVaSunUW7Pf/rQ5kpg0STOoMg/yuGIK4z+3Pi1swrp4a2b0IkoVfSulY542loiZcpwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578370; c=relaxed/simple; bh=3Os/T7XYPPuIQ9wkr2Su5Kx7M9odE7Rv2QP5TKP3BkE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JaADIRyNbdSVHcC9XaSJiEIuEvkSBJh+lgawFz2mAFcPTNqjZjwok8QAGkg2xtwoN/ufSJc2GqhgQah3bVOXCMGbQ+IkT7SUU+5m+0G6Skb0t/EAlyHxoiScnfPTztELM0twRt6ld6v2oJxutm2QXGzTCLTlpcZjfXs4Vsc58ak= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com; spf=pass smtp.mailfrom=luigi311.com; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b=u0ItyWUb; arc=none smtp.client-ip=136.175.108.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=luigi311.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b="u0ItyWUb" Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta49.mxroute.com (ZoneMTA) with ESMTPSA id 18e8200738e0003bea.010 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 27 Mar 2024 22:20:51 +0000 X-Zone-Loop: d8b053442ad62904a278918700941c46136e02bad003 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=luigi311.com; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=KW1mmB+UsQBWu80vviFCvkS83K6yY9xI4ffO4IjmdFk=; b=u0ItyWUb09UfcJxkaIveclCfXh xBOlan1n/02oKFXfvTm1s80u8WWKXF/2XsJUUc4r04bycRw+nrXanaRi7LA2/Z+7uDZuwITZ4GL6r 4qTyvTEAjeIK2t8ofXNg0LY70w20wWaA/XjhhuLGvRgBKErQYUJxED7hV8L/fXTUSAAfvVlCtHrCz Qg5CGjGpOw85bi9JkaxzCc/eRQ0rw6fA6//7GKM8TU/phxx7ueujmMi3hEq0tuIuY2TJqIVyL4HIt oVNl5uQnN7uFT377WZaE94XlhJKX1nyBNotWQ0/7mZNmOl5EwrezJ+QQ/+bSW1Hux86eWwrorPB3l s2jHPlmw==; From: git@luigi311.com To: linux-media@vger.kernel.org Cc: dave.stevenson@raspberrypi.com, jacopo.mondi@ideasonboard.com, mchehab@kernel.org, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, sakari.ailus@linux.intel.com, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x@xnux.eu Subject: [PATCH 03/23] media: i2c: imx258: Disable digital cropping on binned modes Date: Wed, 27 Mar 2024 16:20:15 -0600 Message-ID: <20240327222035.47208-4-git@luigi311.com> In-Reply-To: <20240327222035.47208-1-git@luigi311.com> References: <20240327222035.47208-1-git@luigi311.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authenticated-Id: personal@luigi311.com From: Dave Stevenson The binned modes set DIG_CROP_X_OFFSET and DIG_CROP_IMAGE_WIDTH to less than the full image, even though the image being captured is meant to be a scaled version of the full array size. Reduce X_OFFSET to 0, and increase IMAGE_WIDTH to the full array. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx258.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 4a7048d834c6..0ae4371940ca 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -340,11 +340,11 @@ static const struct imx258_reg mode_2104_1560_regs[] = { { 0x0404, 0x00 }, { 0x0405, 0x20 }, { 0x0408, 0x00 }, - { 0x0409, 0x02 }, + { 0x0409, 0x00 }, { 0x040A, 0x00 }, { 0x040B, 0x00 }, { 0x040C, 0x10 }, - { 0x040D, 0x6A }, + { 0x040D, 0x70 }, { 0x040E, 0x06 }, { 0x040F, 0x18 }, { 0x3038, 0x00 }, @@ -459,11 +459,11 @@ static const struct imx258_reg mode_1048_780_regs[] = { { 0x0404, 0x00 }, { 0x0405, 0x40 }, { 0x0408, 0x00 }, - { 0x0409, 0x06 }, + { 0x0409, 0x00 }, { 0x040A, 0x00 }, { 0x040B, 0x00 }, { 0x040C, 0x10 }, - { 0x040D, 0x64 }, + { 0x040D, 0x70 }, { 0x040E, 0x03 }, { 0x040F, 0x0C }, { 0x3038, 0x00 }, From patchwork Wed Mar 27 22:20:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Garcia X-Patchwork-Id: 783837 Received: from mail-108-mta14.mxroute.com (mail-108-mta14.mxroute.com [136.175.108.14]) (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 D9F0315530B for ; Wed, 27 Mar 2024 22:26:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=136.175.108.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578374; cv=none; b=dCnKtPkfCTEgbn5FLBvwpWtezZ/xPiXLa9gHmTPpRltLNWQtTv9InUUyK9UP77wp++rBtD4sIc7vVLL2M1M3z0oV4TAu51pCXkc5seyYP6N03euOce8G01VqK4o8CuTd00mo/7EVaqW/Wx07XlqxBeb3IZER9iq8CWzHivruN6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578374; c=relaxed/simple; bh=B4s2yCDpIKOW86tAjjQ6L/UaYF/IQ6mt7oWrgOD4HUs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o8Um7RidcRKr5nkC/IwNgab5dt3O6wtyY1EnrX3AWMD5YfqrclqtvaJYrP1qAcAwwDdIQvIZfM7diOXNORoUIEbcm6iwci0Ie6qC8V4IP43LA/wHNSsSu6wOHY8oz2J6DSAmil+iGXfeaU/PCSAdzkWmGZNvWgxykniILPwEKl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com; spf=pass smtp.mailfrom=luigi311.com; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b=MqX3fr/K; arc=none smtp.client-ip=136.175.108.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=luigi311.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b="MqX3fr/K" Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta14.mxroute.com (ZoneMTA) with ESMTPSA id 18e82007a190003bea.010 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 27 Mar 2024 22:20:53 +0000 X-Zone-Loop: 4345b266aba912aec4716709037d361b8ffce40242ec DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=luigi311.com; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8bhqgLzRjHq8zDgKCYHR1LOSNnMHG3H17WmIQSeJXnE=; b=MqX3fr/KR2+xxLWjV6UgowE1Je IT+8u+qiekK5aAhIE2blnT3okZK2v6Q1DPHvl1UdCIO70g9SZ4pQUcK53HJgIsFpMMPFrTv9UzDwu WOgaLgnQ+qDiWRSHE7asfcUcIIXs5MYHQbnfE2vVnEjoH5dgSsX8C5PitVGuFIXStNbKoVGDx/Xb7 Ad5c4J8rxKbEhrjwakKQPBZQtQUSMflPYI2u+3aSIBvaIOYF8uPp553KF5TecISCjLwSmVQMN5o9A z6WGGuvnFOYbJK1DbfYtGSNJrAKkUKhtouHjY8lWFE2BBgTx9W+oZ2OjFflemwcKxNbt+91KM9CTW 5mmO7sZA==; From: git@luigi311.com To: linux-media@vger.kernel.org Cc: dave.stevenson@raspberrypi.com, jacopo.mondi@ideasonboard.com, mchehab@kernel.org, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, sakari.ailus@linux.intel.com, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x@xnux.eu Subject: [PATCH 04/23] media: i2c: imx258: Remove redundant I2C writes. Date: Wed, 27 Mar 2024 16:20:16 -0600 Message-ID: <20240327222035.47208-5-git@luigi311.com> In-Reply-To: <20240327222035.47208-1-git@luigi311.com> References: <20240327222035.47208-1-git@luigi311.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authenticated-Id: personal@luigi311.com From: Dave Stevenson Registers 0x0202 and 0x0203 are written via the control handler for V4L2_CID_EXPOSURE, so are not needed from the mode lists. Signed-off-by: Dave Stevenson Reviewed-by: Jacopo Mondi --- drivers/media/i2c/imx258.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 0ae4371940ca..df7ed4716762 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -237,8 +237,6 @@ static const struct imx258_reg mode_4208x3120_regs[] = { { 0x034E, 0x0C }, { 0x034F, 0x30 }, { 0x0350, 0x01 }, - { 0x0202, 0x0C }, - { 0x0203, 0x46 }, { 0x0204, 0x00 }, { 0x0205, 0x00 }, { 0x020E, 0x01 }, @@ -356,8 +354,6 @@ static const struct imx258_reg mode_2104_1560_regs[] = { { 0x034E, 0x06 }, { 0x034F, 0x18 }, { 0x0350, 0x01 }, - { 0x0202, 0x06 }, - { 0x0203, 0x2E }, { 0x0204, 0x00 }, { 0x0205, 0x00 }, { 0x020E, 0x01 }, @@ -475,8 +471,6 @@ static const struct imx258_reg mode_1048_780_regs[] = { { 0x034E, 0x03 }, { 0x034F, 0x0C }, { 0x0350, 0x01 }, - { 0x0202, 0x03 }, - { 0x0203, 0x42 }, { 0x0204, 0x00 }, { 0x0205, 0x00 }, { 0x020E, 0x01 }, From patchwork Wed Mar 27 22:20:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Garcia X-Patchwork-Id: 783430 Received: from mail-108-mta109.mxroute.com (mail-108-mta109.mxroute.com [136.175.108.109]) (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 DEACD154436 for ; Wed, 27 Mar 2024 22:26:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=136.175.108.109 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578370; cv=none; b=mP/HP7W3Z8bM9mUpbFJ/VJ/a/+Skxv6rw4fr0vq3Bui5qxSswevlhPRIUQZnFe394h5LSS+NECYuptK53ZA/qKLcME4AGPtNIuVYuTRBEAQBGRGdjXnUkyDyuqj/Gj+PxroM/oploECITW8JJKZJQBqNoxqScjfOiozyRUtfqUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578370; c=relaxed/simple; bh=1iE8P7W9oJH44MhsahqLftnU88zvC+0TSEH6ZniPwWY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uO80eXHN1o4jlTkpvu0zxfMUBZS8A1eKqM8kQ6B+JH4jgV1jcZZ524gvM7qRto9FXhvtnvMnKTXECwKYWeK24X6/LngrEqzdpvJllGo8vkM/GTfreEVZdespeLvVSVcO/c6vrh89TQx5hcNpzUYXxOl5kFOZ1UJ0MQqej45fKJE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com; spf=pass smtp.mailfrom=luigi311.com; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b=l5j3WqYw; arc=none smtp.client-ip=136.175.108.109 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=luigi311.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b="l5j3WqYw" Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta109.mxroute.com (ZoneMTA) with ESMTPSA id 18e8200834f0003bea.010 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 27 Mar 2024 22:20:55 +0000 X-Zone-Loop: be3d1b9a5cb607629627e65328e0371e01e005522f31 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=luigi311.com; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=hq3LXvJ1k7/mJNF6jC9ba4k3K25mnAdHN91vxGscAic=; b=l5j3WqYwm1yQqP4q7XGWFUr8cc jt4NAY3WR2i7sG+rGOZtAWOJFXP9BtTGtXVgF+3fVP3xD+DshPQatURUBS35MZzndim5GnnqOhva0 5ALuPnLQ7h1qrc7Ggu7+Pv7R1gHKNqNVWYyDJFmEvI4Db9CE91ULHxHIwSh2fRY1rA5U1sSryVeaV qZ12MvXLadtqt72XB/FMnr+ci+UvmUr4ogD6mzF5ES2mmtZn32Xc0ZSzsY56rpC8eXBCc2MKQyVU8 o1rcJtLDaIpXkmZsQQa61WDvwKcVEAyyBcfpQy8FhcODzG758tEYG2BbRl5Grh/Bkit1sHNQjNxBT bnYAYfbQ==; From: git@luigi311.com To: linux-media@vger.kernel.org Cc: dave.stevenson@raspberrypi.com, jacopo.mondi@ideasonboard.com, mchehab@kernel.org, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, sakari.ailus@linux.intel.com, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x@xnux.eu, Luigi311 Subject: [PATCH 05/23] media: i2c: imx258: Add regulator control Date: Wed, 27 Mar 2024 16:20:17 -0600 Message-ID: <20240327222035.47208-6-git@luigi311.com> In-Reply-To: <20240327222035.47208-1-git@luigi311.com> References: <20240327222035.47208-1-git@luigi311.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authenticated-Id: personal@luigi311.com From: Dave Stevenson The device tree bindings define the relevant regulators for the sensor, so update the driver to request the regulators and control them at the appropriate times. Signed-off-by: Dave Stevenson Signed-off-by: Luigi311 --- drivers/media/i2c/imx258.c | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index df7ed4716762..495eaada2945 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -507,6 +508,16 @@ static const char * const imx258_test_pattern_menu[] = { "Pseudorandom Sequence (PN9)", }; +/* regulator supplies */ +static const char * const imx258_supply_name[] = { + /* Supplies can be enabled in any order */ + "vana", /* Analog (2.8V) supply */ + "vdig", /* Digital Core (1.2V) supply */ + "vif", /* IF (1.8V) supply */ +}; + +#define IMX258_NUM_SUPPLIES ARRAY_SIZE(imx258_supply_name) + /* Configurations for supported link frequencies */ #define IMX258_LINK_FREQ_634MHZ 633600000ULL #define IMX258_LINK_FREQ_320MHZ 320000000ULL @@ -611,6 +622,7 @@ struct imx258 { struct mutex mutex; struct clk *clk; + struct regulator_bulk_data supplies[IMX258_NUM_SUPPLIES]; }; static inline struct imx258 *to_imx258(struct v4l2_subdev *_sd) @@ -995,9 +1007,19 @@ static int imx258_power_on(struct device *dev) struct imx258 *imx258 = to_imx258(sd); int ret; + ret = regulator_bulk_enable(IMX258_NUM_SUPPLIES, + imx258->supplies); + if (ret) { + dev_err(dev, "%s: failed to enable regulators\n", + __func__); + return ret; + } + ret = clk_prepare_enable(imx258->clk); - if (ret) + if (ret) { dev_err(dev, "failed to enable clock\n"); + regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies); + } return ret; } @@ -1008,6 +1030,7 @@ static int imx258_power_off(struct device *dev) struct imx258 *imx258 = to_imx258(sd); clk_disable_unprepare(imx258->clk); + regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies); return 0; } @@ -1220,6 +1243,18 @@ static void imx258_free_controls(struct imx258 *imx258) mutex_destroy(&imx258->mutex); } +static int imx258_get_regulators(struct imx258 *imx258, + struct i2c_client *client) +{ + unsigned int i; + + for (i = 0; i < IMX258_NUM_SUPPLIES; i++) + imx258->supplies[i].supply = imx258_supply_name[i]; + + return devm_regulator_bulk_get(&client->dev, + IMX258_NUM_SUPPLIES, imx258->supplies); +} + static int imx258_probe(struct i2c_client *client) { struct imx258 *imx258; @@ -1230,6 +1265,11 @@ static int imx258_probe(struct i2c_client *client) if (!imx258) return -ENOMEM; + ret = imx258_get_regulators(imx258, client); + if (ret) + return dev_err_probe(&client->dev, ret, + "failed to get regulators\n"); + imx258->clk = devm_clk_get_optional(&client->dev, NULL); if (IS_ERR(imx258->clk)) return dev_err_probe(&client->dev, PTR_ERR(imx258->clk), From patchwork Wed Mar 27 22:20:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Garcia X-Patchwork-Id: 783428 Received: from mail-108-mta102.mxroute.com (mail-108-mta102.mxroute.com [136.175.108.102]) (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 19CD31552E0 for ; Wed, 27 Mar 2024 22:26:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=136.175.108.102 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578380; cv=none; b=RRSVrOLknJ7pwq7gdZPQHoP1f1itgNlPibQdOo8XlamO0OsKG3L0ZWElmgCqeGsH9oBC9M/XswM1FlbxbR1MISuytslrf/68INGHGZdHG4g1cIqiiin1UxJOSfZGx2geapf/STxgBh13oIBv1vOv1GU82SZh9Ga9ISTdI7i78mM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578380; c=relaxed/simple; bh=sWAfFhAGvw4CqbUg4tIVjRY+a1yJUW3dKOY9ml8HHIc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TzfdlJ/AYDRPMNunCXq235sOb6qaxW1+ISQIo/xX4CQVQT4g26JbDerhiI/YaLeV9p395LmHr40m/Vt734nSCvhyYLzXhA2U8cWs15BQapKmEmAVjSEnizosFKcJ4OM2dBbCyK9a7d67Cgjl7l+fw6FxoVtq3vIE7Ep6ckWfDt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com; spf=pass smtp.mailfrom=luigi311.com; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b=g7SU4XMM; arc=none smtp.client-ip=136.175.108.102 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=luigi311.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b="g7SU4XMM" Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta102.mxroute.com (ZoneMTA) with ESMTPSA id 18e82008a100003bea.010 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 27 Mar 2024 22:20:57 +0000 X-Zone-Loop: 54e5962c25a839908c4dc8b4bbc4004766ec48b5d6ee DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=luigi311.com; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=XYmNM0zbv3+O+YfnDH4hEcGfkU7Y/smW11E/sBjJxo8=; b=g7SU4XMM9krCpmgXNfHrKEJBpW CTnnP2TprTEucaiqC+47/lOIbypqNpPpmywUcFzqmKdTy61emrqfiRPzlGOIsqEze5g/A2uUiMIWI zcePYWKiUEuIsJ/30qHjmi0t/P1fUGSl9iGA6IGP0OxSF5TQR+B11+tD6gv0GB6IiaP6GDsEnCFGy SNfI+AxvGKgL3zD289MEFgWmi3zr8bRC0fB0cvsl+3UIusc0hqk63sEHLg+Zx3+AvHp2HGIEabo2T v1Zn607jf1aPKfIqzQwYSEj2aamwi5QOQdM8FlmXRnAjZdmIsP0ASJqlQ2Fa7WfqHeGtZzvOWn5iO +B1ZfjXw==; From: git@luigi311.com To: linux-media@vger.kernel.org Cc: dave.stevenson@raspberrypi.com, jacopo.mondi@ideasonboard.com, mchehab@kernel.org, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, sakari.ailus@linux.intel.com, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x@xnux.eu Subject: [PATCH 06/23] media: i2c: imx258: Make V4L2_CID_VBLANK configurable. Date: Wed, 27 Mar 2024 16:20:18 -0600 Message-ID: <20240327222035.47208-7-git@luigi311.com> In-Reply-To: <20240327222035.47208-1-git@luigi311.com> References: <20240327222035.47208-1-git@luigi311.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authenticated-Id: personal@luigi311.com From: Dave Stevenson The values and ranges of V4L2_CID_VBLANK are all computed, so there is no reason for it to be a read only control. Remove the register values from the mode lists, add the handler, and remove the read only flag. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx258.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 495eaada2945..321b504c6a48 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -30,6 +30,8 @@ #define IMX258_VTS_30FPS_VGA 0x034c #define IMX258_VTS_MAX 0xffff +#define IMX258_REG_VTS 0x0340 + /* HBLANK control - read only */ #define IMX258_PPL_DEFAULT 5352 @@ -202,8 +204,6 @@ static const struct imx258_reg mode_4208x3120_regs[] = { { 0x0114, 0x03 }, { 0x0342, 0x14 }, { 0x0343, 0xE8 }, - { 0x0340, 0x0C }, - { 0x0341, 0x50 }, { 0x0344, 0x00 }, { 0x0345, 0x00 }, { 0x0346, 0x00 }, @@ -319,8 +319,6 @@ static const struct imx258_reg mode_2104_1560_regs[] = { { 0x0114, 0x03 }, { 0x0342, 0x14 }, { 0x0343, 0xE8 }, - { 0x0340, 0x06 }, - { 0x0341, 0x38 }, { 0x0344, 0x00 }, { 0x0345, 0x00 }, { 0x0346, 0x00 }, @@ -436,8 +434,6 @@ static const struct imx258_reg mode_1048_780_regs[] = { { 0x0114, 0x03 }, { 0x0342, 0x14 }, { 0x0343, 0xE8 }, - { 0x0340, 0x03 }, - { 0x0341, 0x4C }, { 0x0344, 0x00 }, { 0x0345, 0x00 }, { 0x0346, 0x00 }, @@ -800,6 +796,11 @@ static int imx258_set_ctrl(struct v4l2_ctrl *ctrl) BIT(IMX258_HDR_RATIO_MAX)); } break; + case V4L2_CID_VBLANK: + ret = imx258_write_reg(imx258, IMX258_REG_VTS, + IMX258_REG_VALUE_16BIT, + imx258->cur_mode->height + ctrl->val); + break; default: dev_info(&client->dev, "ctrl(id:0x%x,val:0x%x) is not handled\n", @@ -1174,9 +1175,6 @@ static int imx258_init_controls(struct imx258 *imx258) IMX258_VTS_MAX - imx258->cur_mode->height, 1, vblank_def); - if (imx258->vblank) - imx258->vblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; - imx258->hblank = v4l2_ctrl_new_std( ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_HBLANK, IMX258_PPL_DEFAULT - imx258->cur_mode->width, From patchwork Wed Mar 27 22:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Garcia X-Patchwork-Id: 783836 Received: from mail-108-mta43.mxroute.com (mail-108-mta43.mxroute.com [136.175.108.43]) (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 6E00A15531C for ; Wed, 27 Mar 2024 22:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=136.175.108.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578380; cv=none; b=ANADlLhsxIrWlsqsN/Lw0POMGfLqtTrNuThCcMZp1Uj5iRnaNncxi37uVhY2Z3P1tw/2iYTuf5IpuS4Rq8P0gXWO3fusXM8FFlYeR9/jkuoPXBke+MMk9L1JGAzCVbA/wwmfh4akWdWwR4Mvy062b3Jxwxo/Bb4gCq34HIHtURo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578380; c=relaxed/simple; bh=EJ+FJnRlZhoxTDV+e79XawEmBOjEGQW5SwK6cuWM8Mg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T50qD1mDU/xna7ONTtUu6XQDqnwRwPW8w8BdajtPjra2fbYuU6O7/twWSHa0DrGqdQwZVW+uFRVniU/SStZuZ6nnvYa5VUJmHJUdav5HL12ffjNwK14djhaL55YtAgNFYi3fbRE0+KDRPp4s5PguRUILNdN9tTp6OX/TSeBJW+I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com; spf=pass smtp.mailfrom=luigi311.com; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b=uYOhn33R; arc=none smtp.client-ip=136.175.108.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=luigi311.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b="uYOhn33R" Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta43.mxroute.com (ZoneMTA) with ESMTPSA id 18e820090bd0003bea.010 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 27 Mar 2024 22:20:58 +0000 X-Zone-Loop: 2edde42004015a6b7773c3880c00ef5871a748419fad DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=luigi311.com; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JsJQaJuq/Y8/E5VAKWZ8Y8tdFAXhqbEJOpojskktF5o=; b=uYOhn33RlHH78GMuPuCoIDNmV7 82VBfVS7DJ7DlJUQKaNsn3/TZfZ7q34hC4F0/ms+0l9JpPGIeoGQYoZR3UHJacQeZtp0R7yVYQMF7 b91aZjeij1EyheGTtx+x31nC8r0yGgsoBKqCRbmx71ITaf3wwVaHWgMvQpkfQ4z/b9lE6hhjkpH7e HeU2oggqVyw889z8P1np2xROVKpfxPqzIE3tJFKCzl+oTq4OGZcxQ876pIrwD1xsmaCl+7k1Qv58p L267DPGDkZqdbFlUg8wtfh8/AMPyU10zh65f4oVNjFkCywjhBnScGBoy+YxJuZOa4NDcxXuuJ+pHL X+p08lmw==; From: git@luigi311.com To: linux-media@vger.kernel.org Cc: dave.stevenson@raspberrypi.com, jacopo.mondi@ideasonboard.com, mchehab@kernel.org, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, sakari.ailus@linux.intel.com, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x@xnux.eu Subject: [PATCH 07/23] media: i2c: imx258: Split out common registers from the mode based ones Date: Wed, 27 Mar 2024 16:20:19 -0600 Message-ID: <20240327222035.47208-8-git@luigi311.com> In-Reply-To: <20240327222035.47208-1-git@luigi311.com> References: <20240327222035.47208-1-git@luigi311.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authenticated-Id: personal@luigi311.com From: Dave Stevenson Out of all the registers that are defined for each mode, only around 10 differ between the modes. Split the table into common and mode specific ones. Signed-off-by: Dave Stevenson Reviewed-by: Jacopo Mondi --- drivers/media/i2c/imx258.c | 236 ++++--------------------------------- 1 file changed, 21 insertions(+), 215 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 321b504c6a48..351add1bc5d5 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -151,7 +151,7 @@ static const struct imx258_reg mipi_data_rate_640mbps[] = { { 0x0823, 0x00 }, }; -static const struct imx258_reg mode_4208x3120_regs[] = { +static const struct imx258_reg mode_common_regs[] = { { 0x0136, 0x13 }, { 0x0137, 0x33 }, { 0x3051, 0x00 }, @@ -216,27 +216,17 @@ static const struct imx258_reg mode_4208x3120_regs[] = { { 0x0383, 0x01 }, { 0x0385, 0x01 }, { 0x0387, 0x01 }, - { 0x0900, 0x00 }, - { 0x0901, 0x11 }, - { 0x0401, 0x00 }, { 0x0404, 0x00 }, - { 0x0405, 0x10 }, { 0x0408, 0x00 }, { 0x0409, 0x00 }, { 0x040A, 0x00 }, { 0x040B, 0x00 }, { 0x040C, 0x10 }, { 0x040D, 0x70 }, - { 0x040E, 0x0C }, - { 0x040F, 0x30 }, { 0x3038, 0x00 }, { 0x303A, 0x00 }, { 0x303B, 0x10 }, { 0x300D, 0x00 }, - { 0x034C, 0x10 }, - { 0x034D, 0x70 }, - { 0x034E, 0x0C }, - { 0x034F, 0x30 }, { 0x0350, 0x01 }, { 0x0204, 0x00 }, { 0x0205, 0x00 }, @@ -266,234 +256,43 @@ static const struct imx258_reg mode_4208x3120_regs[] = { { 0x0220, 0x00 }, }; +static const struct imx258_reg mode_4208x3120_regs[] = { + { 0x0900, 0x00 }, + { 0x0901, 0x11 }, + { 0x0401, 0x00 }, + { 0x0405, 0x10 }, + { 0x040E, 0x0C }, + { 0x040F, 0x30 }, + { 0x034C, 0x10 }, + { 0x034D, 0x70 }, + { 0x034E, 0x0C }, + { 0x034F, 0x30 }, +}; + static const struct imx258_reg mode_2104_1560_regs[] = { - { 0x0136, 0x13 }, - { 0x0137, 0x33 }, - { 0x3051, 0x00 }, - { 0x3052, 0x00 }, - { 0x4E21, 0x14 }, - { 0x6B11, 0xCF }, - { 0x7FF0, 0x08 }, - { 0x7FF1, 0x0F }, - { 0x7FF2, 0x08 }, - { 0x7FF3, 0x1B }, - { 0x7FF4, 0x23 }, - { 0x7FF5, 0x60 }, - { 0x7FF6, 0x00 }, - { 0x7FF7, 0x01 }, - { 0x7FF8, 0x00 }, - { 0x7FF9, 0x78 }, - { 0x7FFA, 0x00 }, - { 0x7FFB, 0x00 }, - { 0x7FFC, 0x00 }, - { 0x7FFD, 0x00 }, - { 0x7FFE, 0x00 }, - { 0x7FFF, 0x03 }, - { 0x7F76, 0x03 }, - { 0x7F77, 0xFE }, - { 0x7FA8, 0x03 }, - { 0x7FA9, 0xFE }, - { 0x7B24, 0x81 }, - { 0x7B25, 0x00 }, - { 0x6564, 0x07 }, - { 0x6B0D, 0x41 }, - { 0x653D, 0x04 }, - { 0x6B05, 0x8C }, - { 0x6B06, 0xF9 }, - { 0x6B08, 0x65 }, - { 0x6B09, 0xFC }, - { 0x6B0A, 0xCF }, - { 0x6B0B, 0xD2 }, - { 0x6700, 0x0E }, - { 0x6707, 0x0E }, - { 0x9104, 0x00 }, - { 0x4648, 0x7F }, - { 0x7420, 0x00 }, - { 0x7421, 0x1C }, - { 0x7422, 0x00 }, - { 0x7423, 0xD7 }, - { 0x5F04, 0x00 }, - { 0x5F05, 0xED }, - { 0x0112, 0x0A }, - { 0x0113, 0x0A }, - { 0x0114, 0x03 }, - { 0x0342, 0x14 }, - { 0x0343, 0xE8 }, - { 0x0344, 0x00 }, - { 0x0345, 0x00 }, - { 0x0346, 0x00 }, - { 0x0347, 0x00 }, - { 0x0348, 0x10 }, - { 0x0349, 0x6F }, - { 0x034A, 0x0C }, - { 0x034B, 0x2F }, - { 0x0381, 0x01 }, - { 0x0383, 0x01 }, - { 0x0385, 0x01 }, - { 0x0387, 0x01 }, { 0x0900, 0x01 }, { 0x0901, 0x12 }, { 0x0401, 0x01 }, - { 0x0404, 0x00 }, { 0x0405, 0x20 }, - { 0x0408, 0x00 }, - { 0x0409, 0x00 }, - { 0x040A, 0x00 }, - { 0x040B, 0x00 }, - { 0x040C, 0x10 }, - { 0x040D, 0x70 }, { 0x040E, 0x06 }, { 0x040F, 0x18 }, - { 0x3038, 0x00 }, - { 0x303A, 0x00 }, - { 0x303B, 0x10 }, - { 0x300D, 0x00 }, { 0x034C, 0x08 }, { 0x034D, 0x38 }, { 0x034E, 0x06 }, { 0x034F, 0x18 }, - { 0x0350, 0x01 }, - { 0x0204, 0x00 }, - { 0x0205, 0x00 }, - { 0x020E, 0x01 }, - { 0x020F, 0x00 }, - { 0x0210, 0x01 }, - { 0x0211, 0x00 }, - { 0x0212, 0x01 }, - { 0x0213, 0x00 }, - { 0x0214, 0x01 }, - { 0x0215, 0x00 }, - { 0x7BCD, 0x01 }, - { 0x94DC, 0x20 }, - { 0x94DD, 0x20 }, - { 0x94DE, 0x20 }, - { 0x95DC, 0x20 }, - { 0x95DD, 0x20 }, - { 0x95DE, 0x20 }, - { 0x7FB0, 0x00 }, - { 0x9010, 0x3E }, - { 0x9419, 0x50 }, - { 0x941B, 0x50 }, - { 0x9519, 0x50 }, - { 0x951B, 0x50 }, - { 0x3030, 0x00 }, - { 0x3032, 0x00 }, - { 0x0220, 0x00 }, }; static const struct imx258_reg mode_1048_780_regs[] = { - { 0x0136, 0x13 }, - { 0x0137, 0x33 }, - { 0x3051, 0x00 }, - { 0x3052, 0x00 }, - { 0x4E21, 0x14 }, - { 0x6B11, 0xCF }, - { 0x7FF0, 0x08 }, - { 0x7FF1, 0x0F }, - { 0x7FF2, 0x08 }, - { 0x7FF3, 0x1B }, - { 0x7FF4, 0x23 }, - { 0x7FF5, 0x60 }, - { 0x7FF6, 0x00 }, - { 0x7FF7, 0x01 }, - { 0x7FF8, 0x00 }, - { 0x7FF9, 0x78 }, - { 0x7FFA, 0x00 }, - { 0x7FFB, 0x00 }, - { 0x7FFC, 0x00 }, - { 0x7FFD, 0x00 }, - { 0x7FFE, 0x00 }, - { 0x7FFF, 0x03 }, - { 0x7F76, 0x03 }, - { 0x7F77, 0xFE }, - { 0x7FA8, 0x03 }, - { 0x7FA9, 0xFE }, - { 0x7B24, 0x81 }, - { 0x7B25, 0x00 }, - { 0x6564, 0x07 }, - { 0x6B0D, 0x41 }, - { 0x653D, 0x04 }, - { 0x6B05, 0x8C }, - { 0x6B06, 0xF9 }, - { 0x6B08, 0x65 }, - { 0x6B09, 0xFC }, - { 0x6B0A, 0xCF }, - { 0x6B0B, 0xD2 }, - { 0x6700, 0x0E }, - { 0x6707, 0x0E }, - { 0x9104, 0x00 }, - { 0x4648, 0x7F }, - { 0x7420, 0x00 }, - { 0x7421, 0x1C }, - { 0x7422, 0x00 }, - { 0x7423, 0xD7 }, - { 0x5F04, 0x00 }, - { 0x5F05, 0xED }, - { 0x0112, 0x0A }, - { 0x0113, 0x0A }, - { 0x0114, 0x03 }, - { 0x0342, 0x14 }, - { 0x0343, 0xE8 }, - { 0x0344, 0x00 }, - { 0x0345, 0x00 }, - { 0x0346, 0x00 }, - { 0x0347, 0x00 }, - { 0x0348, 0x10 }, - { 0x0349, 0x6F }, - { 0x034A, 0x0C }, - { 0x034B, 0x2F }, - { 0x0381, 0x01 }, - { 0x0383, 0x01 }, - { 0x0385, 0x01 }, - { 0x0387, 0x01 }, { 0x0900, 0x01 }, { 0x0901, 0x14 }, { 0x0401, 0x01 }, - { 0x0404, 0x00 }, { 0x0405, 0x40 }, - { 0x0408, 0x00 }, - { 0x0409, 0x00 }, - { 0x040A, 0x00 }, - { 0x040B, 0x00 }, - { 0x040C, 0x10 }, - { 0x040D, 0x70 }, { 0x040E, 0x03 }, { 0x040F, 0x0C }, - { 0x3038, 0x00 }, - { 0x303A, 0x00 }, - { 0x303B, 0x10 }, - { 0x300D, 0x00 }, { 0x034C, 0x04 }, { 0x034D, 0x18 }, { 0x034E, 0x03 }, { 0x034F, 0x0C }, - { 0x0350, 0x01 }, - { 0x0204, 0x00 }, - { 0x0205, 0x00 }, - { 0x020E, 0x01 }, - { 0x020F, 0x00 }, - { 0x0210, 0x01 }, - { 0x0211, 0x00 }, - { 0x0212, 0x01 }, - { 0x0213, 0x00 }, - { 0x0214, 0x01 }, - { 0x0215, 0x00 }, - { 0x7BCD, 0x00 }, - { 0x94DC, 0x20 }, - { 0x94DD, 0x20 }, - { 0x94DE, 0x20 }, - { 0x95DC, 0x20 }, - { 0x95DD, 0x20 }, - { 0x95DE, 0x20 }, - { 0x7FB0, 0x00 }, - { 0x9010, 0x3E }, - { 0x9419, 0x50 }, - { 0x941B, 0x50 }, - { 0x9519, 0x50 }, - { 0x951B, 0x50 }, - { 0x3030, 0x00 }, - { 0x3032, 0x00 }, - { 0x0220, 0x00 }, }; static const char * const imx258_test_pattern_menu[] = { @@ -955,6 +754,13 @@ static int imx258_start_streaming(struct imx258 *imx258) return ret; } + ret = imx258_write_regs(imx258, mode_common_regs, + ARRAY_SIZE(mode_common_regs)); + if (ret) { + dev_err(&client->dev, "%s failed to set common regs\n", __func__); + return ret; + } + /* Apply default values of current mode */ reg_list = &imx258->cur_mode->reg_list; ret = imx258_write_regs(imx258, reg_list->regs, reg_list->num_of_regs); From patchwork Wed Mar 27 22:20:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Garcia X-Patchwork-Id: 783835 Received: from mail-108-mta44.mxroute.com (mail-108-mta44.mxroute.com [136.175.108.44]) (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 20471154424 for ; Wed, 27 Mar 2024 22:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=136.175.108.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578390; cv=none; b=fkWcxI+tIIvP5+1j4d9XkuYBpON2Oflj/EugOYGO8OpDgFZ3/XTJ2oNnU7YDpYtpyThWa5Vjv3tKrnF77ZB8x6dLTvYJucX8VbmAqGJdaOVdMiw8mKEV6Z0SibjRHft8UhXNIUfbFYs44WB27ANyIxWsFGrs1HKlLa+vWPKIbvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578390; c=relaxed/simple; bh=zpwx5OxJWYlYVMYFl5htgqXaFY/A560ArRuvTJuVbFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c///RR1CH2fCDUtj9LeoUgiWRHG1bBZCZSt10ngQt0UT+/K6ZdCqtL6OCsrOcWLddTT7vWVE9nTNEYO7c3fWqZxsnnYgh0w72QPdrLysN3f9Q3CKXjCktLVyzYKKDkPU4prrEswG7v1sgivAhOs+BmTZF6c54F/dz/NZGnGYY6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com; spf=pass smtp.mailfrom=luigi311.com; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b=opPAC+jt; arc=none smtp.client-ip=136.175.108.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=luigi311.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b="opPAC+jt" Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta44.mxroute.com (ZoneMTA) with ESMTPSA id 18e82009d450003bea.010 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 27 Mar 2024 22:21:02 +0000 X-Zone-Loop: 0c137be092eae1fc34f77d5ae40b4eeea16ef68f4ace DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=luigi311.com; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=v0tIOtHXLmE3QmL+EJPups6PUsU/L3wQwMMW/4d4ByM=; b=opPAC+jtvGpf9Ov1U/CDoTZfvI pnI/Xrzg42bYV1gJzpvSa28r/kUwcK3Sf7H1NP1T+Dz0H5olVouka6ao4widru9WNndt0AX0qPIrA h13SO2H7ykDKh8+9hUkBsB0aexfj0dXYv2JluqBuWf+cyrKq4GOPxydbZhuPzSWh1hMqazc8qlGlS tKEGQ5JHKOKX28grnkIWZ4HeGM4lRBRT8vqrhyShE/8TUI08qAU7jrsPu07p9azX0hU1jaJ7sXwpF rYEeH3B50Onxwlz9ZxqUZkIVMm7lH75M/MjzcV02AWPB8GvbdyjZcf5zuvzkQ7K6qjGD1ucYc2qTp f9Yr6rLQ==; From: git@luigi311.com To: linux-media@vger.kernel.org Cc: dave.stevenson@raspberrypi.com, jacopo.mondi@ideasonboard.com, mchehab@kernel.org, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, sakari.ailus@linux.intel.com, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x@xnux.eu, Luigi311 Subject: [PATCH 08/23] media: i2c: imx258: Add support for 24MHz clock Date: Wed, 27 Mar 2024 16:20:20 -0600 Message-ID: <20240327222035.47208-9-git@luigi311.com> In-Reply-To: <20240327222035.47208-1-git@luigi311.com> References: <20240327222035.47208-1-git@luigi311.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authenticated-Id: personal@luigi311.com From: Dave Stevenson There's no reason why only a clock of 19.2MHz is supported. Indeed this isn't even a frequency listed in the datasheet. Add support for 24MHz as well. The PLL settings result in slightly different link frequencies, so parameterise those. Signed-off-by: Dave Stevenson Signed-off-by: Luigi311 --- drivers/media/i2c/imx258.c | 133 +++++++++++++++++++++++++++++-------- 1 file changed, 107 insertions(+), 26 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 351add1bc5d5..6ee7de079454 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -76,9 +76,6 @@ #define REG_CONFIG_MIRROR_FLIP 0x03 #define REG_CONFIG_FLIP_TEST_PATTERN 0x02 -/* Input clock frequency in Hz */ -#define IMX258_INPUT_CLOCK_FREQ 19200000 - struct imx258_reg { u16 address; u8 val; @@ -115,7 +112,9 @@ struct imx258_mode { }; /* 4208x3120 needs 1267Mbps/lane, 4 lanes */ -static const struct imx258_reg mipi_data_rate_1267mbps[] = { +static const struct imx258_reg mipi_1267mbps_19_2mhz[] = { + { 0x0136, 0x13 }, + { 0x0137, 0x33 }, { 0x0301, 0x05 }, { 0x0303, 0x02 }, { 0x0305, 0x03 }, @@ -133,7 +132,29 @@ static const struct imx258_reg mipi_data_rate_1267mbps[] = { { 0x0823, 0xCC }, }; -static const struct imx258_reg mipi_data_rate_640mbps[] = { +static const struct imx258_reg mipi_1272mbps_24mhz[] = { + { 0x0136, 0x18 }, + { 0x0137, 0x00 }, + { 0x0301, 0x05 }, + { 0x0303, 0x02 }, + { 0x0305, 0x04 }, + { 0x0306, 0x00 }, + { 0x0307, 0xD4 }, + { 0x0309, 0x0A }, + { 0x030B, 0x01 }, + { 0x030D, 0x02 }, + { 0x030E, 0x00 }, + { 0x030F, 0xD8 }, + { 0x0310, 0x00 }, + { 0x0820, 0x13 }, + { 0x0821, 0x4C }, + { 0x0822, 0xCC }, + { 0x0823, 0xCC }, +}; + +static const struct imx258_reg mipi_640mbps_19_2mhz[] = { + { 0x0136, 0x13 }, + { 0x0137, 0x33 }, { 0x0301, 0x05 }, { 0x0303, 0x02 }, { 0x0305, 0x03 }, @@ -151,9 +172,27 @@ static const struct imx258_reg mipi_data_rate_640mbps[] = { { 0x0823, 0x00 }, }; +static const struct imx258_reg mipi_642mbps_24mhz[] = { + { 0x0136, 0x18 }, + { 0x0137, 0x00 }, + { 0x0301, 0x05 }, + { 0x0303, 0x02 }, + { 0x0305, 0x04 }, + { 0x0306, 0x00 }, + { 0x0307, 0x6B }, + { 0x0309, 0x0A }, + { 0x030B, 0x01 }, + { 0x030D, 0x02 }, + { 0x030E, 0x00 }, + { 0x030F, 0xD8 }, + { 0x0310, 0x00 }, + { 0x0820, 0x0A }, + { 0x0821, 0x00 }, + { 0x0822, 0x00 }, + { 0x0823, 0x00 }, +}; + static const struct imx258_reg mode_common_regs[] = { - { 0x0136, 0x13 }, - { 0x0137, 0x33 }, { 0x3051, 0x00 }, { 0x3052, 0x00 }, { 0x4E21, 0x14 }, @@ -313,10 +352,6 @@ static const char * const imx258_supply_name[] = { #define IMX258_NUM_SUPPLIES ARRAY_SIZE(imx258_supply_name) -/* Configurations for supported link frequencies */ -#define IMX258_LINK_FREQ_634MHZ 633600000ULL -#define IMX258_LINK_FREQ_320MHZ 320000000ULL - enum { IMX258_LINK_FREQ_1267MBPS, IMX258_LINK_FREQ_640MBPS, @@ -335,25 +370,55 @@ static u64 link_freq_to_pixel_rate(u64 f) } /* Menu items for LINK_FREQ V4L2 control */ -static const s64 link_freq_menu_items[] = { +/* Configurations for supported link frequencies */ +#define IMX258_LINK_FREQ_634MHZ 633600000ULL +#define IMX258_LINK_FREQ_320MHZ 320000000ULL + +static const s64 link_freq_menu_items_19_2[] = { IMX258_LINK_FREQ_634MHZ, IMX258_LINK_FREQ_320MHZ, }; +/* Configurations for supported link frequencies */ +#define IMX258_LINK_FREQ_636MHZ 636000000ULL +#define IMX258_LINK_FREQ_321MHZ 321000000ULL + +static const s64 link_freq_menu_items_24[] = { + IMX258_LINK_FREQ_636MHZ, + IMX258_LINK_FREQ_321MHZ, +}; + /* Link frequency configs */ -static const struct imx258_link_freq_config link_freq_configs[] = { +static const struct imx258_link_freq_config link_freq_configs_19_2[] = { [IMX258_LINK_FREQ_1267MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, .reg_list = { - .num_of_regs = ARRAY_SIZE(mipi_data_rate_1267mbps), - .regs = mipi_data_rate_1267mbps, + .num_of_regs = ARRAY_SIZE(mipi_1267mbps_19_2mhz), + .regs = mipi_1267mbps_19_2mhz, } }, [IMX258_LINK_FREQ_640MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, .reg_list = { - .num_of_regs = ARRAY_SIZE(mipi_data_rate_640mbps), - .regs = mipi_data_rate_640mbps, + .num_of_regs = ARRAY_SIZE(mipi_640mbps_19_2mhz), + .regs = mipi_640mbps_19_2mhz, + } + }, +}; + +static const struct imx258_link_freq_config link_freq_configs_24[] = { + [IMX258_LINK_FREQ_1267MBPS] = { + .pixels_per_line = IMX258_PPL_DEFAULT, + .reg_list = { + .num_of_regs = ARRAY_SIZE(mipi_1272mbps_24mhz), + .regs = mipi_1272mbps_24mhz, + } + }, + [IMX258_LINK_FREQ_640MBPS] = { + .pixels_per_line = IMX258_PPL_DEFAULT, + .reg_list = { + .num_of_regs = ARRAY_SIZE(mipi_642mbps_24mhz), + .regs = mipi_642mbps_24mhz, } }, }; @@ -410,6 +475,9 @@ struct imx258 { /* Current mode */ const struct imx258_mode *cur_mode; + const struct imx258_link_freq_config *link_freq_configs; + const s64 *link_freq_menu_items; + /* * Mutex for serialized access: * Protect sensor module set pad format and start/stop streaming safely. @@ -713,7 +781,7 @@ static int imx258_set_pad_format(struct v4l2_subdev *sd, imx258->cur_mode = mode; __v4l2_ctrl_s_ctrl(imx258->link_freq, mode->link_freq_index); - link_freq = link_freq_menu_items[mode->link_freq_index]; + link_freq = imx258->link_freq_menu_items[mode->link_freq_index]; pixel_rate = link_freq_to_pixel_rate(link_freq); __v4l2_ctrl_s_ctrl_int64(imx258->pixel_rate, pixel_rate); /* Update limits and set FPS to default */ @@ -727,7 +795,7 @@ static int imx258_set_pad_format(struct v4l2_subdev *sd, vblank_def); __v4l2_ctrl_s_ctrl(imx258->vblank, vblank_def); h_blank = - link_freq_configs[mode->link_freq_index].pixels_per_line + imx258->link_freq_configs[mode->link_freq_index].pixels_per_line - imx258->cur_mode->width; __v4l2_ctrl_modify_range(imx258->hblank, h_blank, h_blank, 1, h_blank); @@ -747,7 +815,7 @@ static int imx258_start_streaming(struct imx258 *imx258) /* Setup PLL */ link_freq_index = imx258->cur_mode->link_freq_index; - reg_list = &link_freq_configs[link_freq_index].reg_list; + reg_list = &imx258->link_freq_configs[link_freq_index].reg_list; ret = imx258_write_regs(imx258, reg_list->regs, reg_list->num_of_regs); if (ret) { dev_err(&client->dev, "%s failed to set plls\n", __func__); @@ -946,9 +1014,9 @@ static int imx258_init_controls(struct imx258 *imx258) imx258->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_LINK_FREQ, - ARRAY_SIZE(link_freq_menu_items) - 1, + ARRAY_SIZE(link_freq_menu_items_19_2) - 1, 0, - link_freq_menu_items); + imx258->link_freq_menu_items); if (imx258->link_freq) imx258->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; @@ -964,8 +1032,10 @@ static int imx258_init_controls(struct imx258 *imx258) if (vflip) vflip->flags |= V4L2_CTRL_FLAG_READ_ONLY; - pixel_rate_max = link_freq_to_pixel_rate(link_freq_menu_items[0]); - pixel_rate_min = link_freq_to_pixel_rate(link_freq_menu_items[1]); + pixel_rate_max = + link_freq_to_pixel_rate(imx258->link_freq_menu_items[0]); + pixel_rate_min = + link_freq_to_pixel_rate(imx258->link_freq_menu_items[1]); /* By default, PIXEL_RATE is read only */ imx258->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_PIXEL_RATE, @@ -1086,8 +1156,19 @@ static int imx258_probe(struct i2c_client *client) } else { val = clk_get_rate(imx258->clk); } - if (val != IMX258_INPUT_CLOCK_FREQ) { - dev_err(&client->dev, "input clock frequency not supported\n"); + + switch (val) { + case 19200000: + imx258->link_freq_configs = link_freq_configs_19_2; + imx258->link_freq_menu_items = link_freq_menu_items_19_2; + break; + case 24000000: + imx258->link_freq_configs = link_freq_configs_24; + imx258->link_freq_menu_items = link_freq_menu_items_24; + break; + default: + dev_err(&client->dev, "input clock frequency of %u not supported\n", + val); return -EINVAL; } From patchwork Wed Mar 27 22:20:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Garcia X-Patchwork-Id: 783427 Received: from mail-108-mta238.mxroute.com (mail-108-mta238.mxroute.com [136.175.108.238]) (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 0C346153BE2 for ; Wed, 27 Mar 2024 22:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=136.175.108.238 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578390; cv=none; b=hMdj4DknzbQXL+mP8a1LpanZ1G+K4dgnUJvb2SNdzxjccUwYbNC3t0Mpkq9HWmSeFF9fdAnC7SZHdLM7qDGhZKaisk5F7t+dufxH52y3fs18fsFC31EesPAWKnO/UQgHINyqbGSehC9NmGMl1elyH7wD8+9td6KLwjNj3woRY+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578390; c=relaxed/simple; bh=NA4X1r1+uHBdhIRfrPTtAP2uPVsX5ISROQaTF9/cHho=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CTPCWLR6+jvx1CzZ0tjjr7im3vSHxQ4kdvdzXaKU+3KXluVd8xd9j4nUeL+kBFgAZeuY4IBXaVqIdt2fltQZpJRE4bilLVA8l0F8LA0Hw7mMGdLqLvJcOZea3S30RL8syRBUqBdnFY1X1idikjf2q//bqMmBdqUKpxmPBubX/Cw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com; spf=pass smtp.mailfrom=luigi311.com; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b=zSXtklX1; arc=none smtp.client-ip=136.175.108.238 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=luigi311.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b="zSXtklX1" Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta238.mxroute.com (ZoneMTA) with ESMTPSA id 18e8200a3200003bea.010 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 27 Mar 2024 22:21:03 +0000 X-Zone-Loop: 079d316219697bc96f37354bd9378a6057a1d1c138cd DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=luigi311.com; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JSVvy6qYqNREABJ9B24Hgd/994IGZ+daMOMn7F0GMDk=; b=zSXtklX19AqK1y2StbkvgusVkN +kcE0HGGwYodEGai8R0iFRx74csIE7itCHjyOrD6lj9+47ynC0RjIj6I928KP5+Draffmxa/QFeOF FI3R7NTDhjdFAkdLFmBmusRBjrRaMD0VS7UrRV7dZnxKnLS4Pm5aUqQK/ZDYUeaMvmolD6unbq5xD 9Ivvp/d3N03gn/HDGOdokoZPULXPdC4cJ/7SV5vOolr2Z3X1JKY9BlEQiWoVQ35+0rF5Zdaadxpwd +hwjp7EvaiNGUtzPlI4oQPNZtrb7b2Uen3FW0SCwbj6D3ksbabGJxCHo5EjjarlAfGDTR1f+gqBiu RxTTP4tQ==; From: git@luigi311.com To: linux-media@vger.kernel.org Cc: dave.stevenson@raspberrypi.com, jacopo.mondi@ideasonboard.com, mchehab@kernel.org, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, sakari.ailus@linux.intel.com, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x@xnux.eu, Luigi311 Subject: [PATCH 09/23] media: i2c: imx258: Add support for running on 2 CSI data lanes Date: Wed, 27 Mar 2024 16:20:21 -0600 Message-ID: <20240327222035.47208-10-git@luigi311.com> In-Reply-To: <20240327222035.47208-1-git@luigi311.com> References: <20240327222035.47208-1-git@luigi311.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authenticated-Id: personal@luigi311.com From: Dave Stevenson Extends the driver to also support 2 data lanes. Frame rates are obviously more restricted on 2 lanes, but some hardware simply hasn't wired more up. Signed-off-by: Dave Stevenson Signed-off-by: Luigi311 --- drivers/media/i2c/imx258.c | 214 ++++++++++++++++++++++++++++++++----- 1 file changed, 190 insertions(+), 24 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 6ee7de079454..c65b9aad3b0a 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -86,12 +86,18 @@ struct imx258_reg_list { const struct imx258_reg *regs; }; +enum { + IMX258_2_LANE_MODE, + IMX258_4_LANE_MODE, + IMX258_LANE_CONFIGS, +}; + /* Link frequency config */ struct imx258_link_freq_config { u32 pixels_per_line; /* PLL registers for this link frequency */ - struct imx258_reg_list reg_list; + struct imx258_reg_list reg_list[IMX258_LANE_CONFIGS]; }; /* Mode : resolution and related config&values */ @@ -111,8 +117,34 @@ struct imx258_mode { struct imx258_reg_list reg_list; }; -/* 4208x3120 needs 1267Mbps/lane, 4 lanes */ -static const struct imx258_reg mipi_1267mbps_19_2mhz[] = { +/* + * 4208x3120 @ 30 fps needs 1267Mbps/lane, 4 lanes. + * To avoid further computation of clock settings, adopt the same per + * lane data rate when using 2 lanes, thus allowing a maximum of 15fps. + */ +static const struct imx258_reg mipi_1267mbps_19_2mhz_2l[] = { + { 0x0136, 0x13 }, + { 0x0137, 0x33 }, + { 0x0301, 0x0A }, + { 0x0303, 0x02 }, + { 0x0305, 0x03 }, + { 0x0306, 0x00 }, + { 0x0307, 0xC6 }, + { 0x0309, 0x0A }, + { 0x030B, 0x01 }, + { 0x030D, 0x02 }, + { 0x030E, 0x00 }, + { 0x030F, 0xD8 }, + { 0x0310, 0x00 }, + + { 0x0114, 0x01 }, + { 0x0820, 0x09 }, + { 0x0821, 0xa6 }, + { 0x0822, 0x66 }, + { 0x0823, 0x66 }, +}; + +static const struct imx258_reg mipi_1267mbps_19_2mhz_4l[] = { { 0x0136, 0x13 }, { 0x0137, 0x33 }, { 0x0301, 0x05 }, @@ -126,16 +158,18 @@ static const struct imx258_reg mipi_1267mbps_19_2mhz[] = { { 0x030E, 0x00 }, { 0x030F, 0xD8 }, { 0x0310, 0x00 }, + + { 0x0114, 0x03 }, { 0x0820, 0x13 }, { 0x0821, 0x4C }, { 0x0822, 0xCC }, { 0x0823, 0xCC }, }; -static const struct imx258_reg mipi_1272mbps_24mhz[] = { +static const struct imx258_reg mipi_1272mbps_24mhz_2l[] = { { 0x0136, 0x18 }, { 0x0137, 0x00 }, - { 0x0301, 0x05 }, + { 0x0301, 0x0a }, { 0x0303, 0x02 }, { 0x0305, 0x04 }, { 0x0306, 0x00 }, @@ -146,13 +180,59 @@ static const struct imx258_reg mipi_1272mbps_24mhz[] = { { 0x030E, 0x00 }, { 0x030F, 0xD8 }, { 0x0310, 0x00 }, + + { 0x0114, 0x01 }, { 0x0820, 0x13 }, { 0x0821, 0x4C }, { 0x0822, 0xCC }, { 0x0823, 0xCC }, }; -static const struct imx258_reg mipi_640mbps_19_2mhz[] = { +static const struct imx258_reg mipi_1272mbps_24mhz_4l[] = { + { 0x0136, 0x18 }, + { 0x0137, 0x00 }, + { 0x0301, 0x05 }, + { 0x0303, 0x02 }, + { 0x0305, 0x04 }, + { 0x0306, 0x00 }, + { 0x0307, 0xD4 }, + { 0x0309, 0x0A }, + { 0x030B, 0x01 }, + { 0x030D, 0x02 }, + { 0x030E, 0x00 }, + { 0x030F, 0xD8 }, + { 0x0310, 0x00 }, + + { 0x0114, 0x03 }, + { 0x0820, 0x13 }, + { 0x0821, 0xE0 }, + { 0x0822, 0x00 }, + { 0x0823, 0x00 }, +}; + +static const struct imx258_reg mipi_640mbps_19_2mhz_2l[] = { + { 0x0136, 0x13 }, + { 0x0137, 0x33 }, + { 0x0301, 0x05 }, + { 0x0303, 0x02 }, + { 0x0305, 0x03 }, + { 0x0306, 0x00 }, + { 0x0307, 0x64 }, + { 0x0309, 0x0A }, + { 0x030B, 0x01 }, + { 0x030D, 0x02 }, + { 0x030E, 0x00 }, + { 0x030F, 0xD8 }, + { 0x0310, 0x00 }, + + { 0x0114, 0x01 }, + { 0x0820, 0x05 }, + { 0x0821, 0x00 }, + { 0x0822, 0x00 }, + { 0x0823, 0x00 }, +}; + +static const struct imx258_reg mipi_640mbps_19_2mhz_4l[] = { { 0x0136, 0x13 }, { 0x0137, 0x33 }, { 0x0301, 0x05 }, @@ -166,13 +246,37 @@ static const struct imx258_reg mipi_640mbps_19_2mhz[] = { { 0x030E, 0x00 }, { 0x030F, 0xD8 }, { 0x0310, 0x00 }, + + { 0x0114, 0x03 }, + { 0x0820, 0x0A }, + { 0x0821, 0x00 }, + { 0x0822, 0x00 }, + { 0x0823, 0x00 }, +}; + +static const struct imx258_reg mipi_642mbps_24mhz_2l[] = { + { 0x0136, 0x18 }, + { 0x0137, 0x00 }, + { 0x0301, 0x0A }, + { 0x0303, 0x02 }, + { 0x0305, 0x04 }, + { 0x0306, 0x00 }, + { 0x0307, 0x6B }, + { 0x0309, 0x0A }, + { 0x030B, 0x01 }, + { 0x030D, 0x02 }, + { 0x030E, 0x00 }, + { 0x030F, 0xD8 }, + { 0x0310, 0x00 }, + + { 0x0114, 0x01 }, { 0x0820, 0x0A }, { 0x0821, 0x00 }, { 0x0822, 0x00 }, { 0x0823, 0x00 }, }; -static const struct imx258_reg mipi_642mbps_24mhz[] = { +static const struct imx258_reg mipi_642mbps_24mhz_4l[] = { { 0x0136, 0x18 }, { 0x0137, 0x00 }, { 0x0301, 0x05 }, @@ -186,6 +290,8 @@ static const struct imx258_reg mipi_642mbps_24mhz[] = { { 0x030E, 0x00 }, { 0x030F, 0xD8 }, { 0x0310, 0x00 }, + + { 0x0114, 0x03 }, { 0x0820, 0x0A }, { 0x0821, 0x00 }, { 0x0822, 0x00 }, @@ -240,7 +346,6 @@ static const struct imx258_reg mode_common_regs[] = { { 0x5F05, 0xED }, { 0x0112, 0x0A }, { 0x0113, 0x0A }, - { 0x0114, 0x03 }, { 0x0342, 0x14 }, { 0x0343, 0xE8 }, { 0x0344, 0x00 }, @@ -359,11 +464,13 @@ enum { /* * pixel_rate = link_freq * data-rate * nr_of_lanes / bits_per_sample - * data rate => double data rate; number of lanes => 4; bits per pixel => 10 + * data rate => double data rate; + * number of lanes => (configurable 2 or 4); + * bits per pixel => 10 */ -static u64 link_freq_to_pixel_rate(u64 f) +static u64 link_freq_to_pixel_rate(u64 f, unsigned int nlanes) { - f *= 2 * 4; + f *= 2 * nlanes; do_div(f, 10); return f; @@ -393,15 +500,27 @@ static const struct imx258_link_freq_config link_freq_configs_19_2[] = { [IMX258_LINK_FREQ_1267MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, .reg_list = { - .num_of_regs = ARRAY_SIZE(mipi_1267mbps_19_2mhz), - .regs = mipi_1267mbps_19_2mhz, + [IMX258_2_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_1267mbps_19_2mhz_2l), + .regs = mipi_1267mbps_19_2mhz_2l, + }, + [IMX258_4_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_1267mbps_19_2mhz_4l), + .regs = mipi_1267mbps_19_2mhz_4l, + }, } }, [IMX258_LINK_FREQ_640MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, .reg_list = { - .num_of_regs = ARRAY_SIZE(mipi_640mbps_19_2mhz), - .regs = mipi_640mbps_19_2mhz, + [IMX258_2_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_640mbps_19_2mhz_2l), + .regs = mipi_640mbps_19_2mhz_2l, + }, + [IMX258_4_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_640mbps_19_2mhz_4l), + .regs = mipi_640mbps_19_2mhz_4l, + }, } }, }; @@ -410,15 +529,27 @@ static const struct imx258_link_freq_config link_freq_configs_24[] = { [IMX258_LINK_FREQ_1267MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, .reg_list = { - .num_of_regs = ARRAY_SIZE(mipi_1272mbps_24mhz), - .regs = mipi_1272mbps_24mhz, + [IMX258_2_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_1272mbps_24mhz_2l), + .regs = mipi_1272mbps_24mhz_2l, + }, + [IMX258_4_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_1272mbps_24mhz_4l), + .regs = mipi_1272mbps_24mhz_4l, + }, } }, [IMX258_LINK_FREQ_640MBPS] = { .pixels_per_line = IMX258_PPL_DEFAULT, .reg_list = { - .num_of_regs = ARRAY_SIZE(mipi_642mbps_24mhz), - .regs = mipi_642mbps_24mhz, + [IMX258_2_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_642mbps_24mhz_2l), + .regs = mipi_642mbps_24mhz_2l, + }, + [IMX258_4_LANE_MODE] = { + .num_of_regs = ARRAY_SIZE(mipi_642mbps_24mhz_4l), + .regs = mipi_642mbps_24mhz_4l, + }, } }, }; @@ -477,6 +608,7 @@ struct imx258 { const struct imx258_link_freq_config *link_freq_configs; const s64 *link_freq_menu_items; + unsigned int nlanes; /* * Mutex for serialized access: @@ -782,7 +914,7 @@ static int imx258_set_pad_format(struct v4l2_subdev *sd, __v4l2_ctrl_s_ctrl(imx258->link_freq, mode->link_freq_index); link_freq = imx258->link_freq_menu_items[mode->link_freq_index]; - pixel_rate = link_freq_to_pixel_rate(link_freq); + pixel_rate = link_freq_to_pixel_rate(link_freq, imx258->nlanes); __v4l2_ctrl_s_ctrl_int64(imx258->pixel_rate, pixel_rate); /* Update limits and set FPS to default */ vblank_def = imx258->cur_mode->vts_def - @@ -811,11 +943,13 @@ static int imx258_start_streaming(struct imx258 *imx258) { struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); const struct imx258_reg_list *reg_list; + const struct imx258_link_freq_config *link_freq_cfg; int ret, link_freq_index; /* Setup PLL */ link_freq_index = imx258->cur_mode->link_freq_index; - reg_list = &imx258->link_freq_configs[link_freq_index].reg_list; + link_freq_cfg = &imx258->link_freq_configs[link_freq_index]; + reg_list = &link_freq_cfg->reg_list[imx258->nlanes == 2 ? 0 : 1]; ret = imx258_write_regs(imx258, reg_list->regs, reg_list->num_of_regs); if (ret) { dev_err(&client->dev, "%s failed to set plls\n", __func__); @@ -1033,9 +1167,11 @@ static int imx258_init_controls(struct imx258 *imx258) vflip->flags |= V4L2_CTRL_FLAG_READ_ONLY; pixel_rate_max = - link_freq_to_pixel_rate(imx258->link_freq_menu_items[0]); + link_freq_to_pixel_rate(imx258->link_freq_menu_items[0], + imx258->nlanes); pixel_rate_min = - link_freq_to_pixel_rate(imx258->link_freq_menu_items[1]); + link_freq_to_pixel_rate(imx258->link_freq_menu_items[1], + imx258->nlanes); /* By default, PIXEL_RATE is read only */ imx258->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_PIXEL_RATE, @@ -1132,6 +1268,10 @@ static int imx258_get_regulators(struct imx258 *imx258, static int imx258_probe(struct i2c_client *client) { struct imx258 *imx258; + struct fwnode_handle *endpoint; + struct v4l2_fwnode_endpoint ep = { + .bus_type = V4L2_MBUS_CSI2_DPHY + }; int ret; u32 val = 0; @@ -1172,13 +1312,35 @@ static int imx258_probe(struct i2c_client *client) return -EINVAL; } + endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(&client->dev), NULL); + if (!endpoint) { + dev_err(&client->dev, "Endpoint node not found\n"); + return -EINVAL; + } + + ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &ep); + fwnode_handle_put(endpoint); + if (ret) { + dev_err(&client->dev, "Parsing endpoint node failed\n"); + return ret; + } + + /* Get number of data lanes */ + imx258->nlanes = ep.bus.mipi_csi2.num_data_lanes; + if (imx258->nlanes != 2 && imx258->nlanes != 4) { + dev_err(&client->dev, "Invalid data lanes: %u\n", + imx258->nlanes); + ret = -EINVAL; + goto error_endpoint_free; + } + /* Initialize subdev */ v4l2_i2c_subdev_init(&imx258->sd, client, &imx258_subdev_ops); /* Will be powered off via pm_runtime_idle */ ret = imx258_power_on(&client->dev); if (ret) - return ret; + goto error_endpoint_free; /* Check module identity */ ret = imx258_identify_module(imx258); @@ -1211,6 +1373,7 @@ static int imx258_probe(struct i2c_client *client) pm_runtime_set_active(&client->dev); pm_runtime_enable(&client->dev); pm_runtime_idle(&client->dev); + v4l2_fwnode_endpoint_free(&ep); return 0; @@ -1223,6 +1386,9 @@ static int imx258_probe(struct i2c_client *client) error_identify: imx258_power_off(&client->dev); +error_endpoint_free: + v4l2_fwnode_endpoint_free(&ep); + return ret; } From patchwork Wed Mar 27 22:20:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Garcia X-Patchwork-Id: 783840 Received: from mail-108-mta71.mxroute.com (mail-108-mta71.mxroute.com [136.175.108.71]) (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 721C3152DEF for ; Wed, 27 Mar 2024 22:21:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=136.175.108.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578083; cv=none; b=CYXpUNW4CgfBMb6CZ45NNgJm1Z0fqP1cuGqx7GIX/S9ldCBpGxqreYcRU5zh77MJsGFSZ8669tkQlV/YKPPxC/RRAvwQvI1sLzrv6pWqNRlCQ9XU8M4aMzGPAm2z73Ym04lA6lyQUo30OLnJPuTPnflxt9SbbmczpiLN4UAj52g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711578083; c=relaxed/simple; bh=l/d1KTSxrdSi8t1Av6GsBX7faXE7YS03/s1Y6XmUM9o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XDlVDzrTOoCeDc5cSgupNaiya1jONaW73T2EASqocqCpOwX6HNE69Mb3BMkBE7ZUKw6PV9jt8yGfc5FTAXDyD6F5l2bnOE9PQmiOM1SNDPeIELjrWAwQ2ulShk4N48no8+Gg+QDuUx3VFmICnQri/lD/nb4ZGnmkrK8SNvyqN6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com; spf=pass smtp.mailfrom=luigi311.com; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b=wkfO23G8; arc=none smtp.client-ip=136.175.108.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=luigi311.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=luigi311.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=luigi311.com header.i=@luigi311.com header.b="wkfO23G8" Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta71.mxroute.com (ZoneMTA) with ESMTPSA id 18e8200a9520003bea.010 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 27 Mar 2024 22:21:05 +0000 X-Zone-Loop: 179dd9af5a2cae214f1b37b868534bb1618c98be9ab2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=luigi311.com; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Wfd3IM9yvSlmOOZPNTkn/UcYNYLQj3XQ9wKwbMSeFFA=; b=wkfO23G8d0f1UmDKwI19ALxOur Whk3/ewONqmq7ThLU38LoZaX7TeVQZ/ZlWhkVCY1Nv72S47KuKoOsoZPYF5APnEL11iLUJPqE40ZQ UeGs1Py8YqIIcqYkUDRvFcF0XycPaaersLvz1IDyI+8ExNFLwf07T/bgSeB7rBV0Z4Vg7tGKdc00f ZF9VlALEMgUZEvkk0Zgljww5smZWqUoEtjXB5t1CEVSvVFQs/jziUp1nED2tsJ2wrD1WCqUZWR7h6 RnGE5Ifiy+US2qVPFxjNTNMtSDYZPm/Vw46Bz4FodRkj0K2tNnbv/VrZ+uiMiRmOqJA0ZWmFMFMF6 +HODCqiA==; From: git@luigi311.com To: linux-media@vger.kernel.org Cc: dave.stevenson@raspberrypi.com, jacopo.mondi@ideasonboard.com, mchehab@kernel.org, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, sakari.ailus@linux.intel.com, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, x@xnux.eu Subject: [PATCH 10/23] media: i2c: imx258: Follow normal V4L2 behaviours for clipping exposure Date: Wed, 27 Mar 2024 16:20:22 -0600 Message-ID: <20240327222035.47208-11-git@luigi311.com> In-Reply-To: <20240327222035.47208-1-git@luigi311.com> References: <20240327222035.47208-1-git@luigi311.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authenticated-Id: personal@luigi311.com From: Dave Stevenson V4L2 sensor drivers are expected are expected to clip the supported exposure range based on the VBLANK configured. IMX258 wasn't doing that as register 0x350 (FRM_LENGTH_CTL) switches it to a mode where frame length tracks coarse exposure time. Disable this mode and clip the range for V4L2_CID_EXPOSURE appropriately based on V4L2_CID_VBLANK. Signed-off-by: Dave Stevenson Reviewed-by: Jacopo Mondi --- drivers/media/i2c/imx258.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index c65b9aad3b0a..1f5fb980cfbe 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -37,10 +37,11 @@ /* Exposure control */ #define IMX258_REG_EXPOSURE 0x0202 +#define IMX258_EXPOSURE_OFFSET 10 #define IMX258_EXPOSURE_MIN 4 #define IMX258_EXPOSURE_STEP 1 #define IMX258_EXPOSURE_DEFAULT 0x640 -#define IMX258_EXPOSURE_MAX 65535 +#define IMX258_EXPOSURE_MAX (IMX258_VTS_MAX - IMX258_EXPOSURE_OFFSET) /* Analog gain control */ #define IMX258_REG_ANALOG_GAIN 0x0204 @@ -371,7 +372,7 @@ static const struct imx258_reg mode_common_regs[] = { { 0x303A, 0x00 }, { 0x303B, 0x10 }, { 0x300D, 0x00 }, - { 0x0350, 0x01 }, + { 0x0350, 0x00 }, { 0x0204, 0x00 }, { 0x0205, 0x00 }, { 0x020E, 0x01 }, @@ -741,6 +742,19 @@ static int imx258_update_digital_gain(struct imx258 *imx258, u32 len, u32 val) return 0; } +static void imx258_adjust_exposure_range(struct imx258 *imx258) +{ + int exposure_max, exposure_def; + + /* Honour the VBLANK limits when setting exposure. */ + exposure_max = imx258->cur_mode->height + imx258->vblank->val - + IMX258_EXPOSURE_OFFSET; + exposure_def = min(exposure_max, imx258->exposure->val); + __v4l2_ctrl_modify_range(imx258->exposure, imx258->exposure->minimum, + exposure_max, imx258->exposure->step, + exposure_def); +} + static int imx258_set_ctrl(struct v4l2_ctrl *ctrl) { struct imx258 *imx258 = @@ -748,6 +762,13 @@ static int imx258_set_ctrl(struct v4l2_ctrl *ctrl) struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); int ret = 0; + /* + * The VBLANK control may change the limits of usable exposure, so check + * and adjust if necessary. + */ + if (ctrl->id == V4L2_CID_VBLANK) + imx258_adjust_exposure_range(imx258); + /* * Applying V4L2 control value only happens * when power is up for streaming