7
7
* Copyright (C) 2014-2017 Glider bvba
8
8
*/
9
9
10
+ #include <linux/bitfield.h>
10
11
#include <linux/bitmap.h>
11
12
#include <linux/clk.h>
12
13
#include <linux/completion.h>
@@ -84,20 +85,19 @@ struct sh_msiof_spi_priv {
84
85
85
86
/* SITMDR1 and SIRMDR1 */
86
87
#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) */
96
96
#define SIMDR1_XXSTP BIT(0) /* Transmission/Reception Stop on FIFO */
97
97
/* SITMDR1 */
98
98
#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 */
101
101
102
102
/* SITMDR2 and SIRMDR2 */
103
103
#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)
341
341
return 0 ;
342
342
}
343
343
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 ));
346
347
347
348
return val ;
348
349
}
@@ -361,16 +362,18 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, u32 ss,
361
362
* 1 0 11 11 0 0
362
363
* 1 1 11 11 1 1
363
364
*/
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 );
367
369
tmp |= sh_msiof_spi_get_dtdl_and_syncdl (p );
368
370
if (spi_controller_is_target (p -> ctlr )) {
369
371
sh_msiof_write (p , SITMDR1 , tmp | SITMDR1_PCON );
370
372
} else {
371
373
sh_msiof_write (p , SITMDR1 ,
372
374
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 ));
374
377
}
375
378
if (p -> ctlr -> flags & SPI_CONTROLLER_MUST_TX ) {
376
379
/* These bits are reserved if RX needs TX */
@@ -579,12 +582,12 @@ static int sh_msiof_spi_setup(struct spi_device *spi)
579
582
return 0 ;
580
583
581
584
/* 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 ) ;
584
587
if (spi -> mode & SPI_CS_HIGH )
585
- clr |= BIT ( SIMDR1_SYNCAC_SHIFT ) ;
588
+ clr |= SIMDR1_SYNCAC ;
586
589
else
587
- set |= BIT ( SIMDR1_SYNCAC_SHIFT ) ;
590
+ set |= SIMDR1_SYNCAC ;
588
591
pm_runtime_get_sync (& p -> pdev -> dev );
589
592
tmp = sh_msiof_read (p , SITMDR1 ) & ~clr ;
590
593
sh_msiof_write (p , SITMDR1 , tmp | set | SIMDR1_TRMD | SITMDR1_PCON );
0 commit comments