[U-Boot] [PATCH] spi-nor: Correct the logic to detect flash rw mode

Bin Meng bmeng.cn at gmail.com
Thu Feb 18 06:12:27 CET 2016


spi->mode includes all available modes for operating on SPI flashes,
and we should test each bit instead of a switch..case statement to
make the detection logic correct.

Signed-off-by: Bin Meng <bmeng.cn at gmail.com>
---

 drivers/mtd/spi-nor/m25p80.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/mtd/spi-nor/m25p80.c b/drivers/mtd/spi-nor/m25p80.c
index 4e0a53c..9d17449 100644
--- a/drivers/mtd/spi-nor/m25p80.c
+++ b/drivers/mtd/spi-nor/m25p80.c
@@ -178,26 +178,16 @@ static int m25p80_spi_nor(struct spi_nor *nor)
 		return ret;
 	}
 
-	switch (spi->mode) {
-	case SPI_RX_SLOW:
+	if (spi->mode & SPI_RX_SLOW)
 		nor->read_mode = SNOR_READ;
-		break;
-	case SPI_RX_DUAL:
+	else if (spi->mode & SPI_RX_DUAL)
 		nor->read_mode = SNOR_READ_1_1_2;
-		break;
-	case SPI_RX_QUAD:
+	else if (spi->mode & SPI_RX_QUAD)
 		nor->read_mode = SNOR_READ_1_1_4;
-		break;
-	}
-
-	switch (spi->mode) {
-	case SPI_TX_BYTE:
+	else if (spi->mode & SPI_TX_BYTE)
 		nor->mode = SNOR_WRITE_1_1_BYTE;
-		break;
-	case SPI_TX_QUAD:
+	else if (spi->mode & SPI_TX_QUAD)
 		nor->mode = SNOR_WRITE_1_1_4;
-		break;
-	}
 
 	nor->memory_map = spi->memory_map;
 	nor->max_write_size = spi->max_write_size;
-- 
1.8.2.1



More information about the U-Boot mailing list