mtd: spi-nor: sfdp: Get the 8D-8D-8D byte order from BFPT
authorTudor Ambarus <tudor.ambarus@linaro.org>
Thu, 26 Sep 2024 14:19:54 +0000 (22:19 +0800)
committerTudor Ambarus <tudor.ambarus@linaro.org>
Wed, 2 Oct 2024 07:28:40 +0000 (10:28 +0300)
Parse BFPT in order to retrieve the byte order in 8D-8D-8D mode.

This info flag will be used as a basis to determine whether
there is byte swapping of data for SPI NOR flash in octal
DTR mode.

The controller driver will check whether byte swapping is supported
to determine whether the corresponding operation are supported,
thus avoiding the generation of unexpected data order.

Merge Tudor's patch and add modifications for suiting newer version
of Linux kernel.

Reviewed-by: Michael Walle <mwalle@kernel.org>
Signed-off-by: JaimeLiao <jaimeliao@mxic.com.tw>
Signed-off-by: AlvinZhou <alvinzhou@mxic.com.tw>
Link: https://lore.kernel.org/r/20240926141956.2386374-5-alvinzhou.tw@gmail.com
Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
drivers/mtd/spi-nor/sfdp.c
drivers/mtd/spi-nor/sfdp.h

index 5b1117265bd289702a283e8440ac956912478add..21727f9a4ac6926080a116e30830c9533122fdad 100644 (file)
@@ -671,6 +671,10 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
                return -EOPNOTSUPP;
        }
 
+       /* Byte order in 8D-8D-8D mode */
+       if (bfpt.dwords[SFDP_DWORD(18)] & BFPT_DWORD18_BYTE_ORDER_SWAPPED)
+               nor->flags |= SNOR_F_SWAP16;
+
        return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt);
 }
 
index da0fe5aa9bb0a13b46a69c95cbd3ba960332bbb5..f74a0eb339ea79b69932d5d396e6ec8b9ae00380 100644 (file)
@@ -130,6 +130,7 @@ struct sfdp_bfpt {
 #define BFPT_DWORD18_CMD_EXT_INV               (0x1UL << 29) /* Invert */
 #define BFPT_DWORD18_CMD_EXT_RES               (0x2UL << 29) /* Reserved */
 #define BFPT_DWORD18_CMD_EXT_16B               (0x3UL << 29) /* 16-bit opcode */
+#define BFPT_DWORD18_BYTE_ORDER_SWAPPED                BIT(31) /* Byte order swapped in 8D-8D-8D mode */
 
 struct sfdp_parameter_header {
        u8              id_lsb;