From nobody Tue Feb 10 22:18:17 2026 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 808E535BDCE; Wed, 19 Nov 2025 16:15:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763568943; cv=none; b=i3+hxiMgC6HKpDZwlEbAhytIJ1wZVWtUAlQ0NF2SiRT8zCbaJHQcQy1xo0iW3s6xuGbjNpEEE256XCDwjlTHl5RY2ZX7c6bnEEMIz2yvwzX05Z8vTSvOsIsH2u49yQAhez5uNFtQ8Jao6TOeLesKKlJnnsbDfE7qmiKlnWnBfYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763568943; c=relaxed/simple; bh=zqS7KC0O37iXU6ZkafAIXrDH+QRO56J5SOLz38B1YkE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A0E9bhrBLcZ+LfSUj390b0fjPM1kr7xiE6LQQ3AEElg1gR4CsvMvWOfclrO/gT07MCH1bb90ZlVCD/L9B7Nq5NtTc4p74399fODeSmqJI66PhjJX5Q3/F8OwOmtTVw/SnFXpNR2mP8TYxWGjDoSDkI8Q/6pr9D7yPo6B9KfDWN4= 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.172 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: vsy0+T6rR2e/jtvlNgZw4g== X-CSE-MsgGUID: XCik1o4+QQ+TY6d6r2YQhg== Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 20 Nov 2025 01:15:41 +0900 Received: from demon-pc.localdomain (unknown [10.226.92.87]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 3122A406C471; Thu, 20 Nov 2025 01:15:36 +0900 (JST) From: Cosmin Tanislav To: Fabrizio Castro , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm , Philipp Zabel Cc: linux-spi@vger.kernel.org, linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v4 04/13] spi: rzv2h-rspi: move register writes out of rzv2h_rspi_setup_clock() Date: Wed, 19 Nov 2025 18:14:25 +0200 Message-ID: <20251119161434.595677-5-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251119161434.595677-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20251119161434.595677-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" In preparation for caching the last requested transfer frequency, move register writes outside of rzv2h_rspi_setup_clock(). The transfer list is iterated to determine the speed of the transfer and the bits per word. The speed of the transfer is used to compute SPR and BRDV inside rzv2h_rspi_setup_clock(). BRDV and SPB are stored in the SPCMD register. Move the transfer iteration earlier, move the SPR and BRDV writing out of rzv2h_rspi_setup_clock(), consolidate writing BRDV and SPB into the initial write to the SPCMD register. Signed-off-by: Cosmin Tanislav --- V4: * no changes V3: * no changes V2: * no changes drivers/spi/spi-rzv2h-rspi.c | 45 ++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/spi/spi-rzv2h-rspi.c b/drivers/spi/spi-rzv2h-rspi.c index a1f17ec8727b..f02f25b98ec6 100644 --- a/drivers/spi/spi-rzv2h-rspi.c +++ b/drivers/spi/spi-rzv2h-rspi.c @@ -83,6 +83,8 @@ struct rzv2h_rspi_priv { unsigned int bytes_per_word; u32 freq; u16 status; + u8 spr; + u8 brdv; }; =20 #define RZV2H_RSPI_TX(func, type) \ @@ -263,8 +265,8 @@ static u32 rzv2h_rspi_setup_clock(struct rzv2h_rspi_pri= v *rspi, u32 hz) return 0; =20 clock_found: - rzv2h_rspi_reg_rmw(rspi, RSPI_SPCMD, RSPI_SPCMD_BRDV, brdv); - writeb(spr, rspi->base + RSPI_SPBR); + rspi->spr =3D spr; + rspi->brdv =3D brdv; =20 return rzv2h_rspi_calc_bitrate(tclk_rate, spr, brdv); } @@ -283,6 +285,25 @@ static int rzv2h_rspi_prepare_message(struct spi_contr= oller *ctlr, /* Make sure SPCR.SPE is 0 before amending the configuration */ rzv2h_rspi_spe_disable(rspi); =20 + list_for_each_entry(xfer, &message->transfers, transfer_list) { + if (!xfer->speed_hz) + continue; + + speed_hz =3D min(xfer->speed_hz, speed_hz); + bits_per_word =3D xfer->bits_per_word; + } + + if (speed_hz =3D=3D U32_MAX) + return -EINVAL; + + rspi->bytes_per_word =3D roundup_pow_of_two(BITS_TO_BYTES(bits_per_word)); + + rspi->freq =3D rzv2h_rspi_setup_clock(rspi, speed_hz); + if (!rspi->freq) + return -EINVAL; + + writeb(rspi->spr, rspi->base + RSPI_SPBR); + /* Configure the device to work in "host" mode */ conf32 =3D RSPI_SPCR_MSTR; =20 @@ -301,6 +322,8 @@ static int rzv2h_rspi_prepare_message(struct spi_contro= ller *ctlr, conf32 =3D FIELD_PREP(RSPI_SPCMD_CPOL, !!(spi->mode & SPI_CPOL)); conf32 |=3D FIELD_PREP(RSPI_SPCMD_CPHA, !!(spi->mode & SPI_CPHA)); conf32 |=3D FIELD_PREP(RSPI_SPCMD_LSBF, !!(spi->mode & SPI_LSB_FIRST)); + conf32 |=3D FIELD_PREP(RSPI_SPCMD_SPB, bits_per_word - 1); + conf32 |=3D FIELD_PREP(RSPI_SPCMD_BRDV, rspi->brdv); conf32 |=3D FIELD_PREP(RSPI_SPCMD_SSLKP, 1); conf32 |=3D FIELD_PREP(RSPI_SPCMD_SSLA, spi_get_chipselect(spi, 0)); writel(conf32, rspi->base + RSPI_SPCMD); @@ -316,24 +339,6 @@ static int rzv2h_rspi_prepare_message(struct spi_contr= oller *ctlr, =20 rzv2h_rspi_clear_fifos(rspi); =20 - list_for_each_entry(xfer, &message->transfers, transfer_list) { - if (!xfer->speed_hz) - continue; - - speed_hz =3D min(xfer->speed_hz, speed_hz); - bits_per_word =3D xfer->bits_per_word; - } - - if (speed_hz =3D=3D U32_MAX) - return -EINVAL; - - rspi->bytes_per_word =3D roundup_pow_of_two(BITS_TO_BYTES(bits_per_word)); - rzv2h_rspi_reg_rmw(rspi, RSPI_SPCMD, RSPI_SPCMD_SPB, bits_per_word - 1); - - rspi->freq =3D rzv2h_rspi_setup_clock(rspi, speed_hz); - if (!rspi->freq) - return -EINVAL; - rzv2h_rspi_spe_enable(rspi); =20 return 0; --=20 2.52.0