Skip to content

Commit 3f9c5d9

Browse files
ambarusduraikvddp
authored andcommitted
spi: spi-mem: Allow specifying the byte order in DTR mode
There are NOR flashes (Macronix) that swap the bytes on a 16-bit boundary when configured in DTR mode. The byte order of 16-bit words is swapped when read or written in Double Transfer Rate (DTR) mode compared to Single Transfer Rate (STR) mode. If one writes D0 D1 D2 D3 bytes using 1-1-1 mode, and uses 8D-8D-8D SPI mode for reading, it will read back D1 D0 D3 D2. Swapping the bytes is a bad design decision because this may introduce some endianness problems. It can affect the boot sequence if the entire boot sequence is not handled in either 8D-8D-8D mode or 1-1-1 mode. Fortunately there are controllers that can swap back the bytes at runtime, fixing the endiannesses. Provide a way for the upper layers to specify the byte order in DTR mode. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> [durai.manickamkr@microchip.com: fixed conflicts while porting from 5.15 to 6.1.4] Signed-off-by: Durai Manickam KR <durai.manickamkr@microchip.com> [durai.manickamkr@microchip.com: fixed conflicts and ported to 6.6.9] Signed-off-by: Durai Manickam KR <durai.manickamkr@microchip.com>
1 parent e3c0f88 commit 3f9c5d9

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

include/linux/spi/spi-mem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ enum spi_mem_data_dir {
9090
* @data.buswidth: number of IO lanes used to send/receive the data
9191
* @data.dtr: whether the data should be sent in DTR mode or not
9292
* @data.ecc: whether error correction is required or not
93+
* @data.dtr_bswap16: whether the byte order of 16-bit words is swapped when
94+
* read or written in DTR mode compared to STR mode.
9395
* @data.dir: direction of the transfer
9496
* @data.nbytes: number of data bytes to send/receive. Can be zero if the
9597
* operation does not involve transferring data
@@ -125,6 +127,7 @@ struct spi_mem_op {
125127
u8 dtr : 1;
126128
u8 ecc : 1;
127129
u8 __pad : 6;
130+
u8 dtr_bswap16 : 1;
128131
enum spi_mem_data_dir dir;
129132
unsigned int nbytes;
130133
union {

0 commit comments

Comments
 (0)