Skip to content

Commit 030ace4

Browse files
committed
spi: spi-mem: Allow specifying the byte order in Octal DTR mode
There are NOR flashes (Macronix) that swap the bytes on a 16-bit boundary when configured in Octal DTR mode. The byte order of 16-bit words is swapped when read or written in Octal Double Transfer Rate (DTR) mode compared to Single Transfer Rate (STR) modes. 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 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. Therefore, it is necessary to swap the bytes back to ensure the same byte order as in STR modes. Fortunately there are controllers that could swap the bytes back at runtime, addressing the flash's endianness requirements. Provide a way for the upper layers to specify the byte order in Octal DTR mode. Merge Tudor's patch and add modifications for suiting newer version of Linux kernel. Suggested-by: Michael Walle <mwalle@kernel.org> Signed-off-by: JaimeLiao <jaimeliao@mxic.com.tw> Signed-off-by: AlvinZhou <alvinzhou@mxic.com.tw> Acked-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20240926141956.2386374-3-alvinzhou.tw@gmail.com Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
1 parent 9852d85 commit 030ace4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

drivers/spi/spi-mem.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,
172172
if (!spi_mem_controller_is_capable(ctlr, dtr))
173173
return false;
174174

175+
if (op->data.swap16 && !spi_mem_controller_is_capable(ctlr, swap16))
176+
return false;
177+
175178
if (op->cmd.nbytes != 2)
176179
return false;
177180
} else {

include/linux/spi/spi-mem.h

Lines changed: 7 additions & 1 deletion
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.swap16: whether the byte order of 16-bit words is swapped when read
94+
* or written in Octal 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
@@ -124,7 +126,8 @@ struct spi_mem_op {
124126
u8 buswidth;
125127
u8 dtr : 1;
126128
u8 ecc : 1;
127-
u8 __pad : 6;
129+
u8 swap16 : 1;
130+
u8 __pad : 5;
128131
enum spi_mem_data_dir dir;
129132
unsigned int nbytes;
130133
union {
@@ -297,10 +300,13 @@ struct spi_controller_mem_ops {
297300
* struct spi_controller_mem_caps - SPI memory controller capabilities
298301
* @dtr: Supports DTR operations
299302
* @ecc: Supports operations with error correction
303+
* @swap16: Supports swapping bytes on a 16 bit boundary when configured in
304+
* Octal DTR
300305
*/
301306
struct spi_controller_mem_caps {
302307
bool dtr;
303308
bool ecc;
309+
bool swap16;
304310
};
305311

306312
#define spi_mem_controller_is_capable(ctlr, cap) \

0 commit comments

Comments
 (0)