summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>2025-11-19 18:14:25 +0200
committerMark Brown <broonie@kernel.org>2025-11-24 14:10:42 +0000
commit1b7ce968ab2579702ea9dbc2fb599e540bbd8c88 (patch)
treeb189d160111a7bc01649d6857f0ad9558d47bfee
parentebd7d6ae0dc7d65e21460c928519f40ccf95f3b9 (diff)
spi: rzv2h-rspi: move register writes out of rzv2h_rspi_setup_clock()
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 <cosmin-gabriel.tanislav.xa@renesas.com> Link: https://patch.msgid.link/20251119161434.595677-5-cosmin-gabriel.tanislav.xa@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/spi/spi-rzv2h-rspi.c45
1 files 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;
};
#define RZV2H_RSPI_TX(func, type) \
@@ -263,8 +265,8 @@ static u32 rzv2h_rspi_setup_clock(struct rzv2h_rspi_priv *rspi, u32 hz)
return 0;
clock_found:
- rzv2h_rspi_reg_rmw(rspi, RSPI_SPCMD, RSPI_SPCMD_BRDV, brdv);
- writeb(spr, rspi->base + RSPI_SPBR);
+ rspi->spr = spr;
+ rspi->brdv = brdv;
return rzv2h_rspi_calc_bitrate(tclk_rate, spr, brdv);
}
@@ -283,6 +285,25 @@ static int rzv2h_rspi_prepare_message(struct spi_controller *ctlr,
/* Make sure SPCR.SPE is 0 before amending the configuration */
rzv2h_rspi_spe_disable(rspi);
+ list_for_each_entry(xfer, &message->transfers, transfer_list) {
+ if (!xfer->speed_hz)
+ continue;
+
+ speed_hz = min(xfer->speed_hz, speed_hz);
+ bits_per_word = xfer->bits_per_word;
+ }
+
+ if (speed_hz == U32_MAX)
+ return -EINVAL;
+
+ rspi->bytes_per_word = roundup_pow_of_two(BITS_TO_BYTES(bits_per_word));
+
+ rspi->freq = 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 = RSPI_SPCR_MSTR;
@@ -301,6 +322,8 @@ static int rzv2h_rspi_prepare_message(struct spi_controller *ctlr,
conf32 = FIELD_PREP(RSPI_SPCMD_CPOL, !!(spi->mode & SPI_CPOL));
conf32 |= FIELD_PREP(RSPI_SPCMD_CPHA, !!(spi->mode & SPI_CPHA));
conf32 |= FIELD_PREP(RSPI_SPCMD_LSBF, !!(spi->mode & SPI_LSB_FIRST));
+ conf32 |= FIELD_PREP(RSPI_SPCMD_SPB, bits_per_word - 1);
+ conf32 |= FIELD_PREP(RSPI_SPCMD_BRDV, rspi->brdv);
conf32 |= FIELD_PREP(RSPI_SPCMD_SSLKP, 1);
conf32 |= 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_controller *ctlr,
rzv2h_rspi_clear_fifos(rspi);
- list_for_each_entry(xfer, &message->transfers, transfer_list) {
- if (!xfer->speed_hz)
- continue;
-
- speed_hz = min(xfer->speed_hz, speed_hz);
- bits_per_word = xfer->bits_per_word;
- }
-
- if (speed_hz == U32_MAX)
- return -EINVAL;
-
- rspi->bytes_per_word = 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 = rzv2h_rspi_setup_clock(rspi, speed_hz);
- if (!rspi->freq)
- return -EINVAL;
-
rzv2h_rspi_spe_enable(rspi);
return 0;