From: Pavel Machek <pavel@nabladev.com>
To: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
Cc: cip-dev@lists.cip-project.org, pavel@nabladev.com,
nobuhiro.iwamatsu.x90@mail.toshiba
Subject: Re: [PATCH 6.12.y-cip v3 10/17] spi: rzv2h-rspi: make transfer clock rate finding chip-specific
Date: Fri, 13 Mar 2026 11:25:15 +0100 [thread overview]
Message-ID: <abPmC/HquWcaDtom@duo.ucw.cz> (raw)
In-Reply-To: <20260309150619.761962-11-cosmin-gabriel.tanislav.xa@renesas.com>
[-- Attachment #1: Type: text/plain, Size: 1900 bytes --]
Hi!
> commit 77d931584dd38916b66c65320c80a65cbef4b122 upstream.
>
> The Renesas RZ/T2H (R9A09G077) and RZ/N2H (R9A09G087) SoCs have a more
> complicated clocking setup for the SPI transfer clock than RZ/V2H, as
> the clock from which it is generated supports multiple dividers.
>
> To prepare for adding support for these SoCs, split out the logic for
> finding the SPR and BRDV for a fixed clock into
> rzv2h_rspi_find_rate_fixed(), and add and use a .find_tclk_rate()
> callback into the chip-specific structure.
> @@ -255,21 +270,49 @@ static u32 rzv2h_rspi_setup_clock(struct rzv2h_rspi_priv *rspi, u32 hz)
> * * n = SPR - is RSPI_SPBR.SPR (from 0 to 255)
> * * N = BRDV - is RSPI_SPCMD.BRDV (from 0 to 3)
> */
> - tclk_rate = clk_get_rate(rspi->tclk);
> + clk_rate = clk_get_rate(clk);
> for (brdv = RSPI_SPCMD_BRDV_MIN; brdv <= RSPI_SPCMD_BRDV_MAX; brdv++) {
> - spr = DIV_ROUND_UP(tclk_rate, hz * (1 << (brdv + 1)));
> + spr = DIV_ROUND_UP(clk_rate, hz * (1 << (brdv + 1)));
> spr--;
> - if (spr >= RSPI_SPBR_SPR_MIN && spr <= RSPI_SPBR_SPR_MAX)
> + if (spr >= spr_min && spr <= spr_max)
> goto clock_found;
> }
>
> - return 0;
> + return;
>
> clock_found:
> - rspi->spr = spr;
> - rspi->brdv = brdv;
> + actual_hz = rzv2h_rspi_calc_bitrate(clk_rate, spr, brdv);
> + error = abs((long)hz - (long)actual_hz);
>
> - return rzv2h_rspi_calc_bitrate(tclk_rate, spr, brdv);
> + if (error >= best->error)
> + return;
> +
> + *best = (struct rzv2h_rspi_best_clock) {
> + .clk = clk,
> + .clk_rate = clk_rate,
> + .error = error,
> + .actual_hz = actual_hz,
> + .brdv = brdv,
> + .spr = spr,
> + };
> +}
This is really quite strange code... looks like Rust more than C.
Filling clk, error, actual_hz, .... into temporary variable and then
just assiging it may be better.
Best regards,
Pavel
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next prev parent reply other threads:[~2026-03-13 10:25 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 15:06 [PATCH 6.12.y-cip v3 00/17] Add RSPI support for RZ/T2H and RZ/N2H Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 01/17] spi: dt-bindings: Document the RZ/V2H(P) RSPI Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 02/17] spi: Add driver for the RZ/V2H(P) RSPI IP Cosmin Tanislav
2026-03-13 10:17 ` [cip-dev] " Pavel Machek
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 03/17] arm64: defconfig: Enable the RZ/V2H(P) RSPI driver Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 04/17] clk: renesas: r9a09g077: Add SPI module clocks Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 05/17] spi: rzv2h-rspi: make resets optional Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 06/17] spi: rzv2h-rspi: make FIFO size chip-specific Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 07/17] spi: rzv2h-rspi: make clocks chip-specific Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 08/17] spi: rzv2h-rspi: move register writes out of rzv2h_rspi_setup_clock() Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 09/17] spi: rzv2h-rspi: avoid recomputing transfer frequency Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 10/17] spi: rzv2h-rspi: make transfer clock rate finding chip-specific Cosmin Tanislav
2026-03-13 10:25 ` Pavel Machek [this message]
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 11/17] spi: rzv2h-rspi: add support for using PCLK for transfer clock Cosmin Tanislav
2026-03-12 3:22 ` nobuhiro.iwamatsu.x90
2026-03-12 7:56 ` Cosmin-Gabriel Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 12/17] spi: rzv2h-rspi: add support for variable " Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 13/17] spi: rzv2h-rspi: add support for loopback mode Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 14/17] spi: rzv2h-rspi: add support for RZ/T2H and RZ/N2H Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 15/17] spi: dt-bindings: renesas,rzv2h-rspi: document " Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 16/17] arm64: dts: renesas: r9a09g077: Add SPI nodes Cosmin Tanislav
2026-03-09 15:06 ` [PATCH 6.12.y-cip v3 17/17] arm64: dts: renesas: r9a09g087: " Cosmin Tanislav
2026-03-12 3:28 ` [PATCH 6.12.y-cip v3 00/17] Add RSPI support for RZ/T2H and RZ/N2H nobuhiro.iwamatsu.x90
2026-03-13 10:31 ` [cip-dev] " Pavel Machek
2026-03-18 5:31 ` nobuhiro.iwamatsu.x90
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=abPmC/HquWcaDtom@duo.ucw.cz \
--to=pavel@nabladev.com \
--cc=cip-dev@lists.cip-project.org \
--cc=cosmin-gabriel.tanislav.xa@renesas.com \
--cc=nobuhiro.iwamatsu.x90@mail.toshiba \
/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