Skip to content

Commit 1b7ce96

Browse files
Demon000broonie
authored andcommitted
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>
1 parent ebd7d6a commit 1b7ce96

1 file changed

Lines changed: 25 additions & 20 deletions

File tree

drivers/spi/spi-rzv2h-rspi.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ struct rzv2h_rspi_priv {
8383
unsigned int bytes_per_word;
8484
u32 freq;
8585
u16 status;
86+
u8 spr;
87+
u8 brdv;
8688
};
8789

8890
#define RZV2H_RSPI_TX(func, type) \
@@ -263,8 +265,8 @@ static u32 rzv2h_rspi_setup_clock(struct rzv2h_rspi_priv *rspi, u32 hz)
263265
return 0;
264266

265267
clock_found:
266-
rzv2h_rspi_reg_rmw(rspi, RSPI_SPCMD, RSPI_SPCMD_BRDV, brdv);
267-
writeb(spr, rspi->base + RSPI_SPBR);
268+
rspi->spr = spr;
269+
rspi->brdv = brdv;
268270

269271
return rzv2h_rspi_calc_bitrate(tclk_rate, spr, brdv);
270272
}
@@ -283,6 +285,25 @@ static int rzv2h_rspi_prepare_message(struct spi_controller *ctlr,
283285
/* Make sure SPCR.SPE is 0 before amending the configuration */
284286
rzv2h_rspi_spe_disable(rspi);
285287

288+
list_for_each_entry(xfer, &message->transfers, transfer_list) {
289+
if (!xfer->speed_hz)
290+
continue;
291+
292+
speed_hz = min(xfer->speed_hz, speed_hz);
293+
bits_per_word = xfer->bits_per_word;
294+
}
295+
296+
if (speed_hz == U32_MAX)
297+
return -EINVAL;
298+
299+
rspi->bytes_per_word = roundup_pow_of_two(BITS_TO_BYTES(bits_per_word));
300+
301+
rspi->freq = rzv2h_rspi_setup_clock(rspi, speed_hz);
302+
if (!rspi->freq)
303+
return -EINVAL;
304+
305+
writeb(rspi->spr, rspi->base + RSPI_SPBR);
306+
286307
/* Configure the device to work in "host" mode */
287308
conf32 = RSPI_SPCR_MSTR;
288309

@@ -301,6 +322,8 @@ static int rzv2h_rspi_prepare_message(struct spi_controller *ctlr,
301322
conf32 = FIELD_PREP(RSPI_SPCMD_CPOL, !!(spi->mode & SPI_CPOL));
302323
conf32 |= FIELD_PREP(RSPI_SPCMD_CPHA, !!(spi->mode & SPI_CPHA));
303324
conf32 |= FIELD_PREP(RSPI_SPCMD_LSBF, !!(spi->mode & SPI_LSB_FIRST));
325+
conf32 |= FIELD_PREP(RSPI_SPCMD_SPB, bits_per_word - 1);
326+
conf32 |= FIELD_PREP(RSPI_SPCMD_BRDV, rspi->brdv);
304327
conf32 |= FIELD_PREP(RSPI_SPCMD_SSLKP, 1);
305328
conf32 |= FIELD_PREP(RSPI_SPCMD_SSLA, spi_get_chipselect(spi, 0));
306329
writel(conf32, rspi->base + RSPI_SPCMD);
@@ -316,24 +339,6 @@ static int rzv2h_rspi_prepare_message(struct spi_controller *ctlr,
316339

317340
rzv2h_rspi_clear_fifos(rspi);
318341

319-
list_for_each_entry(xfer, &message->transfers, transfer_list) {
320-
if (!xfer->speed_hz)
321-
continue;
322-
323-
speed_hz = min(xfer->speed_hz, speed_hz);
324-
bits_per_word = xfer->bits_per_word;
325-
}
326-
327-
if (speed_hz == U32_MAX)
328-
return -EINVAL;
329-
330-
rspi->bytes_per_word = roundup_pow_of_two(BITS_TO_BYTES(bits_per_word));
331-
rzv2h_rspi_reg_rmw(rspi, RSPI_SPCMD, RSPI_SPCMD_SPB, bits_per_word - 1);
332-
333-
rspi->freq = rzv2h_rspi_setup_clock(rspi, speed_hz);
334-
if (!rspi->freq)
335-
return -EINVAL;
336-
337342
rzv2h_rspi_spe_enable(rspi);
338343

339344
return 0;

0 commit comments

Comments
 (0)