Skip to content

Commit 9c9bf4f

Browse files
Demon000broonie
authored andcommitted
spi: rzv2h-rspi: add support for variable transfer clock
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, do the following changes. Use the minimum frequency of SPI clock to calculate the SPI controller's min_speed_hz, and the maximum frequency to calculate max_speed_hz. Apply the clock rate found by the .find_tclk_rate() to the found clock. Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com> Link: https://patch.msgid.link/20251119161434.595677-9-cosmin-gabriel.tanislav.xa@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 1ce3e8a commit 9c9bf4f

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

drivers/spi/spi-rzv2h-rspi.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ static u32 rzv2h_rspi_setup_clock(struct rzv2h_rspi_priv *rspi, u32 hz)
308308
struct rzv2h_rspi_best_clock best_clock = {
309309
.error = ULONG_MAX,
310310
};
311+
int ret;
311312

312313
rspi->info->find_tclk_rate(rspi->tclk, hz, RSPI_SPBR_SPR_MIN,
313314
RSPI_SPBR_SPR_MAX, &best_clock);
@@ -323,6 +324,10 @@ static u32 rzv2h_rspi_setup_clock(struct rzv2h_rspi_priv *rspi, u32 hz)
323324
if (!best_clock.clk_rate)
324325
return -EINVAL;
325326

327+
ret = clk_set_rate(best_clock.clk, best_clock.clk_rate);
328+
if (ret)
329+
return 0;
330+
326331
rspi->use_pclk = best_clock.clk == rspi->pclk;
327332
rspi->spr = best_clock.spr;
328333
rspi->brdv = best_clock.brdv;
@@ -426,8 +431,8 @@ static int rzv2h_rspi_probe(struct platform_device *pdev)
426431
struct device *dev = &pdev->dev;
427432
struct rzv2h_rspi_priv *rspi;
428433
struct clk_bulk_data *clks;
429-
unsigned long tclk_rate;
430434
int irq_rx, ret, i;
435+
long tclk_rate;
431436

432437
controller = devm_spi_alloc_host(dev, sizeof(*rspi));
433438
if (!controller)
@@ -460,8 +465,6 @@ static int rzv2h_rspi_probe(struct platform_device *pdev)
460465
if (!rspi->tclk)
461466
return dev_err_probe(dev, -EINVAL, "Failed to get tclk\n");
462467

463-
tclk_rate = clk_get_rate(rspi->tclk);
464-
465468
rspi->resets[0].id = "presetn";
466469
rspi->resets[1].id = "tresetn";
467470
ret = devm_reset_control_bulk_get_optional_exclusive(dev, RSPI_RESET_NUM,
@@ -493,9 +496,23 @@ static int rzv2h_rspi_probe(struct platform_device *pdev)
493496
controller->unprepare_message = rzv2h_rspi_unprepare_message;
494497
controller->num_chipselect = 4;
495498
controller->transfer_one = rzv2h_rspi_transfer_one;
499+
500+
tclk_rate = clk_round_rate(rspi->tclk, 0);
501+
if (tclk_rate < 0) {
502+
ret = tclk_rate;
503+
goto quit_resets;
504+
}
505+
496506
controller->min_speed_hz = rzv2h_rspi_calc_bitrate(tclk_rate,
497507
RSPI_SPBR_SPR_MAX,
498508
RSPI_SPCMD_BRDV_MAX);
509+
510+
tclk_rate = clk_round_rate(rspi->tclk, ULONG_MAX);
511+
if (tclk_rate < 0) {
512+
ret = tclk_rate;
513+
goto quit_resets;
514+
}
515+
499516
controller->max_speed_hz = rzv2h_rspi_calc_bitrate(tclk_rate,
500517
RSPI_SPBR_SPR_MIN,
501518
RSPI_SPCMD_BRDV_MIN);

0 commit comments

Comments
 (0)