From patchwork Thu Jan 9 11:17:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 13932417 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 6C9DAC2FB for ; Thu, 9 Jan 2025 11:17:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736421429; cv=none; b=DSjiEZNdmb/f6z9YVq/mfwnkPQ+XhUFXvm3jy4mwdCFgD7DlCtYDbKMEByZ7V0FZl2lDAFdZd2wgjDC9a9qMoiVWbgvq2U1ltXWjPBkOsBADdODvPhussXCbtHZ2ATLR5B9fG8/yXuP3bseKD6QCh4bBVIDQmIJZ1TQ9KTmjJ1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736421429; c=relaxed/simple; bh=P5rmfT+DUSR4asm5Gjw6aql5IBSI7KzjoYlfc6YPovA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cOBr/X99gjHIjC4XGW3wQ8l4aBDlPhK+/8ApBrsuwu9cgeSqNJm667W9Y+bunq44zZfenCds3Hj3bSt81ebau3pDR2s4Led86NsTzTo41BRYThAoWpiXJjkeqWHOfKZ/AECPmZisLTjca8XiJcXADtKewUQfBAyaHfBtBY2it08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=kyGl3OGS; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="kyGl3OGS" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-436a03197b2so5938995e9.2 for ; Thu, 09 Jan 2025 03:17:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1736421426; x=1737026226; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QDdoRqFWp8CVeTiidXm9/TF+voRsLtSMvxR1TwzmO9M=; b=kyGl3OGSTYIQkMnYLN/OtEiMUhQXedLbMN7M60RnxwSmsGvvU9aq6KtqvhHx2mj1LJ 4cIpT2NoW3XyFsmO3xYBSZTOAkhsrQCTMO6sddQjMsQ91ZTvXnyHNyPnR6O0it2+CDmo QI223svogXQS2A+VXAOr2dapWuDEsT4IsIlNFITVPh8+FJ/wo3eIkH2oi4BnLQAws3bN 2FISrApUtH3lmwEI+HhoMhjskANX6CREqPGeNTb8MxKS2xAz4hq5F4/MTjUY9RrMr87p GHu8h/3OiW61lCtr4TUIipoxeQBdL1Waalh29Xvsjs6LpZao2kav/CtNyiuUqJVP123c KEvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736421426; x=1737026226; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QDdoRqFWp8CVeTiidXm9/TF+voRsLtSMvxR1TwzmO9M=; b=OSSYJULl/9JtZ9qsjmwDKeI2jjBCdXE648OOcGmCoRg0Hb3EToPGL7CGc9lGDahbT6 Pv36D25hJvf241TKu3Dekt3Cb19KcFhAZ2aYLVhz7EsYYmmkoHXnCkoQjHNr7Ol+Nkun sk9BG+WW+zMc6zr9HAy8arLwCS/3oIiMyq8F05QUHQRwOcPx6zHT8anNcE41JvXqXGXD 02dMYtiWilo/vxzWHi9DOz/BjEt4ceDSTMmULyD7jPRbND36cLJZ6NVs+ONmZrjncLtl uSgRQWzV+KPypfmXuuqifqAVFIfPAvbTh2dzOYF5aD9+wKV3/iLLtuF6tRtdo8tWTouX L6NA== X-Gm-Message-State: AOJu0Yy1tQCOh1kJudQgzaP+JMNGrZM2ah1CNZra3nEOiN2lPepGopcM J/dMZ76EZlLd5hK0e3DvIiVRmLWA1tEn0t2ioPE61f8lF6yjvQdRPYgeAuSc+mE8804EzEuVYT4 o X-Gm-Gg: ASbGncs49c0aOEMeJ2UHkIafNqVzVpwEQMCoQqDmll0DV4sH+d7tiik0Ap7PP7epvBg eqMuOEK7Gsi3aSyDZ7IfRO+oDeMUTktsxtC3WJ19ZganvldGIGfPc2K0oNMsauBf682pgtLKz4g 1g+8y+JQsbhPw+2iuPLeefvFUVmQCtb56uHqIaQsqg38o8F6BC1GraAXLcy5tbeFKRuHLldo7VR 3EE3j+TuAO2TyaDcEVphCiOVqNdzepVSeZ3lYa1NeX3ItRb X-Google-Smtp-Source: AGHT+IGxW9l3fSCerDGzK3rf7x9nD9OspcRLe2JZVa23n7iAsWmXbz7f5JIE0MjVjI6CztxS9Y/A1w== X-Received: by 2002:a5d:584d:0:b0:386:4a16:dad7 with SMTP id ffacd0b85a97d-38a872d2a33mr6039436f8f.10.1736421425737; Thu, 09 Jan 2025 03:17:05 -0800 (PST) Received: from [127.0.1.1] ([2a00:1098:3142:e::8]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-436e2dc0bb7sm51383635e9.16.2025.01.09.03.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 03:17:05 -0800 (PST) From: Dave Stevenson Date: Thu, 09 Jan 2025 11:17:00 +0000 Subject: [PATCH 1/3] media: i2c: imx415: Add read/write control of VBLANK Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-media-imx415-v1-1-366ba6a234ab@raspberrypi.com> References: <20250109-media-imx415-v1-0-366ba6a234ab@raspberrypi.com> In-Reply-To: <20250109-media-imx415-v1-0-366ba6a234ab@raspberrypi.com> To: Sakari Ailus , Michael Riesch , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Dave Stevenson X-Mailer: b4 0.14.1 This also requires that the ranges for the exposure control are updated. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx415.c | 51 ++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/drivers/media/i2c/imx415.c b/drivers/media/i2c/imx415.c index 3f7924aa1bd3..2c8c0905aa99 100644 --- a/drivers/media/i2c/imx415.c +++ b/drivers/media/i2c/imx415.c @@ -26,6 +26,7 @@ #define IMX415_PIXEL_ARRAY_WIDTH 3864 #define IMX415_PIXEL_ARRAY_HEIGHT 2192 #define IMX415_PIXEL_ARRAY_VBLANK 58 +#define IMX415_EXPOSURE_OFFSET 8 #define IMX415_NUM_CLK_PARAM_REGS 11 @@ -51,6 +52,7 @@ #define IMX415_OUTSEL CCI_REG8(0x30c0) #define IMX415_DRV CCI_REG8(0x30c1) #define IMX415_VMAX CCI_REG24_LE(0x3024) +#define IMX415_VMAX_MAX 0xfffff #define IMX415_HMAX CCI_REG16_LE(0x3028) #define IMX415_SHR0 CCI_REG24_LE(0x3050) #define IMX415_GAIN_PCG_0 CCI_REG16_LE(0x3090) @@ -447,7 +449,6 @@ static const struct imx415_clk_params imx415_clk_params[] = { /* all-pixel 2-lane 720 Mbps 15.74 Hz mode */ static const struct cci_reg_sequence imx415_mode_2_720[] = { - { IMX415_VMAX, 0x08CA }, { IMX415_HMAX, 0x07F0 }, { IMX415_LANEMODE, IMX415_LANEMODE_2 }, { IMX415_TCLKPOST, 0x006F }, @@ -463,7 +464,6 @@ static const struct cci_reg_sequence imx415_mode_2_720[] = { /* all-pixel 2-lane 1440 Mbps 30.01 Hz mode */ static const struct cci_reg_sequence imx415_mode_2_1440[] = { - { IMX415_VMAX, 0x08CA }, { IMX415_HMAX, 0x042A }, { IMX415_LANEMODE, IMX415_LANEMODE_2 }, { IMX415_TCLKPOST, 0x009F }, @@ -479,7 +479,6 @@ static const struct cci_reg_sequence imx415_mode_2_1440[] = { /* all-pixel 4-lane 891 Mbps 30 Hz mode */ static const struct cci_reg_sequence imx415_mode_4_891[] = { - { IMX415_VMAX, 0x08CA }, { IMX415_HMAX, 0x044C }, { IMX415_LANEMODE, IMX415_LANEMODE_4 }, { IMX415_TCLKPOST, 0x007F }, @@ -600,6 +599,7 @@ struct imx415 { struct v4l2_ctrl *vblank; struct v4l2_ctrl *hflip; struct v4l2_ctrl *vflip; + struct v4l2_ctrl *exposure; unsigned int cur_mode; unsigned int num_data_lanes; @@ -730,17 +730,37 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl) ctrls); const struct v4l2_mbus_framefmt *format; struct v4l2_subdev_state *state; + u32 exposure_max; unsigned int vmax; unsigned int flip; int ret; - if (!pm_runtime_get_if_in_use(sensor->dev)) - return 0; - state = v4l2_subdev_get_locked_active_state(&sensor->subdev); format = v4l2_subdev_state_get_format(state, 0); + if (ctrl->id == V4L2_CID_VBLANK) { + exposure_max = format->height + ctrl->val - + IMX415_EXPOSURE_OFFSET; + __v4l2_ctrl_modify_range(sensor->exposure, + sensor->exposure->minimum, + exposure_max, sensor->exposure->step, + sensor->exposure->default_value); + } + + if (!pm_runtime_get_if_in_use(sensor->dev)) + return 0; + switch (ctrl->id) { + case V4L2_CID_VBLANK: + ret = cci_write(sensor->regmap, IMX415_VMAX, + format->height + ctrl->val, NULL); + if (ret) + return ret; + /* + * Deliberately fall through as exposure is set based on VMAX + * which has just changed. + */ + fallthrough; case V4L2_CID_EXPOSURE: /* clamp the exposure value to VMAX. */ vmax = format->height + sensor->vblank->cur.val; @@ -787,7 +807,8 @@ static int imx415_ctrls_init(struct imx415 *sensor) u64 pixel_rate = supported_modes[sensor->cur_mode].pixel_rate; u64 lane_rate = supported_modes[sensor->cur_mode].lane_rate; u32 exposure_max = IMX415_PIXEL_ARRAY_HEIGHT + - IMX415_PIXEL_ARRAY_VBLANK - 8; + IMX415_PIXEL_ARRAY_VBLANK - + IMX415_EXPOSURE_OFFSET; u32 hblank; unsigned int i; int ret; @@ -816,8 +837,9 @@ static int imx415_ctrls_init(struct imx415 *sensor) if (ctrl) ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; - v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, V4L2_CID_EXPOSURE, - 4, exposure_max, 1, exposure_max); + sensor->exposure = v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, + V4L2_CID_EXPOSURE, 4, + exposure_max, 1, exposure_max); v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, V4L2_CID_ANALOGUE_GAIN, IMX415_AGAIN_MIN, @@ -834,16 +856,9 @@ static int imx415_ctrls_init(struct imx415 *sensor) sensor->vblank = v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, V4L2_CID_VBLANK, IMX415_PIXEL_ARRAY_VBLANK, - IMX415_PIXEL_ARRAY_VBLANK, 1, - IMX415_PIXEL_ARRAY_VBLANK); - if (sensor->vblank) - sensor->vblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; + IMX415_VMAX_MAX - IMX415_PIXEL_ARRAY_HEIGHT, + 1, IMX415_PIXEL_ARRAY_VBLANK); - /* - * The pixel rate used here is a virtual value and can be used for - * calculating the frame rate together with hblank. It may not - * necessarily be the physically correct pixel clock. - */ v4l2_ctrl_new_std(&sensor->ctrls, NULL, V4L2_CID_PIXEL_RATE, pixel_rate, pixel_rate, 1, pixel_rate); From patchwork Thu Jan 9 11:17:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 13932419 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 23E3721638D for ; Thu, 9 Jan 2025 11:17:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736421430; cv=none; b=qLLFDuZp3H7lYXpufJXZ6BlOdwanuKdNHfWCt+Jnzun2hHAmjNJCDD/MIG/rDTKz+U9HaUnZN270PplPdHH7QKiJ1iJXdBXq+CeNAq9orPBeK6/S8u4W6IykqL7vZHcLO1tUjD5WnljgIci9gIypq1adJQ8OXlMOIP2UAHTTRts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736421430; c=relaxed/simple; bh=2SVlAKy9ycVKrxI/OiosWqeUtu66MzqT8puLexKAmtA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FAUGCWWLNMM3h+IXP6N4Ld3ypqaAks2XcUsKeeteiG/PPw/u+9TbA03NhdLIO5evnpxrPa21GkLKCe569cAuakREaI1UlnJWQdV2uowUAzq9hNpTmux1any/Sw0Qc4KDiugx3w2oexKy75Ta+3hpm2woM22LXsYkmjwtIA8UDMo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=k/6imb7L; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="k/6imb7L" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-385e3621518so434593f8f.1 for ; Thu, 09 Jan 2025 03:17:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1736421426; x=1737026226; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=pj9OsK0gjG/VTlu5wLrvObt5Ggsq7mHWz27kkYt3hmc=; b=k/6imb7LqfzekWvix/vaEKWGTVxqlz5iAOsxIlexZCcUKuk4HxI2QoDol0fo4aQLTp 6QGlE0C9zzzB7VVTOWe7o/4bI6SNPfcXJzQVeRMcOFUU5F6IzOJb9K2H3KAgSopjj1Bb qE2tl0VMd3TaLZ78MhnEg3wjIUjoB4WEbntNppduHCzC+iNI3bw/0szSSyV3HhhjDk/s e7xBWpGhtC8C5jGFe1uVkc1sqU3ZzlUPbpTHtqRhkxxUzSUtAmzmD6f2pFln0Py0XTyL 7s95rILHiAcWmgmkkPXOBwzAMGJPwj7PyMx8ISgwtkwcfISJJ9nTDXzIshi6PLdhf7mc rlMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736421426; x=1737026226; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pj9OsK0gjG/VTlu5wLrvObt5Ggsq7mHWz27kkYt3hmc=; b=UcoDGtKUi62gELSQG/G9rQVAtHYRsnOlGQc1b1JCHZhiQNRZg+HdYmCOfuTIOuNmB6 TR2gWQ6uaswp/fVc0ws54i/uJOyTBpLdPqopkXjrIyfbrUqIvrvrQywz4uj14xfKt+QF jGxjX46zJPRsQJUIQnwor6SgBGk5HcvLpp8arJo8ziN6G9LvuBfgce6Ypy3D9B46H3x1 ZL9E3FpU/sLAnnw82BDmrNXJWwrDnaO2TcIsle6svjKsg0vpmQf/LGX09/PBKoV3426Q BNGd+e8tpcdTrs50oqCNLqBoSDnH+3mXWU7wkuNp82FtHocIkfu6Auk2gFqXPZ67Ltxy SGSg== X-Gm-Message-State: AOJu0YxsjaPVr9IJpLo0+4HJaO4HQrj2p+La4VeX825SH9JiaJGUW2HL ebk5FVEmRbUaPoXWt7526ohehH2WG+Ybc1xwdkdlaaF2d0u36zCehMp732rv3JjtbntKazsrHdm K X-Gm-Gg: ASbGnctXXO5f5K9aV3CH39RZxJa9Qlp2Lo6/xZa/zY9xzUL+2FOFBMKzHddwwSTPB8s uHD7CMkaCaJ0ARXzOFC3u4rgCTl1Wu2079i7bq4f0RYGDieLfKKrXSIDZEumd57gCZpE8FoIIIY DDtu7K32ihTsq9L7RgD3TCP3cOccZcxGeDUjhapUtRYGlqYJQQpRxYtGb078nkgblhPiGcMKUQe E+uSKzBotTi7/viYDwNUKcUV09lGqUAW/hdsZp61hIvcnHg X-Google-Smtp-Source: AGHT+IHcYceMEWIHrOmEnsg9w5rQz45ovuijkrOlL7eWQJzaZvrM+EccGEDkpkyfT8xcwmPZD8aAZw== X-Received: by 2002:a5d:6d82:0:b0:385:fb59:8358 with SMTP id ffacd0b85a97d-38a87358c39mr5153473f8f.53.1736421426425; Thu, 09 Jan 2025 03:17:06 -0800 (PST) Received: from [127.0.1.1] ([2a00:1098:3142:e::8]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-436e2dc0bb7sm51383635e9.16.2025.01.09.03.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 03:17:06 -0800 (PST) From: Dave Stevenson Date: Thu, 09 Jan 2025 11:17:01 +0000 Subject: [PATCH 2/3] media: i2c: imx415: Make HBLANK controllable and in consistent units Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-media-imx415-v1-2-366ba6a234ab@raspberrypi.com> References: <20250109-media-imx415-v1-0-366ba6a234ab@raspberrypi.com> In-Reply-To: <20250109-media-imx415-v1-0-366ba6a234ab@raspberrypi.com> To: Sakari Ailus , Michael Riesch , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Dave Stevenson X-Mailer: b4 0.14.1 The control of HMAX documented in the datasheet is consistent with being in terms of a scaled INCK, being always 72MHz or 74.25MHz. It is NOT link frequency dependent, but the minimum value for HMAX is dictated by the link frequency. If PIXEL_RATE is defined as being 12 times the 72 or 74.25MHz, and all values are scaled down again when writing HMAX, then the numbers all work out regardless of INCK or link frequency. Retain an hmax_min (set to the same value as the previous fixed hmax register value) to set as the default value to avoid changing the behaviour for existing users. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx415.c | 87 +++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/drivers/media/i2c/imx415.c b/drivers/media/i2c/imx415.c index 2c8c0905aa99..e23b41027987 100644 --- a/drivers/media/i2c/imx415.c +++ b/drivers/media/i2c/imx415.c @@ -28,6 +28,9 @@ #define IMX415_PIXEL_ARRAY_VBLANK 58 #define IMX415_EXPOSURE_OFFSET 8 +#define IMX415_PIXEL_RATE_74_25MHZ 891000000 +#define IMX415_PIXEL_RATE_72MHZ 864000000 + #define IMX415_NUM_CLK_PARAM_REGS 11 #define IMX415_MODE CCI_REG8(0x3000) @@ -54,6 +57,8 @@ #define IMX415_VMAX CCI_REG24_LE(0x3024) #define IMX415_VMAX_MAX 0xfffff #define IMX415_HMAX CCI_REG16_LE(0x3028) +#define IMX415_HMAX_MAX 0xffff +#define IMX415_HMAX_MULTIPLIER 12 #define IMX415_SHR0 CCI_REG24_LE(0x3050) #define IMX415_GAIN_PCG_0 CCI_REG16_LE(0x3090) #define IMX415_AGAIN_MIN 0 @@ -449,7 +454,6 @@ static const struct imx415_clk_params imx415_clk_params[] = { /* all-pixel 2-lane 720 Mbps 15.74 Hz mode */ static const struct cci_reg_sequence imx415_mode_2_720[] = { - { IMX415_HMAX, 0x07F0 }, { IMX415_LANEMODE, IMX415_LANEMODE_2 }, { IMX415_TCLKPOST, 0x006F }, { IMX415_TCLKPREPARE, 0x002F }, @@ -464,7 +468,6 @@ static const struct cci_reg_sequence imx415_mode_2_720[] = { /* all-pixel 2-lane 1440 Mbps 30.01 Hz mode */ static const struct cci_reg_sequence imx415_mode_2_1440[] = { - { IMX415_HMAX, 0x042A }, { IMX415_LANEMODE, IMX415_LANEMODE_2 }, { IMX415_TCLKPOST, 0x009F }, { IMX415_TCLKPREPARE, 0x0057 }, @@ -479,7 +482,6 @@ static const struct cci_reg_sequence imx415_mode_2_1440[] = { /* all-pixel 4-lane 891 Mbps 30 Hz mode */ static const struct cci_reg_sequence imx415_mode_4_891[] = { - { IMX415_HMAX, 0x044C }, { IMX415_LANEMODE, IMX415_LANEMODE_4 }, { IMX415_TCLKPOST, 0x007F }, { IMX415_TCLKPREPARE, 0x0037 }, @@ -497,39 +499,10 @@ struct imx415_mode_reg_list { const struct cci_reg_sequence *regs; }; -/* - * Mode : number of lanes, lane rate and frame rate dependent settings - * - * pixel_rate and hmax_pix are needed to calculate hblank for the v4l2 ctrl - * interface. These values can not be found in the data sheet and should be - * treated as virtual values. Use following table when adding new modes. - * - * lane_rate lanes fps hmax_pix pixel_rate - * - * 594 2 10.000 4400 99000000 - * 891 2 15.000 4400 148500000 - * 720 2 15.748 4064 144000000 - * 1782 2 30.000 4400 297000000 - * 2079 2 30.000 4400 297000000 - * 1440 2 30.019 4510 304615385 - * - * 594 4 20.000 5500 247500000 - * 594 4 25.000 4400 247500000 - * 720 4 25.000 4400 247500000 - * 720 4 30.019 4510 304615385 - * 891 4 30.000 4400 297000000 - * 1440 4 30.019 4510 304615385 - * 1440 4 60.038 4510 609230769 - * 1485 4 60.000 4400 594000000 - * 1782 4 60.000 4400 594000000 - * 2079 4 60.000 4400 594000000 - * 2376 4 90.164 4392 891000000 - */ struct imx415_mode { u64 lane_rate; u32 lanes; - u32 hmax_pix; - u64 pixel_rate; + u32 hmax_min; struct imx415_mode_reg_list reg_list; }; @@ -538,8 +511,7 @@ static const struct imx415_mode supported_modes[] = { { .lane_rate = 720000000, .lanes = 2, - .hmax_pix = 4064, - .pixel_rate = 144000000, + .hmax_min = 2032, .reg_list = { .num_of_regs = ARRAY_SIZE(imx415_mode_2_720), .regs = imx415_mode_2_720, @@ -548,8 +520,7 @@ static const struct imx415_mode supported_modes[] = { { .lane_rate = 1440000000, .lanes = 2, - .hmax_pix = 4510, - .pixel_rate = 304615385, + .hmax_min = 1066, .reg_list = { .num_of_regs = ARRAY_SIZE(imx415_mode_2_1440), .regs = imx415_mode_2_1440, @@ -558,8 +529,7 @@ static const struct imx415_mode supported_modes[] = { { .lane_rate = 891000000, .lanes = 4, - .hmax_pix = 4400, - .pixel_rate = 297000000, + .hmax_min = 1100, .reg_list = { .num_of_regs = ARRAY_SIZE(imx415_mode_4_891), .regs = imx415_mode_4_891, @@ -586,6 +556,7 @@ static const char *const imx415_test_pattern_menu[] = { struct imx415 { struct device *dev; struct clk *clk; + unsigned long pixel_rate; struct regulator_bulk_data supplies[ARRAY_SIZE(imx415_supply_names)]; struct gpio_desc *reset; struct regmap *regmap; @@ -597,6 +568,7 @@ struct imx415 { struct v4l2_ctrl_handler ctrls; struct v4l2_ctrl *vblank; + struct v4l2_ctrl *hblank; struct v4l2_ctrl *hflip; struct v4l2_ctrl *vflip; struct v4l2_ctrl *exposure; @@ -786,6 +758,12 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl) ret = imx415_set_testpattern(sensor, ctrl->val); break; + case V4L2_CID_HBLANK: + return cci_write(sensor->regmap, IMX415_HMAX, + (format->width + ctrl->val) / + IMX415_HMAX_MULTIPLIER, + NULL); + default: ret = -EINVAL; break; @@ -804,12 +782,11 @@ static int imx415_ctrls_init(struct imx415 *sensor) { struct v4l2_fwnode_device_properties props; struct v4l2_ctrl *ctrl; - u64 pixel_rate = supported_modes[sensor->cur_mode].pixel_rate; u64 lane_rate = supported_modes[sensor->cur_mode].lane_rate; u32 exposure_max = IMX415_PIXEL_ARRAY_HEIGHT + IMX415_PIXEL_ARRAY_VBLANK - IMX415_EXPOSURE_OFFSET; - u32 hblank; + u32 hblank_min, hblank_max; unsigned int i; int ret; @@ -846,12 +823,14 @@ static int imx415_ctrls_init(struct imx415 *sensor) IMX415_AGAIN_MAX, IMX415_AGAIN_STEP, IMX415_AGAIN_MIN); - hblank = supported_modes[sensor->cur_mode].hmax_pix - - IMX415_PIXEL_ARRAY_WIDTH; + hblank_min = (supported_modes[sensor->cur_mode].hmax_min * + IMX415_HMAX_MULTIPLIER) - IMX415_PIXEL_ARRAY_WIDTH; + hblank_max = (IMX415_HMAX_MAX * IMX415_HMAX_MULTIPLIER) - + IMX415_PIXEL_ARRAY_WIDTH; ctrl = v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, - V4L2_CID_HBLANK, hblank, hblank, 1, hblank); - if (ctrl) - ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; + V4L2_CID_HBLANK, hblank_min, + hblank_max, IMX415_HMAX_MULTIPLIER, + hblank_min); sensor->vblank = v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, V4L2_CID_VBLANK, @@ -859,8 +838,9 @@ static int imx415_ctrls_init(struct imx415 *sensor) IMX415_VMAX_MAX - IMX415_PIXEL_ARRAY_HEIGHT, 1, IMX415_PIXEL_ARRAY_VBLANK); - v4l2_ctrl_new_std(&sensor->ctrls, NULL, V4L2_CID_PIXEL_RATE, pixel_rate, - pixel_rate, 1, pixel_rate); + v4l2_ctrl_new_std(&sensor->ctrls, NULL, V4L2_CID_PIXEL_RATE, + sensor->pixel_rate, sensor->pixel_rate, 1, + sensor->pixel_rate); sensor->hflip = v4l2_ctrl_new_std(&sensor->ctrls, &imx415_ctrl_ops, V4L2_CID_HFLIP, 0, 1, 1, 0); @@ -1332,6 +1312,17 @@ static int imx415_parse_hw_config(struct imx415 *sensor) "no valid sensor mode defined\n"); goto done_endpoint_free; } + switch (inck) { + case 27000000: + case 37125000: + case 74250000: + sensor->pixel_rate = IMX415_PIXEL_RATE_74_25MHZ; + break; + case 24000000: + case 72000000: + sensor->pixel_rate = IMX415_PIXEL_RATE_72MHZ; + break; + } lane_rate = supported_modes[sensor->cur_mode].lane_rate; for (i = 0; i < ARRAY_SIZE(imx415_clk_params); ++i) { From patchwork Thu Jan 9 11:17:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 13932420 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.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 5BAC72165F7 for ; Thu, 9 Jan 2025 11:17:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736421431; cv=none; b=iS1SNwa1kys8VCJvB4lgYkuPfd1r1lFgQg1hVqVxYphDMjTtJt5mKkGT+0p0JPnX9VIsimIt4LeV81l5J0LjwHT/yWk0H3j7nQ2UkFskgblyKg4gyOb/zW3U2ABt7IqR7oYpCKhkoKPatSbHI88ulTey5seMCj1qwoy7KxIH8Hk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736421431; c=relaxed/simple; bh=xthAa1cQTtOTVbLk7Tq3zBebO5O/vfenPLhC6pmLsM4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aDJ0yFqa3Td+GGjQL/bVcs8SPzMhmhA3I8WMY1rsPI2rZN/rWEorN0oGiGWW8MUoUltr/86sRo4SwXYCyUSP1ZxytNw3SZl6xMzo/pwpD1MxhMRyJUwHRknWRG0wAgrHYGzV93zIgh5GZjhCyyYAAqf9sposUuBoYRpGkfQG9iI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=dLe+fCjL; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="dLe+fCjL" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4361815b96cso6004755e9.1 for ; Thu, 09 Jan 2025 03:17:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1736421428; x=1737026228; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ENKXg0WVMIM6tIrW1zc4FaXBY9LbCyw/evnc79n5e0k=; b=dLe+fCjLLCuBvozJZ8XjOV3Tu39MIQoP2lCUrtk92MJrzNSCHnqDSbCfv0Ztovq1ou 7f1zg9SCu/naLFqW5mBk/BaxHV1Sj+xI7RbQiMISnz/m4IOCJN2mJfxQkj0i1tUa3pAu ENy1mYFRqFKgw49yGxPv55EDYdg3HT5Jciuclk1dFpix+LcY4b/Y5G5kdPLEn3NjsKku 89goOxJvkVI+OvVMuUN211BqKchrVWF0vtlqXoBbJ8IbTKnpSMrwCSsGyeh7qtF7zIOj e+Sp86g3vlTeu+3pnRNZm8UQYEDJ5Pu9/hHSDbxwmBVETuMrbpKGyIg/I+UJVqJpQr7W K5qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736421428; x=1737026228; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ENKXg0WVMIM6tIrW1zc4FaXBY9LbCyw/evnc79n5e0k=; b=eFLq3mS3hmx/Hp29BolcXgT6mNZVQ3PpcDefetVq03gkubwDX9DTCji2nQU2usgrds mNgm3vNRNVtpSk52KY5/UJa2o4aISoIOlv8jhGy8Lo9UqLj5q5vj78eb/7IYMITzDRVK 7hCgSpzxcxv7KPJfUl6c1jqeRTL+w6nvydOQSjP3H9rIorTKS2HAtDDcIKuS+6RmmqtE g6j4PzPgi7CI63gqKZ6XBQAmaGjLOYpo26LFG3PRFEA5Uaqv+bhsJI5WwMySUi/fEZ9O ZDtjXW5t+nPFDH+GZdirIpgKdvulWi6VXwkYD4walam5wHCf4c2kAwapCCn7AWvxL99o Yonw== X-Gm-Message-State: AOJu0YwoYvahG8C1nwvoSkcDnlFufpMYDgv9UzPjI2rB9MAvqN7H/l97 jSwpQe7+FPVUN0E0aK0E+HCRG14TABB/vnfV6I+jtxTs4c+zDjhcvdabuXgzX3T1YKaXuq04Xh2 w X-Gm-Gg: ASbGncvsfjE5axfUK6/yxh+bwkFBtGEL58uIwPyw8Pggm2bnRv99a3b3lbHypohdac0 PJQU4zcUOfiRBs/RtDi2gohacwXgl+GAp0ud+8oF49J9KkvInO/tHUgL3xVA77UaiueJ1Irs2Nm qjOWrf/hbn7/Ff6+kJVosSn1qN8sS4+DN8hKaMjAhwxy1hDwTGlpFOi3vCZgXmC4CftixG5xP0V VvM6l1bbpUl5y81IrKqcOXCaWwM7Iox0sckceTRN3sgvMph X-Google-Smtp-Source: AGHT+IEG6RDcQzUUAmt24CybgylRmmcezNzdtUB8E8rnoCU+2bOcaekT9eUJt1BxsyPj/AuO1ssEzg== X-Received: by 2002:a05:600c:1d9c:b0:436:1af4:5e07 with SMTP id 5b1f17b1804b1-436e2696d35mr51753455e9.1.1736421427705; Thu, 09 Jan 2025 03:17:07 -0800 (PST) Received: from [127.0.1.1] ([2a00:1098:3142:e::8]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-436e2dc0bb7sm51383635e9.16.2025.01.09.03.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 03:17:07 -0800 (PST) From: Dave Stevenson Date: Thu, 09 Jan 2025 11:17:02 +0000 Subject: [PATCH 3/3] media: i2c: imx415: Link frequencies are not exclusive to num lanes Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-media-imx415-v1-3-366ba6a234ab@raspberrypi.com> References: <20250109-media-imx415-v1-0-366ba6a234ab@raspberrypi.com> In-Reply-To: <20250109-media-imx415-v1-0-366ba6a234ab@raspberrypi.com> To: Sakari Ailus , Michael Riesch , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Dave Stevenson X-Mailer: b4 0.14.1 The link frequencies are equally valid in 2 or 4 lane modes, but they change the hmax_min value for the mode as the MIPI block has to have sufficient time to send the pixel data for each line. Remove the association with number of lanes, and add hmax_min configuration for both lane options. Signed-off-by: Dave Stevenson --- drivers/media/i2c/imx415.c | 53 ++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/drivers/media/i2c/imx415.c b/drivers/media/i2c/imx415.c index e23b41027987..1071900416d2 100644 --- a/drivers/media/i2c/imx415.c +++ b/drivers/media/i2c/imx415.c @@ -452,9 +452,8 @@ static const struct imx415_clk_params imx415_clk_params[] = { }, }; -/* all-pixel 2-lane 720 Mbps 15.74 Hz mode */ -static const struct cci_reg_sequence imx415_mode_2_720[] = { - { IMX415_LANEMODE, IMX415_LANEMODE_2 }, +/* 720 Mbps CSI configuration */ +static const struct cci_reg_sequence imx415_linkrate_720mbps[] = { { IMX415_TCLKPOST, 0x006F }, { IMX415_TCLKPREPARE, 0x002F }, { IMX415_TCLKTRAIL, 0x002F }, @@ -466,9 +465,8 @@ static const struct cci_reg_sequence imx415_mode_2_720[] = { { IMX415_TLPX, 0x0027 }, }; -/* all-pixel 2-lane 1440 Mbps 30.01 Hz mode */ -static const struct cci_reg_sequence imx415_mode_2_1440[] = { - { IMX415_LANEMODE, IMX415_LANEMODE_2 }, +/* 1440 Mbps CSI configuration */ +static const struct cci_reg_sequence imx415_linkrate_1440mbps[] = { { IMX415_TCLKPOST, 0x009F }, { IMX415_TCLKPREPARE, 0x0057 }, { IMX415_TCLKTRAIL, 0x0057 }, @@ -480,9 +478,8 @@ static const struct cci_reg_sequence imx415_mode_2_1440[] = { { IMX415_TLPX, 0x004F }, }; -/* all-pixel 4-lane 891 Mbps 30 Hz mode */ -static const struct cci_reg_sequence imx415_mode_4_891[] = { - { IMX415_LANEMODE, IMX415_LANEMODE_4 }, +/* 891 Mbps CSI configuration */ +static const struct cci_reg_sequence imx415_linkrate_891mbps[] = { { IMX415_TCLKPOST, 0x007F }, { IMX415_TCLKPREPARE, 0x0037 }, { IMX415_TCLKTRAIL, 0x0037 }, @@ -501,8 +498,7 @@ struct imx415_mode_reg_list { struct imx415_mode { u64 lane_rate; - u32 lanes; - u32 hmax_min; + u32 hmax_min[2]; struct imx415_mode_reg_list reg_list; }; @@ -510,29 +506,26 @@ struct imx415_mode { static const struct imx415_mode supported_modes[] = { { .lane_rate = 720000000, - .lanes = 2, - .hmax_min = 2032, + .hmax_min = { 2032, 1066 }, .reg_list = { - .num_of_regs = ARRAY_SIZE(imx415_mode_2_720), - .regs = imx415_mode_2_720, + .num_of_regs = ARRAY_SIZE(imx415_linkrate_720mbps), + .regs = imx415_linkrate_720mbps, }, }, { .lane_rate = 1440000000, - .lanes = 2, - .hmax_min = 1066, + .hmax_min = { 1066, 533 }, .reg_list = { - .num_of_regs = ARRAY_SIZE(imx415_mode_2_1440), - .regs = imx415_mode_2_1440, + .num_of_regs = ARRAY_SIZE(imx415_linkrate_1440mbps), + .regs = imx415_linkrate_1440mbps, }, }, { .lane_rate = 891000000, - .lanes = 4, - .hmax_min = 1100, + .hmax_min = { 1100, 550 }, .reg_list = { - .num_of_regs = ARRAY_SIZE(imx415_mode_4_891), - .regs = imx415_mode_4_891, + .num_of_regs = ARRAY_SIZE(imx415_linkrate_891mbps), + .regs = imx415_linkrate_891mbps, }, }, }; @@ -782,7 +775,8 @@ static int imx415_ctrls_init(struct imx415 *sensor) { struct v4l2_fwnode_device_properties props; struct v4l2_ctrl *ctrl; - u64 lane_rate = supported_modes[sensor->cur_mode].lane_rate; + const struct imx415_mode *cur_mode = &supported_modes[sensor->cur_mode]; + u64 lane_rate = cur_mode->lane_rate; u32 exposure_max = IMX415_PIXEL_ARRAY_HEIGHT + IMX415_PIXEL_ARRAY_VBLANK - IMX415_EXPOSURE_OFFSET; @@ -823,7 +817,7 @@ static int imx415_ctrls_init(struct imx415 *sensor) IMX415_AGAIN_MAX, IMX415_AGAIN_STEP, IMX415_AGAIN_MIN); - hblank_min = (supported_modes[sensor->cur_mode].hmax_min * + hblank_min = (cur_mode->hmax_min[sensor->num_data_lanes == 2 ? 0 : 1] * IMX415_HMAX_MULTIPLIER) - IMX415_PIXEL_ARRAY_WIDTH; hblank_max = (IMX415_HMAX_MAX * IMX415_HMAX_MULTIPLIER) - IMX415_PIXEL_ARRAY_WIDTH; @@ -885,7 +879,12 @@ static int imx415_set_mode(struct imx415 *sensor, int mode) IMX415_NUM_CLK_PARAM_REGS, &ret); - return 0; + ret = cci_write(sensor->regmap, IMX415_LANEMODE, + sensor->num_data_lanes == 2 ? IMX415_LANEMODE_2 : + IMX415_LANEMODE_4, + NULL); + + return ret; } static int imx415_setup(struct imx415 *sensor, struct v4l2_subdev_state *state) @@ -1296,8 +1295,6 @@ static int imx415_parse_hw_config(struct imx415 *sensor) } for (j = 0; j < ARRAY_SIZE(supported_modes); ++j) { - if (sensor->num_data_lanes != supported_modes[j].lanes) - continue; if (bus_cfg.link_frequencies[i] * 2 != supported_modes[j].lane_rate) continue;