From: Thierry Reding <treding@nvidia.com>
To: admin@tsv-stahl-riesa.de
Cc: Prashant Gaikwad <pgaikwad@nvidia.com>,
Stephen Boyd <sboyd@kernel.org>,
Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
Thierry Reding <thierry.reding@kernel.org>,
Jonathan Hunter <jonathanh@nvidia.com>,
Mikko Perttunen <mperttunen@nvidia.com>,
Svyatoslav Ryhel <clamor95@gmail.com>,
Brian Masney <bmasney@redhat.com>,
linux-clk@vger.kernel.org, linux-tegra@vger.kernel.org,
linux-kernel@vger.kernel.org, stable+noautosel@kernel.org
Subject: Re: [PATCH] clk: tegra: tegra124-emc: Skip timings whose parent rate cannot be set
Date: Wed, 25 Nov 2026 11:28:40 +0100 [thread overview]
Message-ID: <awa1pk-vFb_zq75r@orome> (raw)
In-Reply-To: <20261111-upstream-clk-emc-parent-v1-1-636eea572572@tsv-stahl-riesa.de>
[-- Attachment #1: Type: text/plain, Size: 5701 bytes --]
On Wed, Nov 11, 2026 at 11:14:10AM +0100, Patrick Fischer via B4 Relay wrote:
> From: Patrick Fischer <admin@tsv-stahl-riesa.de>
>
> Each EMC timing names a parent clock and the rate that parent has to run
> at. On Tegra114, PLLM is registered with TEGRA_PLL_FIXED, so its rate
> cannot be changed, but the Tegra114 device trees still contain timings
> on pll_m at rates the bootloader did not set up, e.g. 792 MHz on a
> Tegra Note 7 where the bootloader leaves PLLM at 408 MHz.
>
> emc_set_timing() calls clk_set_rate() on the parent, which succeeds
> without changing anything, and then loads the 792 MHz timing while the
> EMC runs at 408 MHz. On the Tegra Note 7 that gives a refresh interval
> of about 15 us instead of 7.7 us (DDR3 allows 7.8 us), and the clock
> core then reports 408 MHz, so later requests for 408 MHz keep the
> 792 MHz register values.
>
> Skip timings whose parent cannot be rounded to the requested rate when
> loading them, so that the highest reachable timing is used instead.
> On Tegra124 PLLM is not fixed, so its timings should all stay; this was
> not tested on Tegra124.
>
> Fixes: cf561283254d ("clk: tegra: set up proper EMC clock implementation for Tegra114")
> Cc: stable+noautosel@kernel.org # needs the Tegra114 EMC auto-calibration fixes
> Signed-off-by: Patrick Fischer <admin@tsv-stahl-riesa.de>
> ---
> Tested on a Tegra Note 7 (Tegra114, P1640) with Svyatoslav's tegratab
> device tree on top of v7.3: both 792 MHz timings on pll_m are skipped at
> boot ("pll_m cannot run at 792000000 Hz, skipping"), the EMC goes up to
> 624 MHz on pll_c instead, and the timing registers match the table at
> each rate. Actmon requests for 792 MHz now end up at 624 MHz without
> errors; a memory test of 3 h 20 min with mostly such requests ran
> without errors, together with the EMC series below. Before, an actmon
> request for 792 MHz left the EMC at 408 MHz with the 792 MHz register
> values.
>
> This came up together with a series for the Tegra114 EMC driver,
> "memory: tegra114-emc: Fix bus width and pad auto-calibration" [1],
> which I sent to the memory controller tree earlier today. This patch
> builds without it, but please do not let it land in a release without
> "memory: tegra114-emc: Stop clearing EMC_AUTO_CAL_CONFIG" from that
> series: this patch moves the EMC from 408 MHz with the wrong register
> values to a real 624 MHz on pll_c, and both kernel panics I saw on a
> change to 624 MHz were with the pad auto-calibration cleared. For the
> same reason it is not marked for stable and asks to be left out of
> AUTOSEL, despite the Fixes tag: I could not show that the wrong register
> values cause failures, while 624 MHz without calibration did.
>
> [1] https://lore.kernel.org/r/20261111-upstream-emc-t114-v1-0-54d9e1bceb6a@tsv-stahl-riesa.de
>
> As Svyatoslav confirmed, PLLM does not have to be fixed on Tegra114, so
> the proper fix would be to make it scalable, as the downstream kernel
> does. Until then, this keeps the EMC from running with register values
> for another rate.
>
> Tool use (see Documentation/process/generated-content.rst): the patch,
> its changelog and this note were prepared with an LLM coding assistant
> (Claude Code). It traced the rate change through the EMC clock code,
> read the EMC registers on the device, wrote the code change and drafted
> the texts from my measurements and instructions. I reviewed the change
> and ran the tests on the device.
> ---
> drivers/clk/tegra/clk-tegra124-emc.c | 23 ++++++++++++++++++++---
> 1 file changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/clk/tegra/clk-tegra124-emc.c b/drivers/clk/tegra/clk-tegra124-emc.c
> index 0fc74808fe39..2f4d39922b73 100644
> --- a/drivers/clk/tegra/clk-tegra124-emc.c
> +++ b/drivers/clk/tegra/clk-tegra124-emc.c
> @@ -458,7 +458,7 @@ static int load_timings_from_dt(struct tegra_clk_emc *tegra,
> tegra->num_timings += child_count;
>
> for_each_child_of_node_scoped(node, child) {
> - struct emc_timing *timing = timings_ptr + (i++);
> + struct emc_timing *timing = timings_ptr + i;
>
> err = load_one_timing_from_dt(tegra, timing, child);
> if (err) {
> @@ -466,11 +466,28 @@ static int load_timings_from_dt(struct tegra_clk_emc *tegra,
> return err;
> }
>
> + /*
> + * The register values of a timing are only valid at its rate.
> + * If the parent cannot provide the parent rate, for example
> + * because the PLL has a fixed rate, the EMC would run at a
> + * different rate with these values. Skip such a timing.
> + */
> + if (clk_round_rate(timing->parent, timing->parent_rate) !=
> + timing->parent_rate) {
> + pr_warn("timing %pOF: %s cannot run at %lu Hz, skipping\n",
> + child, __clk_get_name(timing->parent),
> + timing->parent_rate);
> + clk_put(timing->parent);
The clk_put() here might warrant a comment because it undoes something
that load_one_timing_from_dt() does and hence it looks asymmetric. Now
that I think about it, should we perhaps move this check into the
load_one_timing_from_dt() function? It's all just dealing with that one
timing anyway, so makes sense within that function. That'd get rid of
the asymmetry, too.
> + continue;
> + }
> +
> timing->ram_code = ram_code;
> + i++;
> }
>
> - sort(timings_ptr, child_count, sizeof(struct emc_timing),
> - cmp_timings, NULL);
> + tegra->num_timings -= child_count - i;
This seems a bit weird now. should we just remove the tegra->num_timings
increment all the way above and just do:
tegra->num_timings += i;
here instead?
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2026-11-25 10:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 10:14 Patrick Fischer via B4 Relay
2026-11-24 17:18 ` Brian Masney
2026-11-25 10:28 ` Thierry Reding [this message]
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=awa1pk-vFb_zq75r@orome \
--to=treding@nvidia.com \
--cc=admin@tsv-stahl-riesa.de \
--cc=bmasney+clk@redhat.com \
--cc=bmasney@redhat.com \
--cc=clamor95@gmail.com \
--cc=jbrunet+clk@baylibre.com \
--cc=jonathanh@nvidia.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mperttunen@nvidia.com \
--cc=pgaikwad@nvidia.com \
--cc=sboyd@kernel.org \
--cc=stable+noautosel@kernel.org \
--cc=thierry.reding@kernel.org \
/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
all inboxes | Powered by JetHome®