Linux Media Controller development
 help / color / mirror / Atom feed
From: Alexander Shiyan <eagle.alexander923@gmail.com>
To: linux-media@vger.kernel.org
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Alexander Shiyan <eagle.alexander923@gmail.com>
Subject: [PATCH] media: ccs-pll: Fix OP_SYS_DDR handling in op_sys_clk_freq_hz_sdr calculation
Date: Fri,  8 May 2026 10:56:53 +0300	[thread overview]
Message-ID: <20260508075653.1536443-1-eagle.alexander923@gmail.com> (raw)

When OP_SYS_DDR flag is set, the PLL's effective SDR-equivalent
frequency should be based on the link frequency (bitrate per lane)
without an extra factor of 2, because two bits are transferred per
clock cycle. The current code always multiplies link_freq by 2,
overestimating the effective frequency for DDR mode. This leads to
excessive VCO frequencies and PLL calculation failures for high link
frequencies.

Fix this by halving the multiplication factor when OP_SYS_DDR is set.

All further calculations (pixel_rate_csi, mul/div, sys_clk_freq_hz,
pix_clk_freq_hz) remain consistent because sys_clk_freq_hz is
additionally shifted by op_sys_ddr().

Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
 drivers/media/i2c/ccs-pll.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/ccs-pll.c b/drivers/media/i2c/ccs-pll.c
index 1605cfa5db19..788dec797259 100644
--- a/drivers/media/i2c/ccs-pll.c
+++ b/drivers/media/i2c/ccs-pll.c
@@ -801,9 +801,11 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,
 	switch (pll->bus_type) {
 	case CCS_PLL_BUS_TYPE_CSI2_DPHY:
 	case CCS_PLL_BUS_TYPE_CSI2_CPHY:
-		op_sys_clk_freq_hz_sdr = pll->link_freq * 2
+		op_sys_clk_freq_hz_sdr = pll->link_freq
 			* (pll->flags & CCS_PLL_FLAG_LANE_SPEED_MODEL ?
 			   1 : pll->csi2.lanes);
+		if (!(pll->flags & CCS_PLL_FLAG_OP_SYS_DDR))
+			op_sys_clk_freq_hz_sdr *= 2;
 		break;
 	default:
 		return -EINVAL;
-- 
2.52.0


                 reply	other threads:[~2026-05-08  7:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260508075653.1536443-1-eagle.alexander923@gmail.com \
    --to=eagle.alexander923@gmail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox