From patchwork Tue Feb 20 09:28:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 774763 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 58B0D60DC4; Tue, 20 Feb 2024 09:28:33 +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=1708421315; cv=none; b=Gz4wtKurpYQQEkB9Qz9Jd+E+rZIed1LDXK8l1v+G08haYrxdMRxyOtNvr75YZFcIgHurUCigg3nUBs+yWxQb6TFf+yf+BDo/Z5qiM4Jp/q2PoemxB/A1svSUZlMbwM/CR/O5fzwbEPJtllAYZp28XWwKPTRozAD2c2psllAJXc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708421315; c=relaxed/simple; bh=ojTTiT7sFsKLZQgcQ3xTUQAx0XjIPRDu5NRR820vWbM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cycs/Xk0wabHxfkOW5AwMYzYMzEzDsQf1TiOG3Yr4E+00SIww9BvIi8FQn6E7QGlAUQuoVjHeU4hp9aGVLOWiINvhPv1ULgZ9GOo9aokcGNLMUknHXSRKMtlW/pm1nZs8lb7vH+jK4+/mLRUe8If6uVeupN/bNdC++RKtEnfdWQ= 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=FNHqudLS; 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="FNHqudLS" Received: from umang.jain (unknown [103.86.18.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2E3A214AF; Tue, 20 Feb 2024 10:28:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1708421304; bh=ojTTiT7sFsKLZQgcQ3xTUQAx0XjIPRDu5NRR820vWbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FNHqudLSaF49k70GYlsIMmJOhIlAVqlyMliyANY3PDGKX7BhaKdduZcOtHmydPyKb qmYLH5rfVbtl818UdnBxBZ7TltCU+fCoTZ69/hfG9ZDUA0HRmy807W73iMUSXeIwja VRkwZWIcPBMiY6mvQc/J9Gr9ue0YvXYxm6f7PUHo= From: Umang Jain To: linux-media@vger.kernel.org Cc: Kieran Bingham , Mauro Carvalho Chehab , open list , Sakari Ailus , Umang Jain , Matthias Fend Subject: [PATCH v3 1/5] media: imx335: Set reserved register to default value Date: Tue, 20 Feb 2024 14:58:17 +0530 Message-ID: <20240220092821.1993-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220092821.1993-1-umang.jain@ideasonboard.com> References: <20240220092821.1993-1-umang.jain@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 0x3a00 is a reserved register as per the datasheet. The driver currently sets to it 0x01 while the datasheet claims 0x00 to be the default value. On one of the setup based on i.MX8MP platform with IMX335, this register write broke the CSI-2 configuration. Setting 0x3a00 to its default value (i.e. 0x00) fixed the issue. It is not clear from the datasheet what this register write is responsible for but setting it to its default value seems the right thing to do, provided it has been found responsible to break CSI-2 configuration on one of the platform. Signed-off-by: Umang Jain Reported-by: Matthias Fend --- drivers/media/i2c/imx335.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index 7a37eb327ff4..3d3848a58fa7 100644 --- a/drivers/media/i2c/imx335.c +++ b/drivers/media/i2c/imx335.c @@ -249,7 +249,7 @@ static const struct imx335_reg mode_2592x1940_regs[] = { {0x3794, 0x7a}, {0x3796, 0xa1}, {0x37b0, 0x36}, - {0x3a00, 0x01}, + {0x3a00, 0x00}, }; static const struct imx335_reg raw10_framefmt_regs[] = { From patchwork Tue Feb 20 09:28:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 774427 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 89D73612CB; Tue, 20 Feb 2024 09:28:34 +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=1708421316; cv=none; b=J9OKsSLEKuXS6UMXj0wMFgapWrOQUIQeqR8c/GRP6BOmLf2gyLyKxau3yDRifUmXW5pCT15X3n9K4KY9jYODgvuX6wvZVgTHubnt3SmX9NcieW+nkBEN0GU3L6SrYdhgfu9UP1vkF/tikV0y0NyAxL8ckV3fLMmvTCsOPZxY06E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708421316; c=relaxed/simple; bh=XipfuQdTOnh77bpSpgYNKleDJ+dxjzI8KT+7+T0Y2ww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pevqB7fqGk1i6gsL7yB21Ushi4uiN5qv8DjsGC88YuWhQwu43KveGTM9HD+gk3FcmC2zps0NG5WpIA9qr04rpgryWGaqBNvKyVncKuq4JzsspAYFvkv8TgL9qKQXGqNxc3OGeiLwmAQx1L0XK8PpT1M+K6fiBJljqp8BqCWNDQg= 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=jiMrrOL5; 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="jiMrrOL5" Received: from umang.jain (unknown [103.86.18.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7C03314B0; Tue, 20 Feb 2024 10:28:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1708421306; bh=XipfuQdTOnh77bpSpgYNKleDJ+dxjzI8KT+7+T0Y2ww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jiMrrOL5lo7Kxaj6OlAd+WFp+0ajFQf5+uFwaQfiBpFcwAt6UNLN/8xgf4WxBohI2 ePHsWV/vHlglSpsUk3yMRtb2Sy8M38Kuepe75EtaHgnRiikQaP7gqtne9B43H9/Dbr xaCpQy0BKCZDKHrszUzF8esjEdiWRswaIKY2v4Xs= From: Umang Jain To: linux-media@vger.kernel.org Cc: Kieran Bingham , Mauro Carvalho Chehab , open list , Sakari Ailus , Umang Jain Subject: [PATCH v3 2/5] media: imx335: Use v4l2_link_freq_to_bitmap helper Date: Tue, 20 Feb 2024 14:58:18 +0530 Message-ID: <20240220092821.1993-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220092821.1993-1-umang.jain@ideasonboard.com> References: <20240220092821.1993-1-umang.jain@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the v4l2_link_freq_to_bitmap() helper to figure out which driver-supported link frequencies can be used on a given system. Signed-off-by: Umang Jain --- drivers/media/i2c/imx335.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index 3d3848a58fa7..e34e34503dda 100644 --- a/drivers/media/i2c/imx335.c +++ b/drivers/media/i2c/imx335.c @@ -49,7 +49,7 @@ #define IMX335_INCLK_RATE 24000000 /* CSI2 HW configuration */ -#define IMX335_LINK_FREQ 594000000 +#define IMX335_LINK_FREQ 594000000LL #define IMX335_NUM_DATA_LANES 4 #define IMX335_REG_MIN 0x00 @@ -134,6 +134,7 @@ struct imx335_mode { * @vblank: Vertical blanking in lines * @cur_mode: Pointer to current selected sensor mode * @mutex: Mutex for serializing sensor controls + * @link_freq_bitmap: Menu bitmap for link_freq_ctrl * @cur_mbus_code: Currently selected media bus format code */ struct imx335 { @@ -157,6 +158,7 @@ struct imx335 { u32 vblank; const struct imx335_mode *cur_mode; struct mutex mutex; + unsigned long link_freq_bitmap; u32 cur_mbus_code; }; @@ -405,7 +407,8 @@ static int imx335_update_controls(struct imx335 *imx335, { int ret; - ret = __v4l2_ctrl_s_ctrl(imx335->link_freq_ctrl, mode->link_freq_idx); + ret = __v4l2_ctrl_s_ctrl(imx335->link_freq_ctrl, + __ffs(imx335->link_freq_bitmap)); if (ret) return ret; @@ -691,6 +694,13 @@ static int imx335_init_state(struct v4l2_subdev *sd, fmt.which = sd_state ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE; imx335_fill_pad_format(imx335, &supported_mode, &fmt); + mutex_lock(&imx335->mutex); + __v4l2_ctrl_modify_range(imx335->link_freq_ctrl, 0, + __fls(imx335->link_freq_bitmap), + ~(imx335->link_freq_bitmap), + __ffs(imx335->link_freq_bitmap)); + mutex_unlock(&imx335->mutex); + return imx335_set_pad_format(sd, sd_state, &fmt); } @@ -939,19 +949,10 @@ static int imx335_parse_hw_config(struct imx335 *imx335) goto done_endpoint_free; } - if (!bus_cfg.nr_of_link_frequencies) { - dev_err(imx335->dev, "no link frequencies defined\n"); - ret = -EINVAL; - goto done_endpoint_free; - } - - for (i = 0; i < bus_cfg.nr_of_link_frequencies; i++) - if (bus_cfg.link_frequencies[i] == IMX335_LINK_FREQ) - goto done_endpoint_free; - - dev_err(imx335->dev, "no compatible link frequencies found\n"); - - ret = -EINVAL; + ret = v4l2_link_freq_to_bitmap(imx335->dev, bus_cfg.link_frequencies, + bus_cfg.nr_of_link_frequencies, + link_freq, ARRAY_SIZE(link_freq), + &imx335->link_freq_bitmap); done_endpoint_free: v4l2_fwnode_endpoint_free(&bus_cfg); @@ -1099,9 +1100,8 @@ static int imx335_init_controls(struct imx335 *imx335) imx335->link_freq_ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr, &imx335_ctrl_ops, V4L2_CID_LINK_FREQ, - ARRAY_SIZE(link_freq) - - 1, - mode->link_freq_idx, + __fls(imx335->link_freq_bitmap), + __ffs(imx335->link_freq_bitmap), link_freq); if (imx335->link_freq_ctrl) imx335->link_freq_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; From patchwork Tue Feb 20 09:28:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 774762 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 DA9DC60881; Tue, 20 Feb 2024 09:28: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=1708421318; cv=none; b=EI7qP8FNgKKW4lsWsBjGzVMLx62TQ7lxgdYnVvfSe/0JrFae+tmf+HinNbe6UprkdvQDz6FAZS13U1FiNI3mdLe0E1zrspcpAU01gQdiwZwfvycohf/KY4iWCImmiqN51leachdSbF+ikQIyTetKJgjvxXrMpSZ2aMgK8zDHMWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708421318; c=relaxed/simple; bh=qXG+xWIeAzR0Odss+ql3FBGpuSNVYP9vQKaFrOq/7lM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OAp8oD6gcuGNDE8rt+kgmYE54km20o7BDSI30cAjgMEhYxnqD8KhlbKMSjQ/G1DsbUAapJj5jQy+r3NrFcTOzp85/Tj4b0GzIhZFGP8bl6R/AJSfIlUmuytIzH2yNNPi5HYIVsh+H5pF7BfRWLCkGkSSiQb7xDFkuxHytF6BwvA= 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=UO4s/xrP; 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="UO4s/xrP" Received: from umang.jain (unknown [103.86.18.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 94C6E1536; Tue, 20 Feb 2024 10:28:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1708421308; bh=qXG+xWIeAzR0Odss+ql3FBGpuSNVYP9vQKaFrOq/7lM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UO4s/xrPT2paE7l1twzre7srmKkBASkpodFN16l9oRWIs6gkFLy6+IG9lRV3NljDY Jcf1BFhGm7gRJBgi40WrEF71mZWJYo9xU37zNiknjfZ63ITgJqMREGddtojhFgq8SX pGPZQ5e8eit1HSvtOn/YJk4BeIYy4ak89oJV+s1I= From: Umang Jain To: linux-media@vger.kernel.org Cc: Kieran Bingham , Mauro Carvalho Chehab , open list , Sakari Ailus , Umang Jain Subject: [PATCH v3 3/5] media: imx335: Support multiple link frequency Date: Tue, 20 Feb 2024 14:58:19 +0530 Message-ID: <20240220092821.1993-4-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220092821.1993-1-umang.jain@ideasonboard.com> References: <20240220092821.1993-1-umang.jain@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Support link frequency of 445MHz in addition to 594MHz. Break out the register set specific to each data lane rate and also add the general timing register set corresponding to the each data lane rate. Signed-off-by: Umang Jain --- drivers/media/i2c/imx335.c | 84 +++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 14 deletions(-) diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index e34e34503dda..27f850a5b9b7 100644 --- a/drivers/media/i2c/imx335.c +++ b/drivers/media/i2c/imx335.c @@ -49,7 +49,9 @@ #define IMX335_INCLK_RATE 24000000 /* CSI2 HW configuration */ -#define IMX335_LINK_FREQ 594000000LL +#define IMX335_LINK_FREQ_594MHz 594000000LL +#define IMX335_LINK_FREQ_445MHz 445500000LL + #define IMX335_NUM_DATA_LANES 4 #define IMX335_REG_MIN 0x00 @@ -99,7 +101,6 @@ static const char * const imx335_supply_name[] = { * @vblank_min: Minimum vertical blanking in lines * @vblank_max: Maximum vertical blanking in lines * @pclk: Sensor pixel clock - * @link_freq_idx: Link frequency index * @reg_list: Register list for sensor mode */ struct imx335_mode { @@ -111,7 +112,6 @@ struct imx335_mode { u32 vblank_min; u32 vblank_max; u64 pclk; - u32 link_freq_idx; struct imx335_reg_list reg_list; }; @@ -162,16 +162,10 @@ struct imx335 { u32 cur_mbus_code; }; -static const s64 link_freq[] = { - IMX335_LINK_FREQ, -}; - /* Sensor mode registers */ static const struct imx335_reg mode_2592x1940_regs[] = { {0x3000, 0x01}, {0x3002, 0x00}, - {0x300c, 0x3b}, - {0x300d, 0x2a}, {0x3018, 0x04}, {0x302c, 0x3c}, {0x302e, 0x20}, @@ -179,10 +173,6 @@ static const struct imx335_reg mode_2592x1940_regs[] = { {0x3074, 0xc8}, {0x3076, 0x28}, {0x304c, 0x00}, - {0x314c, 0xc6}, - {0x315a, 0x02}, - {0x3168, 0xa0}, - {0x316a, 0x7e}, {0x31a1, 0x00}, {0x3288, 0x21}, {0x328a, 0x02}, @@ -268,6 +258,65 @@ static const struct imx335_reg raw12_framefmt_regs[] = { {0x341d, 0x00}, }; +static const struct imx335_reg mipi_data_rate_1188Mbps[] = { + {0x300c, 0x3b}, + {0x300d, 0x2a}, + {0x314c, 0xc6}, + {0x314d, 0x00}, + {0x315a, 0x02}, + {0x3168, 0xa0}, + {0x316a, 0x7e}, + {0x319e, 0x01}, + {0x3a18, 0x8f}, + {0x3a1a, 0x4f}, + {0x3a1c, 0x47}, + {0x3a1e, 0x37}, + {0x3a1f, 0x01}, + {0x3a20, 0x4f}, + {0x3a22, 0x87}, + {0x3a24, 0x4f}, + {0x3a26, 0x7f}, + {0x3a28, 0x3f}, +}; + +static const struct imx335_reg mipi_data_rate_891Mbps[] = { + {0x300c, 0x3b}, + {0x300d, 0x2a}, + {0x314c, 0x29}, + {0x314d, 0x01}, + {0x315a, 0x06}, + {0x3168, 0xa0}, + {0x316a, 0x7e}, + {0x319e, 0x02}, + {0x3a18, 0x7f}, + {0x3a1a, 0x37}, + {0x3a1c, 0x37}, + {0x3a1e, 0xf7}, + {0x3a20, 0x3f}, + {0x3a22, 0x6f}, + {0x3a24, 0x3f}, + {0x3a26, 0x5f}, + {0x3a28, 0x2f}, +}; + +static const s64 link_freq[] = { + /* Corresponds to 1188Mbps data lane rate */ + IMX335_LINK_FREQ_594MHz, + /* Corresponds to 891Mbps data lane rate */ + IMX335_LINK_FREQ_445MHz, +}; + +static const struct imx335_reg_list link_freq_reglist[] = { + { + .num_of_regs = ARRAY_SIZE(mipi_data_rate_1188Mbps), + .regs = mipi_data_rate_1188Mbps, + }, + { + .num_of_regs = ARRAY_SIZE(mipi_data_rate_891Mbps), + .regs = mipi_data_rate_891Mbps, + }, +}; + static const u32 imx335_mbus_codes[] = { MEDIA_BUS_FMT_SRGGB12_1X12, MEDIA_BUS_FMT_SRGGB10_1X10, @@ -282,7 +331,6 @@ static const struct imx335_mode supported_mode = { .vblank_min = 2560, .vblank_max = 133060, .pclk = 396000000, - .link_freq_idx = 0, .reg_list = { .num_of_regs = ARRAY_SIZE(mode_2592x1940_regs), .regs = mode_2592x1940_regs, @@ -765,6 +813,14 @@ static int imx335_start_streaming(struct imx335 *imx335) const struct imx335_reg_list *reg_list; int ret; + /* Setup PLL */ + reg_list = &link_freq_reglist[__ffs(imx335->link_freq_bitmap)]; + ret = imx335_write_regs(imx335, reg_list->regs, reg_list->num_of_regs); + if (ret) { + dev_err(imx335->dev, "%s failed to set plls\n", __func__); + return ret; + } + /* Write sensor mode registers */ reg_list = &imx335->cur_mode->reg_list; ret = imx335_write_regs(imx335, reg_list->regs, From patchwork Tue Feb 20 09:28:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 774426 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 7DA2263410; Tue, 20 Feb 2024 09:28:38 +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=1708421320; cv=none; b=Vo096vDu+wS0uP01dpdFynfbn5vZ12/7ol/o5Jc99+/rp9RXssxB+HcVR2ZQMh3vbmNuVPKdLsXwaiMq1c2lr96S/SsPUr8uwgo6TIShkeOzXDpcHQw/WG6do5r5ZO+EJIznEXPBXVc7RaU1RnoLYMronZLfYhKMInKuAmzjK78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708421320; c=relaxed/simple; bh=7/nlcTXjn6fmMKJ6B7TxNKPbpJTYZY5Sd+dT6NQXmgI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qGK26k5RlLFhqjipqegO005gRd77II2wK8MWkwsyDa2pcWEJ4pgEY2UT3Ug7YRDC1IgfFoKG9exysFMoECOIEHws8XweqOlzWjpRBvdK+/vRdxTmvMnCSp9fIbTLPKkbOYhMRnOOZwaFxzIXpt+x87bueqSNBIinp3uf5CNa6qk= 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=ttiucm6u; 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="ttiucm6u" Received: from umang.jain (unknown [103.86.18.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AF1931593; Tue, 20 Feb 2024 10:28:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1708421310; bh=7/nlcTXjn6fmMKJ6B7TxNKPbpJTYZY5Sd+dT6NQXmgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ttiucm6uWkPdAzg00xsrPDHowYPf5Vmm0N0DbC+ogiKfoqo8tCJJItrF1qpgpAibi gJWSZ2FQKfFmxIf00Qr27Ii5f8HPmlXQsMzMna+BvqfgAP6D9oQpkbTtOX3ToFPP/H d1JfUhpdX9zdX7kaT0LbMXWo3HIBgizWaD4DmQTM= From: Umang Jain To: linux-media@vger.kernel.org Cc: Kieran Bingham , Mauro Carvalho Chehab , open list , Sakari Ailus , Umang Jain Subject: [PATCH v3 4/5] media: imx335: Refactor power sequence to set controls Date: Tue, 20 Feb 2024 14:58:20 +0530 Message-ID: <20240220092821.1993-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220092821.1993-1-umang.jain@ideasonboard.com> References: <20240220092821.1993-1-umang.jain@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Additional controls might require the sensor to be powered up to set the control value. Currently, only the exposure control powers up the sensor. Move the power up sequence out of the switch-case block. In a subsequent patch, test pattern control will be added that needs the sensor to be powered up. Hence, refactor the power sequence to be present outside the switch-case block. The VBLANK control is also moved out of the switch-case in order to be handled early on, to propagate the changes to other controls. Signed-off-by: Umang Jain --- drivers/media/i2c/imx335.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index 27f850a5b9b7..e2445b94cf91 100644 --- a/drivers/media/i2c/imx335.c +++ b/drivers/media/i2c/imx335.c @@ -527,26 +527,31 @@ static int imx335_set_ctrl(struct v4l2_ctrl *ctrl) u32 exposure; int ret; - switch (ctrl->id) { - case V4L2_CID_VBLANK: + /* Propagate change of current control to all related controls */ + if (ctrl->id == V4L2_CID_VBLANK) { imx335->vblank = imx335->vblank_ctrl->val; dev_dbg(imx335->dev, "Received vblank %u, new lpfr %u\n", imx335->vblank, imx335->vblank + imx335->cur_mode->height); - ret = __v4l2_ctrl_modify_range(imx335->exp_ctrl, - IMX335_EXPOSURE_MIN, - imx335->vblank + - imx335->cur_mode->height - - IMX335_EXPOSURE_OFFSET, - 1, IMX335_EXPOSURE_DEFAULT); - break; - case V4L2_CID_EXPOSURE: - /* Set controls only if sensor is in power on state */ - if (!pm_runtime_get_if_in_use(imx335->dev)) - return 0; + return __v4l2_ctrl_modify_range(imx335->exp_ctrl, + IMX335_EXPOSURE_MIN, + imx335->vblank + + imx335->cur_mode->height - + IMX335_EXPOSURE_OFFSET, + 1, IMX335_EXPOSURE_DEFAULT); + } + + /* + * Applying V4L2 control value only happens + * when power is up for streaming. + */ + if (pm_runtime_get_if_in_use(imx335->dev) == 0) + return 0; + switch (ctrl->id) { + case V4L2_CID_EXPOSURE: exposure = ctrl->val; analog_gain = imx335->again_ctrl->val; @@ -555,14 +560,14 @@ static int imx335_set_ctrl(struct v4l2_ctrl *ctrl) ret = imx335_update_exp_gain(imx335, exposure, analog_gain); - pm_runtime_put(imx335->dev); - break; default: dev_err(imx335->dev, "Invalid control %d\n", ctrl->id); ret = -EINVAL; } + pm_runtime_put(imx335->dev); + return ret; } From patchwork Tue Feb 20 09:28:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 774761 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 B469164CD0; Tue, 20 Feb 2024 09:28:40 +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=1708421322; cv=none; b=iCU+nTrz0M+jbPwiS2kj5R54K+Tdue6PZFBBmLim5s67KBmDeTZcNLJ/kNvuXlZrkyHE4IiIgxKki0QLLiJST+vkFw6ZRN2B5ZHNnrcs1niej49GwB+lCM714klBUwckkPHoYI7zs8Kvv8ub1GcNkvjJeFFMOBH2esd44wWA9eM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708421322; c=relaxed/simple; bh=kKxMnPSqYT9qIUkqI4fHrZWKiMHCC/3+G1YH1yVFWls=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qG3oSZMSrlTpmHctAYWwUoLyUfdcBuiarg8Z7qQoqUNazRxtqpMznW86dbkeK8r/qezJ9WGUQs+SnjkV+q+sW0B65/GHdIhj4RgIvneEGNajjI0Y9y6VJN1xXxx5LVC/+jtInwg+RILLrsQXoqfjC8F09m1S/qXjdGB51r0Kjb4= 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=YgpesD7J; 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="YgpesD7J" Received: from umang.jain (unknown [103.86.18.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CC2B613AC; Tue, 20 Feb 2024 10:28:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1708421312; bh=kKxMnPSqYT9qIUkqI4fHrZWKiMHCC/3+G1YH1yVFWls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YgpesD7JrKzfT8j/4eHuZlPLZr/jZfqCymfkGvlHAaEIWkUuqa4kcvvAJezCAnwGc QxUYvkdKLdUSQ/a412tplw38oTRTZnKrdu4Syo4tl38CgJYON9H8opTWW/DdjUEaL9 CTBFvvh8fHtbbGlDAfotGfnhs4Ag7ubAIHF/+pmg= From: Umang Jain To: linux-media@vger.kernel.org Cc: Kieran Bingham , Mauro Carvalho Chehab , open list , Sakari Ailus , Matthias Fend , Umang Jain Subject: [PATCH v3 5/5] media: imx335: Add support for test pattern generator Date: Tue, 20 Feb 2024 14:58:21 +0530 Message-ID: <20240220092821.1993-6-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220092821.1993-1-umang.jain@ideasonboard.com> References: <20240220092821.1993-1-umang.jain@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Matthias Fend Add support for the sensor's test pattern generator. Signed-off-by: Matthias Fend Signed-off-by: Kieran Bingham Signed-off-by: Umang Jain --- drivers/media/i2c/imx335.c | 102 ++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index e2445b94cf91..dab6d080bc4c 100644 --- a/drivers/media/i2c/imx335.c +++ b/drivers/media/i2c/imx335.c @@ -45,6 +45,21 @@ /* Group hold register */ #define IMX335_REG_HOLD 0x3001 +/* Test pattern generator */ +#define IMX335_REG_TPG 0x329e +#define IMX335_TPG_ALL_000 0 +#define IMX335_TPG_ALL_FFF 1 +#define IMX335_TPG_ALL_555 2 +#define IMX335_TPG_ALL_AAA 3 +#define IMX335_TPG_TOG_555_AAA 4 +#define IMX335_TPG_TOG_AAA_555 5 +#define IMX335_TPG_TOG_000_555 6 +#define IMX335_TPG_TOG_555_000 7 +#define IMX335_TPG_TOG_000_FFF 8 +#define IMX335_TPG_TOG_FFF_000 9 +#define IMX335_TPG_H_COLOR_BARS 10 +#define IMX335_TPG_V_COLOR_BARS 11 + /* Input clock rate */ #define IMX335_INCLK_RATE 24000000 @@ -162,6 +177,38 @@ struct imx335 { u32 cur_mbus_code; }; +static const char * const imx335_tpg_menu[] = { + "Disabled", + "All 000h", + "All FFFh", + "All 555h", + "All AAAh", + "Toggle 555/AAAh", + "Toggle AAA/555h", + "Toggle 000/555h", + "Toggle 555/000h", + "Toggle 000/FFFh", + "Toggle FFF/000h", + "Horizontal color bars", + "Vertical color bars", +}; + +static const int imx335_tpg_val[] = { + IMX335_TPG_ALL_000, + IMX335_TPG_ALL_000, + IMX335_TPG_ALL_FFF, + IMX335_TPG_ALL_555, + IMX335_TPG_ALL_AAA, + IMX335_TPG_TOG_555_AAA, + IMX335_TPG_TOG_AAA_555, + IMX335_TPG_TOG_000_555, + IMX335_TPG_TOG_555_000, + IMX335_TPG_TOG_000_FFF, + IMX335_TPG_TOG_FFF_000, + IMX335_TPG_H_COLOR_BARS, + IMX335_TPG_V_COLOR_BARS, +}; + /* Sensor mode registers */ static const struct imx335_reg mode_2592x1940_regs[] = { {0x3000, 0x01}, @@ -507,6 +554,49 @@ static int imx335_update_exp_gain(struct imx335 *imx335, u32 exposure, u32 gain) return ret; } +static int imx335_update_test_pattern(struct imx335 *imx335, u32 pattern_index) +{ + int ret; + + if (pattern_index >= ARRAY_SIZE(imx335_tpg_val)) + return -EINVAL; + + if (pattern_index) { + const struct imx335_reg tpg_enable_regs[] = { + { 0x3148, 0x10 }, + { 0x3280, 0x00 }, + { 0x329c, 0x01 }, + { 0x32a0, 0x11 }, + { 0x3302, 0x00 }, + { 0x3303, 0x00 }, + { 0x336c, 0x00 }, + }; + + ret = imx335_write_reg(imx335, IMX335_REG_TPG, 1, + imx335_tpg_val[pattern_index]); + if (ret) + return ret; + + ret = imx335_write_regs(imx335, tpg_enable_regs, + ARRAY_SIZE(tpg_enable_regs)); + } else { + const struct imx335_reg tpg_disable_regs[] = { + { 0x3148, 0x00 }, + { 0x3280, 0x01 }, + { 0x329c, 0x00 }, + { 0x32a0, 0x10 }, + { 0x3302, 0x32 }, + { 0x3303, 0x00 }, + { 0x336c, 0x01 }, + }; + + ret = imx335_write_regs(imx335, tpg_disable_regs, + ARRAY_SIZE(tpg_disable_regs)); + } + + return ret; +} + /** * imx335_set_ctrl() - Set subdevice control * @ctrl: pointer to v4l2_ctrl structure @@ -560,6 +650,10 @@ static int imx335_set_ctrl(struct v4l2_ctrl *ctrl) ret = imx335_update_exp_gain(imx335, exposure, analog_gain); + break; + case V4L2_CID_TEST_PATTERN: + ret = imx335_update_test_pattern(imx335, ctrl->val); + break; default: dev_err(imx335->dev, "Invalid control %d\n", ctrl->id); @@ -1117,7 +1211,7 @@ static int imx335_init_controls(struct imx335 *imx335) u32 lpfr; int ret; - ret = v4l2_ctrl_handler_init(ctrl_hdlr, 6); + ret = v4l2_ctrl_handler_init(ctrl_hdlr, 7); if (ret) return ret; @@ -1151,6 +1245,12 @@ static int imx335_init_controls(struct imx335 *imx335) mode->vblank_max, 1, mode->vblank); + v4l2_ctrl_new_std_menu_items(ctrl_hdlr, + &imx335_ctrl_ops, + V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(imx335_tpg_menu) - 1, + 0, 0, imx335_tpg_menu); + /* Read only controls */ imx335->pclk_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, &imx335_ctrl_ops,