Skip to content

Commit 6bae252

Browse files
geertubroonie
authored andcommitted
spi: sh-msiof: SITMDR1/SIRMDR1 bitfield conversion
Convert MSIOF Transmit and Receive Mode Register 1 field accesses to use the FIELD_PREP() bitfield access macro. This gets rid of explicit shifts. Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://patch.msgid.link/9685c54e752b8ef4256c9b281e9d8292e71d222e.1747401908.git.geert+renesas@glider.be Signed-off-by: Mark Brown <[email protected]>
1 parent 74cb19c commit 6bae252

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

drivers/spi/spi-sh-msiof.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Copyright (C) 2014-2017 Glider bvba
88
*/
99

10+
#include <linux/bitfield.h>
1011
#include <linux/bitmap.h>
1112
#include <linux/clk.h>
1213
#include <linux/completion.h>
@@ -84,20 +85,19 @@ struct sh_msiof_spi_priv {
8485

8586
/* SITMDR1 and SIRMDR1 */
8687
#define SIMDR1_TRMD BIT(31) /* Transfer Mode (1 = Master mode) */
87-
#define SIMDR1_SYNCMD_MASK GENMASK(29, 28) /* SYNC Mode */
88-
#define SIMDR1_SYNCMD_SPI (2 << 28) /* Level mode/SPI */
89-
#define SIMDR1_SYNCMD_LR (3 << 28) /* L/R mode */
90-
#define SIMDR1_SYNCAC_SHIFT 25 /* Sync Polarity (1 = Active-low) */
91-
#define SIMDR1_BITLSB_SHIFT 24 /* MSB/LSB First (1 = LSB first) */
92-
#define SIMDR1_DTDL_SHIFT 20 /* Data Pin Bit Delay for MSIOF_SYNC */
93-
#define SIMDR1_SYNCDL_SHIFT 16 /* Frame Sync Signal Timing Delay */
94-
#define SIMDR1_FLD_MASK GENMASK(3, 2) /* Frame Sync Signal Interval (0-3) */
95-
#define SIMDR1_FLD_SHIFT 2
88+
#define SIMDR1_SYNCMD GENMASK(29, 28) /* SYNC Mode */
89+
#define SIMDR1_SYNCMD_SPI 2U /* Level mode/SPI */
90+
#define SIMDR1_SYNCMD_LR 3U /* L/R mode */
91+
#define SIMDR1_SYNCAC BIT(25) /* Sync Polarity (1 = Active-low) */
92+
#define SIMDR1_BITLSB BIT(24) /* MSB/LSB First (1 = LSB first) */
93+
#define SIMDR1_DTDL GENMASK(22, 20) /* Data Pin Bit Delay for MSIOF_SYNC */
94+
#define SIMDR1_SYNCDL GENMASK(18, 16) /* Frame Sync Signal Timing Delay */
95+
#define SIMDR1_FLD GENMASK(3, 2) /* Frame Sync Signal Interval (0-3) */
9696
#define SIMDR1_XXSTP BIT(0) /* Transmission/Reception Stop on FIFO */
9797
/* SITMDR1 */
9898
#define SITMDR1_PCON BIT(30) /* Transfer Signal Connection */
99-
#define SITMDR1_SYNCCH_MASK GENMASK(27, 26) /* Sync Signal Channel Select */
100-
#define SITMDR1_SYNCCH_SHIFT 26 /* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */
99+
#define SITMDR1_SYNCCH GENMASK(27, 26) /* Sync Signal Channel Select */
100+
/* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */
101101

102102
/* SITMDR2 and SIRMDR2 */
103103
#define SIMDR2_BITLEN1(i) (((i) - 1) << 24) /* Data Size (8-32 bits) */
@@ -341,8 +341,9 @@ static u32 sh_msiof_spi_get_dtdl_and_syncdl(struct sh_msiof_spi_priv *p)
341341
return 0;
342342
}
343343

344-
val = sh_msiof_get_delay_bit(p->info->dtdl) << SIMDR1_DTDL_SHIFT;
345-
val |= sh_msiof_get_delay_bit(p->info->syncdl) << SIMDR1_SYNCDL_SHIFT;
344+
val = FIELD_PREP(SIMDR1_DTDL, sh_msiof_get_delay_bit(p->info->dtdl)) |
345+
FIELD_PREP(SIMDR1_SYNCDL,
346+
sh_msiof_get_delay_bit(p->info->syncdl));
346347

347348
return val;
348349
}
@@ -361,16 +362,18 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, u32 ss,
361362
* 1 0 11 11 0 0
362363
* 1 1 11 11 1 1
363364
*/
364-
tmp = SIMDR1_SYNCMD_SPI | 1 << SIMDR1_FLD_SHIFT | SIMDR1_XXSTP;
365-
tmp |= !cs_high << SIMDR1_SYNCAC_SHIFT;
366-
tmp |= lsb_first << SIMDR1_BITLSB_SHIFT;
365+
tmp = FIELD_PREP(SIMDR1_SYNCMD, SIMDR1_SYNCMD_SPI) |
366+
FIELD_PREP(SIMDR1_FLD, 1) | SIMDR1_XXSTP |
367+
FIELD_PREP(SIMDR1_SYNCAC, !cs_high) |
368+
FIELD_PREP(SIMDR1_BITLSB, lsb_first);
367369
tmp |= sh_msiof_spi_get_dtdl_and_syncdl(p);
368370
if (spi_controller_is_target(p->ctlr)) {
369371
sh_msiof_write(p, SITMDR1, tmp | SITMDR1_PCON);
370372
} else {
371373
sh_msiof_write(p, SITMDR1,
372374
tmp | SIMDR1_TRMD | SITMDR1_PCON |
373-
(ss < MAX_SS ? ss : 0) << SITMDR1_SYNCCH_SHIFT);
375+
FIELD_PREP(SITMDR1_SYNCCH,
376+
ss < MAX_SS ? ss : 0));
374377
}
375378
if (p->ctlr->flags & SPI_CONTROLLER_MUST_TX) {
376379
/* These bits are reserved if RX needs TX */
@@ -579,12 +582,12 @@ static int sh_msiof_spi_setup(struct spi_device *spi)
579582
return 0;
580583

581584
/* Configure native chip select mode/polarity early */
582-
clr = SIMDR1_SYNCMD_MASK;
583-
set = SIMDR1_SYNCMD_SPI;
585+
clr = SIMDR1_SYNCMD;
586+
set = FIELD_PREP(SIMDR1_SYNCMD, SIMDR1_SYNCMD_SPI);
584587
if (spi->mode & SPI_CS_HIGH)
585-
clr |= BIT(SIMDR1_SYNCAC_SHIFT);
588+
clr |= SIMDR1_SYNCAC;
586589
else
587-
set |= BIT(SIMDR1_SYNCAC_SHIFT);
590+
set |= SIMDR1_SYNCAC;
588591
pm_runtime_get_sync(&p->pdev->dev);
589592
tmp = sh_msiof_read(p, SITMDR1) & ~clr;
590593
sh_msiof_write(p, SITMDR1, tmp | set | SIMDR1_TRMD | SITMDR1_PCON);

0 commit comments

Comments
 (0)