From patchwork Thu Jan 25 15:49:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 192149 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp66131dyb; Thu, 25 Jan 2024 07:50:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHM9OrSGmajP+I0gnPvKaEm0L8a+Ov+cvgzjPDkiYJvsoWgGqGsyt8uOTvey/sExokxvdrI X-Received: by 2002:a05:6870:9113:b0:204:34ca:b85e with SMTP id o19-20020a056870911300b0020434cab85emr1103946oae.118.1706197827386; Thu, 25 Jan 2024 07:50:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706197827; cv=pass; d=google.com; s=arc-20160816; b=AP8+mz6Lv6qZivvUNOXHwkoJstFUgV1G3X9fbkX7UsWU1uYGqkonr9s3Btgg6Jtfb+ 0UwxxPP9stSjyjsqBBYqTumGqkdtY5p49vkinB96lowvRUz16ZLtq4mdq1jeJRtM1fDb /Wra3io6Fu+t+NC/TQt1EbKfFMNE5+fvUgtlmAq2h7b+4jkAxypVdeLAJQb4npv7Zl3p plcEbuSLyMEf+XPb7bLQWQ6fx86BXiiYMQVQ7SoTKDRGiOZgl08T/9M+9yVoDFef6cul QZ5XR8jNJijweFXGKEbCNyg/cMbJ9RQl9j67Og/5OcTVup8xlTA7/vPnGjglGbdqKhAv amDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+HRdLyqPzrxihsj9aE15diySL8xiA+MabkVSsamz+d8=; fh=6f/5I72Sv/UY+cHLlGttfBgvh/IGbPGmmEwVFdv7piE=; b=VFvaj3qQMQrT+eFgAS2Qq5b6olXLr2/LRzwW9UGNVej9TvVTvo7Tgr3C5zytN72YAM 70hHH/RqPS3vbhU/wwMGIXwlCJQDskbxiJNzqG6Lon/zA+yjUa6Wp9dmjR4Y3ExOD4bd 3qjhc8LZKRU2IpN2HQpfzlpqQMQxmvziZ4sJ2dQFgKkn4DQN1D2xftXlKSlnAR4F84dS tXoM/gJRCG5eJDWTVXt1CnZGF53RGSo+AnjRFuGPP4aP1X7rFK24ET4lzZB7Qk2HaLY0 u2qLZBNwnE/5xu577jn3HJme+OSzIzLTvsn9AW/Okp20e7USXwqe9ygffu+oAyNSTtkQ DZpw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=OX2EIbgj; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-38850-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38850-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v17-20020a05622a189100b0042a6087d10csi3574149qtc.612.2024.01.25.07.50.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 07:50:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38850-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=OX2EIbgj; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-38850-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38850-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CB5B61C234DD for ; Thu, 25 Jan 2024 15:50:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25DC4768F5; Thu, 25 Jan 2024 15:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OX2EIbgj" 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 D570D73175; Thu, 25 Jan 2024 15:49:28 +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=1706197770; cv=none; b=I2ctgmaeoXK/clEroAKvS3C/GbJXcoNiLjW8Mp4ApN9D9+qcKf69TWKeDZOMF1ZXMMzTiTqwgaeJSGUVIhV2tzLQfyiq3OiE+UJSRrRR02CttacAQIhHgJfI+r0VxTb25OVG4YEB80hT8AzmChGWg7KTWnW29r0doQtOY1g9Hto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706197770; c=relaxed/simple; bh=E0w/XiH4qT+OHnPrSm3O8kwqTF6mJdF3nkwwq5HY+/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=efiCUXT6bYrkWo4dLfQU21C9/TkGj986eCGDN5ZKr88uTJEnmIJC19i7hkbXmaFCDyZBOOZIy1wmOXJ9GuI2R2wt5Pd1wQh36NhWxlgBEn+PckWakUR4dGW1NVNTwPf0ajWlNcwxcf3m4P0jQwkJn5xOBU/tT+j6mYdoRBELev8= 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=OX2EIbgj; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from umang.jain (unknown [103.86.18.175]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 584BD552; Thu, 25 Jan 2024 16:48:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1706197686; bh=E0w/XiH4qT+OHnPrSm3O8kwqTF6mJdF3nkwwq5HY+/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OX2EIbgjw5kG/6+UCF8+6bBs/CwYgBG8P3F77beraH1q4fP0S6DyCCiH+1oB9knp2 HVvt0x4mVNLGIGH1QGFyPjlAmO7jk8W9TH7W99jghJ5fXcnD2ZXAnPqBLNKOckn4TE 551IS3UwEoPB8VM19ek3mYYOyQosQVs+s5SvoU8M= From: Umang Jain To: linux-media@vger.kernel.org Cc: Kieran Bingham , Mauro Carvalho Chehab , open list , Sakari Ailus , Umang Jain Subject: [PATCH 1/4] media: i2c: imx335: Drop setting of 0x3a00 register Date: Thu, 25 Jan 2024 21:19:05 +0530 Message-ID: <20240125154908.465191-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240125154908.465191-1-umang.jain@ideasonboard.com> References: <20240125154908.465191-1-umang.jain@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789078093006957644 X-GMAIL-MSGID: 1789078093006957644 Register 0x3a00 is a reserved field as per the IMX335 datasheet, hence shouldn't be set by the driver. Signed-off-by: Umang Jain --- drivers/media/i2c/imx335.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index 5cca8d637952..0df9ea189fff 100644 --- a/drivers/media/i2c/imx335.c +++ b/drivers/media/i2c/imx335.c @@ -249,7 +249,6 @@ static const struct imx335_reg mode_2592x1940_regs[] = { {0x3794, 0x7a}, {0x3796, 0xa1}, {0x37b0, 0x36}, - {0x3a00, 0x01}, }; static const struct imx335_reg raw10_framefmt_regs[] = { From patchwork Thu Jan 25 15:49:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 192150 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp66241dyb; Thu, 25 Jan 2024 07:50:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IGICNmO1XDmq5mBno/S1JY7Bsr1goPSg5gOreBHex1crNiavcY19e4lx6vtAbN7UP7epND5 X-Received: by 2002:a2e:9b88:0:b0:2cc:87d7:a8e7 with SMTP id z8-20020a2e9b88000000b002cc87d7a8e7mr988257lji.102.1706197841250; Thu, 25 Jan 2024 07:50:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706197841; cv=pass; d=google.com; s=arc-20160816; b=nnTu1kyLR9D7XX+kgcLkefUvh12U3d+QPg5t0C1E0b198maHQ4OQTrzTHxrTaCdj1Q AGV7hkjE47nIwAf9hK8DdMIVY45Nd5dcAYNZ0MzqAC+5oaVueQK65dDnGlRio9pD8rZA fAqjHT/8y/ixhFxMtEU+f5Vs1Lu3sGfV8TKwx3xaFLoxh3Mdm5ZqHOsm/J4OZrKsR1Qc 9OTyLuCUrCUNZgsI7Ov4ImrFNePDCEGVaokW8tCFs62MhMD59u/ANRngzPvAx7GWkWoI M+QF76E938Xx8lc8Ene3qvFgIShZm68mVjd1lFJkLmgWcZ6PQi3bMO8cIgS3+5D2IB0D 521w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=skkgt8nN96I9B92yud8opQD7+W98tLYnFuxLW2qQn8s=; fh=6f/5I72Sv/UY+cHLlGttfBgvh/IGbPGmmEwVFdv7piE=; b=iOda+G5IUztKMf3gAuZAhQfyzQlae4BUkIJKyevLC7DMHllSoK9OJHw9K0dvD4n3vg aVehRKf2qISw4Lype4Rj+SA36ZLpd92SMcwyYl0/XEHByjoVGRfnZrwBhSUZNm9KG8Ue IjfXc+EF2SaZPGwfPSMX6diIqhRR5+xFlirQDx+zLYC7xquArkQ5wfB84vGbWWZ9rV21 llNU3PbKF0J8BErr3NZDusKrcuXrIeE4qqsGpbUEoJKpmS+bBbFIsy3xuAHA0DbWSeEE z0vait3Yx7eAHDbIW4B4YzBbpgLe++uL8+fEtwUYsukMK3BTHekKsxxkJKwESGkdAL8T 9R8A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=n3I6TOoN; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-38851-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38851-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i12-20020a50fc0c000000b0055c6587138dsi3620351edr.407.2024.01.25.07.50.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 07:50:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38851-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=n3I6TOoN; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-38851-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38851-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D0C9B1F2622A for ; Thu, 25 Jan 2024 15:50:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB23176901; Thu, 25 Jan 2024 15:49:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="n3I6TOoN" 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 D21F674E2E; Thu, 25 Jan 2024 15:49:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706197773; cv=none; b=m8XURXG4V1mbPeq6Za5zYJSkCYWrlqHCawoNhd7sRC5PLRMHPqeylFFbzOkOrZ8Mq1Zehs3w4OJq2fR1tr1SbVVqRZf4NL4YD5ODyjbsyFEcbN3s35h5QoT1L8SZFJrAZMLH4X0rRWytinoOVrIYuKKcWSsqi1ynPIeF7Dq2KMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706197773; c=relaxed/simple; bh=qPG6O3t7fXsKr/KZeQDHeleOcdDGSiCC1BklX+oeDXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NeXdVlxVQ9+/JxyS34vE2MXP98VLbyBRpx8iqCFijzv+t2IWpWowedu3n+/UU4LANi0GJIscbvVN0qQtGX+q/efLfCuwM89kUfTzf/VjsNQS3bL3kFdCAIr29vdS8sNATHUvPjjtvYvsj3aSPA7Y1DvXPsDxq8XT9JCoJe3El/k= 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=n3I6TOoN; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from umang.jain (unknown [103.86.18.175]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 159F4A9A; Thu, 25 Jan 2024 16:48:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1706197689; bh=qPG6O3t7fXsKr/KZeQDHeleOcdDGSiCC1BklX+oeDXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n3I6TOoN5Dqf99Xt1f/VSRpZ8GoNR7RFildvHv3YiTQ72UpzY1MoeV66bzoLcL132 h491vhqDv3+HOU5rk1VJ4tPP93LC6rMsc3ou4OPCo7vsPbgjyWuY2OhElcn4tEZpSv WW4I3+fZwZ81DFpsILUGNdYRiofw5gak2P+AIDaM= From: Umang Jain To: linux-media@vger.kernel.org Cc: Kieran Bingham , Mauro Carvalho Chehab , open list , Sakari Ailus , Umang Jain Subject: [PATCH 2/4] media: i2c: imx335: Refactor power sequence to set controls Date: Thu, 25 Jan 2024 21:19:06 +0530 Message-ID: <20240125154908.465191-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240125154908.465191-1-umang.jain@ideasonboard.com> References: <20240125154908.465191-1-umang.jain@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789078107398955378 X-GMAIL-MSGID: 1789078107398955378 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 | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index 0df9ea189fff..5add50af20e6 100644 --- a/drivers/media/i2c/imx335.c +++ b/drivers/media/i2c/imx335.c @@ -475,8 +475,8 @@ 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", @@ -489,12 +489,17 @@ static int imx335_set_ctrl(struct v4l2_ctrl *ctrl) 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; + } + + /* + * 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; @@ -503,14 +508,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 Thu Jan 25 15:49:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 192153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp69300dyb; Thu, 25 Jan 2024 07:56:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfbcYcKAHt9SKg42JRkP+HTaQQ59XfYL7QUo8Tg4jnq2yNtrjEwNdjZ9EF0U3GZ7fHk6u0 X-Received: by 2002:a17:902:ecc1:b0:1d7:8b8e:52e7 with SMTP id a1-20020a170902ecc100b001d78b8e52e7mr1195292plh.17.1706198177363; Thu, 25 Jan 2024 07:56:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706198177; cv=pass; d=google.com; s=arc-20160816; b=H1rNXnQACbSnaaWdrixqecu4shnXHtky0lkOjjhm/5zuEGHtAmqiLKwa7x7uFAHftv 6jQBdUTN/fjU2vRTgi/wZUq6h81pWDdi+A+1QaGJo8sBOhkUq4DU+k2dX/g3U+hFG7mG WrUNOJvWUenm42kHK6J/TTExKz08GX3LJeaLzKWMPRoR8vTwU5OsV7fRbXabnFaD168K xc9Okzhkpndo9sxVk10lAxBWz46SPwyvSKVFbHTjitSGzjl3RS1xnFuttwGNIg3yuv5t U1374ef1IVuQ9v4NDOvUH3q+vqASBOj5HC/48dbUSeSGaWLzdmlHZk3PwnqmjESq/s+r dH/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=4qoGMy6awRNm1ozhWjcD6o+7rvNstGDv1oJfyWB0UP0=; fh=6f/5I72Sv/UY+cHLlGttfBgvh/IGbPGmmEwVFdv7piE=; b=YpW7AXqeYuB7hcbbABF8XwqLjO20gRFScp2C5GRGo6bvlZqBCSD/bRKtZB/B5eCWWM fwdSD58DMcmtfq4CAuWEkYDZvLvfbmUUth09thyZXBLptobdw2SXsElJZl41LakpZaHb J3bqEMi2UyLpA9bkC1grT0Td1j74ArYirHbjxai8tBGzq8f6WOsYEN6avM8v4nbPsJTk xDLoFlK7FNrWpbboXuSsi44gQ9IQO/HLdcJydoASuCg4PWwfCuwe83uz8/1Mt9zECO1q s91KGA90nY7kdlR6baJM4HR3AZ3c1qg87UuY9yAIXD4CnYWX9yUTsOqaS23cQwkpP2PX 2pJA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=RxGJO89s; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-38852-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38852-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c3-20020a170902aa4300b001d056bdad56si13305314plr.166.2024.01.25.07.56.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 07:56:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38852-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=RxGJO89s; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-38852-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38852-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E487AB24E9A for ; Thu, 25 Jan 2024 15:50:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 102F37CF2B; Thu, 25 Jan 2024 15:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RxGJO89s" 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 32E1F74E39; Thu, 25 Jan 2024 15:49:31 +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=1706197773; cv=none; b=Dm1ccn6w8zjyyIXi94UY6hhNlTmRBQ787iasLgq9ViojIa1M5opFxTiYwZ/gZvvbpMKsrbQoajKcZMJ+2s0k7lqMFyAGbUsLDjdGhqplwiJ8btgLfjlnmt3hXrocpeLNFiUeZOoFneAZH08aS+dZznnToL9uukfjs/0Qx9qQ9ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706197773; c=relaxed/simple; bh=sNqc72hXfiqjcA5T1DAcrQtkWiD9ghOesnwHAwy4z+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GPAlx7hwGnXVc8OLOdaLYedz5SisZL/5gn9XCfQT/a6nt0drRgXi5zvMxYyRwZxISl1A08r6ur4pZogr8AIFyO1eUM2dsFqpoo6EGBvvRC3kIyWucpboTgSp7CDRrtSAElwSmUORFkbZVwya40TEPYPIpix8XXOdiQ11vAzWbyg= 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=RxGJO89s; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from umang.jain (unknown [103.86.18.175]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C84004AB0; Thu, 25 Jan 2024 16:48:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1706197692; bh=sNqc72hXfiqjcA5T1DAcrQtkWiD9ghOesnwHAwy4z+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RxGJO89sbqewdlb3+I6ggRl3YXi16E+yMGe7Yhtxs7/qHBsJgeKv9H8Y95/CTb/bJ xkd+ZnZYmp2L+KomWQhrvdxoZwouuuJtqvHC9SOIbjtdLN4OrQy6gNdI/4wf/7mptt XztoTeEeIRrnxm2ihkD5RAycxdNGtLfjTldSyHZg= From: Umang Jain To: linux-media@vger.kernel.org Cc: Kieran Bingham , Mauro Carvalho Chehab , open list , Sakari Ailus , Umang Jain Subject: [PATCH 3/4] media: i2c: imx335: Support multiple link frequency Date: Thu, 25 Jan 2024 21:19:07 +0530 Message-ID: <20240125154908.465191-4-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240125154908.465191-1-umang.jain@ideasonboard.com> References: <20240125154908.465191-1-umang.jain@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789078460097145036 X-GMAIL-MSGID: 1789078460097145036 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 | 108 +++++++++++++++++++++++++++++-------- 1 file changed, 87 insertions(+), 21 deletions(-) diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index 5add50af20e6..e64ee99cbae4 100644 --- a/drivers/media/i2c/imx335.c +++ b/drivers/media/i2c/imx335.c @@ -49,7 +49,8 @@ #define IMX335_INCLK_RATE 24000000 /* CSI2 HW configuration */ -#define IMX335_LINK_FREQ 594000000 +#define IMX335_LINK_FREQ_594MHz 594000000 +#define IMX335_LINK_FREQ_445MHz 445500000 #define IMX335_NUM_DATA_LANES 4 #define IMX335_REG_MIN 0x00 @@ -99,7 +100,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 +111,6 @@ struct imx335_mode { u32 vblank_min; u32 vblank_max; u64 pclk; - u32 link_freq_idx; struct imx335_reg_list reg_list; }; @@ -133,6 +132,7 @@ struct imx335_mode { * @again_ctrl: Pointer to analog gain control * @vblank: Vertical blanking in lines * @cur_mode: Pointer to current selected sensor mode + * @link_freq_idx: Selected link frequency index * @mutex: Mutex for serializing sensor controls * @cur_mbus_code: Currently selected media bus format code */ @@ -156,20 +156,16 @@ struct imx335 { }; u32 vblank; const struct imx335_mode *cur_mode; + u32 link_freq_idx; struct mutex mutex; 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}, @@ -177,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}, @@ -265,6 +257,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, @@ -279,7 +330,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, @@ -404,7 +454,7 @@ 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, imx335->link_freq_idx); if (ret) return ret; @@ -759,6 +809,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[imx335->link_freq_idx]; + 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, @@ -885,7 +943,7 @@ static int imx335_parse_hw_config(struct imx335 *imx335) }; struct fwnode_handle *ep; unsigned long rate; - unsigned int i; + unsigned int i, j; int ret; if (!fwnode) @@ -949,13 +1007,21 @@ static int imx335_parse_hw_config(struct imx335 *imx335) 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"); + for (i = 0; i < bus_cfg.nr_of_link_frequencies; i++) { + for (j = 0; j < ARRAY_SIZE(link_freq); j++) { + if (bus_cfg.link_frequencies[i] == link_freq[j]) { + imx335->link_freq_idx = j; + break; + } + } - ret = -EINVAL; + if (j == ARRAY_SIZE(link_freq)) { + ret = dev_err_probe(imx335->dev, -EINVAL, + "no supported link freq found\n"); + goto done_endpoint_free; + } + } done_endpoint_free: v4l2_fwnode_endpoint_free(&bus_cfg); @@ -1102,7 +1168,7 @@ static int imx335_init_controls(struct imx335 *imx335) V4L2_CID_LINK_FREQ, ARRAY_SIZE(link_freq) - 1, - mode->link_freq_idx, + imx335->link_freq_idx, link_freq); if (imx335->link_freq_ctrl) imx335->link_freq_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; From patchwork Thu Jan 25 15:49:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 192152 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp66856dyb; Thu, 25 Jan 2024 07:51:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBJSORhD40oDUyfyy4HSBT205po8RUzNPXjIM+Xazao/kZyRMjNCZGK/ZE6eduXss+gCbt X-Received: by 2002:aa7:c302:0:b0:55d:1818:a61f with SMTP id l2-20020aa7c302000000b0055d1818a61fmr146726edq.56.1706197907871; Thu, 25 Jan 2024 07:51:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706197907; cv=pass; d=google.com; s=arc-20160816; b=dlEbUp/qPU/d927U797aFr06eAuNykdcQWqtaF401ymYmq6VcXlDmXY1A2x8cChnXb zGHW7vK2NNKyYuJL2bNrRt1YDjBGpGwjvAp7XUdrWVXTZ3vLeRNNMtBOPrqSuBjh0HcS bY56p5BPMFemzYZkOT5JHUkLnB+Y9zEsE9+MXmDwUJMhU5abwhx2nMTr6OQCBPH25NsB qMlRl0eNgK9LwctP7q3CQtO4eUcb8jiJMB9acJh0yT7Iy2HH6XV1/5SpAR5lHMb3tHDx 6RnbxTMvQV9r7iFLCvGSqW7EPdPIN2x0KUR9BsLIQRDzYh+Gz41kVBM2TAtaG3qm760N 4sRw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=hOCUTUFWAycEpBXwmLXswqjh6f3cwYE4nuRtFQQPRAg=; fh=sm2MKrLKbZDLCL1DnC1zGAWx+IXS/LhgeDG/k75WZVg=; b=RWrAeQUVr+QU1L1ARDuEekxZO9gRtAPqUqfWcJa4yTK0hGKim7FInVDQJ2NOJjaSyJ dCwUaR7adZOyZx+fbHzljQ07qSvjIaftjujX/WpLNJRRadHASNAj5yL+tXTz2KXQmjGR PUB5eDZqnNLq41JovpHwRufeeE7Ol2/L4VddPwGVQFdr5GWCMLYnhQTUzEtWnOSfyo9F FgAYZDRcP00+PfWl/cCG198zLQ5jwe7ku+vFY5PCJgXhnOUVauPwOtrALbFFbUOeQQ3L M5FwEc6bRNHGkqEXHMXANZd5v0o1MbE/9Pu+XgJIR+8JZwb9u61s0iIPXnOyup83y+rv MjYw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=OZiRQtwq; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-38853-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38853-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r15-20020a056402234f00b0055c2df7fa74si4813959eda.529.2024.01.25.07.51.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 07:51:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38853-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=OZiRQtwq; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-38853-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38853-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0752E1F216AD for ; Thu, 25 Jan 2024 15:51:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48D537E771; Thu, 25 Jan 2024 15:49:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OZiRQtwq" 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 EA6797A707; Thu, 25 Jan 2024 15:49: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=1706197776; cv=none; b=a658ZMYhoV4UP8AnCs/fKQ+HqmNcKCppKE9irFdizelDIP+s4+lO2jZLaBnm9ih84F+CSrMyxvaMUuONFNpkS4ox/Ihu6ySrl8xTc48h8sTE5NsFzygLv0QTzrkQvZEvXfVMm6KIAEkl9arwv75gACykiuukflz4KxB8dD2QRrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706197776; c=relaxed/simple; bh=W1Z5z7CyCm6OJIhlRbgJ7qn8gVztgK3gJEzxblTd6J0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i/R976hNReNV8NH/tN61XCIgHIj/63aDxjx8P2GIp92Jy6Tt0pJkymfG+11FiLiR/acS/+AQFkfBaOOPZEPhysg+JWabCuhc02fVRgndCBY44KD6dbjn5mEjsnY9wV30sSsEg9ER1qb+C/7u93oE3aEIgCVQ4kPMrg5rG8/le34= 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=OZiRQtwq; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from umang.jain (unknown [103.86.18.175]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B760951A6; Thu, 25 Jan 2024 16:48:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1706197695; bh=W1Z5z7CyCm6OJIhlRbgJ7qn8gVztgK3gJEzxblTd6J0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OZiRQtwqP73QFH7tCmGmTedDWV1o1yIGO/87wKQ3AgVVk2nCEmP8YoZURugOc0zTa b1+Y+pItMc1UrCvsmQd5mcp1AcyfT/FW6Z12Mf5LKzCjVeI9VNvhOkInPCZ1xJzXeD PZTdq7DD3jacYG180ySdXqbm9iSs1ZgHB/WqhXjs= 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 4/4] media: i2c: imx335: Add support for test pattern generator Date: Thu, 25 Jan 2024 21:19:08 +0530 Message-ID: <20240125154908.465191-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240125154908.465191-1-umang.jain@ideasonboard.com> References: <20240125154908.465191-1-umang.jain@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789078177399107304 X-GMAIL-MSGID: 1789078177399107304 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 | 99 +++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index e64ee99cbae4..f9a2337a80c0 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 { }; +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}, @@ -505,6 +552,46 @@ 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 @@ -558,6 +645,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); @@ -1122,7 +1213,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; @@ -1156,6 +1247,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,