From nobody Fri Dec 19 14:38:29 2025 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5BA062FD684; Wed, 5 Nov 2025 09:15:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762334141; cv=none; b=JpMiLFtiajpyHCD+8VEVz2IkfDzfD4/F/3TGxxT6QguZAJj1k+Mlg8swsukGHLF2Pd29q5etVlNuw7Mkx3oFYUK01aEj00MjHNSkBPruXXxpTuy6rEPANfUE8dy63Ok1yS+7Aqqi1We4J5xiiQudiDTGtIHHnBspAY4JOJ5uOKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762334141; c=relaxed/simple; bh=ugy++yZKwUeSdQAW+Rk8cLfei+lO6wAKkDC35SHcARw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kY13/ZSaAF39GDLeQaC3YUzNTUW6SqHezDjFmH7adwCmYLX0TmXEYldriGjpHAbDZhOtBgf1Yh5Ue0dClK4gbhFB5VNHZVoYXL5u6DzuptlToR8PfLB10+S5LeDJd0wkUBLMb884YhNY/wxPUESMYao218MtV1ewO0qB0v36efw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; arc=none smtp.client-ip=210.160.252.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com X-CSE-ConnectionGUID: iAS1hmNURhypBFyKRU9Xtg== X-CSE-MsgGUID: zr6l7uXZRkiqLvELPR1tUg== Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 05 Nov 2025 18:15:38 +0900 Received: from demon-pc.localdomain (unknown [10.226.92.38]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 8D60941763FB; Wed, 5 Nov 2025 18:15:33 +0900 (JST) From: Cosmin Tanislav To: Cc: Fabrizio Castro , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm , Michael Turquette , Stephen Boyd , Philipp Zabel , linux-spi@vger.kernel.org, linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Cosmin Tanislav Subject: [PATCH 09/14] spi: rzv2h-rspi: add support for variable transfer clock Date: Wed, 5 Nov 2025 11:13:53 +0200 Message-ID: <20251105091401.1462985-10-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251105091401.1462985-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20251105091401.1462985-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- drivers/spi/spi-rzv2h-rspi.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-rzv2h-rspi.c b/drivers/spi/spi-rzv2h-rspi.c index e9d8ee919261..be45269e8853 100644 --- a/drivers/spi/spi-rzv2h-rspi.c +++ b/drivers/spi/spi-rzv2h-rspi.c @@ -308,6 +308,7 @@ static u32 rzv2h_rspi_setup_clock(struct rzv2h_rspi_pri= v *rspi, u32 hz) struct rzv2h_rspi_best_clock best_clock =3D { .error =3D ULONG_MAX, }; + int ret; =20 rspi->info->find_tclk_rate(rspi->tclk, hz, RSPI_SPBR_SPR_MIN, RSPI_SPBR_SPR_MAX, &best_clock); @@ -323,6 +324,10 @@ static u32 rzv2h_rspi_setup_clock(struct rzv2h_rspi_pr= iv *rspi, u32 hz) if (!best_clock.clk_rate) return -EINVAL; =20 + ret =3D clk_set_rate(best_clock.clk, best_clock.clk_rate); + if (ret) + return 0; + rspi->use_pclk =3D best_clock.clk =3D=3D rspi->pclk; rspi->spr =3D best_clock.spr; rspi->brdv =3D best_clock.brdv; @@ -426,8 +431,8 @@ static int rzv2h_rspi_probe(struct platform_device *pde= v) struct device *dev =3D &pdev->dev; struct rzv2h_rspi_priv *rspi; struct clk_bulk_data *clks; - unsigned long tclk_rate; int irq_rx, ret, i; + long tclk_rate; =20 controller =3D devm_spi_alloc_host(dev, sizeof(*rspi)); if (!controller) @@ -460,8 +465,6 @@ static int rzv2h_rspi_probe(struct platform_device *pde= v) if (!rspi->tclk) return dev_err_probe(dev, -EINVAL, "Failed to get tclk\n"); =20 - tclk_rate =3D clk_get_rate(rspi->tclk); - rspi->resets[0].id =3D "presetn"; rspi->resets[1].id =3D "tresetn"; ret =3D devm_reset_control_bulk_get_optional_exclusive(dev, RSPI_RESET_NU= M, @@ -493,9 +496,23 @@ static int rzv2h_rspi_probe(struct platform_device *pd= ev) controller->unprepare_message =3D rzv2h_rspi_unprepare_message; controller->num_chipselect =3D 4; controller->transfer_one =3D rzv2h_rspi_transfer_one; + + tclk_rate =3D clk_round_rate(rspi->tclk, 0); + if (tclk_rate < 0) { + ret =3D tclk_rate; + goto quit_resets; + } + controller->min_speed_hz =3D rzv2h_rspi_calc_bitrate(tclk_rate, RSPI_SPBR_SPR_MAX, RSPI_SPCMD_BRDV_MAX); + + tclk_rate =3D clk_round_rate(rspi->tclk, ULONG_MAX); + if (tclk_rate < 0) { + ret =3D tclk_rate; + goto quit_resets; + } + controller->max_speed_hz =3D rzv2h_rspi_calc_bitrate(tclk_rate, RSPI_SPBR_SPR_MIN, RSPI_SPCMD_BRDV_MIN); --=20 2.51.2