Skip to content

Commit 39d0856

Browse files
geertubroonie
authored andcommitted
spi: sh-msiof: Simplify BRG's Division Ratio
As FIELD_PREP() masks the value to be stored in the field, the Baud Rate Generator's Division Ratio handling can be simplified from a look-up table to a single subtraction. Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://patch.msgid.link/e736221942b0381fb53dc64109a1389f7ec5f44a.1747401908.git.geert+renesas@glider.be Signed-off-by: Mark Brown <[email protected]>
1 parent 5b91dc7 commit 39d0856

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

drivers/spi/spi-sh-msiof.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ struct sh_msiof_spi_priv {
112112
/* SITSCR and SIRSCR */
113113
#define SISCR_BRPS GENMASK(12, 8) /* Prescaler Setting (1-32) */
114114
#define SISCR_BRDV GENMASK(2, 0) /* Baud Rate Generator's Division Ratio */
115-
#define SISCR_BRDV_DIV_2 0U
116-
#define SISCR_BRDV_DIV_4 1U
117-
#define SISCR_BRDV_DIV_8 2U
118-
#define SISCR_BRDV_DIV_16 3U
119-
#define SISCR_BRDV_DIV_32 4U
120-
#define SISCR_BRDV_DIV_1 7U
121115

122116
/* SICTR */
123117
#define SICTR_TSCKIZ GENMASK(31, 30) /* Transmit Clock I/O Polarity Select */
@@ -256,11 +250,6 @@ static void sh_msiof_spi_reset_regs(struct sh_msiof_spi_priv *p)
256250
100);
257251
}
258252

259-
static const u32 sh_msiof_spi_div_array[] = {
260-
SISCR_BRDV_DIV_1, SISCR_BRDV_DIV_2, SISCR_BRDV_DIV_4,
261-
SISCR_BRDV_DIV_8, SISCR_BRDV_DIV_16, SISCR_BRDV_DIV_32,
262-
};
263-
264253
static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p,
265254
struct spi_transfer *t)
266255
{
@@ -299,7 +288,8 @@ static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p,
299288

300289
t->effective_speed_hz = parent_rate / (brps << div_pow);
301290

302-
scr = FIELD_PREP(SISCR_BRDV, sh_msiof_spi_div_array[div_pow]) |
291+
/* div_pow == 0 maps to SISCR_BRDV_DIV_1 == all ones */
292+
scr = FIELD_PREP(SISCR_BRDV, div_pow - 1) |
303293
FIELD_PREP(SISCR_BRPS, brps - 1);
304294
sh_msiof_write(p, SITSCR, scr);
305295
if (!(p->ctlr->flags & SPI_CONTROLLER_MUST_TX))

0 commit comments

Comments
 (0)