Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nihal Kumar Gupta" <nihal.gupta@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	media-ci@linuxtv.org
Subject: Re: [PATCH v6 2/3] media: qcom: camss: csid: Scale the clocks with the CSI-2 link rate
Date: Thu, 03 Dec 2026 08:39:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-247364@kernel.org> (raw)
In-Reply-To: <20261203-hawi-camss-v6-2-6a30cc09a064@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] media: qcom: camss: leaf-branch votes fail to protect shared
  cphy_rx RCG
- [Medium] media: qcom: camss: csid_cap_clock_level() is a no-op for
  known link rates
- [Medium] media: qcom: camss: clk_set_rate_range() leaves CSID clocks
  stuck high
--

commit 4e29d22048255b4715c551cb9170cf49335975d6
Author: Loic Poulain <loic.poulain@oss.qualcomm.com>

media: qcom: camss: csid: Scale the clocks with the CSI-2 link rate

This commit scales the CSID core and CSIPHY receive clocks according to
the sensor CSI-2 link frequency across all CAMSS generations using
clk_set_rate_range(), and drops those minimum rate votes on power-off.

> diff --git a/drivers/media/platform/qcom/camss/camss-csid.c b/drivers/media/platform/qcom/camss/camss-csid.c
> index 123c097ee54bf..543ea9d05127f 100644
> --- a/drivers/media/platform/qcom/camss/camss-csid.c
> +++ b/drivers/media/platform/qcom/camss/camss-csid.c

[ ... ]

> +/* Lower a level down to max_rate, but never below what min_rate needs */
> +static int csid_cap_clock_level(struct camss_clock *clock, int level,
> +				u64 min_rate, u64 max_rate)
> +{
> +	while (level > 0 && clock->freq[level] > max_rate &&
> +	       clock->freq[level - 1] > min_rate)
> +		level--;
> +
> +	return level;
> +}

[Severity: Medium]
Is csid_cap_clock_level() a no-op for every known sensor link rate?

When min_rate is non-zero, csid_find_clock_level() returns the lowest
index where clock->freq[level] > min_rate, so clock->freq[level - 1] is
always <= min_rate.  The while loop can therefore only execute when
min_rate is 0.

Because csid_set_clock_rates() also settles core_rate before resolving
phy_rx clocks, a phy_rx clock can outrun the core clock even when a
faster core OPP exists.

For example, on SM6150 with 269.33 MHz <= min_rate < 320 MHz,
vfe0_cphy_rx steps up to 384 MHz while vfe0_csid stays at 320 MHz
despite 540 MHz being available, risking CSID backpressure or overflow.

Resolving the phy_rx clock first and selecting a core level at least as
high would keep the core clock ahead.

[ ... ]

> +		/*
> +		 * Vote for the rate as a minimum, as the clock may be shared
> +		 * with another CSID which needs it to run faster.
> +		 */
> +		ret = clk_set_rate_range(clock->clk, clock->freq[j], ULONG_MAX);
> +		if (ret < 0) {
> +			dev_err(dev, "clk set rate range failed: %d\n", ret);
> +			return ret;
>  		}
>  	}

[Severity: Medium]
Does calling clk_set_rate_range() with ULONG_MAX alone leave scaled
clocks stuck at a higher rate?

clk_set_rate_range_nolock() clamps clk->core->req_rate to [min, max],
so passing ULONG_MAX never lowers an already-higher req_rate.  On
X1E80100, tpg_set_clock_rates() leaves csid_csiphy_rx at 400 MHz after
power-off, keeping a later 300 MHz sensor stuck at 400 MHz.

Rounding and setting clock->freq[j] afterwards, as
csid_release_clock_rates() does, would lower req_rate while still
respecting higher votes on the same clock.

[ ... ]

> +static void csid_release_clock_rates(struct csid_device *csid)
> +{
> +	int i;
> +
> +	for (i = 0; i < csid->nclocks; i++) {
> +		struct camss_clock *clock = &csid->clock[i];
> +		long rate;
> +
> +		if (!clock->nfreqs || !csid_match_scaled_clock_name(clock))
> +			continue;
> +
> +		clk_drop_range(clock->clk);
> +
> +		/* Round first, so that the rate respects the other votes */
> +		rate = clk_round_rate(clock->clk, clock->freq[0]);
> +		if (rate > 0)
> +			clk_set_rate(clock->clk, rate);
> +	}
> +}

[Severity: High]
Can sibling CSID branch clocks sharing a parent RCG still underclock an
actively streaming CSID?

clk_set_rate_range() records min_rate only on the leaf clk_branch2
consumer, and clk_core_get_boundaries() aggregates votes only across
core->clks of that clock.  Because clk_branch2_ops propagates rate
changes via CLK_SET_RATE_PARENT, the shared parent RCG's min_rate stays 0.

On SM8550 and X1E80100, full CSIDs scale cam_cc_csid_csiphy_rx_clk while
lite CSIDs scale cam_cc_ife_lite_cphy_rx_clk, two distinct clk_branch2
children of cam_cc_cphy_rx_clk_src (and SM6150 has three vfe*_cphy_rx
siblings).

When a full CSID streams at 480 MHz and a lite CSID starts a slower
sensor or powers off via csid_release_clock_rates() (including on the
csid_set_power() error path), the sibling branch lowers
cam_cc_cphy_rx_clk_src underneath the active CSID.

Underclocking the receive clock below link_freq / 4 causes CSI-2 receive
FIFO overruns, dropped or corrupted frames, or stream failure during
concurrent multi-camera capture.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-hawi-camss-v6-0-6a30cc09a064@oss.qualcomm.com?part=2

  reply	other threads:[~2026-12-03  8:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  8:17 [PATCH v6 0/3] Add CAMSS support for Qualcomm Hawi and Maili Nihal Kumar Gupta
2026-12-03  8:17 ` [PATCH v6 1/3] dt-bindings: media: Add CAMSS device for " Nihal Kumar Gupta
2026-12-03  8:32   ` sashiko-bot
2026-12-03  8:17 ` [PATCH v6 2/3] media: qcom: camss: csid: Scale the clocks with the CSI-2 link rate Nihal Kumar Gupta
2026-12-03  8:39   ` sashiko-bot [this message]
2026-12-03  8:17 ` [PATCH v6 3/3] media: qcom: camss: Add support for Hawi Nihal Kumar Gupta

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=sashiko-outbox-247364@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=nihal.gupta@oss.qualcomm.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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